102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
rendering.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
15#include "pcdogs/actor/types.h"
22#include "pcdogs/game/globals.h"
28#include "pcdogs/math/globals.h"
29#include "pcdogs/math/types.h"
31#include "pcdogs/scene/types.h"
34#include <math.h>
35#include <stdarg.h>
36#include <string.h>
37
38// Original pcdogs.exe: 0x401000
39// Tests the pause camera's mode-dependent coordinate gate after checking for a nonnull actor. The asymmetric coordinate expression is preserved and is not a distance calculation.
41{
42 if (!actor)
43 return 0;
44
45 struct Graphics_Render_ListState *render_state = render_list_state;
46 int32_t saved_eye_delta_z = Script_OpPauseToggle_SavedActorWorldRenderPosY - render_state->eye_pos.z;
47 int32_t saved_eye_delta_x = Script_OpPauseToggle_SavedActorWorldRenderPosX - render_state->eye_pos.x;
48 int32_t saved_eye_delta_y = Script_OpPauseToggle_SavedActorWorldRenderPosZ - render_state->eye_pos.y;
49 int32_t coordinate_gate_magnitude;
50
51 if (saved_eye_delta_x >= 0)
52 {
53 int32_t negative_z_flag = (uint8_t)(saved_eye_delta_z < 0);
54
55 if (negative_z_flag == -(saved_eye_delta_x))
56 {
57 int32_t negative_y_flag = (uint8_t)(saved_eye_delta_y < 0);
58
59 if (negative_y_flag != -(saved_eye_delta_z))
60 saved_eye_delta_y = -(saved_eye_delta_y);
61
62 coordinate_gate_magnitude = saved_eye_delta_y;
63 }
64 else
65 coordinate_gate_magnitude = -(saved_eye_delta_z);
66 }
67 else
68 coordinate_gate_magnitude = -(saved_eye_delta_x);
69
70 int32_t game_mode = g_currentGameMode;
71
72 if (game_mode) // Game mode 0 may be normal gameplay - distance check varies by mode
73 {
74 if (game_mode == ACTOR_RENDER_DISTANCE_RANGE_EXCLUSION && (uint32_t)coordinate_gate_magnitude > ACTOR_RENDER_EXCLUDED_RANGE_BEGIN && (uint32_t)coordinate_gate_magnitude < ACTOR_RENDER_EXCLUDED_RANGE_END)
75 return 0;
76 }
77 // Magic value ACTOR_RENDER_EXCLUDED_DISTANCE (33665) - possibly a specific distance threshold constant
78 else if (coordinate_gate_magnitude == ACTOR_RENDER_EXCLUDED_DISTANCE)
79 return 0;
80
81 return 1;
82}
83
84// Original pcdogs.exe: 0x4028f0
85// Updates actor animation and visibility, traverses eligible render nodes, and submits trails and world geometry before finalizing mesh state.
87{
88 // Set global actor pointer for rendering pipeline access
90 // After PrepareActorForRendering: access component at offset 0x78 (render_component pointer) to check
91 // flags at offset 0x65
93
94 // Check object_flags bit 0 (visibility processed) and actor flags at offset 0x0d (node_type related flags)
95 int32_t behavior_flags = actor->behavior_flags;
96 uint8_t root_traversal_flags = (*(struct Scene_Node **)actor->render_node_list)->traversal_flags;
97 int32_t behavior_low_bit = behavior_flags & ACTOR_BEHAVIOR_SKIP_UPDATE;
98
99 // Check keyframe visibility; set hidden/visible bits on node flags
100 if (!behavior_low_bit || !(actor->lifecycle_flags & ACTOR_LIFECYCLE_HIDDEN))
101 {
102 uint8_t lifecycle_flags;
103
104 if (!behavior_low_bit)
105 lifecycle_flags = actor->lifecycle_flags;
106
107 if (behavior_low_bit || lifecycle_flags & (ACTOR_LIFECYCLE_DISABLED | ACTOR_LIFECYCLE_DESTROYING))
109 else
110 {
111 actor->lifecycle_flags = lifecycle_flags & ((uint8_t)~ACTOR_LIFECYCLE_HIDDEN);
112 actor->behavior_flags = behavior_flags & ((uint32_t)~ACTOR_BEHAVIOR_ANIMATION_PENDING);
113 }
114
115 Actor_RenderNodeTree(); // ProcessComponentNodes dispatches rendering for all actor components
116 }
117
119
120 if (root_traversal_flags & SCENE_NODE_DISABLED)
121 {
122 actor->sub_pos = (struct Math_Vec3I32){
123 .z = 0,
124 .y = 0,
125 .x = 0};
126
128 }
129 else
131
132 struct Graphics_Render_ListState *render_state = render_list_state;
133
136 render_state->render_actor_ptr = NULL;
137}
138
139// Traverses the current actor's flat render-node list, using subtree counts to skip nodes and dispatching skeletal, morph, trail, audio, and geometry work. It relies on global rendering context and is not reentrant.
140void Actor_RenderNodesWithCachedTick(int32_t node_animation_tick)
141{
142 struct Actor *current_actor =
144 if (current_actor->morph_table_list)
145 {
147 {
148 uint32_t previous_morph_timing =
149 current_actor->previous_morph_timing;
150 struct Animation_DataBlock *morph_animation =
151 current_actor->anim_asset_table->anim_ptrs[(uint32_t)(uint8_t)(previous_morph_timing >> 4)];
152
153 if (morph_animation)
154 {
156 &morph_animation->morph_channels[(int32_t)morph_animation->num_morph_channels - 1],
157 (struct Actor_State *)current_actor);
158 current_actor =
160 }
161 }
162
163 int32_t morph_sequence_index = (uint16_t)(current_actor->anim_seq_index);
164
165 current_actor->previous_morph_timing =
166 ((uint32_t)current_actor->anim_tick << 8 | (uint32_t)morph_sequence_index) << 4;
168 }
169
170 uint8_t actor_lifecycle_flags = current_actor->lifecycle_flags;
171 struct Animation_DataBlock *cached_animation = NULL;
172 struct Actor *owner_actor = render_list_state->render_actor_ptr;
173 if (!owner_actor)
174 owner_actor = current_actor;
175 struct Scene_Type1RenderOwnerView *render_owner = (struct Scene_Type1RenderOwnerView *)owner_actor;
176 struct Scene_Node *owner_node = (struct Scene_Node *)owner_actor;
177 struct Actor_RenderNodeView **render_node_list = current_actor->render_nodes;
178 struct Actor_RenderNodeView *render_node = *render_node_list;
179 struct Actor_RenderNodeView *saved_render_node = render_node;
180 struct Actor_RenderNodeView **node_cursor = &render_node_list[1];
181 int32_t blend_reciprocal_q18 = 0;
182
183 if (render_node)
184 {
185 while (true)
186 {
188 int32_t node_sequence_index = (uint16_t)(render_node->animation_sequence);
189 struct Animation_DataBlock *node_animation =
190 current_actor->anim_asset_table->anim_ptrs[node_sequence_index];
191 int32_t effective_animation_tick;
192
193 if (cached_animation == node_animation)
194 effective_animation_tick = node_animation_tick;
195 else
196 {
197 cached_animation = node_animation;
198
199 if (!node_animation)
200 effective_animation_tick = node_animation_tick;
201 else
202 {
203 effective_animation_tick = current_actor->anim_tick - render_node->animation_start_tick;
204 node_animation_tick = effective_animation_tick;
205
206 if (effective_animation_tick >= ((int32_t)node_animation->keyframe_range.max - (int32_t)node_animation->keyframe_range.min + 1) << 6)
207 {
208 render_node->blend_duration =
209 current_actor->anim_seq_timer;
210
211 int32_t anim_frame_time =
213
214 render_node->animation_start_tick = anim_frame_time;
215
216 struct Actor *actor_after_animation_switch =
218 uint8_t animation_fixup_flags = node_animation->fixup_flags;
219
220 node_animation_tick =
221 actor_after_animation_switch->anim_tick - anim_frame_time;
222
223 if (animation_fixup_flags & ANIMATION_DATA_NODE_STATE)
224 {
225 uint16_t anim_seq_index = (uint16_t)actor_after_animation_switch->anim_seq_index;
226
227 render_node->animation_sequence = anim_seq_index;
228 cached_animation = Actor_ProcessRendering_CurrentRenderActor->anim_asset_table->anim_ptrs[anim_seq_index];
229 }
230
231 effective_animation_tick = node_animation_tick;
232 }
233 else if (node_animation->fixup_flags & ANIMATION_DATA_NODE_STATE)
234 {
235 if (effective_animation_tick >= (int32_t)render_node->blend_duration)
236 {
237 render_node->blend_duration = 0;
238 current_actor =
240 }
241
243 }
244 else
245 render_node->blend_duration =
246 current_actor->anim_seq_timer;
247
248 int32_t blend_duration = (int32_t)render_node->blend_duration;
249
250 blend_reciprocal_q18 = effective_animation_tick >= blend_duration ? 0
251 : ACTOR_ANIMATION_BLEND_UNIT_Q18 / (blend_duration - effective_animation_tick);
252 }
253 }
254
255 struct Scene_TransformNodePrefix *parent_transform = render_node->parent_transform;
256 uint32_t inherited_visibility_flags = parent_transform->lifecycle_or_traversal_flags & (SCENE_NODE_DISABLED | SCENE_NODE_FORCE_REINITIALIZE);
257 uint32_t effective_visibility_flags = inherited_visibility_flags;
258 uint32_t prior_node_flags_for_dispatch;
259 uint8_t visibility_flags_byte;
260 struct Animation_DataBlock *active_animation;
261
262 active_animation = cached_animation;
263
264 if (!inherited_visibility_flags)
265 {
267
268 int32_t animation_visibility_flag;
269
270 if (!active_animation)
271 animation_visibility_flag = 0;
272 else
273 {
274 int32_t visibility_channel = (int32_t)render_node->visibility_channel;
275
276 if (visibility_channel < 0)
277 animation_visibility_flag = 0;
278 else if (!Animation_CheckKeyframeActive(effective_animation_tick,
279 &active_animation->visibility_channels[visibility_channel]))
280 animation_visibility_flag = 0;
281 else
282 animation_visibility_flag = SCENE_NODE_FORCE_REINITIALIZE;
283 }
284
285 inherited_visibility_flags = animation_visibility_flag | (actor_lifecycle_flags & SCENE_NODE_VISIBILITY_HIDDEN);
286 effective_visibility_flags = inherited_visibility_flags;
287 }
288
289 if (inherited_visibility_flags)
290 {
291 visibility_flags_byte = (uint8_t)effective_visibility_flags;
292 prior_node_flags_for_dispatch = prior_node_flags;
293 render_node->flags |= visibility_flags_byte | SCENE_NODE_VISIBILITY_HIDDEN;
294 }
295
296 if (inherited_visibility_flags && ((uint8_t)prior_node_flags_for_dispatch & SCENE_NODE_VISIBILITY_HIDDEN))
297 {
298 node_cursor = &node_cursor[render_node->subtree_skip_count];
300 }
301 else
302 {
303 uint32_t prior_flags_without_render_bit;
304
305 if (inherited_visibility_flags)
306 {
307 prior_flags_without_render_bit = prior_node_flags_for_dispatch;
308 prior_flags_without_render_bit &= ~SCENE_NODE_RENDER_REQUESTED;
309 }
310 else
311 prior_node_flags_for_dispatch = prior_node_flags;
312
313 if (!inherited_visibility_flags || prior_flags_without_render_bit == SCENE_NODE_DISABLED)
314 {
315 if (active_animation)
316 {
317 int32_t position_channel = (int32_t)render_node->position_channel;
318
319 if (position_channel >= 0)
320 {
321 if (blend_reciprocal_q18)
322 Animation_InterpolateKeyframeVec3Blend(effective_animation_tick,
323 blend_reciprocal_q18,
324 &active_animation->position_channels[position_channel],
325 &render_node->local_position);
326 else
327 Animation_InterpolateVec3(effective_animation_tick,
328 &active_animation->position_channels[position_channel],
329 &render_node->local_position);
330 }
331
332 int32_t rotation_channel = (int32_t)render_node->rotation_channel;
333
334 if (rotation_channel < 0)
335 {
336 visibility_flags_byte = (uint8_t)effective_visibility_flags;
337 prior_node_flags_for_dispatch = prior_node_flags;
338 }
339 else if (blend_reciprocal_q18)
340 {
341 struct Math_QuaternionI16 blended_quaternion;
342
343 Math_BuildQuaternionFromMatrix(&render_node->local_rotation, &blended_quaternion);
344 Animation_InterpolateKeyframeQuatBlend(effective_animation_tick,
345 blend_reciprocal_q18 << 2,
346 &cached_animation->rotation_channels[rotation_channel], &blended_quaternion);
347
348 int32_t x = (int32_t)blended_quaternion.x;
349 int32_t quaternion_x_squared = x * x;
350 int32_t y = (int32_t)blended_quaternion.y;
351 int32_t quaternion_y_squared = y * y;
352 int32_t z = (int32_t)blended_quaternion.z;
353 int32_t quaternion_zy_product = z * y;
354 int32_t w = (int32_t)blended_quaternion.w;
355 int32_t quaternion_yx_product = y * x;
356 int32_t quaternion_wx_product = w * x;
357 int32_t quaternion_zx_product = z * x;
358 int32_t quaternion_wz_product = w * z;
359 int32_t quaternion_wy_product = w * y;
360
361 render_node->local_rotation.m00 =
362
363 (int16_t)((PHYSICS_QUATERNION_DIAGONAL_HALF_Q28 - z * z - quaternion_y_squared) >> PHYSICS_QUATERNION_MATRIX_SHIFT);
364 render_node->local_rotation.m10 = (int16_t)((quaternion_yx_product - quaternion_wz_product) >> PHYSICS_QUATERNION_MATRIX_SHIFT);
365 render_node->local_rotation.m20 = (int16_t)((quaternion_wy_product + quaternion_zx_product) >> PHYSICS_QUATERNION_MATRIX_SHIFT);
366 render_node->local_rotation.m01 = (int16_t)((quaternion_wz_product + quaternion_yx_product) >> PHYSICS_QUATERNION_MATRIX_SHIFT);
367 render_node->local_rotation.m11 =
368 (int16_t)((PHYSICS_QUATERNION_DIAGONAL_HALF_Q28 - z * z - quaternion_x_squared) >> PHYSICS_QUATERNION_MATRIX_SHIFT);
369 render_node->local_rotation.m02 = (int16_t)((quaternion_zx_product - quaternion_wy_product) >> PHYSICS_QUATERNION_MATRIX_SHIFT);
370 render_node->local_rotation.m21 = (int16_t)((quaternion_zy_product - quaternion_wx_product) >> PHYSICS_QUATERNION_MATRIX_SHIFT);
371 render_node->local_rotation.m12 = (int16_t)((quaternion_wx_product + quaternion_zy_product) >> PHYSICS_QUATERNION_MATRIX_SHIFT);
372 effective_animation_tick = node_animation_tick;
373 render_node->local_rotation.m22 =
374 (int16_t)((PHYSICS_QUATERNION_DIAGONAL_HALF_Q28 - quaternion_y_squared - quaternion_x_squared) >> PHYSICS_QUATERNION_MATRIX_SHIFT);
375 visibility_flags_byte = (uint8_t)effective_visibility_flags;
376 prior_node_flags_for_dispatch = prior_node_flags;
377 }
378 else
379 {
380 Animation_ConvertQuatToRotMatrix(effective_animation_tick,
381 &cached_animation->rotation_channels[rotation_channel],
382 &render_node->local_rotation);
383 visibility_flags_byte = (uint8_t)effective_visibility_flags;
384 prior_node_flags_for_dispatch = prior_node_flags;
385 }
386 }
387 else
388 visibility_flags_byte = (uint8_t)effective_visibility_flags;
389 }
390
391 int32_t node_type = (uint8_t)(render_node->node_type);
392
393 if (node_type == SCENE_NODE_SUBMESH)
394 {
395 if (prior_node_flags_for_dispatch == SCENE_NODE_RENDER_REQUESTED)
396 {
397 struct Actor *geometry_actor =
399 struct Submesh_RenderSpan *entries = (struct Submesh_RenderSpan *)geometry_actor->attach_point_table;
400 struct Submesh_RenderSpan *geometry_entry = &entries[render_node->render_entry_index];
402 (int32_t)geometry_entry->render_node_entry_index;
403
405 {
406 struct Component_TrailObject *trail = &geometry_actor->trail_chain_ptr[render_node_entry_index - 1];
407 char active;
408
410 active = 1;
411 else
412 active = 0;
413
415
416 if ((active || trail->expiry_countdown) && Trail_UpdateEffect(trail, (struct Actor_State *)geometry_actor, (struct Graphics_Render_PolygonRenderRef *)&geometry_actor->mesh_polygon_array[geometry_entry->polygon_ref_start_index], active))
417 {
420 }
421 }
423 {
424 struct Math_TransformQ12Q6 *geometry_world_transform =
425 &render_node->world_transform;
426
427 g_renderWorldTransformPtr = geometry_world_transform;
428
429 if (owner_actor != geometry_actor)
430 geometry_entry = &render_owner->render_entries[render_node->render_entry_index];
431
432 struct Graphics_Render_SpriteNodeData *sprite_entry = (struct Graphics_Render_SpriteNodeData *)geometry_entry;
433 if (owner_actor == geometry_actor || sprite_entry->node_type != SCENE_NODE_BILLBOARD)
434 {
435 if (geometry_entry->polygon_ref_count > 0)
436 {
437 int32_t secondary_index = (int32_t)render_node->secondary_index;
438
439 if (secondary_index >= 0)
440 {
441 uint32_t packed_morph_timing =
442 render_node->packed_morph_timing;
443 struct Animation_DataBlock *selected_morph_animation =
444 geometry_actor->anim_asset_table->anim_ptrs[(uint32_t)(uint8_t)(packed_morph_timing >> 4)];
445
446 if (selected_morph_animation && render_owner->reserved_b0)
447 {
449 packed_morph_timing >> PHYSICS_FIXED_FRACTION_BITS,
450 &selected_morph_animation->morph_channels[secondary_index],
451 (struct Bone_SkinningOwnerView *)owner_actor, (struct Submesh_Entry *)geometry_entry);
452 geometry_world_transform = g_renderWorldTransformPtr;
453 }
454 }
455
456 Scene_ComposeRenderTransform(geometry_world_transform);
458 (struct Graphics_Render_PolygonRenderRef *)&render_owner->polygon_array[(int32_t)geometry_entry->polygon_ref_start_index],
459 (int32_t)geometry_entry->polygon_ref_count);
460 geometry_world_transform = g_renderWorldTransformPtr;
461 render_node = saved_render_node;
462 effective_animation_tick = node_animation_tick;
463 }
464
465 if (geometry_entry->weighted_vertex_count)
467 geometry_entry, geometry_world_transform);
468 }
469 else
470 Bone_ProcessExternalRef(owner_node, sprite_entry);
471 }
472 }
473
474 if (render_node->secondary_index >= 0)
475 {
476 int32_t packed_morph_sequence_index = (uint16_t)(render_node->animation_sequence);
477
478 render_node->packed_morph_timing =
479 ((uint32_t)effective_animation_tick << 8 | (uint32_t)packed_morph_sequence_index) << 4;
480 }
481 }
482 else if (node_type == SCENE_NODE_BILLBOARD)
483 {
485 {
486 struct Math_TransformQ12Q6 *sprite_world_transform =
487 &render_node->world_transform;
488
489 g_renderWorldTransformPtr = sprite_world_transform;
490
491 struct Submesh_RenderSpan *mesh_render_span = &render_owner->render_entries[render_node->render_entry_index];
492 struct Graphics_Render_SpriteNodeData *sprite_ctx = (struct Graphics_Render_SpriteNodeData *)mesh_render_span;
493
494 if (sprite_ctx->node_type != SCENE_NODE_BILLBOARD)
495 {
496 if (mesh_render_span->polygon_ref_count > 0)
497 {
498 Scene_ComposeRenderTransform(sprite_world_transform);
500 (struct Graphics_Render_PolygonRenderRef *)&render_owner->polygon_array[(int32_t)mesh_render_span->polygon_ref_start_index],
501 (int32_t)mesh_render_span->polygon_ref_count);
502 sprite_world_transform = g_renderWorldTransformPtr;
503 render_node = saved_render_node;
504 effective_animation_tick = node_animation_tick;
505 }
506
507 if (mesh_render_span->weighted_vertex_count)
509 mesh_render_span, sprite_world_transform);
510 }
511 else
512 Bone_ProcessExternalRef(owner_node, sprite_ctx);
513 }
514
515 if (cached_animation && !effective_visibility_flags)
516 {
517 int32_t scale_channel = (int32_t)render_node->scale_channel;
518
519 if (scale_channel >= 0)
520 {
521 struct Math_Vec3I32 interpolated_scale;
522
523 Animation_InterpolateVec3(effective_animation_tick,
524 &cached_animation->scale_channels[scale_channel], &interpolated_scale);
525 Actor_ProcessRendering_CurrentRenderActor->attach_point_table[(int32_t)
526 render_node->render_entry_index]
527 .bound_extent.x =
528 (int16_t)(interpolated_scale.x >> 6);
529 Actor_ProcessRendering_CurrentRenderActor->attach_point_table[(int32_t)
530 render_node->render_entry_index]
531 .bound_extent.y =
532 (int16_t)(interpolated_scale.y >> 6);
533 }
534 }
535 }
536
538 {
539 int64_t node_world_position_x_product_x = (int64_t)(int32_t)parent_transform->world_rot_matrix.m00 * render_node->local_position.x;
540 int64_t node_world_position_x_product_y = (int64_t)(int32_t)parent_transform->world_rot_matrix.m01 * render_node->local_position.y;
541 int64_t node_world_position_x_partial_sum = node_world_position_x_product_x + node_world_position_x_product_y;
542 int64_t node_world_position_x_product_z = (int64_t)(int32_t)parent_transform->world_rot_matrix.m02 * render_node->local_position.z;
543
544 saved_render_node->world_position.x = parent_transform->world_position.x + ((int32_t)((node_world_position_x_product_z + node_world_position_x_partial_sum) >> PHYSICS_FIXED_FRACTION_BITS));
545
546 int64_t node_world_position_y_product_x = (int64_t)(int32_t)parent_transform->world_rot_matrix.m10 * render_node->local_position.x;
547 int64_t node_world_position_y_product_y = (int64_t)(int32_t)parent_transform->world_rot_matrix.m11 * render_node->local_position.y;
548 int64_t node_world_position_y_partial_sum = node_world_position_y_product_x + node_world_position_y_product_y;
549 int64_t node_world_position_y_product_z = (int64_t)(int32_t)parent_transform->world_rot_matrix.m12 * render_node->local_position.z;
550
551 saved_render_node->world_position.y = parent_transform->world_position.y + ((int32_t)((node_world_position_y_product_z + node_world_position_y_partial_sum) >> PHYSICS_FIXED_FRACTION_BITS));
552
553 int64_t node_world_position_z_product_x = (int64_t)(int32_t)parent_transform->world_rot_matrix.m20 * render_node->local_position.x;
554 int64_t node_world_position_z_product_y = (int64_t)(int32_t)parent_transform->world_rot_matrix.m21 * render_node->local_position.y;
555 int64_t node_world_position_z_partial_sum = node_world_position_z_product_x + node_world_position_z_product_y;
556 int64_t node_world_position_z_product_z = (int64_t)(int32_t)parent_transform->world_rot_matrix.m22 * render_node->local_position.z;
557 bool skip_world_rotation_update = saved_render_node->flags & SCENE_NODE_RESET_REQUESTED;
558
559 saved_render_node->world_position.z = parent_transform->world_position.z + ((int32_t)((node_world_position_z_product_z + node_world_position_z_partial_sum) >> PHYSICS_FIXED_FRACTION_BITS));
560
561 if (!skip_world_rotation_update)
562 {
563 Math_MulMat3x3Q12(&saved_render_node->world_rotation,
564 &saved_render_node->local_rotation,
565 &parent_transform->world_rot_matrix);
566
567 if (node_type == SCENE_SOUND_EVENT_INDEX && saved_render_node->render_entry_index == 3)
568 {
569 struct Actor *joint_tracking_actor =
571 int32_t tracking_component_index = (uint8_t)(saved_render_node->secondary_index);
572 struct Actor_State *tracking_reference_actor;
573 int32_t explicit_reference_joint_index;
574
575 if (joint_tracking_actor->behavior_flags & ACTOR_BEHAVIOR_GROUND_TRACKING)
576 explicit_reference_joint_index =
578 (struct Actor_State *)joint_tracking_actor, &tracking_reference_actor,
579 UINT32_MAX - tracking_component_index);
580 else
581 {
582 explicit_reference_joint_index = 0;
583 tracking_reference_actor = NULL;
584 }
585
587 &joint_tracking_actor->component_array[tracking_component_index - 1],
588 tracking_reference_actor, explicit_reference_joint_index);
589 }
590 }
591
592 current_actor =
594 }
595 else
596 {
597 render_node->flags &= ((uint8_t)~SCENE_NODE_VISIBILITY_HIDDEN);
598
599 struct Actor *sound_event_actor =
601
602 sound_event_actor->lifecycle_flags &= ((uint8_t)~ACTOR_LIFECYCLE_HIDDEN);
603 current_actor =
605
606 if (effective_animation_tick < (int32_t)current_actor->move_anim_speed)
607 {
608 if (visibility_flags_byte & SCENE_NODE_FORCE_REINITIALIZE)
609 {
610 int32_t sound_index = (uint8_t)(render_node->secondary_index);
611
612 if (sound_index >= 0)
613 {
614 char render_entry_index = render_node->render_entry_index;
615
616 if (!(render_entry_index & ACTOR_RENDER_ENTRY_INITIALIZED))
617 {
618 if (render_entry_index)
619 {
620 render_node->render_entry_index = render_entry_index | ACTOR_RENDER_ENTRY_INITIALIZED;
621 current_actor =
623 }
624
626 &current_actor->position);
627 current_actor =
629 }
630 }
631 }
632 else
633 {
634 render_node->render_entry_index &= ((uint8_t)~ACTOR_RENDER_ENTRY_INITIALIZED);
635
636 int32_t sound_index_or_mode = (uint8_t)(render_node->secondary_index);
637
638 Audio_StopOrUpdateSoundsAtPosition(sound_index_or_mode,
640 current_actor =
642 }
643 }
644 else if ((visibility_flags_byte ^ (uint8_t)prior_node_flags) & SCENE_NODE_FORCE_REINITIALIZE)
645 {
646 int32_t sound_index = (uint8_t)(render_node->secondary_index);
647
648 if (sound_index >= 0)
649 {
650 char render_entry_index = render_node->render_entry_index;
651
652 if (!(render_entry_index & ACTOR_RENDER_ENTRY_INITIALIZED))
653 {
654 if (render_entry_index)
655 {
656 render_node->render_entry_index = render_entry_index | ACTOR_RENDER_ENTRY_INITIALIZED;
657 current_actor =
659 }
660
662 &current_actor->position);
663 current_actor =
665 }
666 }
667 }
668 }
669 }
670
671 saved_render_node = *node_cursor;
672 node_cursor = &node_cursor[1];
673
674 if (!saved_render_node)
675 break;
676
677 render_node = saved_render_node;
678 }
679 }
680
681 Scene_FinalizeNodeRender(owner_node);
682}
683
684// Original pcdogs.exe: 0x4342e0
685// Updates world render translation from actor position, optionally adding the rotated shape origin.
687{
688 /* 43431b..4343d5 uses IMUL/ADD/ADC/SHRD for full 64-bit dot products. */
689 const struct Actor_CollisionShapeNodeView *shape =
690 (const void *)actor->collision_component_or_parent_component;
691
692 if (!shape)
693 {
694 actor->world_render_pos = actor->position;
695
696 return;
697 }
698
699 const int16_t *matrix = (const int16_t *)&actor->rot_mat;
700 const int32_t *local = (const int32_t *)((const uint8_t *)shape + 0x20);
701 int32_t *world = (int32_t *)&actor->world_render_pos;
702 const int32_t *position = (const int32_t *)&actor->position;
703
704 for (int row = 0; row < 3; ++row)
705 {
706 int64_t dot = (int64_t)matrix[row * 3] * local[0] +
707 (int64_t)matrix[row * 3 + 1] * local[1] + (int64_t)matrix[row * 3 + 2] * local[2];
708
709 world[row] = (uint32_t)position[row] + (uint32_t)(dot >> PHYSICS_FIXED_FRACTION_BITS);
710 }
711}
712
713// Original pcdogs.exe: 0x43ace0
714// Moves the fade value toward zero or 127, copies it into the color channels, and updates fade-state flags. The step divisor uses the requested step count plus one.
715void Actor_SetAlphaFade(struct Actor_State *actor, int32_t fade_steps, int32_t fade_in)
716{
717 char updated_alpha;
718 struct Actor_State *fading_actor;
719
720 if (fade_in)
721 {
722 fading_actor = actor;
723
724 int32_t previous_fade_in_alpha = (uint8_t)(fading_actor->fade_alpha);
725
726 updated_alpha = (char)((int64_t)(ACTOR_FADE_ALPHA_MAX - previous_fade_in_alpha) / (fade_steps + 1)) + (uint8_t)previous_fade_in_alpha;
727
728 if (!fade_steps)
729 fading_actor->behavior_flags &= ((int32_t)((uint32_t)~(ACTOR_FADE_MODE_LOW | ACTOR_FADE_OUT | ACTOR_FADE_MODE_HIGH | ACTOR_FADE_ACTIVE)));
730 }
731 else
732 {
733 fading_actor = actor;
734
735 int32_t behavior_flags = fading_actor->behavior_flags;
736
738 {
739 fading_actor->fade_color.b = ACTOR_FADE_ALPHA_MAX;
741 }
742
743 int32_t previous_fade_out_alpha = (uint8_t)(fading_actor->fade_alpha);
744
745 updated_alpha = (uint8_t)previous_fade_out_alpha - (char)((int64_t)previous_fade_out_alpha / (fade_steps + 1));
746 }
747
748 fading_actor->fade_color.r = updated_alpha;
749 fading_actor->fade_color.g = updated_alpha;
750 fading_actor->fade_color.b = (uint8_t)updated_alpha;
751}
752
753// Original pcdogs.exe: 0x43ad80
754// Starts or decrements a signed fade timer, updates alpha, and marks the actor for removal when the timer expires. It returns a byte-sized completion flag.
755uint8_t Actor_UpdateFadeOut(struct Actor_State *actor, int16_t fade_ticks)
756{
758 {
759 struct Actor_State *child_actor = actor->child_actor;
760
761 actor->fade_timer = fade_ticks;
762 actor->movement_handler_index = 0;
763 actor->collision_class = 0;
764
765 if (child_actor)
767
769 }
770 else
771 {
772 actor->fade_timer -= 1;
773 Actor_SetAlphaFade(actor, (int32_t)actor->fade_timer, 0);
774
775 if (!actor->fade_timer)
776 {
778
779 return 1;
780 }
781 }
782
783 return 0;
784}
#define ACTOR_BEHAVIOR_SKIP_UPDATE
Definition constants.h:7
#define ACTOR_FADE_MODE_LOW
Definition constants.h:116
#define ACTOR_BEHAVIOR_ANIMATION_PENDING
Definition constants.h:27
#define ACTOR_BEHAVIOR_MOVEMENT_LOCKED
Definition constants.h:16
#define ACTOR_RENDER_ENTRY_INDEX_MASK
Definition constants.h:86
#define ACTOR_RENDER_EXCLUDED_DISTANCE
Definition constants.h:220
#define ACTOR_RENDER_EXCLUDED_RANGE_END
Definition constants.h:222
#define ACTOR_LIFECYCLE_HIDDEN
Definition constants.h:40
#define ACTOR_RENDER_EXCLUDED_RANGE_BEGIN
Definition constants.h:221
#define ACTOR_FADE_MODE_HIGH
Definition constants.h:118
#define ACTOR_LIFECYCLE_DISABLED
Definition constants.h:39
#define ACTOR_BEHAVIOR_GROUND_TRACKING
Definition constants.h:12
#define ACTOR_RENDER_ENTRY_INITIALIZED
Definition constants.h:85
#define ACTOR_LIFECYCLE_DESTROYING
Definition constants.h:43
#define ACTOR_FADE_ACTIVE
Definition constants.h:119
#define ACTOR_ANIMATION_BLEND_UNIT_Q18
Definition constants.h:223
#define ACTOR_FADE_OUT
Definition constants.h:117
#define ACTOR_BEHAVIOR_FADE_DESTROY
Definition constants.h:29
#define ACTOR_FADE_ALPHA_MAX
Definition constants.h:202
#define ACTOR_BEHAVIOR_TRAIL_OVERRIDE
Definition constants.h:10
#define ACTOR_BEHAVIOR_BYPASS_COLLISION
Definition constants.h:18
@ ACTOR_RENDER_DISTANCE_RANGE_EXCLUSION
Definition constants.h:238
void Actor_UpdateAnimationAndVisibility(struct Actor_State *actor)
Definition animation.c:45
void Actor_RenderNodeTree(void)
#define Actor_ProcessRendering_CurrentRenderActor
Definition globals.h:64
void Actor_UpdateWorldRenderPosition(struct Actor_State *actor)
Definition rendering.c:686
void Actor_RenderNodesWithCachedTick(int32_t node_animation_tick)
Definition rendering.c:140
uint8_t Actor_UpdateFadeOut(struct Actor_State *actor, int16_t fade_ticks)
Definition rendering.c:755
void Actor_ProcessRendering(struct Actor_State *actor)
Definition rendering.c:86
BOOL Actor_PassesPauseCameraCoordinateGate(struct Actor_State *actor)
Definition rendering.c:40
void Actor_SetAlphaFade(struct Actor_State *actor, int32_t fade_steps, int32_t fade_in)
Definition rendering.c:715
#define ANIMATION_DATA_NODE_STATE
Definition constants.h:33
void Bone_TransformWeightedVerticesForRender(struct Scene_Node *node, struct Submesh_RenderSpan *weighted_span, struct Math_TransformQ12Q6 const *world_transform)
Definition skinning.c:308
void Bone_UpdateJointTracking(struct Bone_JointTrackState *track, struct Actor_State *target_actor, int32_t explicit_reference_joint_index)
void Bone_TransformVerticesMorphed(uint32_t sample_time, struct Animation_SplineChannelMorph *morph_channels, struct Actor_State *actor)
Definition skinning.c:84
void Bone_TransformVerticesWeighted(uint32_t sample_time, struct Animation_SplineChannelMorph *bone_channels, struct Bone_SkinningOwnerView *actor, struct Submesh_Entry *mesh_piece)
Definition skinning.c:132
void Animation_InterpolateVec3(uint32_t frame_time, struct Animation_SplineChannelVec3 *vec3_track, struct Math_Vec3I32 *out_vec3)
void Animation_InterpolateKeyframeQuatBlend(uint32_t frame_time, int32_t blend_weight_q14, struct Animation_SplineChannelQuat *quat_track, struct Math_QuaternionI16 *inout_quat)
Definition quaternion.c:48
void Animation_ConvertQuatToRotMatrix(uint32_t frame_time, struct Animation_SplineChannelQuat *quat_track, struct Math_Matrix3x3I16 *out_matrix)
Definition quaternion.c:262
void Bone_ProcessExternalRef(struct Scene_Node *node, struct Graphics_Render_SpriteNodeData *sprite_ctx)
uint8_t Animation_CheckKeyframeActive(uint32_t sample_time, struct Animation_SplineChannelVis *channel)
Definition controller.c:17
void Animation_InterpolateKeyframeVec3Blend(uint32_t frame_time, int32_t blend_weight_q12, struct Animation_SplineChannelVec3 *vec3_track, struct Math_Vec3I32 *inout_vec3)
void Audio_PlayLevelSoundIndexAtPosition(int32_t sound_index, struct Math_Vec3I32 *position)
Definition spatial.c:52
void Audio_StopOrUpdateSoundsAtPosition(int32_t sound_index_or_mode, struct Math_Vec3I32 *position, char looping_only)
Definition spatial.c:76
#define Collision_ProcessActorToActorCollisions_StateHandlerTable
Definition globals.h:78
#define GAME_TRANSITION_OBJECT_VISIBLE
Definition constants.h:29
#define Game_FrameTransitionFlags
Definition globals.h:47
#define g_currentGameMode
Definition globals.h:74
void Graphics_UpdateMeshCommandState(struct Mesh_CmdList *cmd_list)
Definition meshes.c:109
void Graphics_RenderSceneGeometry(struct Scene_Node *node, struct Graphics_Render_PolygonRenderRef *polygon_refs, int32_t count)
Definition geometry.c:31
#define g_graphicsCapabilityFlags
Definition globals.h:158
#define render_list_state
Definition globals.h:152
void Math_BuildQuaternionFromMatrix(struct Math_Matrix3x3I16 *matrix, struct Math_QuaternionI16 *output_quat)
Definition matrices.c:250
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 g_renderWorldTransformPtr
Definition globals.h:27
#define PHYSICS_QUATERNION_DIAGONAL_HALF_Q28
Definition constants.h:32
#define PHYSICS_QUATERNION_MATRIX_SHIFT
Definition constants.h:31
#define PHYSICS_FIXED_FRACTION_BITS
Definition constants.h:6
#define SCENE_NODE_RESET_REQUESTED
Definition constants.h:26
#define SCENE_NODE_VISIBILITY_HIDDEN
Definition constants.h:25
#define SCENE_NODE_FORCE_REINITIALIZE
Definition constants.h:32
#define SCENE_SOUND_EVENT_INDEX
Definition constants.h:52
#define SCENE_NODE_DISABLED
Definition constants.h:24
#define SCENE_NODE_RENDER_REQUESTED
Definition constants.h:27
#define SCENE_TRAIL_ACTIVE
Definition constants.h:49
@ SCENE_NODE_SUBMESH
Definition constants.h:13
@ SCENE_NODE_BILLBOARD
Definition constants.h:14
void Scene_ComposeRenderTransform(const struct Math_TransformQ12Q6 *world)
Definition rendering.c:550
void Scene_FinalizeNodeRender(struct Scene_Node *node)
Definition rendering.c:805
#define Script_OpPauseToggle_SavedActorWorldRenderPosZ
Definition globals.h:51
#define Script_OpPauseToggle_SavedActorWorldRenderPosX
Definition globals.h:45
#define Script_OpPauseToggle_SavedActorWorldRenderPosY
Definition globals.h:48
union Actor_CollisionShapeExtentOverlay shape
Definition types.h:562
uint32_t packed_morph_timing
Definition types.h:367
struct Math_Matrix3x3I16 local_rotation
Definition types.h:340
struct Math_Vec3I32 world_position
Definition types.h:352
uint8_t node_type
Definition types.h:363
uint16_t animation_sequence
Definition types.h:360
char visibility_channel
Definition types.h:358
int32_t animation_start_tick
Definition types.h:362
struct Math_Vec3I32 local_position
Definition types.h:342
struct Math_Matrix3x3I16 world_rotation
Definition types.h:350
int16_t blend_duration
Definition types.h:361
struct Math_TransformQ12Q6 world_transform
Definition types.h:346
uint32_t subtree_skip_count
Definition types.h:338
int8_t render_entry_index
Definition types.h:365
struct Scene_TransformNodePrefix * parent_transform
Definition types.h:339
uint8_t collision_class
Definition types.h:435
struct Animation_ControllerGroup * anim_ctrl_ptr
Definition types.h:401
struct Component_Instance * collision_component_or_parent_component
Definition types.h:437
struct Scene_Node ** render_node_list
Definition types.h:440
struct Math_ColorBGRA8 fade_color
Definition types.h:483
uint8_t lifecycle_flags
Definition types.h:392
uint8_t movement_handler_index
Definition types.h:433
struct Actor_State * child_actor
Definition types.h:478
struct Mesh_Polygon * mesh_polygon_array
Definition types.h:396
int32_t behavior_flags
Definition types.h:407
struct Math_Vec3I32 world_render_pos
Definition types.h:420
int16_t fade_timer
Definition types.h:438
struct Math_Vec3I32 sub_pos
Definition types.h:386
struct Math_Matrix3x3I16 rot_mat
Definition types.h:383
struct Math_Vec3I32 position
Definition types.h:385
int32_t fade_alpha
Definition types.h:482
Definition types.h:118
int16_t anim_seq_timer
Definition types.h:136
struct Animation_StateTable * anim_asset_table
Definition types.h:178
uint8_t lifecycle_flags
Definition types.h:139
struct Math_Vec3I32 position
Definition types.h:132
struct Bone_JointTrackState * component_array
Definition types.h:185
int16_t ** morph_table_list
Definition types.h:216
int16_t anim_seq_index
Definition types.h:135
struct Graphics_Render_SpriteNodeData * attach_point_table
Definition types.h:172
int32_t anim_frame_time
Definition types.h:137
int32_t behavior_flags
Definition types.h:160
int32_t anim_tick
Definition types.h:180
struct Component_TrailObject * trail_chain_ptr
Definition types.h:184
int16_t move_anim_speed
Definition types.h:181
struct Actor_RenderNodeView ** render_nodes
Definition types.h:197
uint32_t previous_morph_timing
Definition types.h:124
char num_morph_channels
Definition types.h:752
Animation_DataBlockFixupFlags fixup_flags
Definition types.h:761
struct Animation_SplineChannelVec3 * scale_channels
Definition types.h:767
struct Animation_SplineChannelVec3 * position_channels
Definition types.h:764
struct Animation_SplineChannelMorph * morph_channels
Definition types.h:768
struct Animation_SplineChannelVis * visibility_channels
Definition types.h:766
struct Math_RangeI16 keyframe_range
Definition types.h:763
struct Animation_SplineChannelQuat * rotation_channels
Definition types.h:765
struct Animation_DataBlock * anim_ptrs[0x2b]
Definition types.h:422
uint8_t expiry_countdown
Definition types.h:235
struct Actor * render_actor_ptr
Definition types.h:682
struct Math_Vec3I32XZY eye_pos
Definition types.h:672
uint8_t b
Definition types.h:25
uint8_t g
Definition types.h:26
uint8_t r
Definition types.h:27
int16_t m21
Definition types.h:169
int16_t m00
Definition types.h:162
int16_t m01
Definition types.h:163
int16_t m12
Definition types.h:167
int16_t m11
Definition types.h:166
int16_t m20
Definition types.h:168
int16_t m22
Definition types.h:170
int16_t m02
Definition types.h:164
int16_t m10
Definition types.h:165
int16_t max
Definition types.h:232
int16_t min
Definition types.h:231
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
uint8_t traversal_flags
Definition types.h:130
struct Math_Matrix3x3I16 world_rot_matrix
Definition types.h:260
struct Math_Vec3I32 world_position
Definition types.h:262
uint8_t lifecycle_or_traversal_flags
Definition types.h:269
struct Mesh_Polygon * polygon_array
Definition types.h:326
struct Submesh_RenderSpan * render_entries
Definition types.h:348
Definition types.h:322
char render_node_entry_index
Definition types.h:349
int16_t polygon_ref_start_index
Definition types.h:352
int16_t weighted_vertex_count
Definition types.h:355
int16_t polygon_ref_count
Definition types.h:353
char Trail_UpdateEffect(struct Component_TrailObject *trail, struct Actor_State const *actor, struct Graphics_Render_PolygonRenderRef const *polygon_ref, char active)
Definition effects.c:72
void Trail_UpdateAndRenderActorTrails(struct Actor_State *actor)
Definition effects.c:44
void Trail_RenderAnimated(struct Trail_RenderRuntimeView *trail, struct Actor_State *actor, struct Submesh_RenderSpan *span)
Definition effects.c:304