This commit is contained in:
Quaternions 2024-03-02 04:58:39 -08:00
parent b065f83faf
commit 9aec0e1b52
2 changed files with 22 additions and 28 deletions

View File

@ -50,12 +50,12 @@ pub enum StageElementBehaviour{
Checkpoint,//this is a combined behaviour for Ordered & Unordered in case a model is used multiple times or for both. Checkpoint,//this is a combined behaviour for Ordered & Unordered in case a model is used multiple times or for both.
} }
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)] #[derive(Clone,Copy,Debug,Hash,id::Id,Eq,PartialEq)]
pub struct CheckpointId(u32); pub struct CheckpointId(u32);
impl CheckpointId{ impl CheckpointId{
pub const FIRST:Self=Self(0); pub const FIRST:Self=Self(0);
} }
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq,Ord,PartialOrd)] #[derive(Clone,Copy,Debug,Hash,id::Id,Eq,PartialEq,Ord,PartialOrd)]
pub struct StageId(u32); pub struct StageId(u32);
impl StageId{ impl StageId{
pub const FIRST:Self=Self(0); pub const FIRST:Self=Self(0);
@ -120,7 +120,7 @@ pub enum Zone{
Finish, Finish,
Anticheat, Anticheat,
} }
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq,Ord,PartialOrd)] #[derive(Clone,Copy,Debug,Hash,id::Id,Eq,PartialEq,Ord,PartialOrd)]
pub struct ModeId(u32); pub struct ModeId(u32);
impl ModeId{ impl ModeId{
pub const MAIN:Self=Self(0); pub const MAIN:Self=Self(0);

View File

@ -10,24 +10,24 @@ impl Time{
pub const ONE_MICROSECOND:Self=Self(1_000); pub const ONE_MICROSECOND:Self=Self(1_000);
pub const ONE_NANOSECOND:Self=Self(1); pub const ONE_NANOSECOND:Self=Self(1);
#[inline] #[inline]
pub fn from_secs(num:i64)->Self{ pub const fn from_secs(num:i64)->Self{
Self(Self::ONE_SECOND.0*num) Self(Self::ONE_SECOND.0*num)
} }
#[inline] #[inline]
pub fn from_millis(num:i64)->Self{ pub const fn from_millis(num:i64)->Self{
Self(Self::ONE_MILLISECOND.0*num) Self(Self::ONE_MILLISECOND.0*num)
} }
#[inline] #[inline]
pub fn from_micros(num:i64)->Self{ pub const fn from_micros(num:i64)->Self{
Self(Self::ONE_MICROSECOND.0*num) Self(Self::ONE_MICROSECOND.0*num)
} }
#[inline] #[inline]
pub fn from_nanos(num:i64)->Self{ pub const fn from_nanos(num:i64)->Self{
Self(Self::ONE_NANOSECOND.0*num) Self(Self::ONE_NANOSECOND.0*num)
} }
//should I have checked subtraction? force all time variables to be positive? //should I have checked subtraction? force all time variables to be positive?
#[inline] #[inline]
pub fn nanos(&self)->i64{ pub const fn nanos(self)->i64{
self.0 self.0
} }
} }
@ -91,7 +91,7 @@ const fn gcd(mut a:u64,mut b:u64)->u64{
}; };
a a
} }
#[derive(Clone,Hash)] #[derive(Clone,Copy,Debug,Hash)]
pub struct Ratio64{ pub struct Ratio64{
num:i64, num:i64,
den:u64, den:u64,
@ -109,15 +109,15 @@ impl Ratio64{
} }
} }
#[inline] #[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) rhs*self.num/(self.den as i64)
} }
#[inline] #[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 rhs*(self.den as i64)/self.num
} }
#[inline] #[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 (num,den)=(self.num*rhs.num,self.den*rhs.den);
let d=gcd(num.unsigned_abs(),den); let d=gcd(num.unsigned_abs(),den);
Self{ Self{
@ -259,7 +259,7 @@ impl std::ops::Div<u64> for Ratio64{
} }
} }
} }
#[derive(Clone,Hash)] #[derive(Clone,Copy,Debug,Hash)]
pub struct Ratio64Vec2{ pub struct Ratio64Vec2{
pub x:Ratio64, pub x:Ratio64,
pub y:Ratio64, pub y:Ratio64,
@ -267,11 +267,11 @@ pub struct Ratio64Vec2{
impl Ratio64Vec2{ impl Ratio64Vec2{
pub const ONE:Self=Self{x:Ratio64::ONE,y:Ratio64::ONE}; pub const ONE:Self=Self{x:Ratio64::ONE,y:Ratio64::ONE};
#[inline] #[inline]
pub fn new(x:Ratio64,y:Ratio64)->Self{ pub const fn new(x:Ratio64,y:Ratio64)->Self{
Self{x,y} Self{x,y}
} }
#[inline] #[inline]
pub fn mul_int(&self,rhs:glam::I64Vec2)->glam::I64Vec2{ pub const fn mul_int(&self,rhs:glam::I64Vec2)->glam::I64Vec2{
glam::i64vec2( glam::i64vec2(
self.x.mul_int(rhs.x), self.x.mul_int(rhs.x),
self.y.mul_int(rhs.y), self.y.mul_int(rhs.y),
@ -606,15 +606,15 @@ impl Planar64Vec3{
Self(glam::i64vec3(x,y,z)) Self(glam::i64vec3(x,y,z))
} }
#[inline] #[inline]
pub fn x(&self)->Planar64{ pub const fn x(&self)->Planar64{
Planar64(self.0.x) Planar64(self.0.x)
} }
#[inline] #[inline]
pub fn y(&self)->Planar64{ pub const fn y(&self)->Planar64{
Planar64(self.0.y) Planar64(self.0.y)
} }
#[inline] #[inline]
pub fn z(&self)->Planar64{ pub const fn z(&self)->Planar64{
Planar64(self.0.z) Planar64(self.0.z)
} }
#[inline] #[inline]
@ -642,7 +642,7 @@ impl Planar64Vec3{
self.0.cmplt(rhs.0) self.0.cmplt(rhs.0)
} }
#[inline] #[inline]
pub fn dot(&self,rhs:Self)->Planar64{ pub const fn dot(&self,rhs:Self)->Planar64{
Planar64((( Planar64(((
(self.0.x as i128)*(rhs.0.x as i128)+ (self.0.x as i128)*(rhs.0.x as i128)+
(self.0.y as i128)*(rhs.0.y as i128)+ (self.0.y as i128)*(rhs.0.y as i128)+
@ -650,13 +650,13 @@ impl Planar64Vec3{
)>>32) as i64) )>>32) as i64)
} }
#[inline] #[inline]
pub fn dot128(&self,rhs:Self)->i128{ pub const fn dot128(&self,rhs:Self)->i128{
(self.0.x as i128)*(rhs.0.x as i128)+ (self.0.x as i128)*(rhs.0.x as i128)+
(self.0.y as i128)*(rhs.0.y as i128)+ (self.0.y as i128)*(rhs.0.y as i128)+
(self.0.z as i128)*(rhs.0.z as i128) (self.0.z as i128)*(rhs.0.z as i128)
} }
#[inline] #[inline]
pub fn cross(&self,rhs:Self)->Planar64Vec3{ pub const fn cross(&self,rhs:Self)->Planar64Vec3{
Planar64Vec3(glam::i64vec3( Planar64Vec3(glam::i64vec3(
(((self.0.y as i128)*(rhs.0.z as i128)-(self.0.z as i128)*(rhs.0.y as i128))>>32) as i64, (((self.0.y as i128)*(rhs.0.z as i128)-(self.0.z as i128)*(rhs.0.y as i128))>>32) as i64,
(((self.0.z as i128)*(rhs.0.x as i128)-(self.0.x as i128)*(rhs.0.z as i128))>>32) as i64, (((self.0.z as i128)*(rhs.0.x as i128)-(self.0.x as i128)*(rhs.0.z as i128))>>32) as i64,
@ -664,12 +664,6 @@ impl Planar64Vec3{
)) ))
} }
#[inline] #[inline]
pub fn walkable(&self,slope:Planar64,up:Self)->bool{
let y=self.dot(up);
let x=self.cross(up).length();
x*slope<y
}
#[inline]
pub fn length(&self)->Planar64{ pub fn length(&self)->Planar64{
let radicand=(self.0.x as i128)*(self.0.x as i128)+(self.0.y as i128)*(self.0.y as i128)+(self.0.z as i128)*(self.0.z as i128); let radicand=(self.0.x as i128)*(self.0.x as i128)+(self.0.y as i128)*(self.0.y as i128)+(self.0.z as i128)*(self.0.z as i128);
Planar64(unsafe{(radicand as f64).sqrt().to_int_unchecked()}) Planar64(unsafe{(radicand as f64).sqrt().to_int_unchecked()})
@ -846,7 +840,7 @@ impl Default for Planar64Mat3{
} }
impl Planar64Mat3{ impl Planar64Mat3{
#[inline] #[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{ Self{
x_axis, x_axis,
y_axis, y_axis,