Optimize rollback hot paths (#53)
## 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>
This commit was merged in pull request #53.
This commit is contained in:
+24
-26
@@ -50,31 +50,29 @@ pub fn air_collide_with_stage(
|
||||
translation.0 + ecb.get_bottom_point(),
|
||||
);
|
||||
|
||||
let mut intersect_results = vec![];
|
||||
|
||||
for (poly_idx, poly) in stage_collision.stage_polys.iter().enumerate() {
|
||||
if let Some(intersect_result) = poly.intersect_ray(ray_segment) {
|
||||
intersect_results.push((
|
||||
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()),
|
||||
));
|
||||
}
|
||||
}
|
||||
intersect_results.sort_by(|(_, a), (_, b)| a.cmp(b));
|
||||
|
||||
intersect_results
|
||||
stage_collision
|
||||
.stage_polys
|
||||
.iter()
|
||||
.last()
|
||||
.map(|(val, _)| val.to_owned().clone())
|
||||
.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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user