102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
animation.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
14#include "pcdogs/actor/types.h"
19#include "pcdogs/entity/types.h"
20#include "pcdogs/game/globals.h"
21#include "pcdogs/game/types.h"
28#include "pcdogs/level/types.h"
31#include "pcdogs/math/globals.h"
32#include "pcdogs/math/types.h"
35#include "pcdogs/scene/types.h"
37#include "pcdogs/script/types.h"
39#include <math.h>
40#include <stdarg.h>
41#include <string.h>
42
43// Original pcdogs.exe: 0x403800
44// Updates animation and render visibility, then prepares primary or alternate geometry. Temporary command-list fields are restored after processing.
46{
47 struct Actor_State *render_actor = actor;
48 // Check if actor needs visibility processing: bit 0 of object_flags at offset 0x30 indicates already
49 // processed
50 struct Actor_State *interpolated_child = NULL;
51 char needs_visibility_update = ~render_actor->behavior_flags & ACTOR_BEHAVIOR_SKIP_UPDATE;
52 int16_t saved_child_height;
53 int16_t saved_child_width;
54
55 if (needs_visibility_update)
56 {
57 // object_flags & 0x11000000: Check FORCE_VISIBLE (0x10000000) and ALWAYS_RENDER (0x01000000) flags
58 int32_t processed_behavior_flags = render_actor->behavior_flags | ACTOR_BEHAVIOR_SKIP_UPDATE;
59
60 render_actor->behavior_flags = processed_behavior_flags;
61
62 if (processed_behavior_flags & (ACTOR_BEHAVIOR_FORCE_VISIBLE | ACTOR_BEHAVIOR_WORKLIST_MEMBER))
63 {
64 uint32_t visible_frame_flags = Game_FrameTransitionFlags | GAME_TRANSITION_OBJECT_VISIBLE;
65
66 Game_FrameTransitionFlags = visible_frame_flags;
67 }
68
69 if ((processed_behavior_flags & (ACTOR_BEHAVIOR_FORCE_VISIBLE | ACTOR_BEHAVIOR_WORKLIST_MEMBER)) ||
73 (int32_t)render_actor->cull_radius, processed_behavior_flags & ACTOR_BEHAVIOR_CULL_MODE) ||
75 {
76 if ((struct Actor *)render_actor == g_scriptPauseToggleState &&
79 return;
80
82 {
83 // Offset 0xa0: component_mesh_header - pointer to ComponentInstance containing mesh rendering data
84 uint32_t distance_gate_frame_flags_before_update = Game_FrameTransitionFlags;
85 uint32_t distance_gate_frame_flags;
86
88 distance_gate_frame_flags = distance_gate_frame_flags_before_update | GAME_TRANSITION_COLOR_FADE;
89 else
90 distance_gate_frame_flags = distance_gate_frame_flags_before_update & ((uint32_t)~GAME_TRANSITION_COLOR_FADE);
91
92 Game_FrameTransitionFlags = distance_gate_frame_flags;
93 }
94
95 int32_t behavior_flags = render_actor->behavior_flags;
96
98 {
100
101 fade_capability_bits |= ACTOR_BEHAVIOR_BYPASS_COLLISION;
102 g_graphicsCapabilityFlags = fade_capability_bits << 0xd | (render_actor->fade_alpha & ACTOR_RENDER_FADE_COLOR_MASK);
103 }
104
105 int32_t completed_update_flags = render_actor->behavior_flags;
106
107 // LOD distance fading: distances ACTOR_LOD_SHRINK_START_DISTANCE to ACTOR_LOD_SHRINK_END_DISTANCE fade from full to half scale. g_renderingDepth set to
108 // component position at offset 0x2c
109 completed_update_flags &= ~ACTOR_BEHAVIOR_SKIP_UPDATE;
110 render_actor->behavior_flags = completed_update_flags;
111 }
112
113 struct Actor_State *child_actor = render_actor->child_actor;
114
116 {
117 uint8_t child_lifecycle_flags = child_actor->lifecycle_flags;
118
119 if (!render_actor->ground_collision_node)
120 child_actor->lifecycle_flags = (uint8_t)child_lifecycle_flags | ACTOR_LIFECYCLE_HIDDEN;
121 else if (!((uint8_t)child_lifecycle_flags & (ACTOR_LIFECYCLE_DISABLED | ACTOR_LIFECYCLE_HIDDEN)))
122 // Subtract velocity (offsets 0x4c-0x54) from position (offsets 0x40-0x48) for interpolated rendering
123 {
124 // Component mesh data layout: 0x2c=render_position, 0x40-0x48=world_pos XYZ, 0x4c-0x54=velocity XYZ,
125 // 0x65=render_flags, 0x68=lod_scale_x, 0x6a=lod_scale_y
126 uint16_t child_width_bits = child_actor->visual_scale.x;
127
128 if ((uint16_t)child_width_bits)
129 {
130 uint16_t child_height_bits = child_actor->visual_scale.y;
131
132 saved_child_height = child_height_bits;
133
134 if ((uint16_t)child_height_bits)
135 {
136 interpolated_child = child_actor;
138
139 // LOD fade calculation: distance range ACTOR_LOD_SHRINK_START_DISTANCE (40960) to ACTOR_LOD_SHRINK_END_DISTANCE (409600) maps to scale 0x1000 (full) down to
140 // ACTOR_LOD_MINIMUM_SCALE_Q12 (half)
141 int32_t child_position_y = interpolated_child->position.y;
142 int32_t child_position_z = interpolated_child->position.z;
143
144 interpolated_child->position.x -= interpolated_child->sub_pos.x;
145
146 int32_t interpolated_child_y = child_position_y - interpolated_child->sub_pos.y;
147
148 interpolated_child->position.y = interpolated_child_y;
149 interpolated_child->position.z = child_position_z - interpolated_child->sub_pos.z;
150
151 int32_t parent_child_y_distance = render_actor->position.y - render_actor->sub_pos.y - interpolated_child_y;
152
153 saved_child_width = interpolated_child->visual_scale.x;
154 saved_child_height = interpolated_child->visual_scale.y;
155
156 if (parent_child_y_distance > ACTOR_LOD_SHRINK_START_DISTANCE)
157 {
158 int32_t child_lod_scale_q12;
159
160 if (parent_child_y_distance <= ACTOR_LOD_SHRINK_END_DISTANCE)
161 {
162 int64_t distance_ramp_wide = (int64_t)(ACTOR_LOD_SHRINK_RAMP_MULTIPLIER) * (parent_child_y_distance - ACTOR_LOD_SHRINK_START_DISTANCE);
163 int32_t distance_ramp_high = (int32_t)((uint64_t)distance_ramp_wide >> 32);
164 int32_t distance_ramp_low = (uint32_t)distance_ramp_wide;
165
166 child_lod_scale_q12 = PHYSICS_FIXED_ONE - ((int32_t)((uint64_t)(((int64_t)(ACTOR_LOD_MINIMUM_SCALE_Q12) * ((int32_t)((uint32_t)distance_ramp_low >> PHYSICS_FIXED_FRACTION_BITS | (uint32_t)distance_ramp_high << PHYSICS_Q12_PRODUCT_HIGH_SHIFT)))) >> PHYSICS_FIXED_FRACTION_BITS));
167 }
168 else
169 child_lod_scale_q12 = ACTOR_LOD_MINIMUM_SCALE_Q12;
170
171 interpolated_child->visual_scale = (struct Math_Vec2I16){
172 .x = (int16_t)(((int32_t)saved_child_width * child_lod_scale_q12) >> PHYSICS_FIXED_FRACTION_BITS),
173 .y = (int16_t)(((int32_t)saved_child_height * child_lod_scale_q12) >> PHYSICS_FIXED_FRACTION_BITS)};
174 }
175 }
176 }
177 }
178 else
179 child_actor->lifecycle_flags = (uint8_t)child_lifecycle_flags & ((uint8_t)~ACTOR_LIFECYCLE_HIDDEN);
180 }
181 }
182
183 int32_t visibility_behavior_flags = render_actor->behavior_flags;
184
185 visibility_behavior_flags &= ~ACTOR_BEHAVIOR_VISIBILITY_PENDING;
186 render_actor->behavior_flags = visibility_behavior_flags;
187
188 if (!needs_visibility_update || (uint8_t)visibility_behavior_flags & ACTOR_BEHAVIOR_SKIP_ANIMATION)
189 {
190 render_list_state->render_actor_ptr = NULL;
191 // Calculate camera distance using ApproximateVector3DMagnitude for LOD/animation selection
193 }
194
196 {
197 struct Graphics_Render_ListState *render_list_state_1 = render_list_state;
198 int32_t camera_distance = Math_ApproxDistance3DWeighted(
199 render_list_state_1->eye_pos.x - render_actor->world_render_pos.x,
200 render_list_state_1->eye_pos.z - render_actor->world_render_pos.y,
201 render_list_state_1->eye_pos.y - render_actor->world_render_pos.z);
202 int32_t lod_flags_or_distance_limit = render_actor->behavior_flags;
203 bool use_primary_mesh = (lod_flags_or_distance_limit & ACTOR_BEHAVIOR_FORCE_PRIMARY_LOD) != 0;
204 struct Pkg_ActorTemplate const *lod_template;
205
206 if (!use_primary_mesh)
207 {
208 lod_template = render_actor->level_local_lod_redirect_record;
209
210 if (!lod_template)
211 use_primary_mesh = true;
212 else if (!(lod_flags_or_distance_limit & ACTOR_BEHAVIOR_FORCE_ALTERNATE_LOD))
213 {
214 // ComponentMeshHeader.lod_distance_threshold (+0x0E) - compare against camera distance
215 // for LOD switch
216 lod_flags_or_distance_limit = (uint16_t)lod_template->lod_distance_threshold;
217
218 // LOD mesh header layout: 0x4=mesh_ptr, 0xe=distance_threshold,
219 // 0x7c=animation_controller_ptr
220 use_primary_mesh = camera_distance >> 6 <= lod_flags_or_distance_limit ||
222 }
223 }
224
225 if (use_primary_mesh)
226 {
227 struct Mesh_CmdList *base_command_list = (struct Mesh_CmdList *)(render_actor->anim_ctrl_ptr);
228
229 if (base_command_list)
230 {
231 int16_t saved_command_count = base_command_list->count;
232
233 // Animation_ControllerGroup::active_controller_count (+1) is zero-extended and temporarily written into
234 // controller_count (+2) for this Render_ProcessMeshCommands call; the original 16-bit controller_count is
235 // restored afterward.
236 base_command_list->count = (uint16_t)base_command_list->base_command_count;
237
238 struct Material_Node **material_nodes_base = (struct Material_Node **)(uintptr_t)((uint32_t)(uint16_t)render_actor->chain_timer | ((uint32_t)(uint16_t)render_actor->chain_state << 16));
239
240 Graphics_ProcessMeshCommands(base_command_list, material_nodes_base, render_actor);
241 // Restore original Animation_ControllerGroup::controller_count after processing only
242 // active_controller_count entries.
243 base_command_list->count = saved_command_count;
244 }
245 }
246 else
247 {
248 // ComponentMeshHeader.mesh_instance_ptr (+0x04) - get alternate ComponentInstance for LOD
249 // rendering
250 render_list_state->render_actor_ptr = (struct Actor *)(lod_template->alternate_lod_node);
251
252 struct Scene_Type1RenderOwnerView *alternate_render_owner =
253 (struct Scene_Type1RenderOwnerView *)(render_list_state->render_actor_ptr);
254 // ComponentMeshHeader.animation_controller_ptr (+0x7C) - get animation controller list for
255 // LOD mesh
256 struct Mesh_CmdList *lod_command_list = alternate_render_owner->command_list;
257
258 if (lod_command_list)
259 {
260 uint32_t lod_command_slice_index = (uint32_t)(lod_command_list->cmdPtrs);
261
262 lod_command_list->cmdPtrs =
263 (void *)((uint8_t *)render_actor->anim_ctrl_ptr->controller_slot_array + lod_command_slice_index * 4);
264
265 struct Material_Node **material_nodes = (struct Material_Node **)(uintptr_t)((uint32_t)(uint16_t)render_actor->chain_timer | ((uint32_t)(uint16_t)render_actor->chain_state << 16));
266
267 Graphics_ProcessMeshCommands(lod_command_list, material_nodes,
268 alternate_render_owner);
269 // Use primary animation controller at offset 0x24, update with anim data from offset 0x20
270 lod_command_list->cmdPtrs = (struct Mesh_Command **)(lod_command_slice_index);
271 }
272 }
273 }
274
275 if (interpolated_child)
276 {
278 interpolated_child->position = (struct Math_Vec3I32){
279 .x = interpolated_child->position.x + interpolated_child->sub_pos.x,
280 .z = interpolated_child->position.z + interpolated_child->sub_pos.z,
281 .y = interpolated_child->position.y + interpolated_child->sub_pos.y};
282
283 interpolated_child->visual_scale = (struct Math_Vec2I16){
284 .x = saved_child_width,
285 .y = saved_child_height};
286 }
287}
288
289// Original pcdogs.exe: 0x40aa90
290// Selects actor animation from movement, airborne, attachment, and forced states, queuing transitions when allowed. The ground selector is tested as zero or nonzero, and selected transitions wait for Q12 animation progress to reach one.
291void Actor_UpdateAnimationState(struct Actor_State *actor, struct Player_ControllerRecordView *record, int32_t surface_trail_mode)
292{
293 struct Actor_State *animation_actor = actor;
294 // Get current animation index to determine state transition
295 int32_t previous_animation_state = Actor_GetAnimSeqIndex(animation_actor);
296 int32_t effective_previous_state = previous_animation_state;
297
298 if (previous_animation_state == ACTOR_ANIMATION_DEATH)
299 return;
300
301 int32_t next_animation_state = previous_animation_state;
302
303 if (((*(struct Scene_Node **)animation_actor->render_node_list)->traversal_flags & SCENE_NODE_DISABLED) ||
304 ((previous_animation_state == ACTOR_ANIMATION_JUMP_START || previous_animation_state == ACTOR_ANIMATION_DAMAGE ||
305 (previous_animation_state >= ACTOR_ANIMATION_PRIMARY_ACTION && previous_animation_state < ACTOR_ANIMATION_FORCED)) &&
307 {
308 if (previous_animation_state >= ACTOR_ANIMATION_PRIMARY_ACTION && previous_animation_state < ACTOR_ANIMATION_FORCED)
309 record->turn_step = (uint32_t)pkg_resource_current_level_data->entity_array[record->owner_entity_index].param_turn_step;
310
311 effective_previous_state = UINT32_MAX;
312 previous_animation_state = ACTOR_ANIMATION_NONE;
313 }
314
315 struct Component_CollisionRecord *component_records = record->component_records;
316 bool use_default_animation = !component_records[1].definition;
317
318 if (!use_default_animation)
319 {
320 char attachment_ticks_1 = record->attachment_ticks;
321
322 if (attachment_ticks_1 <= 0)
323 {
324 record->attachment_ticks = attachment_ticks_1 + 1;
325
326 if (attachment_ticks_1)
327 use_default_animation = true;
328 else
329 {
330 record->attachment_ticks = attachment_ticks_1;
331
332 // The attachment definition controls state-nine spawning and its countdown.
333 use_default_animation = !(record->input.button_bits & INPUT_BUTTON_ACTION_2) ||
334 record->reaction_animation_ticks || !surface_trail_mode;
335 }
336 }
337 }
338
339 if (use_default_animation)
340 {
341 int32_t default_anim_state = (int32_t)pkg_resource_current_level_data->entity_array[(
342 int32_t)record->owner_entity_index]
343 .default_anim_state;
344
345 // A default animation state of minus one enables input and movement selection.
346 next_animation_state = default_anim_state;
347
348 if (default_anim_state == ACTOR_ANIMATION_NONE)
349 {
350 next_animation_state = Actor_GetAnimSeqIndex(animation_actor);
351
352 if (!(ACTOR_BEHAVIOR_AIRBORNE & animation_actor->behavior_flags))
353 {
354 char jump_phase_ticks = record->jump_phase_ticks;
355
356 if (jump_phase_ticks < 0 && (int32_t)jump_phase_ticks == -((int32_t)(int8_t)record->configured_jump_startup_ticks))
357 {
358 next_animation_state = ACTOR_ANIMATION_JUMP_START;
359 effective_previous_state = UINT32_MAX;
360 }
361 else if (surface_trail_mode)
362 { // Airborne state: select falling animation based on velocity
363 int16_t input_axis_x = record->input.axis.x;
364
365 if (input_axis_x || record->input.axis.y != input_axis_x)
366 {
367 int32_t input_axis_y = (int32_t)record->input.axis.y;
368 int32_t wide_input_axis_x = (int32_t)input_axis_x;
369
370 // WALK/RUN THRESHOLD: 0x6C1 (1729). velocity^2 > 0x6C1 ? RUN(3) : WALK(2). 12-bit
371 // fixed point squared magnitude
372 bool is_running_input = ((wide_input_axis_x * wide_input_axis_x) >> PHYSICS_FIXED_FRACTION_BITS) + ((input_axis_y * input_axis_y) >> PHYSICS_FIXED_FRACTION_BITS) >= ACTOR_RUNNING_INPUT_MAGNITUDE_Q12;
373
374 next_animation_state = is_running_input + ACTOR_ANIMATION_WALK;
375 }
376 else if (previous_animation_state != ACTOR_ANIMATION_DAMAGE && (previous_animation_state < ACTOR_ANIMATION_PRIMARY_ACTION || previous_animation_state >= ACTOR_ANIMATION_FORCED))
377 {
378 if (animation_actor->velocity.x || animation_actor->velocity.z)
379 next_animation_state = ACTOR_ANIMATION_DRIFT;
380 else
381 {
382 next_animation_state = ACTOR_ANIMATION_IDLE; // Idle state (anim 0) - no velocity, on ground
383
384 uint8_t input_source_index = record->input_source_index;
385
386 if (g_inputStateCurrentP1[input_source_index].button_bits & INPUT_BUTTON_ACTION_3 && !g_confirmTextEnabled)
387 {
389 next_animation_state = ACTOR_ANIMATION_BONE_ACTION;
390 else if (!Trail_CheckBoneAvailable())
391 next_animation_state = ACTOR_ANIMATION_NO_BONE;
392 }
393 }
394 }
395 }
396 else if (record->input.axis.x || record->input.axis.y)
397 next_animation_state = ACTOR_ANIMATION_SURFACE_MOVE;
398 else
399 next_animation_state = ACTOR_ANIMATION_SURFACE_IDLE;
400 }
401 else if (record->jump_phase_ticks > (int8_t)record->configured_jump_hold_ticks)
402 {
403 next_animation_state = ACTOR_ANIMATION_JUMP_START; // State 4 = JUMP_START - initiating jump when vertical state changes
404
406 effective_previous_state = UINT32_MAX;
407 }
408 else if (previous_animation_state != ACTOR_ANIMATION_JUMP_START && previous_animation_state != ACTOR_ANIMATION_DAMAGE && (previous_animation_state < ACTOR_ANIMATION_PRIMARY_ACTION || previous_animation_state >= ACTOR_ANIMATION_FORCED))
409 next_animation_state = ACTOR_ANIMATION_AIRBORNE;
410
411 struct Entity *action_owner_entity = &pkg_resource_current_level_data->entity_array[(
412 int32_t)record->owner_entity_index];
413
414 if (action_owner_entity->flags & (ENTITY_FLAG_BIT_0 | ENTITY_FLAG_BIT_1))
415 {
416 int32_t action_index_value = 0;
417 int32_t animation_slot_byte_offset = 0x20;
418
419 do
420 {
421 int32_t action_flag_mask = 1 << ((uint8_t)action_index_value & PHYSICS_WORD_SHIFT_MASK);
422 uint32_t flags = action_owner_entity->flags;
423
424 if (flags & action_flag_mask)
425 {
426 action_owner_entity->flags = ~action_flag_mask & flags;
427
428 struct Animation_DataBlock *action_animation =
429 animation_actor->anim_asset_table->anim_ptrs[animation_slot_byte_offset / sizeof(animation_actor->anim_asset_table->anim_ptrs[0])];
430
431 if (action_animation && surface_trail_mode && Actor_GetAnimSeqIndex(actor) != ACTOR_ANIMATION_DAMAGE && (action_animation->fixup_flags & (ANIMATION_DATA_NODE_STATE | ACTOR_ANIMATION_INTERRUPTS_MOVEMENT) || !next_animation_state || next_animation_state > ACTOR_ANIMATION_JUMP_START))
432 // The two animation slots enqueue states eight and nine at most once each.
433 Animation_QueueStateChange(action_index_value + 8);
434
435 animation_actor = actor;
436 }
437
438 animation_slot_byte_offset += 4;
439 action_index_value += 1;
440 } while (animation_slot_byte_offset < 0x28);
441 }
442
443 previous_animation_state = effective_previous_state;
444 }
445 }
446 else
447 {
448 char attachment_ticks = record->attachment_ticks;
449
450 if (attachment_ticks)
451 {
452 record->attachment_ticks = attachment_ticks - 1;
453
454 if (attachment_ticks == 1 || !(record->input.button_bits & INPUT_BUTTON_ACTION_2) || record->reaction_animation_ticks || !surface_trail_mode)
456 }
457 else
458 {
459 next_animation_state = ACTOR_ANIMATION_ATTACHMENT_ACTION;
460 record->jump_phase_ticks = attachment_ticks;
461
462 struct Actor_State *spawned_attachment =
463 Component_SpawnFromCollisionRecord(animation_actor, animation_actor, &component_records[1]);
464
465 record->attached_actors[1] = spawned_attachment;
466
467 if (!spawned_attachment)
469 else
470 {
471 record->attachment_ticks = spawned_attachment->fade_timer;
472 spawned_attachment->attach_refcount += 1;
473 }
474
475 struct Level_Data *current_level = pkg_resource_current_level_data;
476 int32_t current_entity_index = (uint16_t)(current_level->current_entity_index);
477
478 if (current_entity_index == (int32_t)record->owner_entity_index)
479 {
480 struct Pkg_CameraDef *cam_current = current_level->cam_current;
481
482 if (cam_current && !(cam_current->camera_type & CAMERA_DEFINITION_MODE_MASK) && cam_current->flags & CAMERA_DEFINITION_ORBIT && cam_current->transition_speed)
483 current_level->cam_current = NULL;
484 }
485 }
486 }
487
488 if (record->forced_animation_ticks)
489 next_animation_state = ACTOR_ANIMATION_FORCED;
490 else
491 {
492 uint16_t reaction_animation_ticks = record->reaction_animation_ticks;
493
494 if (reaction_animation_ticks == ACTOR_REACTION_ANIMATION_TICKS)
495 {
496 int32_t source_id_1 = (uint8_t)(record->input_source_index);
497
499
500 int32_t source_id = (uint8_t)(record->input_source_index);
501
503 next_animation_state = ACTOR_ANIMATION_DAMAGE;
504 }
505 else if (reaction_animation_ticks &&
506 Actor_GetAnimSeqIndex(animation_actor) == ACTOR_ANIMATION_DAMAGE &&
508 return;
509 }
510
511 if (next_animation_state != previous_animation_state)
512 Animation_QueueStateChange(next_animation_state);
513
514 return;
515}
516
517// Original pcdogs.exe: 0x40e350
518// Returns the actor's animation sequence index as an unsigned 16-bit value extended to 32 bits.
519int32_t Actor_GetAnimSeqIndex(struct Actor_State *actor)
520{
521 return (uint16_t)actor->anim_seq_index;
522}
523
524// Original pcdogs.exe: 0x40e360
525// Returns elapsed animation progress in Q12 units without clamping it. Missing animation data or a nonpositive span returns Q12 one.
527{
528 uint16_t sequence_index = (uint16_t)actor->anim_seq_index;
529 struct Animation_DataBlock *animation = actor->anim_asset_table->anim_ptrs[sequence_index];
530
531 if (!animation)
532 return PHYSICS_FIXED_ONE;
533
534 int32_t keyframe_span = (int32_t)animation->keyframe_range.max - (int32_t)animation->keyframe_range.min;
535
536 if (keyframe_span <= 0)
537 return PHYSICS_FIXED_ONE;
538
539 uint32_t elapsed = (uint32_t)actor->anim_tick - (uint32_t)actor->anim_frame_time;
540 return (int32_t)(elapsed << 6) / keyframe_span;
541}
542
543// Original pcdogs.exe: 0x40e3b0
544// Returns zero for completed or unavailable animation, one for a matching animation still running, and minus one when the requested animation is not active or eligible. Script waits can remain pending on either nonzero result.
545int32_t Actor_GetAnimationWaitStatus(struct Actor_State *actor, int32_t anim_seq_index)
546{
547 struct Actor *animation_actor = (struct Actor *)(actor);
548
549 if (!animation_actor)
550 return 0;
551
552 struct Animation_DataBlock *animation = animation_actor->anim_asset_table->anim_ptrs[anim_seq_index];
553
554 if (!animation)
555 return 0;
556
557 if (anim_seq_index == Actor_GetAnimSeqIndex((struct Actor_State *)(animation_actor)))
558 {
559 int32_t actor_animation_pending = (uint8_t)(animation_actor->anim_tick - animation_actor->anim_frame_time < ((int32_t)animation->keyframe_range.max - (int32_t)animation->keyframe_range.min)
560 << 6);
561
562 // Animation complete when elapsed time >= (endFrame - startFrame) * 0x40. Returns 0=complete,
563 // 1=playing
564 return actor_animation_pending;
565 }
566
567 // Queued node-capable animation can make the non-current sequence eligible later.
569 return UINT32_MAX;
570
571 struct Scene_Node **node_list = animation_actor->node_list;
572 struct Scene_Node *animation_node = (struct Scene_Node *)(uintptr_t)(*(uint32_t *)node_list);
573 struct Scene_Node **next_node_slot = &node_list[1];
574
575 while (animation_node)
576 {
577 int32_t node_sequence_index = (uint16_t)(animation_node->anim_update_sentinel);
578
579 if (node_sequence_index == anim_seq_index)
580 {
581 int32_t node_animation_pending = (uint8_t)(animation_actor->anim_tick - animation_node->cached_anim_tick < ((int32_t)animation->keyframe_range.max - (int32_t)animation->keyframe_range.min)
582 << 6);
583
584 return node_animation_pending;
585 }
586
587 animation_node = (struct Scene_Node *)(uintptr_t)(*(uint32_t *)next_node_slot);
588 next_node_slot = &next_node_slot[1];
589 }
590
591 return UINT32_MAX;
592}
593
594// Original pcdogs.exe: 0x40f220
595// Advances the root-motion timeline directly or through distance-budget spline movement, then applies terminal clamping or the selected wrap behavior. Forward wrapping subtracts one span rather than normalizing arbitrary overshoot.
596void Actor_AdvanceRootMotionTick(struct Scene_Type1RenderOwnerView *owner, int32_t tick_delta)
597{
598 /* Native MOVSX at 0x40f226 reads the signed channel byte at owner+0x58. */
599 int32_t position_channel_index = (int32_t)*(int8_t *)&owner->transform.variant_flags_58;
600 struct Animation_SplineChannelVec3 *position_channels;
601
602 if (position_channel_index >= 0)
603 {
604 position_channels = owner->animation_source.direct_block->position_channels;
605 }
606
607 int32_t applied_tick_delta;
608
609 if (position_channel_index < 0 || !(position_channels[position_channel_index].channel_flags & ((int)ANIMATION_SPLINE_DISTANCE_BUDGETED_POSITION)) || owner->animation_tick < 0)
610 {
611 applied_tick_delta = tick_delta;
612 owner->animation_tick += applied_tick_delta;
613 }
614 else
615 {
616 applied_tick_delta = tick_delta;
617 Actor_ApplySplineMovement(owner, &position_channels[position_channel_index], applied_tick_delta);
618 }
619
620 if (applied_tick_delta <= 0)
621 {
622 int32_t reverse_animation_tick = owner->animation_tick;
623
624 if (reverse_animation_tick <= 0)
625 {
626 if (reverse_animation_tick < applied_tick_delta)
627 {
628 int32_t reverse_frame_count = (uint16_t)(owner->animation_frame_count);
629 uint8_t reverse_terminal_flags = owner->transform.lifecycle_or_traversal_flags | SCENE_NODE_TRANSFORM_DIRTY;
630
631 owner->animation_tick = (reverse_frame_count << 6) - PHYSICS_ANIMATION_FRAME_TICKS;
632 owner->transform.lifecycle_or_traversal_flags = reverse_terminal_flags;
633
634 return;
635 }
636
637 uint32_t behavior_flags = owner->behavior_flags;
638
640 {
641 behavior_flags &= ~ACTOR_BEHAVIOR_MOVEMENT_ACTIVE;
642 owner->animation_tick = 0;
643 owner->behavior_flags = behavior_flags;
645
646 return;
647 }
648
649 int32_t reverse_loop_frame_count = (uint16_t)(owner->animation_frame_count);
650
651 owner->animation_tick = (reverse_loop_frame_count << 6) + reverse_animation_tick - PHYSICS_ANIMATION_FRAME_TICKS;
652 }
653 }
654 else
655 {
656 int32_t forward_frame_count = (uint16_t)(owner->animation_frame_count);
657 int32_t animation_tick = owner->animation_tick;
658
659 if (animation_tick >= (forward_frame_count << 6) - PHYSICS_ANIMATION_FRAME_TICKS)
660 {
661 uint32_t forward_completion_flags = owner->behavior_flags;
662
663 if (!(forward_completion_flags & ACTOR_ROOT_MOTION_LOOP))
664 {
665 forward_completion_flags &= ~ACTOR_BEHAVIOR_MOVEMENT_ACTIVE;
666
667 uint8_t forward_terminal_flags = owner->transform.lifecycle_or_traversal_flags | SCENE_NODE_TRANSFORM_DIRTY;
668
669 owner->animation_tick = (forward_frame_count << 6) - PHYSICS_ANIMATION_FRAME_TICKS;
670 owner->behavior_flags = forward_completion_flags;
671 owner->transform.lifecycle_or_traversal_flags = forward_terminal_flags;
672
673 return;
674 }
675
676 if (forward_completion_flags & ACTOR_ROOT_MOTION_WRAP)
677 {
678 uint8_t forward_loop_flags = owner->transform.lifecycle_or_traversal_flags | SCENE_NODE_TRANSFORM_DIRTY;
679
680 owner->animation_tick = animation_tick - (forward_frame_count << 6) + PHYSICS_ANIMATION_FRAME_TICKS;
681 owner->transform.lifecycle_or_traversal_flags = forward_loop_flags;
682
683 return;
684 }
685 }
686 }
687
689}
690
691// Original pcdogs.exe: 0x42e810
692// Searches hit records backward for the requested actor and a hit depth within the actor's signed scale threshold.
693bool Actor_CheckAnimationTrigger(struct Actor_State *actor, struct Actor_State *other_actor)
694{
695 const struct Component_SpawnParams *record = actor->record_ptr;
696 int count = record->hit_count;
697
698 while (count != 0)
699 {
700 --count;
701
702 uint16_t threshold = (uint16_t)record->hit_depths[count];
703 uint32_t target = (uint32_t)(uintptr_t)record->hit_actors[count];
704
705 if (threshold <= (int32_t)actor->scale_factor && target == (uintptr_t)other_actor)
706 return true;
707 }
708
709 return false;
710}
711
712// Original pcdogs.exe: 0x43a690
713// Resets every animation trail's processing flag, expiry, segment index, and head position derived from its segment limit.
715{
716 for (unsigned i = 0; i < actor->trail_count; ++i)
717 {
718 struct Component_TrailObject *chain = &actor->trail_chain_ptr[i];
719
720 chain->processed_flag = 0;
721 chain->expiry_countdown = 0;
722 chain->head_index = -(int16_t)chain->max_segments;
723 chain->segment_index = 0;
724 }
725}
726
727// Original pcdogs.exe: 0x43a6d0
728// Clears the two animation-angle words in each component record.
730{
731 int32_t remaining_components = (uint8_t)(actor->component_count);
732
733 if (!remaining_components)
734 return;
735
736 int16_t *component_yaw_cursor = &actor->component_array->current_yaw;
737
738 for (; remaining_components != 0; --remaining_components)
739 {
740 component_yaw_cursor[1] = 0;
741 component_yaw_cursor[0] = 0;
742 component_yaw_cursor = &component_yaw_cursor[0x14];
743 }
744}
745
746// Original pcdogs.exe: 0x43ff10
747// Selects chain reset behavior from the sign of the argument, resetting or disabling actor chain state and conditionally linking the actor into the timed-event list. Negative input also clears the attachment slot flag; nonnegative input does not select an indexed chain.
748void Actor_ResetChainState(struct Actor_State *actor, int32_t chain_index)
749{
750 if (chain_index >= 0)
751 {
752 actor->chain_timer = 0;
753 actor->chain_state = 0;
754
755 if ((uintptr_t)actor->anim_ctrl_ptr == UINT32_MAX)
756 {
759 }
760
761 return;
762 }
763
765
767 {
768 actor->chain_timer = 0;
769 actor->chain_state = UINT16_MAX;
770 }
772 {
773 actor->chain_timer = 0;
774 actor->chain_state = 0;
775
776 if ((uintptr_t)actor->anim_ctrl_ptr == UINT32_MAX)
777 {
780 }
781 }
782}
#define ACTOR_BEHAVIOR_SKIP_UPDATE
Definition constants.h:7
#define ACTOR_ROOT_MOTION_WRAP
Definition constants.h:23
#define ACTOR_ATTACHMENT_HAS_TIMED_EVENT
Definition constants.h:47
@ ACTOR_ANIMATION_NONE
Definition constants.h:97
@ ACTOR_ANIMATION_PRIMARY_ACTION
Definition constants.h:106
@ ACTOR_ANIMATION_SURFACE_MOVE
Definition constants.h:113
@ ACTOR_ANIMATION_ATTACHMENT_ACTION
Definition constants.h:107
@ ACTOR_ANIMATION_IDLE
Definition constants.h:98
@ ACTOR_ANIMATION_JUMP_START
Definition constants.h:102
@ ACTOR_ANIMATION_DRIFT
Definition constants.h:105
@ ACTOR_ANIMATION_NO_BONE
Definition constants.h:109
@ ACTOR_ANIMATION_DAMAGE
Definition constants.h:104
@ ACTOR_ANIMATION_BONE_ACTION
Definition constants.h:110
@ ACTOR_ANIMATION_FORCED
Definition constants.h:108
@ ACTOR_ANIMATION_SURFACE_IDLE
Definition constants.h:112
@ ACTOR_ANIMATION_DEATH
Definition constants.h:99
@ ACTOR_ANIMATION_AIRBORNE
Definition constants.h:103
@ ACTOR_ANIMATION_WALK
Definition constants.h:100
#define ACTOR_BEHAVIOR_ANIMATION_PENDING
Definition constants.h:27
#define ACTOR_LOD_SHRINK_RAMP_MULTIPLIER
Definition constants.h:122
#define ACTOR_BEHAVIOR_AIRBORNE
Definition constants.h:13
#define ACTOR_BEHAVIOR_CULL_MODE
Definition constants.h:9
#define ACTOR_BEHAVIOR_FORCE_ALTERNATE_LOD
Definition constants.h:36
#define ACTOR_CONTROLLER_BONE_ACTION
Definition constants.h:50
#define ACTOR_LIFECYCLE_HIDDEN
Definition constants.h:40
#define ACTOR_BEHAVIOR_SKIP_ANIMATION
Definition constants.h:11
#define ACTOR_ANIMATION_INTERRUPTS_MOVEMENT
Definition constants.h:89
#define ACTOR_LIFECYCLE_DISABLED
Definition constants.h:39
#define ACTOR_LOD_SHRINK_END_DISTANCE
Definition constants.h:121
#define ACTOR_RUNNING_INPUT_MAGNITUDE_Q12
Definition constants.h:92
#define ACTOR_BEHAVIOR_WORKLIST_MEMBER
Definition constants.h:34
#define ACTOR_FADE_ACTIVE
Definition constants.h:119
#define ACTOR_RENDER_FADE_COLOR_MASK
Definition constants.h:87
#define ACTOR_ATTACHMENT_RETRY_TICKS
Definition constants.h:90
#define ACTOR_BEHAVIOR_VISIBILITY_PENDING
Definition constants.h:15
#define ACTOR_LOD_MINIMUM_SCALE_Q12
Definition constants.h:123
#define ACTOR_LOD_SHRINK_START_DISTANCE
Definition constants.h:120
#define ACTOR_BEHAVIOR_BYPASS_COLLISION
Definition constants.h:18
#define ACTOR_BEHAVIOR_FORCE_PRIMARY_LOD
Definition constants.h:35
#define ACTOR_BEHAVIOR_UPPER_WORD_MASK
Definition constants.h:37
#define ACTOR_BEHAVIOR_FORCE_VISIBLE
Definition constants.h:30
#define ACTOR_BEHAVIOR_MOVEMENT_ACTIVE
Definition constants.h:19
#define ACTOR_REACTION_ANIMATION_TICKS
Definition constants.h:91
#define ACTOR_ROOT_MOTION_LOOP
Definition constants.h:22
#define ACTOR_LIFECYCLE_FORCE_HIDDEN
Definition constants.h:44
BOOL Actor_PassesPauseCameraCoordinateGate(struct Actor_State *actor)
Definition rendering.c:40
void Actor_ReleaseAttachment(struct Actor_MovementRecordView *record)
Definition attachments.c:34
void Actor_ApplySplineMovement(struct Scene_Type1RenderOwnerView *owner, struct Animation_SplineChannelVec3 *spline_track, int32_t tick_delta)
Definition movement.c:388
int32_t Actor_GetAnimationProgress(struct Actor_State *actor)
Definition animation.c:526
#define ANIMATION_DATA_NODE_STATE
Definition constants.h:33
#define ANIMATION_SPLINE_DISTANCE_BUDGETED_POSITION
Definition enums.h:58
void Animation_QueueStateChange(int32_t anim_state)
Definition controller.c:71
void Actor_ResetChainState(struct Actor_State *actor, int32_t chain_index)
Definition animation.c:748
int32_t Actor_GetAnimationWaitStatus(struct Actor_State *actor, int32_t anim_seq_index)
Definition animation.c:545
bool Actor_CheckAnimationTrigger(struct Actor_State *actor, struct Actor_State *other_actor)
Definition animation.c:693
void Actor_UpdateAnimationAndVisibility(struct Actor_State *actor)
Definition animation.c:45
void Actor_UpdateAnimationState(struct Actor_State *actor, struct Player_ControllerRecordView *record, int32_t surface_trail_mode)
Definition animation.c:291
void Actor_AdvanceRootMotionTick(struct Scene_Type1RenderOwnerView *owner, int32_t tick_delta)
Definition animation.c:596
int32_t Actor_GetAnimSeqIndex(struct Actor_State *actor)
Definition animation.c:519
void Actor_ResetComponentAnimations(struct Actor_State *actor)
Definition animation.c:729
void Actor_ResetAnimationChains(struct Actor_State *actor)
Definition animation.c:714
int32_t Actor_GetAnimationProgress(struct Actor_State *actor)
Definition animation.c:526
#define CAMERA_DEFINITION_ORBIT
Definition constants.h:11
#define CAMERA_DEFINITION_MODE_MASK
Definition constants.h:17
struct Actor_State * Component_SpawnFromCollisionRecord(struct Actor_State *owner_actor, struct Actor_State *target_actor, struct Component_CollisionRecord *collision_record)
Definition lifecycle.c:54
#define ENTITY_FLAG_BIT_1
Definition constants.h:8
#define ENTITY_FLAG_BIT_0
Definition constants.h:7
#define GAME_TRANSITION_RUNNING
Definition constants.h:17
#define GAME_TRANSITION_COLOR_FADE
Definition constants.h:30
#define GAME_TRANSITION_SCRIPT_PAUSED
Definition constants.h:20
#define GAME_TRANSITION_OBJECT_VISIBLE
Definition constants.h:29
#define Game_FrameTransitionFlags
Definition globals.h:47
void Graphics_RenderPolygonMesh(struct Graphics_Render_FlatQuadActorView *actor)
void Graphics_ProcessMeshCommands(struct Mesh_CmdList *cmd_list, struct Material_Node **material_nodes, void *owner_context)
Definition meshes.c:70
int32_t Graphics_CheckFrustumCull(struct Math_Vec3I32 *position, int32_t cull_radius, uint32_t cull_flags)
Definition clipping.c:772
#define g_graphicsCapabilityFlags
Definition globals.h:158
#define render_list_state
Definition globals.h:152
#define INPUT_BUTTON_ACTION_3
Definition constants.h:10
#define INPUT_BUTTON_ACTION_2
Definition constants.h:9
int32_t Input_TriggerRumbleIfAllowed(int32_t source_id, BOOL full_strength, int32_t magnitude_fp12, int32_t duration_units)
#define g_inputStateCurrentP1
Definition globals.h:72
int32_t Math_ApproxDistance3DWeighted(int32_t dx, int32_t dy, int32_t dz)
Definition fixed_point.c:59
struct Math_TransformQ12Q6 * global_type_g_renderWorldTransformPtr
Definition globals.h:26
#define g_renderWorldTransformPtr
Definition globals.h:27
#define pkg_resource_current_level_data
Definition globals.h:117
#define PHYSICS_WORD_SHIFT_MASK
Definition constants.h:14
#define PHYSICS_FIXED_ONE
Definition constants.h:7
#define PHYSICS_ANIMATION_FRAME_TICKS
Definition constants.h:12
#define PHYSICS_FIXED_FRACTION_BITS
Definition constants.h:6
#define SCENE_NODE_DISABLED
Definition constants.h:24
#define SCENE_NODE_TRANSFORM_DIRTY
Definition constants.h:31
#define g_scriptPauseToggleState
Definition globals.h:42
#define Signal_TimedEventListHead
Definition globals.h:23
uint8_t component_count
Definition types.h:430
struct Math_Vec3I32 velocity
Definition types.h:446
void * level_local_lod_redirect_record
Definition types.h:487
struct Animation_ControllerGroup * anim_ctrl_ptr
Definition types.h:401
struct Scene_Node ** render_node_list
Definition types.h:440
int32_t anim_frame_time
Definition types.h:390
int16_t chain_timer
Definition types.h:399
struct Bone_JointTrackState * component_array
Definition types.h:432
int16_t cull_radius
Definition types.h:424
uint8_t lifecycle_flags
Definition types.h:392
struct Actor_State * child_actor
Definition types.h:478
struct Collision_Node * ground_collision_node
Definition types.h:451
struct Math_Vec2I16 visual_scale
Definition types.h:395
struct Animation_StateTable * anim_asset_table
Definition types.h:425
int32_t behavior_flags
Definition types.h:407
uint8_t attach_slot_index
Definition types.h:393
int32_t anim_tick
Definition types.h:427
int16_t scale_factor
Definition types.h:439
int16_t anim_seq_index
Definition types.h:388
struct Math_Vec3I32 world_render_pos
Definition types.h:420
uint8_t trail_count
Definition types.h:429
void * record_ptr
Definition types.h:477
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 Component_TrailObject * trail_chain_ptr
Definition types.h:431
struct Math_Vec3I32 position
Definition types.h:385
int32_t fade_alpha
Definition types.h:482
uint8_t attach_refcount
Definition types.h:436
int16_t chain_state
Definition types.h:400
Definition types.h:118
struct Animation_StateTable * anim_asset_table
Definition types.h:178
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 Scene_Node ** node_list
Definition types.h:196
struct Animation_ControllerSlot ** controller_slot_array
Definition types.h:86
Animation_DataBlockFixupFlags fixup_flags
Definition types.h:761
struct Animation_SplineChannelVec3 * position_channels
Definition types.h:764
struct Math_RangeI16 keyframe_range
Definition types.h:763
Animation_SplineChannelFlags channel_flags
Definition types.h:385
struct Animation_DataBlock * anim_ptrs[0x2b]
Definition types.h:422
int16_t current_yaw
Definition types.h:891
struct Component_Definition * definition
Definition types.h:43
struct Actor * hit_actors[0x6]
Definition types.h:337
int16_t hit_depths[0x6]
Definition types.h:338
int16_t segment_index
Definition types.h:241
uint8_t max_segments
Definition types.h:233
uint8_t processed_flag
Definition types.h:234
uint8_t expiry_countdown
Definition types.h:235
Definition types.h:22
uint32_t flags
Definition types.h:25
struct Math_Vec3I32XZY eye_pos
Definition types.h:672
struct Math_Vec2I16 axis
Definition types.h:84
uint32_t button_bits
Definition types.h:83
struct Pkg_CameraDef * cam_current
Definition types.h:42
int16_t current_entity_index
Definition types.h:43
int16_t max
Definition types.h:232
int16_t min
Definition types.h:231
int16_t x
Definition types.h:402
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
uint8_t base_command_count
Definition types.h:496
int16_t count
Definition types.h:497
struct Mesh_Command ** cmdPtrs
Definition types.h:498
uint16_t lod_distance_threshold
Definition types.h:167
struct PKG_ObjectNodeFixupView * alternate_lod_node
Definition types.h:159
uint8_t flags
Definition types.h:180
int16_t transition_speed
Definition types.h:181
uint8_t camera_type
Definition types.h:179
struct Input_State input
Definition types.h:125
uint8_t configured_jump_hold_ticks
Definition types.h:153
uint16_t reaction_animation_ticks
Definition types.h:136
struct Component_CollisionRecord * component_records
Definition types.h:209
uint8_t configured_jump_startup_ticks
Definition types.h:154
struct Actor_State * attached_actors[2]
Definition types.h:215
uint16_t anim_update_sentinel
Definition types.h:126
int32_t cached_anim_tick
Definition types.h:128
uint32_t variant_flags_58
Definition types.h:264
uint8_t lifecycle_or_traversal_flags
Definition types.h:269
struct Scene_TransformNodePrefix transform
Definition types.h:324
uint16_t animation_frame_count
Definition types.h:365
union Scene_AnimationSource animation_source
Definition types.h:352
struct Mesh_CmdList * command_list
Definition types.h:330
uint8_t emit_param6_low
Definition types.h:91
int32_t Trail_CheckBoneAvailable(void)
Definition effects.c:388
struct Animation_DataBlock * direct_block
Definition types.h:12
#define g_renderingStateFlag
Definition values.h:627
#define g_confirmTextEnabled
Definition values.h:825