const things and code moves

This commit is contained in:
Quaternions 2024-02-16 17:39:04 -08:00
parent 73cd6b74fc
commit 12907fa4a9
2 changed files with 20 additions and 10 deletions

View File

@ -170,10 +170,17 @@ pub struct StrafeSettings{
tick_rate:Ratio64,
}
impl StrafeSettings{
pub fn tick_velocity(&self,velocity:Planar64Vec3,control_dir:Planar64Vec3)->Option<Planar64Vec3>{
let d=velocity.dot(control_dir);
match d<self.mv{
true=>Some(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)]

View File

@ -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<u64> 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,