102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
loading.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
4#include "pcdogs/game/enums.h"
10#include "pcdogs/actor/types.h"
14#include "pcdogs/audio/types.h"
17#include "pcdogs/camera/types.h"
22#include "pcdogs/entity/types.h"
24#include "pcdogs/game/globals.h"
30#include "pcdogs/level/types.h"
34#include "pcdogs/menu/globals.h"
42#include "pcdogs/scene/types.h"
44#include "pcdogs/types/common.h"
45#include "pcdogs/ui/functions.h"
46#include "pcdogs/ui/globals.h"
47#include <math.h>
48#include <stdarg.h>
49#include <string.h>
50
51// Original pcdogs.exe: 0x409750
52// Initializes entity work buffers, actor lists, and movement, behavior, and collision callbacks for the level. Some overlapping buffer record meanings remain unresolved.
54{
59
61
63
68
69 struct Level_Data *current_level_data = pkg_resource_current_level_data;
70
72
73 if (!current_level_data)
74 return;
75
76 int16_t entity_count = current_level_data->entity_count;
77
78 if (entity_count <= 0)
79 return;
80
81 int32_t entity_index = 0;
82 struct Entity *entity_array = current_level_data->entity_array;
83
84 if (entity_count > 0)
85 {
86 int32_t current_entity_count;
87
88 do
89 {
90 entity_array->runtime_target_pos = NULL;
91 entity_array->position_ptr = &entity_array->bonus_respawn_pos;
92
94 Entity_SpawnActor(entity_array);
95
96 entity_index += 1;
97 entity_array = &entity_array[1];
98 current_entity_count = (uint16_t)pkg_resource_current_level_data->entity_count;
99 } while (entity_index < current_entity_count);
100 }
101
109 g_fadeCounter = 0;
115
116 struct Level_Data *current_level_data_2 = pkg_resource_current_level_data;
117
119 Audio_StartMusicWithFade((struct Audio_MusicStreamRecord *)(current_level_data_2->themes[0]));
120
121 int32_t current_game_mode = g_currentGameMode;
122 float maximum_level_scale;
123
124 __builtin_memcpy(&maximum_level_scale, &g_f_MaxLevelScale, sizeof(maximum_level_scale));
125
126 long double selected_level_scale = (long double)maximum_level_scale;
127
128 if (current_game_mode >= 0 && current_game_mode < (int32_t)GAME_MODE_GAMEPLAY_3D)
129 selected_level_scale = (long double)(int32_t)g_actorSpawnParams[current_game_mode];
130 else if (current_game_mode > (int32_t)GAME_MODE_LOADING_SCREEN)
131 selected_level_scale = (long double)LEVEL_DEFAULT_SCALE;
132
133 int32_t level_scale_q12 = __ftol_msvc(selected_level_scale * (long double)4096.0f);
134 float stored_level_scale = (float)selected_level_scale;
135
136 __builtin_memcpy(&g_levelScaleFactor, &stored_level_scale, sizeof(stored_level_scale));
137 g_dynamic_level_scale = level_scale_q12 >> MATH_Q12_SHIFT;
138
139 if (current_game_mode == (int32_t)GAME_MODE_EXTENDED_RENDER_DISTANCE || (current_game_mode < 0 && current_game_mode != ((int32_t)GAME_MODE_STANDARD_RENDER_DISTANCE_NEGATIVE)))
141 else
143
144 struct Scene_Node *object_node_root = g_objectNodeRoot;
145
146 g_levelRenderDistanceQuarter = (float)((long double)g_levelRenderDistance * (long double)0.25f);
148 (float)((long double)g_levelRenderDistance * (long double)0.333332986f);
149
150 if (!object_node_root)
151 {
154
155 return;
156 }
157
158 int32_t child_rot_x = object_node_root->child_rot_x;
159 int32_t actor_system_middle_byte = (uint8_t)((uint8_t)((uint32_t)child_rot_x >> 8));
160 int32_t actor_system_low_byte = (uint8_t)((uint8_t)((uint32_t)child_rot_x >> 16));
161
162 g_levelActorSystemState = ((((uint32_t)(uint8_t)child_rot_x << 8) + actor_system_middle_byte) << 8) + actor_system_low_byte;
164}
165
166// Original pcdogs.exe: 0x40bda0
167// Stops music and destroys runtime actors for entities marked for level cleanup, then handles a pending level transition.
169{
170 struct Level_Data *current_level = pkg_resource_current_level_data;
171
172 if (!current_level || current_level->entity_count == 0)
173 return;
174
176
177 struct Level_Data *pkg_resource_current_level_data_2 = pkg_resource_current_level_data;
178 int32_t entity_index = 0;
179 struct Entity *entity_array = pkg_resource_current_level_data_2->entity_array;
180
181 if (pkg_resource_current_level_data_2->entity_count != 0)
182 {
183 int32_t current_entity_count;
184
185 do
186 {
188 {
189 struct Actor *runtime_actor = entity_array->runtime_actor;
190
191 if (runtime_actor)
192 {
193 Actor_Destroy((struct Actor_State *)(runtime_actor));
194 entity_array->runtime_actor = NULL;
195 pkg_resource_current_level_data_2 = pkg_resource_current_level_data;
196 }
197 }
198
199 entity_index += 1;
200 current_entity_count = (uint16_t)pkg_resource_current_level_data_2->entity_count;
201 entity_array = &entity_array[1];
202 } while (entity_index < current_entity_count);
203 }
204
206 {
209 }
210}
211
212// Original pcdogs.exe: 0x42d460
213// Advances the title, menu, save-loading, and level-loading state machine and reports whether loading has completed.
215{
216 int32_t level_index;
217 int32_t menu_action;
218
219 switch ((int32_t)Menu_LoadState)
220 {
222 {
224 }
225
226 /* fall through */
228 {
231
233 {
234 }
235
237
239
240 return 0;
241 }
242
243 case LEVEL_LOAD_TITLE:
244 {
246
248 {
250
252 {
254
255 return 0;
256 }
257
260 }
261
262 break;
263 }
264
266 {
268 {
270
271 return 0;
272 }
273
274 menu_action = Level_UpdateInterLevelMenu();
275
276 if (menu_action == LEVEL_MENU_RESULT_START_STORY)
277 {
278 g_levelIndex = (uint8_t)menu_action;
281
282 return 0;
283 }
284
285 if (menu_action == LEVEL_MENU_RESULT_OPEN_WORLD_SELECT)
286 {
288
289 return 0;
290 }
291
292 break;
293 }
294
296 {
297 g_levelIndex = 0;
299
302
303 return 0;
304 }
305
307 {
309
310 return 0;
311 }
312
314 {
315 menu_action = Level_UpdateWorldSelectMenu();
316
317 if (menu_action == LEVEL_MENU_RESULT_START_WORLD_HUB)
318 {
320
321 return 0;
322 }
323
324 if (menu_action == LEVEL_MENU_RESULT_OPEN_WORLD_SELECT)
325 {
327
328 return 0;
329 }
330
331 break;
332 }
333
334 case LEVEL_LOAD_STORY:
335 {
337 {
339 level_index = (int32_t)g_levelIndex;
340
341 if (Game_TransitionToLevel(level_index))
342 {
343 return 1;
344 }
345 }
346
347 break;
348 }
349
351 {
353 {
355 level_index = LEVEL_WORLD_HUB;
356
357 if (Game_TransitionToLevel(level_index))
358 {
359 return 1;
360 }
361 }
362
363 break;
364 }
365
367 {
369 {
370 return 1;
371 }
372
373 break;
374 }
375 }
376
377 return 0;
378}
379
380// Original pcdogs.exe: 0x43ec50
381// Loads three package entries through resumable stages, then relocates their material, scene, and entity data. The underlying loads are synchronous, and a null final blob leaves the loader in state 7.
382struct Level_DataHeader *Level_LoadStateMachine(int32_t level_index)
383{
384 uint8_t *result = NULL;
385 int32_t level_stream_load_state = g_levelStreamLoadState;
386
387 if (level_stream_load_state == LEVEL_STREAM_TEXTURES)
388 {
390
391 PKG_LoadEntry(level_index * 3 + PKG_ENTRY_LEVEL_TEXTURES, (void *)(level_stream_load_state), level_stream_load_state);
392
394
395 return 0;
396 }
397
398 if (level_stream_load_state != LEVEL_STREAM_WAIT_TEXTURES)
399 {
400 if (level_stream_load_state == LEVEL_STREAM_AUDIO)
401 {
402 g_levelTexDataB = PKG_LoadEntry(level_index * 3 + PKG_ENTRY_LEVEL_AUDIO, NULL, 0);
403
405
406 return 0;
407 }
408
409 if (level_stream_load_state != LEVEL_STREAM_WAIT_AUDIO)
410 {
411 if (level_stream_load_state == LEVEL_STREAM_DATA)
412 {
413 g_levelBlobPtr = PKG_LoadEntry(level_index * 3 + PKG_ENTRY_LEVEL_DATA, NULL, 0);
414
416
417 return 0;
418 }
419
420 if (level_stream_load_state == LEVEL_STREAM_FIXUP && Pkg_ReturnResourceAlwaysTrue())
421 {
422 uint8_t *level_blob_ptr = g_levelBlobPtr;
423
424 result = level_blob_ptr;
425
426 if (result)
427 {
428 uint8_t *level_tex_data_a = g_levelTexDataA;
429 struct Material_SectionHeader *material_section_raw =
430 (struct Material_SectionHeader *)(&level_blob_ptr[((struct Level_BlobHeader *)level_blob_ptr)->materialSectionOffset]);
431
432 g_levelMaterialSection = material_section_raw;
433
434 Material_LoadAndFixup((struct Material_SectionHeaderRaw *)(material_section_raw), level_tex_data_a);
435
436 struct Scene_Node *node = (struct Scene_Node *)(((struct Level_BlobHeader *)level_blob_ptr)->sceneGraphOffset + level_blob_ptr);
437
438 g_objectNodeRoot = node;
439
441
442 struct Level_Data *level = (struct Level_Data *)(((struct Level_BlobHeader *)level_blob_ptr)->meshCollisionOffset + level_blob_ptr);
443
445
447
448 struct Level_Data *current_level =
450 int32_t count = (uint16_t)(current_level->sound_def_count);
451
453 count, g_levelTexDataB);
454
456 }
457 }
458 }
460 {
462
463 return 0;
464 }
465 }
467 {
469
470 return 0;
471 }
472
473 return (struct Level_DataHeader *)result;
474}
475
476// Original pcdogs.exe: 0x43eda0
477// Releases the level material textures and resource allocation, then frees and clears the two auxiliary resource buffers.
478void Level_UnloadResources(struct Level_DataHeader *level_resource_data)
479{
481 Pkg_FreeResourceMemory(level_resource_data);
482
483 void *level_tex_data_b = g_levelTexDataB;
484
485 if (level_tex_data_b)
486 {
487 Pkg_FreeResourceMemory(level_tex_data_b);
488 g_levelTexDataB = NULL;
489 }
490
491 void *level_tex_data_a = g_levelTexDataA;
492
493 if (level_tex_data_a)
494 {
495 Pkg_FreeResourceMemory(level_tex_data_a);
496 g_levelTexDataA = NULL;
497 }
498}
void Actor_ProcessPlayerBehavior(struct Actor_State *actor)
void Actor_ProcessSnapAndEntityUpdate(struct Actor_State *actor)
Definition movement.c:349
void Actor_Destroy(struct Actor_State *actor)
Definition lifecycle.c:568
int32_t Actor_ProcessCollisionResponse(struct Actor_State *actor, struct Actor_State *other_actor, struct Collision_Polygon *collision_poly, int32_t collision_depth)
Definition collision.c:56
#define g_actorSpawnParams
Definition globals.h:27
#define g_behaviorProcessActorFunc
Definition globals.h:36
#define Actor_DefaultUpdateCallbackSlot
Definition globals.h:30
#define g_behaviorProcessSnapFunc
Definition globals.h:39
void Audio_StopAllSounds(void)
Definition channels.c:39
void Audio_FixupSoundDefinitions(struct Audio_SoundDefinition *sound_defs, int32_t count, void *sample_data_base)
Definition system.c:173
void Audio_StartMusicWithFade(struct Audio_MusicStreamRecord *stream_record)
Definition music.c:268
void Audio_StopMusicAndPause(void)
Definition music.c:245
void Audio_InitializeLevelAudio(void)
Definition system.c:151
#define Audio_TriggerMusicTransition_CurrentTrackIndex
Definition globals.h:57
#define Audio_MusicFadeFrameCount
Definition globals.h:18
void Camera_SetupProjection(struct Camera_Runtime *camera)
Definition projection.c:111
#define g_cameraTransitionCountdown
Definition globals.h:36
#define g_cameraData
Definition globals.h:63
#define g_cameraTransitionFrameCounter
Definition globals.h:39
#define g_cameraTransitionPaused
Definition globals.h:45
#define Camera_UpdateFollow_CurrentCameraCell
Definition globals.h:30
void Collision_InitializeFunctionPointers(void)
Definition actors.c:71
#define Collision_ProcessActorToActorCollisions_StateHandlerTable
Definition globals.h:78
int32_t(* ActorCollisionProbeCallback)(void *subject, void *other_object, struct Collision_Polygon *collision_poly, int32_t collision_depth)
Definition common.h:9
struct Actor_State * Entity_SpawnActor(struct Entity *entity)
Definition lifecycle.c:287
#define EntityNavigationWorkList_BackingBuffer
Definition globals.h:18
#define g_activeEntityWorkListBufferB
Definition globals.h:21
#define EntityNavigationWorkList_StagingBufferPtr
Definition globals.h:15
#define EntityNavigationWorkList_ActiveBufferPtr
Definition globals.h:12
#define GAME_TRANSITION_FADE_COUNTDOWN
Definition constants.h:25
#define GAME_TRANSITION_BONUS_REPLAY
Definition constants.h:27
#define GAME_TRANSITION_SCRIPT_PAUSED
Definition constants.h:20
@ GAME_MODE_LOADING_SCREEN
Definition enums.h:35
@ GAME_MODE_EXTENDED_RENDER_DISTANCE
Definition enums.h:14
@ GAME_MODE_STANDARD_RENDER_DISTANCE_NEGATIVE
Definition enums.h:47
@ GAME_MODE_GAMEPLAY_3D
Definition enums.h:38
void Player_ProcessMovement(struct Actor_State *actor)
Definition player.c:66
bool Game_TransitionToLevel(int32_t level_id)
Definition loop.c:39
#define Game_FrameTransitionFlags
Definition globals.h:47
#define g_currentGameMode
Definition globals.h:74
#define g_playerMovementFunc
Definition globals.h:56
void Graphics_InitializeColorGradient(struct Menu_ColorGradientState *gradient_state, int32_t step_count, uint32_t packed_hold_frames, uint32_t packed_intensity_bounds)
Definition effects.c:323
@ LEVEL_MENU_RESULT_OPEN_WORLD_SELECT
Definition constants.h:120
@ LEVEL_MENU_RESULT_START_WORLD_HUB
Definition constants.h:121
@ LEVEL_MENU_RESULT_START_STORY
Definition constants.h:119
@ LEVEL_STREAM_TEXTURES
Definition constants.h:49
@ LEVEL_STREAM_WAIT_AUDIO
Definition constants.h:52
@ LEVEL_STREAM_WAIT_TEXTURES
Definition constants.h:50
@ LEVEL_STREAM_DATA
Definition constants.h:53
@ LEVEL_STREAM_AUDIO
Definition constants.h:51
@ LEVEL_STREAM_FIXUP
Definition constants.h:54
#define LEVEL_ENTITY_SPAWN_ON_LOAD
Definition constants.h:7
#define LEVEL_MENU_FADE_FRAMES
Definition constants.h:98
#define LEVEL_MENU_HIGHLIGHT_GRADIENT_RATE
Definition constants.h:107
@ LEVEL_WORLD_HUB
Definition constants.h:84
#define LEVEL_ENTITY_DESTROY_ON_UNLOAD
Definition constants.h:8
#define LEVEL_RENDER_DISTANCE_STANDARD
Definition constants.h:103
#define LEVEL_MENU_HIGHLIGHT_GRADIENT_COLOR
Definition constants.h:108
@ LEVEL_MAIN_MENU_INITIALIZE
Definition constants.h:59
@ LEVEL_SAVE_LOAD_BEGIN
Definition constants.h:161
@ LEVEL_SAVE_LOAD_CONTINUE
Definition constants.h:162
@ LEVEL_LOAD_WORLD_MENU
Definition constants.h:41
@ LEVEL_LOAD_INITIALIZE
Definition constants.h:35
@ LEVEL_LOAD_WORLD_HUB
Definition constants.h:43
@ LEVEL_LOAD_MAIN_MENU
Definition constants.h:38
@ LEVEL_LOAD_DIRECT
Definition constants.h:44
@ LEVEL_LOAD_SAVED_GAME
Definition constants.h:36
@ LEVEL_LOAD_OPEN_WORLD_MENU
Definition constants.h:40
@ LEVEL_LOAD_NEW_STORY
Definition constants.h:39
@ LEVEL_LOAD_TITLE
Definition constants.h:37
@ LEVEL_LOAD_STORY
Definition constants.h:42
#define LEVEL_TRANSITION_TARGET_NONE
Definition constants.h:25
@ LEVEL_TRANSITION_IDLE
Definition constants.h:30
#define LEVEL_RENDER_DISTANCE_EXTENDED
Definition constants.h:102
#define LEVEL_MENU_HIGHLIGHT_GRADIENT_STEPS
Definition constants.h:144
#define LEVEL_DEFAULT_SCALE
Definition constants.h:101
BOOL Level_TriggerTransition(int32_t target_level_index, int32_t transition_mode, struct Level_TransitionTimingData const *transition_timing)
Definition transitions.c:47
int32_t Level_UpdateInterLevelMenu(void)
int32_t Level_UpdateWorldSelectMenu(void)
#define g_levelTransitionState
Definition globals.h:118
#define g_levelTransitionEndFrame
Definition globals.h:55
#define g_levelRenderDistanceQuarter
Definition globals.h:121
#define g_levelIndex
Definition globals.h:100
#define g_dynamic_level_scale
Definition globals.h:106
#define g_f_MaxLevelScale
Definition globals.h:18
#define g_levelTexDataA
Definition globals.h:82
#define g_levelTransitionMidFrame
Definition globals.h:52
#define g_levelBlobPtr
Definition globals.h:97
#define g_levelTexDataB
Definition globals.h:85
#define g_levelActorSystemState
Definition globals.h:103
#define g_levelMaterialSection
Definition globals.h:94
#define g_levelRenderDistance
Definition globals.h:115
#define g_levelTransitionStartFrame
Definition globals.h:49
#define g_levelRenderDistanceThird
Definition globals.h:124
#define g_levelScaleFactor
Definition globals.h:112
#define g_levelStreamLoadState
Definition globals.h:79
void Level_UnloadResources(struct Level_DataHeader *level_resource_data)
Definition loading.c:478
void Level_CleanupActors()
Definition loading.c:168
struct Level_DataHeader * Level_LoadStateMachine(int32_t level_index)
Definition loading.c:382
void Level_InitializeActorSystem()
Definition loading.c:53
bool Level_Load()
Definition loading.c:214
void Material_ReleaseSectionTextures(struct Material_SectionHeader *material_section)
Definition textures.c:368
void Material_LoadAndFixup(struct Material_SectionHeaderRaw *material_section_raw, uint8_t *texture_data_entry_base)
Definition resources.c:65
#define MATH_Q12_SHIFT
Definition constants.h:8
void Menu_ShutdownResources(void)
Definition state.c:86
void Menu_ResetState(void)
Definition state.c:358
#define g_mainMenuState
Definition globals.h:135
#define Menu_HighlightGradient
Definition globals.h:156
#define Menu_LoadState
Definition globals.h:153
#define Menu_LoadingFadeDelay
Definition globals.h:147
@ PKG_ENTRY_LEVEL_AUDIO
Definition constants.h:38
@ PKG_ENTRY_LEVEL_DATA
Definition constants.h:39
@ PKG_ENTRY_LEVEL_TEXTURES
Definition constants.h:37
void Shared_LoadCommonResources(void)
Definition resources.c:69
void Pkg_FreeResourceMemory(void *user_ptr)
Definition resources.c:342
bool PKG_UpdateLoadingScreen(int32_t level_index)
Definition resources.c:178
void Pkg_FixUpResourceLevelPointers(struct Pkg_LevelHeader *level)
Definition fixups.c:847
void Pkg_FixUpResourceObjectNodeDispatchByType(struct PKG_ObjectNodeFixupView *node)
Definition fixups.c:29
void * PKG_LoadEntry(int32_t toc_index, void *dest_buffer, int32_t unused_mode)
Definition archive.c:18
uint8_t Pkg_ReturnResourceAlwaysTrue(void)
Definition resources.c:394
#define pkg_resource_current_level_data
Definition globals.h:117
int32_t Physics_ProcessActorCollision(struct Actor_State *actor, void *other_actor_or_out_reference, int32_t distance_or_reference_selector)
Definition behavior.c:39
int64_t __ftol_msvc(long double value)
int32_t Save_LoadGameState(int32_t operation_step)
Definition progress.c:105
void Save_InitializeGameState(void)
Definition progress.c:149
#define g_objectNodeRoot
Definition globals.h:12
Definition types.h:118
Definition types.h:22
struct Math_Vec3I32 * runtime_target_pos
Definition types.h:49
uint8_t flags_high_byte
Definition types.h:30
struct Math_Vec3I32 bonus_respawn_pos
Definition types.h:35
struct Math_Vec3I32 * position_ptr
Definition types.h:78
struct Actor * runtime_actor
Definition types.h:107
struct Audio_SoundDefinition * sound_list
Definition types.h:46
int16_t entity_count
Definition types.h:44
int16_t sound_def_count
Definition types.h:51
char * themes[0x5]
Definition types.h:54
struct Entity * entity_array
Definition types.h:45
int32_t child_rot_x
Definition types.h:197
uint8_t Title_UpdateAndRenderScreen(int32_t command)
Definition title.c:251
#define g_skipTitleScreen
Definition globals.h:50
#define g_renderingStateFlag
Definition values.h:627
#define g_musicFadeStartFrame
Definition values.h:165
#define g_musicTransitionPending
Definition values.h:171
#define g_fadeCounter
Definition values.h:147
#define g_musicTransitionEndFrame
Definition values.h:168