Port to fixed point math

This commit is contained in:
2026-08-24 21:54:23 +02:00
parent 91c5c4e05f
commit 73855ea354
27 changed files with 703 additions and 229 deletions
+53 -16
View File
@@ -1,4 +1,7 @@
use bevy::prelude::*;
use fixed::traits::Fixed;
use crate::math::{int::FGi32, vec::FGVec2};
/// Environment collision box: the diamond used to resolve a fighter against
/// the stage. Purely geometry — the collision response lives in
@@ -6,40 +9,74 @@ use bevy::prelude::*;
#[derive(Component, Debug, Clone, Copy)]
#[require(FighterPreviousECB)]
pub struct FighterECB {
pub vertical_half: f32,
pub horizontal_half: f32,
pub vertical_half: FGi32,
pub horizontal_half: FGi32,
}
#[derive(Component, Debug, Clone, Copy, Default)]
pub struct FighterPreviousECB {
pub vertical_half: f32,
pub horizontal_half: f32,
pub vertical_half: FGi32,
pub horizontal_half: FGi32,
}
impl From<FighterECB> for FighterPreviousECB {
fn from(ecb: FighterECB) -> Self {
Self {
vertical_half: ecb.vertical_half,
horizontal_half: ecb.horizontal_half,
}
}
}
pub fn snapshot_fighter_ecb(
fighters: Query<(&FighterECB, &mut FighterPreviousECB)>,
) {
for (ecb, mut previous_ecb) in fighters {
*previous_ecb = (*ecb).into();
}
}
impl FighterECB {
pub fn to_3d_lineloop(&self, trf: Transform) -> [Vec3; 4] {
let rel_up = trf.transform_point(Vec3::new(0.0, self.vertical_half, 0.0));
let rel_down = trf.transform_point(Vec3::new(0.0, -self.vertical_half, 0.0));
let rel_left = trf.transform_point(Vec3::new(-self.horizontal_half, 0.0, 0.0));
let rel_right = trf.transform_point(Vec3::new(self.horizontal_half, 0.0, 0.0));
let rel_up = trf.transform_point(Vec3::new(0.0, self.vertical_half.to_num(), 0.0));
let rel_down = trf.transform_point(Vec3::new(0.0, (-self.vertical_half).to_num(), 0.0));
let rel_left = trf.transform_point(Vec3::new((-self.horizontal_half).to_num(), 0.0, 0.0));
let rel_right = trf.transform_point(Vec3::new(self.horizontal_half.to_num(), 0.0, 0.0));
[rel_up, rel_right, rel_down, rel_left]
}
pub fn get_bottom_point(&self) -> Vec2 {
Vec2::new(0.0, -self.vertical_half)
pub fn get_bottom_point(&self) -> FGVec2 {
FGVec2::new(FGi32::ZERO, -self.vertical_half)
}
}
impl FighterPreviousECB {
pub fn to_3d_lineloop(&self, trf: Transform) -> [Vec3; 4] {
let rel_up = trf.transform_point(Vec3::new(0.0, self.vertical_half, 0.0));
let rel_down = trf.transform_point(Vec3::new(0.0, -self.vertical_half, 0.0));
let rel_left = trf.transform_point(Vec3::new(-self.horizontal_half, 0.0, 0.0));
let rel_right = trf.transform_point(Vec3::new(self.horizontal_half, 0.0, 0.0));
let rel_up = trf.transform_point(Vec3::new(0.0, self.vertical_half.to_num(), 0.0));
let rel_down = trf.transform_point(Vec3::new(0.0, (-self.vertical_half).to_num(), 0.0));
let rel_left = trf.transform_point(Vec3::new((-self.horizontal_half).to_num(), 0.0, 0.0));
let rel_right = trf.transform_point(Vec3::new(self.horizontal_half.to_num(), 0.0, 0.0));
[rel_up, rel_right, rel_down, rel_left]
}
pub fn get_bottom_point(&self) -> Vec2 {
Vec2::new(0.0, -self.vertical_half)
pub fn get_bottom_point(&self) -> FGVec2 {
FGVec2::new(FGi32::ZERO, -self.vertical_half)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn previous_ecb_copies_current_dimensions() {
let current = FighterECB {
vertical_half: FGi32::lit("0.5"),
horizontal_half: FGi32::lit("0.25"),
};
let previous = FighterPreviousECB::from(current);
assert_eq!(previous.vertical_half, current.vertical_half);
assert_eq!(previous.horizontal_half, current.horizontal_half);
}
}