## Summary Fixes #20. - Reuse fighter animation scratch and output buffers across rollback frames. - Select air-collision hits in one pass without candidate allocations or sorting. - Index contiguous replay input frames directly and binary-search checksums. - Add regression tests for buffer reuse and replay lookup/validation. Reviewed-on: #53 Co-authored-by: Álex Román Núñez <eirexe@eirteam.moe>
79 lines
2.7 KiB
Rust
79 lines
2.7 KiB
Rust
//! Resolving an integrated fighter position against the stage.
|
|
|
|
use crate::fighter::ecb::FighterPreviousECB;
|
|
use crate::fighter::{FighterECB, FighterPreviousTranslation, FighterTranslation};
|
|
use crate::math::segment::FGSegment2d;
|
|
use crate::math::vec::FGVec2;
|
|
use crate::stage::line::{StageCollision, StageLineID};
|
|
/*
|
|
pub fn collide_fighter_with_scene(
|
|
fighters: Query<(&FighterECB, &mut FighterVelocity, &mut FighterTranslation)>,
|
|
stage_planes: Query<&StagePoly>,
|
|
mut gizmos: Gizmos,
|
|
) {
|
|
for (ecb, mut velocity, mut translation) in fighters {
|
|
for plane in stage_planes {
|
|
let ray_from = translation.0;
|
|
let ray_to = translation.0 + Vec2::new(0.0, -ecb.vertical_half);
|
|
|
|
let intersection_result = plane.intersect_ray(Segment2d::new(ray_from, ray_to));
|
|
|
|
if let Some(result) = intersection_result {
|
|
gizmos.sphere(
|
|
Isometry3d::from(Vec3::new(result.position.x, result.position.y, 0.0)),
|
|
0.1f32,
|
|
HOT_PINK,
|
|
);
|
|
velocity.0 = plane.project(velocity.0);
|
|
translation.0 = result.position + Vec2::new(0.0, ecb.vertical_half);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
#[derive(Clone)]
|
|
pub struct AirCollisionWithStageResult {
|
|
pub line_id: StageLineID,
|
|
pub hit_position: FGVec2,
|
|
pub hit_normal: FGVec2,
|
|
}
|
|
|
|
pub fn air_collide_with_stage(
|
|
prev_translation: &FighterPreviousTranslation,
|
|
translation: &FighterTranslation,
|
|
prev_ecb: &FighterPreviousECB,
|
|
ecb: &FighterECB,
|
|
stage_collision: &StageCollision,
|
|
) -> Option<AirCollisionWithStageResult> {
|
|
let ray_segment = FGSegment2d::new(
|
|
prev_translation.0 + prev_ecb.get_bottom_point(),
|
|
translation.0 + ecb.get_bottom_point(),
|
|
);
|
|
|
|
stage_collision
|
|
.stage_polys
|
|
.iter()
|
|
.enumerate()
|
|
.filter_map(|(poly_idx, poly)| {
|
|
poly.intersect_ray(ray_segment).map(|intersect_result| {
|
|
(
|
|
AirCollisionWithStageResult {
|
|
line_id: {
|
|
StageLineID {
|
|
polygon: poly_idx,
|
|
segment: intersect_result.segment_idx,
|
|
}
|
|
},
|
|
hit_position: intersect_result.position,
|
|
hit_normal: intersect_result.normal,
|
|
},
|
|
intersect_result
|
|
.position
|
|
.distance_squared(ray_segment.point2()),
|
|
)
|
|
})
|
|
})
|
|
.max_by(|(_, a), (_, b)| a.cmp(b))
|
|
.map(|(result, _)| result)
|
|
}
|