102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
tracking.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
12#include "pcdogs/camera/types.h"
16#include "pcdogs/entity/types.h"
17#include "pcdogs/game/globals.h"
22#include "pcdogs/level/types.h"
24#include "pcdogs/math/types.h"
27#include "pcdogs/scene/types.h"
30#include <math.h>
31#include <stdarg.h>
32#include <string.h>
33
34static uint32_t Camera_PauseAngleFromDegrees(uint32_t degrees)
35{
36 return (degrees << 9) / CAMERA_DEGREES_TO_ANGLE_DIVISOR;
37}
38
39// Original pcdogs.exe: 0x4071e0
40// Updates the follow camera and projection while rebuilding the double-buffered entity worklists, processing actor and powerup activity, and checking level transitions. Active-entity insertion requires room in the four-slot list and has no local capacity check.
42{
43 // Some camera-state flag meanings remain unresolved.
45
46 struct Camera_Runtime *active_camera = camera;
47 int16_t fov = active_camera->fov;
48
49 *(uint8_t *)&active_camera->pose_state_flags &= (uint8_t)~CAMERA_POSE_FOLLOW_UPDATED;
50
51 uint32_t transition_bits = Game_FrameTransitionFlags;
52 int16_t *pose_storage = &active_camera->look_pitch;
53 struct Camera_Pose saved_pose;
54
55 __builtin_memcpy(&saved_pose, pose_storage, 0x24);
56
57 int32_t direction_length_squared;
58 struct Math_Matrix3x3I16 contact_world_matrix;
59 int32_t local_forward_x;
60 int32_t forward_x;
61
62 if (!(transition_bits & GAME_TRANSITION_RESPAWN_PENDING))
63 {
64 struct Scene_Node *camera_cell =
66
67 if (camera_cell)
68 {
69 struct Level_Data *camera_level = pkg_resource_current_level_data;
70
71 if (camera_cell != (void *)camera_level->cam_default)
72 {
73 struct Scene_Node *first_child =
74 camera_cell->first_child;
75 struct Scene_TransformNodePrefix *target_node = first_child->variant_payload_ptr;
76
77 if (target_node)
78 {
79 saved_pose.target_pos.x = (uint32_t)target_node->world_position.x;
80 saved_pose.target_pos.z = (uint32_t)target_node->world_position.y;
81 saved_pose.target_pos.y = (uint32_t)target_node->world_position.z;
82 }
83
84 saved_pose.eye_pos.x = first_child->world_pos.x;
85 saved_pose.eye_pos.z = first_child->world_pos.y;
86 saved_pose.eye_pos.y = first_child->world_pos.z;
87 saved_pose.view_roll = first_child->render_param_1;
88 saved_pose.fov = (uint16_t)first_child->billboard_scale.y;
89 }
90 else if (camera_level->cam_current)
91 {
92 int32_t follow_entity_index = (uint16_t)(camera_level->current_entity_index);
93 struct Entity *follow_entity =
94 &camera_level->entity_array[follow_entity_index];
95 struct Actor_State *follow_actor = (struct Actor_State *)(follow_entity->runtime_actor);
96 int32_t pause_forward_z;
97 int32_t follow_facing_yaw;
98
99 if (!follow_actor)
100 {
101 follow_facing_yaw = follow_entity->param_F0;
102 forward_x = Math_SinQ14(follow_facing_yaw) >> 2;
103 pause_forward_z = Math_SinQ14(MATH_ANGLE_QUARTER_TURN - follow_facing_yaw) >> 2;
104 }
105 else
106 {
107 struct Collision_Node *pause_ground_node;
108
110 pause_ground_node = follow_actor->ground_collision_node;
111
112 if (follow_actor->behavior_flags & (ACTOR_BEHAVIOR_AIRBORNE | ACTOR_BEHAVIOR_GROUND_BASIS_CHANGED) || !pause_ground_node || pause_ground_node->node_type == COLLISION_NODE_ORIENTED_BOX || !follow_actor->facing_blend)
113 {
114 follow_facing_yaw = (follow_actor->facing_blend + follow_actor->facing_current) & MATH_ANGLE_WRAP_MASK;
115 forward_x = Math_SinQ14(follow_facing_yaw) >> 2;
116 pause_forward_z = Math_SinQ14(MATH_ANGLE_QUARTER_TURN - follow_facing_yaw) >> 2;
117 }
118 else
119 {
120 Math_MulMat3x3Q12(&contact_world_matrix,
121 &follow_actor->contact_basis,
122 &pause_ground_node->transform_matrix);
123
124 int16_t pause_facing_yaw = follow_actor->facing_current;
125 int32_t pause_local_forward_x = Math_SinQ14(pause_facing_yaw) >> 2 << 8;
126
127 local_forward_x = pause_local_forward_x;
128
129 int16_t pause_complement_yaw = MATH_ANGLE_QUARTER_TURN - follow_actor->facing_current;
130 int32_t pause_local_forward_y = 0;
131 int32_t pause_local_forward_z = Math_SinQ14(pause_complement_yaw) >> 2 << 8;
132 int64_t pause_world_x_from_x_wide = (int64_t)(int32_t)contact_world_matrix.m00 * local_forward_x;
133 int64_t pause_world_x_from_y_wide = (int64_t)(int32_t)contact_world_matrix.m01 * pause_local_forward_y;
134 int64_t pause_world_x_from_z_wide = (int64_t)(int32_t)contact_world_matrix.m02 * pause_local_forward_z;
135
136 forward_x = (int32_t)(((uint64_t)pause_world_x_from_z_wide + (uint64_t)pause_world_x_from_x_wide + (uint64_t)pause_world_x_from_y_wide) >> MATH_Q12_SHIFT);
137
138 int64_t pause_world_z_from_x_wide = (int64_t)(int32_t)contact_world_matrix.m20 * local_forward_x;
139 int64_t pause_world_z_from_y_wide = (int64_t)(int32_t)contact_world_matrix.m21 * pause_local_forward_y;
140 int64_t pause_world_z_from_z_wide = (int64_t)(int32_t)contact_world_matrix.m22 * pause_local_forward_z;
141 int32_t pause_world_forward_z =
142 (int32_t)(((uint64_t)pause_world_z_from_z_wide + (uint64_t)pause_world_z_from_x_wide + (uint64_t)pause_world_z_from_y_wide) >> MATH_Q12_SHIFT);
143 int32_t pause_flat_forward_y = 0;
144 int64_t pause_forward_x_square_wide = (int64_t)forward_x * forward_x;
145 int64_t pause_forward_y_square_wide = (int64_t)pause_flat_forward_y * pause_flat_forward_y;
146 int64_t pause_forward_z_square_wide = (int64_t)pause_world_forward_z * pause_world_forward_z;
147
148 direction_length_squared = (int32_t)(((uint64_t)pause_forward_z_square_wide + (uint64_t)pause_forward_x_square_wide + (uint64_t)pause_forward_y_square_wide) >> MATH_Q12_SHIFT);
149
150 int32_t pause_forward_length = Math_SqrtFP12(direction_length_squared);
151
152 if (pause_forward_length)
153 {
154 int32_t pause_inverse_length = INT64_C(0x100000000) / pause_forward_length;
155 int64_t pause_scaled_forward_x_wide = (int64_t)pause_inverse_length * forward_x;
156
157 forward_x = ((int32_t)((uint64_t)pause_scaled_forward_x_wide >> MATH_Q12_SHIFT)) >> 8;
158
159 int64_t pause_scaled_forward_z_wide = (int64_t)pause_inverse_length * pause_world_forward_z;
160
161 pause_forward_z = ((int32_t)((uint64_t)pause_scaled_forward_z_wide >> MATH_Q12_SHIFT)) >> 8;
162 }
163 else
164 {
165 pause_forward_z = 0;
166
167 forward_x = 0;
168 }
169 }
170 }
171
172 uint32_t pause_eye_orbit_angle = Camera_PauseAngleFromDegrees(g_pauseCameraOrbitAngleDeg);
173 int32_t pause_eye_distance_q12 = (int32_t)((uint32_t)g_pauseCameraDistance << MATH_Q12_SHIFT) / 12;
174 int64_t pause_eye_sine_wide = (int64_t)(Math_SinQ14(pause_eye_orbit_angle) >> 2) * pause_eye_distance_q12;
175 int32_t pause_eye_sine_offset = (int32_t)((uint64_t)pause_eye_sine_wide >> MATH_Q12_SHIFT);
176 int64_t pause_eye_cosine_wide = (int64_t)(Math_SinQ14(MATH_ANGLE_QUARTER_TURN - pause_eye_orbit_angle) >> 2) * pause_eye_distance_q12;
177 int32_t pause_eye_cosine_offset = (int32_t)((uint64_t)pause_eye_cosine_wide >> MATH_Q12_SHIFT);
178 int64_t pause_eye_cosine_x_wide = (int64_t)pause_eye_cosine_offset * forward_x;
179 int64_t pause_eye_sine_z_wide = (int64_t)pause_eye_sine_offset * pause_forward_z;
180 int32_t pause_eye_offset_x =
181 ((int32_t)((uint64_t)pause_eye_sine_z_wide >> MATH_Q12_SHIFT)) + ((int32_t)((uint64_t)pause_eye_cosine_x_wide >> MATH_Q12_SHIFT));
182 int64_t pause_eye_cosine_z_wide = (int64_t)pause_eye_cosine_offset * pause_forward_z;
183 int64_t pause_eye_sine_x_wide = (int64_t)pause_eye_sine_offset * forward_x;
184 int32_t pause_eye_height_q12 = (int32_t)((uint32_t)g_pauseCameraHeight << MATH_Q12_SHIFT) / 12;
185
186 saved_pose.eye_pos.x = follow_entity->position_ptr->x + pause_eye_offset_x;
187 saved_pose.eye_pos.z = follow_entity->position_ptr->y + pause_eye_height_q12;
188
189 saved_pose.eye_pos.y = follow_entity->position_ptr->z + ((int32_t)((uint64_t)pause_eye_cosine_z_wide >> MATH_Q12_SHIFT)) - ((int32_t)((uint64_t)pause_eye_sine_x_wide >> MATH_Q12_SHIFT));
190
191 uint32_t pause_target_orbit_angle = Camera_PauseAngleFromDegrees(g_pauseTargetRotationAngle);
192 int32_t pause_target_distance_q12 = (int32_t)((uint32_t)g_pauseTargetDistance << MATH_Q12_SHIFT) / 12;
193 int64_t pause_target_sine_wide = (int64_t)(Math_SinQ14(pause_target_orbit_angle) >> 2) * pause_target_distance_q12;
194 int32_t pause_target_sine_offset = (int32_t)((uint64_t)pause_target_sine_wide >> MATH_Q12_SHIFT);
195 int64_t pause_target_cosine_wide = (int64_t)(Math_SinQ14(MATH_ANGLE_QUARTER_TURN - pause_target_orbit_angle) >> 2) * pause_target_distance_q12;
196 int32_t pause_target_cosine_offset = (int32_t)((uint64_t)pause_target_cosine_wide >> MATH_Q12_SHIFT);
197 int64_t pause_target_cosine_x_wide = (int64_t)pause_target_cosine_offset * forward_x;
198 int64_t pause_target_sine_z_wide = (int64_t)pause_target_sine_offset * pause_forward_z;
199 int32_t pause_target_offset_x =
200 ((int32_t)((uint64_t)pause_target_sine_z_wide >> MATH_Q12_SHIFT)) + ((int32_t)((uint64_t)pause_target_cosine_x_wide >> MATH_Q12_SHIFT));
201 int64_t pause_target_cosine_z_wide = (int64_t)pause_target_cosine_offset * pause_forward_z;
202 int64_t pause_target_sine_x_wide = (int64_t)pause_target_sine_offset * forward_x;
203 int16_t attach_offset_x = follow_entity->attach_offset_x;
204 int32_t pause_target_height_q12 = (int32_t)((uint32_t)g_pauseTargetYOffset << MATH_Q12_SHIFT) / 12;
205 int32_t follow_entity_index_quotient;
206
207 if ((uint16_t)attach_offset_x != CAMERA_FOLLOW_CURRENT_ENTITY_SELECTOR && attach_offset_x > 0)
208 {
209 follow_entity_index_quotient = follow_entity - pkg_resource_current_level_data->entity_array;
210 }
211
212 int32_t pause_target_base_z;
213
214 if ((uint16_t)attach_offset_x == CAMERA_FOLLOW_CURRENT_ENTITY_SELECTOR || (attach_offset_x > 0 && (int32_t)attach_offset_x - 1 == follow_entity_index_quotient))
215 {
216 saved_pose.target_pos.x = follow_entity->position_ptr->x + pause_target_offset_x;
217 saved_pose.target_pos.z = follow_entity->position_ptr->y + pause_target_height_q12;
218 pause_target_base_z = follow_entity->position_ptr->z;
219 }
220 else
221 {
222 saved_pose.target_pos.x = follow_entity->path_result.x + pause_target_offset_x;
223 saved_pose.target_pos.z = follow_entity->path_result.y + pause_target_height_q12;
224 pause_target_base_z = follow_entity->path_result.z;
225 }
226
227 saved_pose.target_pos.y =
228 pause_target_base_z + ((int32_t)((uint64_t)pause_target_cosine_z_wide >> MATH_Q12_SHIFT)) - ((int32_t)((uint64_t)pause_target_sine_x_wide >> MATH_Q12_SHIFT));
229 active_camera = camera;
231 }
232
233 transition_bits = g_cameraTransitionCountdown;
234
235 if (transition_bits)
236 Camera_InterpolateTransition((struct Camera_TransitionState *)(active_camera), &saved_pose,
238 }
239 else if (!((uint8_t)transition_bits & GAME_TRANSITION_SCRIPT_PAUSED))
240 {
241 int32_t previous_border_state = g_screenBorderStateFlag;
242
243 saved_pose.view_roll = 0;
244
245 if (previous_border_state == CAMERA_SCREEN_BORDER_ACTIVE)
246 {
247 g_screenBorderStateFlag = 0xffffffff;
248
249 if ((transition_bits & GAME_TRANSITION_FADE_COUNTDOWN))
250 {
251 transition_bits &= ~GAME_TRANSITION_FADE_COUNTDOWN;
252 Game_FrameTransitionFlags = transition_bits;
254 }
255 }
256
258
259 struct Level_Data *definition_level = pkg_resource_current_level_data;
260 int32_t definition_entity_index = (uint16_t)(definition_level->current_entity_index);
261
262 Camera_UpdateFromDefinition(active_camera,
263 &definition_level->entity_array[definition_entity_index], &saved_pose);
264 }
265 }
266 else
267 {
268 // Clear shadow list at start of camera update
269 struct Actor_State *transition_actor = Entity_GetCurrentOrFirstActiveActor();
270
271 if (transition_actor) // Save camera FOV value before modifications
272 {
273 struct Collision_Node *ground_collision_node = transition_actor->ground_collision_node;
274 int32_t transition_forward_z;
275
276 if (!ground_collision_node || ground_collision_node->node_type == COLLISION_NODE_ORIENTED_BOX || !transition_actor->facing_blend)
277 {
278 int32_t transition_blended_yaw = (transition_actor->facing_blend + transition_actor->facing_current) & MATH_ANGLE_WRAP_MASK;
279
280 forward_x = Math_SinQ14(transition_blended_yaw) >> 2;
281 // Calculate camera position: actor position - forward_direction * 0x3000 (behind actor)
282 transition_forward_z = Math_SinQ14(MATH_ANGLE_QUARTER_TURN - transition_blended_yaw) >> 2;
283 }
284 else
285 {
286 // Bit 25 gates this visibility pass; its canonical flag name is unresolved.
287 Math_MulMat3x3Q12(&contact_world_matrix, &transition_actor->contact_basis,
288 &ground_collision_node->transform_matrix);
289
290 int16_t transition_facing_yaw = transition_actor->facing_current;
291 int32_t transition_yaw_sine_q14;
292 int16_t transition_complement_yaw;
293
294 transition_yaw_sine_q14 = Math_SinQ14(transition_facing_yaw);
295
296 int32_t transition_local_forward_y = 0;
297
298 transition_complement_yaw = MATH_ANGLE_QUARTER_TURN - transition_actor->facing_current;
299 // Check if actor has valid animation component for orientation. If no component or component type is 2, use
300 // simple angle calculation.
301 local_forward_x = transition_yaw_sine_q14 >> 2 << 8;
302
303 int32_t transition_local_forward_z = Math_SinQ14(transition_complement_yaw) >> 2 << 8;
304
305 // Simple orientation: Calculate direction angle from actor rotation. angle = (actor.facing_offset +
306 // actor.base_rotation) & 0xfff
307 int64_t transition_world_x_from_x_wide = (int64_t)(int32_t)contact_world_matrix.m00 * local_forward_x;
308 int64_t transition_world_x_from_y_wide = (int64_t)(int32_t)contact_world_matrix.m01 * transition_local_forward_y;
309
310 // Calculate forward direction vector: dirX = sin(angle) >> 2, dirZ = cos(angle) >> 2
311 int64_t transition_world_x_from_z_wide = (int64_t)(int32_t)contact_world_matrix.m02 * transition_local_forward_z;
312
313 forward_x = (int32_t)(((uint64_t)transition_world_x_from_z_wide + (uint64_t)transition_world_x_from_x_wide + (uint64_t)transition_world_x_from_y_wide) >> MATH_Q12_SHIFT);
314
315 // Complex orientation: Actor has animation component. Multiply actor's rotation matrix by
316 // component's matrix to get world-space forward direction.
317 // Transform base direction vector (sin/cos of actor rotation) by component matrix to get final forward
318 // direction
319 int64_t transition_world_z_from_x_wide = (int64_t)(int32_t)contact_world_matrix.m20 * local_forward_x;
320 int64_t transition_world_z_from_y_wide = (int64_t)(int32_t)contact_world_matrix.m21 * transition_local_forward_y;
321 int64_t transition_world_z_from_z_wide = (int64_t)(int32_t)contact_world_matrix.m22 * transition_local_forward_z;
322 int32_t transition_world_forward_z = (int32_t)(((uint64_t)transition_world_z_from_z_wide + (uint64_t)transition_world_z_from_x_wide + (uint64_t)transition_world_z_from_y_wide) >> MATH_Q12_SHIFT);
323 int32_t transition_flat_forward_y = 0;
324 int64_t transition_forward_x_square_wide = (int64_t)forward_x * forward_x;
325 int64_t transition_forward_y_square_wide = (int64_t)transition_flat_forward_y * transition_flat_forward_y;
326 int64_t transition_forward_z_square_wide = (int64_t)transition_world_forward_z * transition_world_forward_z;
327
328 direction_length_squared = (int32_t)(((uint64_t)transition_forward_z_square_wide + (uint64_t)transition_forward_x_square_wide + (uint64_t)transition_forward_y_square_wide) >> MATH_Q12_SHIFT);
329
330 int32_t transition_forward_length = Math_SqrtFP12(direction_length_squared);
331
332 // Normalize the forward direction vector to unit length
333 if (transition_forward_length)
334 {
335 int32_t transition_inverse_length = INT64_C(0x100000000) / transition_forward_length;
336 int64_t transition_scaled_forward_x_wide = (int64_t)transition_inverse_length * forward_x;
337
338 forward_x = ((int32_t)((uint64_t)transition_scaled_forward_x_wide >> MATH_Q12_SHIFT)) >> 8;
339
340 int64_t transition_scaled_forward_z_wide = (int64_t)transition_inverse_length * transition_world_forward_z;
341
342 active_camera = camera;
343 transition_forward_z = ((int32_t)((uint64_t)transition_scaled_forward_z_wide >> MATH_Q12_SHIFT)) >> 8;
344 }
345 else
346 {
347 active_camera = camera;
348 transition_forward_z = 0;
349
350 forward_x = 0;
351 }
352 }
353
354 int64_t transition_eye_offset_x_wide = (int64_t)CAMERA_TRANSITION_DISTANCE_Q12 * forward_x;
355 int64_t transition_eye_offset_z_wide = (int64_t)CAMERA_TRANSITION_DISTANCE_Q12 * transition_forward_z;
356
357 saved_pose.eye_pos.x = transition_actor->position.x + -(((int32_t)((uint64_t)transition_eye_offset_x_wide >> MATH_Q12_SHIFT)));
358 saved_pose.eye_pos.z = transition_actor->position.y + MATH_Q12_ONE;
359 // Check for active camera transition. If DAT_00455ec0 is set, interpolate camera during transition.
360 saved_pose.eye_pos.y = transition_actor->position.z + -(((int32_t)((uint64_t)transition_eye_offset_z_wide >> MATH_Q12_SHIFT)));
361 saved_pose.target_pos.x = transition_actor->position.x;
362 saved_pose.target_pos.z = transition_actor->position.y + MATH_Q12_ONE;
363 saved_pose.target_pos.y = transition_actor->position.z;
364 }
365
366 transition_bits = g_cameraTransitionTrigger;
367
368 if (transition_bits)
369 {
370 g_cameraTransitionCountdown = transition_bits;
373 }
374 }
375
376 // Copy modified camera data back to main camera structure (9 dwords)
377 __builtin_memcpy(pose_storage, &saved_pose, 0x24);
378
379 uint16_t updated_fov = active_camera->fov;
380
381 if (updated_fov != (uint16_t)fov)
382 Camera_UpdateProjection(active_camera, Camera_CalculateClipDistance(active_camera, updated_fov));
383
384 // Load the navigation queue before swapping the active entity worklist.
385 struct EntityNavigationWorkListBuffer *completed_worklist =
387
388 // Promote the staging list, switch backing buffers and clear the new staging counts.
389 EntityNavigationWorkList_ActiveBufferPtr = completed_worklist;
390
392
393 if (completed_worklist != &g_activeEntityWorkListBufferB)
394 next_staging_worklist = &g_activeEntityWorkListBufferB;
395
396 int32_t entity_index = 0;
397
398 EntityNavigationWorkList_StagingBufferPtr = next_staging_worklist;
399 next_staging_worklist->active_count = 0;
400 EntityNavigationWorkList_StagingBufferPtr->nav_command_count = 0;
401
402 struct Level_Data *worklist_level = pkg_resource_current_level_data;
403 struct Entity *scanned_entity = worklist_level->entity_array;
404
405 if (worklist_level->entity_count > 0)
406 {
407 int32_t entity_count;
408
409 do
410 {
411 // Scripts request next-pass membership by reasserting entity bit 0x4.
412 BOOL entity_visible = Entity_UpdateVisibilityAndSpawn(scanned_entity, NULL);
413
414 if (entity_visible)
415 {
416 // Clear the request before running the script so membership must be renewed.
417 scanned_entity->flags &= ~(uint32_t)ENTITY_FLAG_ACTIVE_WORKLIST_REQUEST;
418 Script_ExecuteBehaviorScript(scanned_entity);
419 }
420
421 uint32_t entity_flags_cleared = scanned_entity->flags;
422
423 entity_flags_cleared &= ~ENTITY_FLAG_UPDATE_GUARD;
424 scanned_entity->flags = entity_flags_cleared;
425
426 struct Actor *runtime_actor = scanned_entity->runtime_actor;
427
428 // Mirror the entity request in actor behavior bit 0x10000000.
429 if ((uint8_t)entity_flags_cleared & ENTITY_FLAG_ACTIVE_WORKLIST_REQUEST)
430 {
431 if (runtime_actor)
433
435 append_worklist =
437
438 // A fifth active entry would overwrite nav_command_count; capacity is unchecked.
439 append_worklist->active_entities[append_worklist->active_count] = scanned_entity;
440
442 count_worklist =
444
445 count_worklist->active_count += 1;
446
447 uint32_t flags = scanned_entity->flags;
448
449 if (!entity_visible)
450 // Ineligible carryover sets bit 0x10 for deferred far-cull/unlink; eligible carryover clears it.
452 else
454
455 scanned_entity->flags = flags;
456 }
457 else if (runtime_actor)
458 runtime_actor->behavior_flags &= ~(uint32_t)ACTOR_BEHAVIOR_WORKLIST_MEMBER;
459
460 worklist_level = pkg_resource_current_level_data;
461 entity_index += 1;
462 scanned_entity = &scanned_entity[1];
463 entity_count = (uint16_t)worklist_level->entity_count;
464 } while (entity_index < entity_count);
465 }
466
467 struct EntityNavigationWorkListBuffer *candidate_worklist =
469 for (int32_t index = 0; index < candidate_worklist->active_count; ++index)
470 {
471 struct Entity *candidate = candidate_worklist->active_entities[index];
472 if (candidate->flags & ENTITY_FLAG_SCRIPT_PAUSED)
473 continue;
474
475 struct Entity *entities = worklist_level->entity_array;
476 int32_t byte_offset = (int32_t)((uintptr_t)candidate - (uintptr_t)entities);
477 int32_t candidate_index = byte_offset / (int32_t)sizeof *candidate;
478 uint16_t current_index = (uint16_t)worklist_level->current_entity_index;
479 if (candidate_index != current_index)
480 {
481 uint32_t current_flags = entities[current_index].flags;
482 if (current_flags & ENTITY_FLAG_ACTIVATION_REQUEST)
483 {
484 if (current_flags & ENTITY_FLAG_ACTIVE_WORKLIST_REQUEST)
485 continue;
486
487 BOOL current_is_active = Entity_IsInActiveList(current_index + 1);
488 worklist_level = pkg_resource_current_level_data;
489 if (!current_is_active)
490 {
492 continue;
493 }
494 }
495 }
496
497 /* 0x407ba6 writes the selected index even when it equals the current one. */
498 *(volatile int16_t *)&worklist_level->current_entity_index = (int16_t)candidate_index;
499 break;
500 }
501
503 Level_TriggerTransition(0xffffffff, 0xffffffff, NULL);
504
506 Audio_TriggerMusicTransition(0xffffffff, 0xffffffff, NULL, 0xffffffff);
507
510}
#define ACTOR_BEHAVIOR_AIRBORNE
Definition constants.h:13
#define ACTOR_BEHAVIOR_GROUND_BASIS_CHANGED
Definition constants.h:32
#define ACTOR_BEHAVIOR_WORKLIST_MEMBER
Definition constants.h:34
int32_t Audio_SetMusicFadeTarget(int32_t target_volume, int16_t frame_count)
Definition music.c:194
void Audio_ResumeAllSounds(void)
Definition channels.c:546
void Audio_TriggerMusicTransition(int32_t track_index, int32_t transition_mode, struct Level_TransitionTimingData const *transition_timing, int32_t volume_percent)
Definition music.c:22
#define CAMERA_DEGREES_TO_ANGLE_DIVISOR
Definition constants.h:55
#define CAMERA_RESUME_MUSIC_FADE_FRAMES
Definition constants.h:67
#define CAMERA_FOLLOW_CURRENT_ENTITY_SELECTOR
Definition constants.h:26
#define CAMERA_DEFAULT_TRANSITION_FRAMES
Definition constants.h:25
@ CAMERA_SCREEN_BORDER_ACTIVE
Definition constants.h:30
#define CAMERA_POSE_FOLLOW_UPDATED
Definition constants.h:18
#define CAMERA_TRANSITION_DISTANCE_Q12
Definition constants.h:54
void Camera_UpdateFromDefinition(struct Camera_Runtime *camera, struct Entity *entity, struct Camera_Pose *pose)
Definition state.c:187
void Camera_UpdateProjection(struct Camera_Runtime *camera, int32_t focal_distance)
Definition projection.c:146
int32_t Camera_CalculateClipDistance(struct Camera_Runtime *camera, int16_t fov)
Definition projection.c:211
void Camera_InterpolateTransition(struct Camera_TransitionState *transition_state, struct Camera_Pose *target_pose, int32_t duration_frames, int32_t recompute_eye_from_angles)
Definition state.c:27
#define g_cameraTransitionTrigger
Definition globals.h:33
#define g_pauseCameraFOV
Definition globals.h:102
#define g_cameraTransitionCountdown
Definition globals.h:36
#define g_pauseCameraDistance
Definition globals.h:99
#define g_pauseCameraOrbitAngleDeg
Definition globals.h:93
#define g_cameraTransitionFrameCounter
Definition globals.h:39
#define g_pauseCameraHeight
Definition globals.h:96
#define Camera_UpdateFollow_CurrentCameraCell
Definition globals.h:30
@ COLLISION_NODE_ORIENTED_BOX
Definition constants.h:8
#define ENTITY_FLAG_ACTIVE_WORKLIST_REQUEST
Definition constants.h:9
#define ENTITY_FLAG_SCRIPT_PAUSED
Definition constants.h:20
#define ENTITY_FLAG_ACTIVE_WORKLIST_DEFERRED
Definition constants.h:11
#define ENTITY_FLAG_ACTIVATION_REQUEST
Definition constants.h:17
#define ENTITY_FLAG_UPDATE_GUARD
Definition constants.h:19
BOOL Entity_UpdateVisibilityAndSpawn(struct Entity *entity, struct Entity *reactivation_requester_or_null)
Definition lifecycle.c:452
struct Actor_State * Entity_GetCurrentOrFirstActiveActor(void)
Definition lifecycle.c:753
BOOL Entity_IsInActiveList(int32_t entity_index_1based)
Definition lifecycle.c:39
#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_RESPAWN_PENDING
Definition constants.h:31
#define GAME_TRANSITION_SCRIPT_PAUSED
Definition constants.h:20
#define Game_FrameTransitionFlags
Definition globals.h:47
void Shadow_ClearList(void)
Definition shadows.c:21
BOOL Level_TriggerTransition(int32_t target_level_index, int32_t transition_mode, struct Level_TransitionTimingData const *transition_timing)
Definition transitions.c:47
#define g_dynamic_level_scale
Definition globals.h:106
#define g_levelTransitionMidFrame
Definition globals.h:52
#define MATH_Q12_SHIFT
Definition constants.h:8
#define MATH_ANGLE_QUARTER_TURN
Definition constants.h:15
#define MATH_ANGLE_WRAP_MASK
Definition constants.h:16
#define MATH_Q12_ONE
Definition constants.h:9
int32_t Math_SinQ14(int32_t angle)
int32_t Math_SqrtFP12(uint32_t value)
void Math_MulMat3x3Q12(struct Math_Matrix3x3I16 *out_matrix, struct Math_Matrix3x3I16 const *right_factor, struct Math_Matrix3x3I16 const *left_factor)
Definition matrices.c:11
#define pkg_resource_current_level_data
Definition globals.h:117
void Powerup_UpdateSpawnLogic(void)
Definition lifecycle.c:109
void Script_ExecuteBehaviorScript(struct Entity *entity)
Definition interpreter.c:79
struct Math_Matrix3x3I16 contact_basis
Definition types.h:380
int16_t facing_current
Definition types.h:447
struct Collision_Node * ground_collision_node
Definition types.h:451
int32_t behavior_flags
Definition types.h:407
int16_t facing_blend
Definition types.h:449
struct Math_Vec3I32 position
Definition types.h:385
Definition types.h:118
int32_t behavior_flags
Definition types.h:160
struct Math_Vec3I32XZY eye_pos
Definition types.h:164
int16_t fov
Definition types.h:162
struct Math_Vec3I32XZY target_pos
Definition types.h:165
int16_t view_roll
Definition types.h:161
int32_t max_render_distance_q12
Definition types.h:271
int16_t pose_state_flags
Definition types.h:255
int16_t look_pitch
Definition types.h:257
int16_t fov
Definition types.h:260
uint8_t node_type
Definition types.h:286
struct Math_Matrix3x3I16 transform_matrix
Definition types.h:281
struct Entity * active_entities[0x4]
Definition types.h:133
Definition types.h:22
uint32_t flags
Definition types.h:25
int16_t attach_offset_x
Definition types.h:42
struct Math_Vec3I32 * position_ptr
Definition types.h:78
int32_t param_F0
Definition types.h:90
struct Actor * runtime_actor
Definition types.h:107
struct Math_Vec3I32 path_result
Definition types.h:114
int16_t entity_count
Definition types.h:44
struct Pkg_CameraDef * cam_default
Definition types.h:41
struct Pkg_CameraDef * cam_current
Definition types.h:42
int16_t current_entity_index
Definition types.h:43
struct Entity * entity_array
Definition types.h:45
int16_t m21
Definition types.h:169
int16_t m00
Definition types.h:162
int16_t m01
Definition types.h:163
int16_t m20
Definition types.h:168
int16_t m22
Definition types.h:170
int16_t m02
Definition types.h:164
int16_t y
Definition types.h:403
int32_t x
Definition types.h:482
int32_t z
Definition types.h:483
int32_t y
Definition types.h:484
int32_t y
Definition types.h:471
int32_t x
Definition types.h:470
int32_t z
Definition types.h:472
struct Math_Vec2I16 billboard_scale
Definition types.h:137
int32_t render_param_1
Definition types.h:136
struct Math_Vec3I32 world_pos
Definition types.h:120
void * variant_payload_ptr
Definition types.h:140
struct Scene_Node * first_child
Definition types.h:114
struct Math_Vec3I32 world_position
Definition types.h:262
static uint32_t Camera_PauseAngleFromDegrees(uint32_t degrees)
Definition tracking.c:34
void Camera_UpdateFollowAndEntityWorklists(struct Camera_Runtime *camera)
Definition tracking.c:41
#define g_pauseTargetDistance
Definition values.h:837
#define g_screenBorderStateFlag
Definition values.h:144
#define g_pauseTargetRotationAngle
Definition values.h:831
#define g_musicTransitionPending
Definition values.h:171
#define g_pauseTargetYOffset
Definition values.h:834