diff --git a/src/gameplay_style.rs b/src/gameplay_style.rs index b619294..7ac1c9f 100644 --- a/src/gameplay_style.rs +++ b/src/gameplay_style.rs @@ -170,10 +170,17 @@ pub struct StrafeSettings{ tick_rate:Ratio64, } impl StrafeSettings{ + pub fn tick_velocity(&self,velocity:Planar64Vec3,control_dir:Planar64Vec3)->Option{ + let d=velocity.dot(control_dir); + match dSome(velocity+control_dir*self.air_accel_limit.map_or(self.mv-d,|limit|limit.min(self.mv-d))), + false=>None, + } + } pub fn next_tick(&self,time:Time)->Time{ Time::from_nanos(self.tick_rate.rhs_div_int(self.tick_rate.mul_int(time.nanos())+1)) } - pub fn allow_strafe(&self,controls:Controls)->bool{ + pub const fn allow_strafe(&self,controls:Controls)->bool{ self.enable.activates(controls) } } @@ -184,9 +191,12 @@ pub struct PropulsionSettings{ magnitude:Planar64, } impl PropulsionSettings{ - pub fn activates(&self,controls:Controls)->bool{ + pub const fn activates(&self,controls:Controls)->bool{ self.enable.activates(controls) } + pub fn acceleration(&self,control_dir:Planar64Vec3)->Planar64Vec3{ + control_dir*self.magnitude + } } #[derive(Clone)] diff --git a/src/integer.rs b/src/integer.rs index 844cf4e..9bf91c6 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -91,7 +91,7 @@ const fn gcd(mut a:u64,mut b:u64)->u64{ }; a } -#[derive(Clone,Hash)] +#[derive(Clone,Copy,Hash)] pub struct Ratio64{ num:i64, den:u64, @@ -109,15 +109,15 @@ impl Ratio64{ } } #[inline] - pub fn mul_int(&self,rhs:i64)->i64{ + pub const fn mul_int(&self,rhs:i64)->i64{ rhs*self.num/(self.den as i64) } #[inline] - pub fn rhs_div_int(&self,rhs:i64)->i64{ + pub const fn rhs_div_int(&self,rhs:i64)->i64{ rhs*(self.den as i64)/self.num } #[inline] - pub fn mul_ref(&self,rhs:&Ratio64)->Ratio64{ + pub const fn mul_ref(&self,rhs:&Ratio64)->Ratio64{ let (num,den)=(self.num*rhs.num,self.den*rhs.den); let d=gcd(num.unsigned_abs(),den); Self{ @@ -259,7 +259,7 @@ impl std::ops::Div for Ratio64{ } } } -#[derive(Clone,Hash)] +#[derive(Clone,Copy,Hash)] pub struct Ratio64Vec2{ pub x:Ratio64, pub y:Ratio64, @@ -267,11 +267,11 @@ pub struct Ratio64Vec2{ impl Ratio64Vec2{ pub const ONE:Self=Self{x:Ratio64::ONE,y:Ratio64::ONE}; #[inline] - pub fn new(x:Ratio64,y:Ratio64)->Self{ + pub const fn new(x:Ratio64,y:Ratio64)->Self{ Self{x,y} } #[inline] - pub fn mul_int(&self,rhs:glam::I64Vec2)->glam::I64Vec2{ + pub const fn mul_int(&self,rhs:glam::I64Vec2)->glam::I64Vec2{ glam::i64vec2( self.x.mul_int(rhs.x), self.y.mul_int(rhs.y), @@ -846,7 +846,7 @@ impl Default for Planar64Mat3{ } impl Planar64Mat3{ #[inline] - pub fn from_cols(x_axis:Planar64Vec3,y_axis:Planar64Vec3,z_axis:Planar64Vec3)->Self{ + pub const fn from_cols(x_axis:Planar64Vec3,y_axis:Planar64Vec3,z_axis:Planar64Vec3)->Self{ Self{ x_axis, y_axis,