33 if (!attachment_joint_index)
34 return attachment_joint_index;
41 int32_t records_remaining = record_count;
42 int32_t candidate_attachment_joint;
46 record_cursor = &record_cursor[1];
48 int32_t remaining_before_advance = records_remaining;
50 records_remaining -= 1;
52 if (remaining_before_advance == 1)
61 *out_reference_actor = reference_actor;
64 *out_reference_actor = NULL;
66 return attachment_joint_index;
92 if (!filtered_collision_result)
102 if (attached_actor && attached_actor != (
struct Actor *)(intptr_t)-1)
115 if (attached_actor_1)
144 if (use_cached_collision_list)
148 if (collision_object_count_2)
165 cached_node_cursor = &cached_node_cursor[1];
166 i = collision_object_count_2;
167 collision_object_count_2 -= 1;
175 uint32_t saved_modified_flag = modified_flag_or_swept_diameter;
177 if (modified_flag_or_swept_diameter)
187 use_cached_collision_list = (BOOL)(runtime_vertices);
190 ground_collision_node_2 = NULL;
201 segment_delta.
x = dx;
205 segment_delta.
y = dy;
206 segment_delta.
z = dz;
210 modified_flag_or_swept_diameter = (uint32_t)swept_bounding_radius * 2;
212 if (actor->
world_render_pos.
x - (uint32_t)ground_collision_node_2->
bounds.
sphere.
center.
x + swept_bounding_radius <= modified_flag_or_swept_diameter && actor->world_render_pos.y - (uint32_t)ground_collision_node_2->
bounds.
sphere.
center.
y + swept_bounding_radius <= modified_flag_or_swept_diameter && actor->world_render_pos.z - (uint32_t)ground_collision_node_2->
bounds.
sphere.
center.
z + swept_bounding_radius <= modified_flag_or_swept_diameter &&
230 ground_collision_node_2 = (
struct Collision_Node *)(runtime_vertices);
232 if (!runtime_vertices)
244 BOOL ground_contact_result;
257 use_cached_collision_list = (BOOL)(runtime_vertices);
260 if (!ground_collision_node_2)
293 int32_t actor_swept_radius = motion_distance + ((int32_t)actor->
cull_radius << 6);
296 int32_t saved_swept_radius = actor_swept_radius;
310 int32_t combined_swept_radius = (obstacle_radius << 6) + actor_swept_radius;
311 int32_t swept_diameter = combined_swept_radius * 2;
312 if ((uint32_t)(actor->
world_render_pos.
x - obstacle_node->
origin.
x + combined_swept_radius) > (uint32_t)swept_diameter ||
313 (uint32_t)(actor->
world_render_pos.
y - obstacle_node->
origin.
y + combined_swept_radius) > (uint32_t)swept_diameter ||
314 (uint32_t)(actor->
world_render_pos.
z - obstacle_node->
origin.
z + combined_swept_radius) > (uint32_t)swept_diameter ||
319 int16_t behavior_flags = (int16_t)obstacle_node->
flags;
332 selected_next_node_slot = saved_next_node_slot;
336 obstacle_node = *selected_next_node_slot;
337 next_node_slot = selected_next_node_slot + 1;
338 saved_next_node_slot = next_node_slot;
343 actor_swept_radius = saved_swept_radius;
359 out_impact_motion->
x = other_actor_1->
sub_pos.
x;
360 out_impact_motion->
y = other_actor_1->
sub_pos.
y;
361 out_impact_motion->
z = other_actor_1->
sub_pos.
z;
365 int32_t relative_motion_y = y - other_actor_1->
sub_pos.
y;
367 int64_t motion_x_fraction_wide = (int64_t)collision_fraction_q12 * relative_contact_x;
369 relative_contact_x = (int32_t)((uint64_t)motion_x_fraction_wide >>
MATH_Q12_SHIFT);
371 int64_t motion_y_fraction_wide = (int64_t)collision_fraction_q12 * relative_motion_y;
372 int64_t motion_z_fraction_wide = (int64_t)collision_fraction_q12 * relative_motion_z;
378 int32_t relative_contact_y = interpolated_world_y - other_actor_1->
world_render_pos.
y;
379 int32_t relative_contact_z = interpolated_world_z - other_actor_1->
world_render_pos.
z;
382 int32_t other_shape_radius;
389 if (other_shape_radius)
393 int32_t actor_shape_radius;
400 if (actor_shape_radius)
402 int32_t radius_fraction = ((int64_t)other_shape_radius *
MATH_Q12_ONE) / (actor_shape_radius + other_shape_radius);
403 int64_t radius_weighted_x_wide = (int64_t)radius_fraction * relative_contact_x;
405 relative_contact_x = (int32_t)((uint64_t)radius_weighted_x_wide >>
MATH_Q12_SHIFT);
407 int64_t radius_weighted_y_wide = (int64_t)radius_fraction * relative_contact_y;
409 relative_contact_y = (int32_t)((uint64_t)radius_weighted_y_wide >>
MATH_Q12_SHIFT);
411 int64_t radius_weighted_z_wide = (int64_t)radius_fraction * relative_contact_z;
413 relative_contact_z = (int32_t)((uint64_t)radius_weighted_z_wide >>
MATH_Q12_SHIFT);
417 int32_t x = out_impact_motion->
x;
419 int32_t final_contact_delta_x;
420 int32_t final_contact_delta_z;
422 if (
x || out_impact_motion->
y || out_impact_motion->
z)
424 int32_t half_collision_fraction_q12 = collision_fraction_q12 >> 1;
425 int64_t half_target_motion_x_wide = (int64_t)half_collision_fraction_q12 *
x;
427 out_contact_pos_1 = out_contact_pos;
428 out_contact_pos_1->
x = (int32_t)((uint64_t)half_target_motion_x_wide >>
MATH_Q12_SHIFT);
430 int64_t half_target_motion_y_wide = (int64_t)half_collision_fraction_q12 * out_impact_motion->
y;
432 out_contact_pos_1->
y = (int32_t)((uint64_t)half_target_motion_y_wide >>
MATH_Q12_SHIFT);
434 int64_t half_target_motion_z_wide = (int64_t)half_collision_fraction_q12 * out_impact_motion->
z;
436 final_contact_delta_z = relative_contact_z;
437 final_contact_delta_x = relative_contact_x;
438 out_contact_pos_1->
z = (int32_t)((uint64_t)half_target_motion_z_wide >>
MATH_Q12_SHIFT);
447 int64_t squared_contact_x_wide = (int64_t)relative_contact_x * relative_contact_x;
448 int64_t squared_contact_y_wide = (int64_t)relative_contact_y * relative_contact_y;
449 int64_t squared_contact_z_wide = (int64_t)relative_contact_z * relative_contact_z;
450 int32_t contact_delta_length =
451 Math_SqrtFP12((int32_t)(((uint64_t)squared_contact_z_wide + (uint64_t)squared_contact_x_wide + (uint64_t)squared_contact_y_wide) >>
MATH_Q12_SHIFT));
454 if (contact_delta_length)
457 int64_t bounce_x_wide = (int64_t)bounce_scale_q16 * relative_contact_x;
459 out_impact_motion->
x = ((int32_t)((uint64_t)bounce_x_wide >>
MATH_Q12_SHIFT)) >> 4;
461 int64_t bounce_y_wide = (int64_t)bounce_scale_q16 * relative_contact_y;
463 out_impact_motion->
y = ((int32_t)((uint64_t)bounce_y_wide >>
MATH_Q12_SHIFT)) >> 4;
465 int64_t bounce_z_wide = (int64_t)bounce_scale_q16 * relative_contact_z;
467 out_impact_motion->
z = ((int32_t)((uint64_t)bounce_z_wide >>
MATH_Q12_SHIFT)) >> 4;
468 out_impact_motion_1 = out_impact_motion;
472 out_impact_motion_1 = out_impact_motion;
479 final_contact_delta_x = relative_contact_x;
480 final_contact_delta_z = relative_contact_z;
481 other_actor_1 = other_actor;
482 out_impact_motion_1->
x = final_contact_delta_x;
483 out_impact_motion_1->
y = relative_contact_y;
484 out_contact_pos_1 = out_contact_pos;
485 out_impact_motion_1->
z = final_contact_delta_z;
489 .x = out_contact_pos_1->
x + final_contact_delta_x + other_actor_1->
world_render_pos.
x,
491 .z = out_contact_pos_1->
z + final_contact_delta_z + other_actor_1->
world_render_pos.
z};
500 int32_t collision_class;
507 collision_class = (int32_t)(int8_t)actor->collision_class;
513 struct Actor *collision_list_prev = actor;
514 struct Actor *last_tested_actor = collision_list_prev;
531 for (; other_actor; other_actor = collision_list_prev->
list_next)
541 last_tested_actor = other_actor;
545 int32_t actor_probe_result =
550 int32_t other_probe_result_raw =
552 int32_t other_probe_result = other_probe_result_raw;
570 if (actor_probe_result > 0 || other_probe_result > 0)
576 world_sweep_delta.
x = dx_1;
578 int32_t dz_1 = world_delta_z - subpos_delta.
z;
580 world_sweep_delta.
y = dy_1;
581 world_sweep_delta.
z = dz_1;
583 int32_t sweep_distance =
585 int32_t sweep_distance_saved = sweep_distance;
587 if (sweep_distance < actor_probe_result)
589 actor_probe_result = state_response_handler((
struct Actor_State *)(actor),
590 (
struct Actor_State *)(other_actor), sweep_distance);
591 sweep_distance = sweep_distance_saved;
593 else if (actor_probe_result > 0)
594 actor_probe_result = 0;
596 if (sweep_distance < other_probe_result)
600 sweep_distance = sweep_distance_saved;
602 else if (other_probe_result > 0)
603 other_probe_result = 0;
605 if (other_probe_result | actor_probe_result && sweep_distance <= combined_swept_radius)
607 int32_t
z = other_actor->world_render_pos.z;
608 int32_t z_1 = other_actor->sub_pos.z;
609 int32_t y = other_actor->world_render_pos.y;
611 world_sweep_delta.
x =
612 other_actor->world_render_pos.x + other_actor->sub_pos.x;
615 (int32_t)other_actor->cull_radius;
617 world_sweep_delta.
y = y + other_actor->sub_pos.y;
618 world_sweep_delta.
z =
z + z_1;
621 &world_sweep_delta, &subpos_delta,
624 (
struct Actor_State *)(other_actor), actor_probe_result,
630 int32_t swept_diameter = combined_swept_radius * 2;
632 if ((uint32_t)(
g_collisionTestPosX - other_actor->world_render_pos.x + combined_swept_radius) <= (uint32_t)swept_diameter && (uint32_t)(
g_collisionTestPosY - other_actor->world_render_pos.y + combined_swept_radius) <= (uint32_t)swept_diameter && (uint32_t)(
g_collisionTestPosZ - other_actor->world_render_pos.z + combined_swept_radius) <= (uint32_t)swept_diameter)
634 int32_t
z = other_actor->world_render_pos.z;
635 int32_t z_1 = other_actor->sub_pos.z;
636 int32_t y = other_actor->world_render_pos.y;
638 world_sweep_delta.
x =
639 other_actor->world_render_pos.x + other_actor->sub_pos.x;
642 (int32_t)other_actor->cull_radius;
644 world_sweep_delta.
y = y + other_actor->sub_pos.y;
645 world_sweep_delta.
z =
z + z_1;
648 &world_sweep_delta, &subpos_delta,
651 (
struct Actor_State *)(other_actor), actor_probe_result,
660 collision_list_prev = last_tested_actor;
688 actor_a = smaller_actor;
690 int32_t saved_actor_a_response = actor_a_response;
692 actor_b = larger_actor;
693 actor_a_response = actor_b_response;
694 larger_actor = actor_a;
695 actor_b_response = saved_actor_a_response;
696 smaller_actor = actor_b;
706 int16_t sphere_extents[3];
710 int16_t sphere_half_extent =
713 sphere_extents[2] = sphere_half_extent;
714 sphere_extents[1] = sphere_half_extent;
715 sphere_extents[0] = sphere_half_extent;
719 target_half_extents = &smaller_actor_collision_shape_node->
shape;
722 int32_t axis_index = 0;
729 int32_t axis_projection[3];
730 int16_t *rotation_column = &smaller_actor->
rot_mat.
m10;
732 int16_t *next_rotation_column = rotation_column;
736 axis_projection[0] = (int32_t)rotation_column[-3];
737 axis_projection[1] = rotation_column[0];
738 axis_projection[2] = rotation_column[3];
740 int32_t axis_half_extent = *(uint16_t *)half_extent_cursor;
741 int32_t expanded_extent_or_corner_z = (axis_half_extent << 6) + collision_radius_q12;
743 if ((uint32_t)(((uint64_t)((int64_t)delta[0] * axis_projection[0]) + (uint64_t)((int64_t)delta[1] * axis_projection[1]) + (uint64_t)((int64_t)delta[2] * axis_projection[2])) >>
MATH_Q12_SHIFT) + (uint32_t)expanded_extent_or_corner_z > (uint32_t)expanded_extent_or_corner_z * 2)
747 for (int32_t i = 0; i < 4;)
749 int32_t packed_corner_xy;
755 *(uint16_t *)&packed_corner_xy = -(*(int16_t *)target_half_extents);
756 *(uint16_t *)((
char *)&packed_corner_xy + 2) =
757 -(target_half_extents->packed_yz.extents_yz_q6);
758 *(uint16_t *)&expanded_extent_or_corner_z = -(target_half_extents->packed_pairs.extent_z_and_probe_radius_q6);
772 *(uint16_t *)((
char *)&packed_corner_xy + 2) =
787 vertices[i].
pos.
z = (int16_t)expanded_extent_or_corner_z;
789 int32_t opposite_vertex_byte_offset = (i - ((i & 1) << 1) + 5) * 0xc;
791 vertices[i - ((i & 1) << 1) + 5].
pos.
x = (int16_t)-(packed_corner_xy);
793 vertices[opposite_vertex_byte_offset /
sizeof(vertices[0])].
pos.
y = (int16_t)-(*(int16_t *)((
char *)&packed_corner_xy + 2));
794 vertices[opposite_vertex_byte_offset /
sizeof(vertices[0])].
pos.
z = -(expanded_extent_or_corner_z);
797 for (int32_t extent_axis_index = 0; extent_axis_index < 3; extent_axis_index++)
800 -((int32_t)(uint16_t)target_half_extents->
box.
half_extents_q6[extent_axis_index]) << 0xa;
808 if (!actor_a_response)
813 if (!actor_b_response)
819 if (!actor_a_response)
822 if (actor_b_response)
825 actor_b->scale_factor = (int16_t)saved_target_scale;
830 bool has_more_axes = axis_index + 1 < 3;
833 next_rotation_column = &next_rotation_column[1];
834 half_extent_cursor = (
void *)((
char *)half_extent_cursor + 2);
841 if (!actor_a_response)
862 rotation_column = next_rotation_column;
#define ACTOR_BEHAVIOR_MOVEMENT_LOCKED
#define ACTOR_BEHAVIOR_AIRBORNE
#define ACTOR_LIFECYCLE_DISABLED
#define ACTOR_BEHAVIOR_WORKLIST_MEMBER
#define ACTOR_LIFECYCLE_DESTROYING
#define ACTOR_BEHAVIOR_PENETRATING
#define ACTOR_BEHAVIOR_GROUNDED_MOTION
#define ACTOR_ATTACHMENT_SUPPRESS_PLATFORM_CONTACT
#define ACTOR_BEHAVIOR_BYPASS_COLLISION
#define ACTOR_BEHAVIOR_PREPROCESSED
#define ACTOR_BEHAVIOR_COLLISION_CORRECTION
#define Actor_CollisionListHead
#define Actor_DefaultUpdateCallbackSlot
void Collision_DetectActorCollisions(struct Actor_State *actor, BOOL use_cached_collision_list)
void Collision_DetectActorObstacles(struct Actor_State *actor)
struct Actor_State * Collision_GetValidCollisionTarget(struct Actor_State *actor, int32_t collision_slot)
void Collision_ProcessActorToActorCollisions()
void Collision_CalculateImpactContactData(struct Actor_State *actor, struct Actor_State *other_actor, int32_t collision_fraction_q12, struct Math_Vec3I32 *out_contact_pos, struct Math_Vec3I32 *out_impact_motion)
void Collision_InitializeFunctionPointers()
void Collision_ResolveActorToActorCollision(struct Actor_State *actor_a, struct Actor_State *actor_b, int32_t actor_a_response, int32_t actor_b_response)
int32_t Collision_HandleComponentCollision(struct Component_ProjectileActorView *comp, struct Actor_State *other_actor)
int32_t ComponentCollision_ResolveReferenceActor(struct Component_CollisionRecord *collision_records, int32_t record_count, int32_t attachment_joint_index, struct Actor_State **out_reference_actor)
uint8_t Audio_CanRegisterCollisionSound(struct Audio_CollisionSoundCooldownEntry *entries, struct Actor_State *other_actor, int32_t sound_key)
#define COLLISION_SOUND_COOLDOWN_RECORD_OFFSET
@ COLLISION_PROBE_SKIP_PAIR
@ COLLISION_PROBE_NO_RESPONSE
#define COLLISION_BOUNCE_NORMALIZATION_NUMERATOR
#define COLLISION_NODE_CULL_DISABLED
@ COLLISION_ACTOR_CLASS_PROJECTILE
@ COLLISION_ACTOR_CLASS_CHARACTER
#define COLLISION_CALLBACK_CONTACT_PROBE
@ COLLISION_EXTENTS_PACKED_PAIRS
#define COLLISION_POLYGON_PLATFORM_CONTACT_ENABLED
#define COLLISION_NODE_COLLIDABLE
#define COLLISION_NODE_SPECIAL_CONTACT
@ COLLISION_CLASS_CAMERA_PROBE
#define COLLISION_NODE_CULL_FORCE_HIDDEN
@ COLLISION_NODE_ORIENTED_BOX
#define COLLISION_PROBE_GROUND_RADIUS_LIMIT_Q6
#define COLLISION_NODE_SKIP_OBSTACLE_QUERY
#define COLLISION_NODE_REFRESH_GROUND_CONTACT
#define COLLISION_NODE_CAMERA_PROBE_SKIP
void Collision_ProcessPowerupCollisions(struct Actor_State *actor)
void Collision_ProcessProjectileLifecycle(struct Actor_State *actor)
struct Collision_Node * Collision_FindActorGroundContact(struct Actor_State *actor, struct Collision_Polygon **out_polygon)
uint8_t Collision_CheckLineSphereIntersection(struct Actor_State *actor, struct Math_Vec3I32 *sphere_center, struct Math_Vec3I32 *segment_delta, uint32_t sphere_radius)
void Collision_DetectObjectNodeCollisions(struct Actor_State *actor, int32_t object_list_index)
void Collision_BuildAndResolveGroundEdgeWalls(struct Actor_State *actor)
int32_t Collision_ProcessProjectileHit(void *subject, void *other_object, struct Collision_Polygon *collision_poly, int32_t collision_depth)
int32_t Collision_GetShapeRadiusQ12(const struct Actor_CollisionShapeNodeView *shape)
void Collision_DetectAndResolve3DCollision(struct Actor_State *actor, struct Collision_Node *collision_source, struct Collision_Vertex *vertices, struct Collision_Polygon *polygons, int32_t polygon_count)
uint8_t Collision_TestLineSphereIntersection(struct Math_Vec3I32 *line_start, struct Math_Vec3I32 *segment_delta, uint32_t sphere_radius)
#define g_collisionTestRadiusQ6
#define g_collisionObjectNodes
#define Collision_ProcessActorToActorCollisions_StateHandlerTable
#define g_collisionObjectCount
#define g_collisionResponseBuffer
#define Collision_BoxFacePolygons
#define g_collisionTestMotionXQ12
#define g_collisionTestPosZ
#define g_collisionTestPosX
#define g_collisionTestMotionZQ12
#define g_collisionTestPosY
#define g_collisionTestMotionYQ12
int32_t(* ActorCollisionResponseCallback)(struct Actor_State *actor, void *other_actor_or_out_reference, int32_t distance_or_reference_selector)
int32_t(* ActorCollisionProbeCallback)(void *subject, void *other_object, struct Collision_Polygon *collision_poly, int32_t collision_depth)
#define COMPONENT_STATE_TARGET_CLEARED
#define COMPONENT_STATE_HAS_TARGET
uint16_t Component_GetDamageAmount(struct Component_ProjectileActorView *comp, int32_t *out_hit_flag)
void Component_UpdateCollisionDetection(struct Component_CollisionRecord *collision_records, int32_t slot_count, struct Actor_State *actor, struct Actor_State *other_actor, struct Math_Vec3I32 *test_pos)
void Component_UpdateProjectileLogic(struct Component_ProjectileActorView *comp)
int32_t Component_CheckActorCollisionTypeAdapter(struct Component_ProjectileActorView *comp, struct Actor_State *other_actor)
#define g_behaviorProcessProjectileFunc
#define g_projectileLogicFunc
int32_t Math_SqrtFP12(uint32_t value)
int32_t Math_ApproxDistance3DWeighted(int32_t dx, int32_t dy, int32_t dz)
uint8_t Physics_UpdateActorPreprocess(struct Actor_State *actor)
int16_t half_extents_q6[3]
int16_t collision_probe_radius_q6
union Actor_CollisionShapeExtentOverlay shape
uint8_t extent_encoding_mode
int32_t collision_response_xz
int32_t collision_push_xz
struct Component_Instance * collision_component_or_parent_component
struct Actor_State::@046003157221137033352243305322145230101305267353::@310120147361127005160350306337045233155315004262 collision_response_components
struct Collision_Polygon * ground_contact_polygon
struct Collision_Node * ground_collision_node
uint8_t behavior_flags_high
struct Actor_State::@000347335321225257200273166125221262042042274352::@355017126165076161135046166331324200333365100231 collision_push_components
uint8_t attach_slot_index
struct Math_Vec3I32 world_render_pos
struct Math_Vec3I32 sub_pos
struct Math_Matrix3x3I16 rot_mat
uint8_t behavior_flags_high
uint32_t subtree_skip_count
union Collision_NodeBoundsOverlay bounds
struct Collision_Vertex * vertices
struct Math_Vec3I32 collision_offset
struct Collision_Polygon * polygons
struct Math_Vec3I32 origin
struct Math_Vec3I32 center
struct Collision_Vertex::@111126275124057154070202104324102117233165176236::@061322026074334072070347216127267241215241121036 pos
struct Collision_Vertex::@111126275124057154070202104324102117233165176236::@335106066264226003006335032356352061154334151042 packed_position
uint16_t attachment_joint_index
struct Actor_State * reference_actor
int32_t homing_turn_step_angle12
struct Component_SpawnParams * spawn_context
struct Component_Definition * definition
struct Actor * attached_actor
uint8_t configured_jump_hold_ticks
struct Actor_State * collision_response_slots_0_to_4[0x5]
struct Mesh_RuntimeVertex * runtime_vertices
struct Actor_CollisionShapeExtentOverlay::@012154035243133015240250250255231204101367116236 packed_yz
struct Actor_CollisionSphereExtentView sphere
int32_t extent_z_and_probe_radius_q6
struct Actor_CollisionShapeExtentOverlay::@051275254310303332307011254315225110223152303125 packed_pairs
struct Actor_CollisionBoxExtentView box
struct Collision_OrientedBoxNodeBoundsView oriented_box
struct Collision_SphereNodeBoundsView sphere