accessors

This commit is contained in:
Quaternions 2024-07-25 12:13:32 -07:00
parent 7e91c85822
commit ba00fed9b8
4 changed files with 93 additions and 12 deletions

View File

@ -6,16 +6,22 @@ pub struct Aabb{
max:Planar64Vec3, max:Planar64Vec3,
} }
impl Default for Aabb { impl Default for Aabb{
fn default()->Self { fn default()->Self{
Self{min:Planar64Vec3::MAX,max:Planar64Vec3::MIN} Self{min:Planar64Vec3::MAX,max:Planar64Vec3::MIN}
} }
} }
impl Aabb{ impl Aabb{
pub fn new(min:Planar64Vec3,max:Planar64Vec3)->Self{ pub const fn new(min:Planar64Vec3,max:Planar64Vec3)->Self{
Self{min,max} Self{min,max}
} }
pub const fn max(&self)->Planar64Vec3{
self.max
}
pub const fn min(&self)->Planar64Vec3{
self.min
}
pub fn grow(&mut self,point:Planar64Vec3){ pub fn grow(&mut self,point:Planar64Vec3){
self.min=self.min.min(point); self.min=self.min.min(point);
self.max=self.max.max(point); self.max=self.max.max(point);

View File

@ -100,6 +100,17 @@ impl Stage{
self.spawn self.spawn
} }
#[inline] #[inline]
pub const fn ordered_checkpoints_count(&self)->u32{
self.ordered_checkpoints_count
}
#[inline]
pub const fn unordered_checkpoints_count(&self)->u32{
self.unordered_checkpoints_count
}
pub fn into_inner(self)->(HashMap<CheckpointId,ModelId>,HashSet<ModelId>){
(self.ordered_checkpoints,self.unordered_checkpoints)
}
#[inline]
pub const fn is_empty(&self)->bool{ pub const fn is_empty(&self)->bool{
self.is_complete(0,0) self.is_complete(0,0)
} }
@ -175,6 +186,21 @@ impl Mode{
elements:HashMap::new(), elements:HashMap::new(),
} }
} }
pub fn into_inner(self)->(
gameplay_style::StyleModifiers,
ModelId,
HashMap<ModelId,Zone>,
Vec<Stage>,
HashMap<ModelId,StageElement>,
){
(
self.style,
self.start,
self.zones,
self.stages,
self.elements,
)
}
pub const fn get_start(&self)->ModelId{ pub const fn get_start(&self)->ModelId{
self.start self.start
} }
@ -273,14 +299,17 @@ impl ModeUpdate{
#[derive(Default,Clone)] #[derive(Default,Clone)]
pub struct Modes{ pub struct Modes{
modes:Vec<Mode>, pub modes:Vec<Mode>,
} }
impl Modes{ impl Modes{
pub fn new(modes:Vec<Mode>)->Self{ pub const fn new(modes:Vec<Mode>)->Self{
Self{ Self{
modes, modes,
} }
} }
pub fn into_inner(self)->Vec<Mode>{
self.modes
}
pub fn push_mode(&mut self,mode:Mode){ pub fn push_mode(&mut self,mode:Mode){
self.modes.push(mode) self.modes.push(mode)
} }

View File

@ -94,6 +94,15 @@ impl ControlsActivation{
controls_contains, controls_contains,
} }
} }
pub const fn controls_mask(&self)->Controls{
self.controls_mask
}
pub const fn controls_intersects(&self)->Controls{
self.controls_intersects
}
pub const fn controls_contains(&self)->Controls{
self.controls_contains
}
pub const fn mask(&self,controls:Controls)->Controls{ pub const fn mask(&self,controls:Controls)->Controls{
controls.intersection(self.controls_mask) controls.intersection(self.controls_mask)
} }
@ -168,7 +177,7 @@ pub struct StrafeSettings{
tick_rate:Ratio64, tick_rate:Ratio64,
} }
impl StrafeSettings{ impl StrafeSettings{
pub fn new( pub const fn new(
enable:ControlsActivation, enable:ControlsActivation,
mv:Planar64, mv:Planar64,
air_accel_limit:Option<Planar64>, air_accel_limit:Option<Planar64>,
@ -176,6 +185,9 @@ impl StrafeSettings{
)->Self{ )->Self{
Self{enable,mv,air_accel_limit,tick_rate} Self{enable,mv,air_accel_limit,tick_rate}
} }
pub fn into_inner(self)->(ControlsActivation,Planar64,Option<Planar64>,Ratio64){
(self.enable,self.mv,self.air_accel_limit,self.tick_rate)
}
pub fn tick_velocity(&self,velocity:Planar64Vec3,control_dir:Planar64Vec3)->Option<Planar64Vec3>{ pub fn tick_velocity(&self,velocity:Planar64Vec3,control_dir:Planar64Vec3)->Option<Planar64Vec3>{
let d=velocity.dot(control_dir); let d=velocity.dot(control_dir);
match d<self.mv{ match d<self.mv{
@ -199,9 +211,12 @@ pub struct PropulsionSettings{
magnitude:Planar64, magnitude:Planar64,
} }
impl PropulsionSettings{ impl PropulsionSettings{
pub fn new(magnitude:Planar64)->Self{ pub const fn new(magnitude:Planar64)->Self{
Self{magnitude} Self{magnitude}
} }
pub fn magnitude(&self)->Planar64{
self.magnitude
}
pub fn acceleration(&self,control_dir:Planar64Vec3)->Planar64Vec3{ pub fn acceleration(&self,control_dir:Planar64Vec3)->Planar64Vec3{
control_dir*self.magnitude control_dir*self.magnitude
} }
@ -215,12 +230,15 @@ pub struct JumpSettings{
calculation:JumpCalculation, calculation:JumpCalculation,
} }
impl JumpSettings{ impl JumpSettings{
pub fn new( pub const fn new(
impulse:JumpImpulse, impulse:JumpImpulse,
calculation:JumpCalculation, calculation:JumpCalculation,
)->Self{ )->Self{
Self{impulse,calculation} Self{impulse,calculation}
} }
pub fn into_inner(self)->(JumpImpulse,JumpCalculation){
(self.impulse,self.calculation)
}
pub fn jumped_velocity(&self,style:&StyleModifiers,jump_dir:Planar64Vec3,velocity:Planar64Vec3)->Planar64Vec3{ pub fn jumped_velocity(&self,style:&StyleModifiers,jump_dir:Planar64Vec3,velocity:Planar64Vec3)->Planar64Vec3{
match self.calculation{ match self.calculation{
//roblox style //roblox style
@ -239,12 +257,18 @@ pub struct AccelerateSettings{
topspeed:Planar64, topspeed:Planar64,
} }
impl AccelerateSettings{ impl AccelerateSettings{
pub fn new( pub const fn new(
accel:Planar64, accel:Planar64,
topspeed:Planar64, topspeed:Planar64,
)->Self{ )->Self{
Self{accel,topspeed} Self{accel,topspeed}
} }
pub const fn accel(&self)->Planar64{
self.accel
}
pub const fn topspeed(&self)->Planar64{
self.topspeed
}
} }
#[derive(Clone,Debug)] #[derive(Clone,Debug)]
pub struct WalkSettings{ pub struct WalkSettings{
@ -255,7 +279,7 @@ pub struct WalkSettings{
surf_dot:Planar64,//surf_dot<n.dot(up)/n.length() surf_dot:Planar64,//surf_dot<n.dot(up)/n.length()
} }
impl WalkSettings{ impl WalkSettings{
pub fn new( pub const fn new(
accelerate:AccelerateSettings, accelerate:AccelerateSettings,
static_friction:Planar64, static_friction:Planar64,
kinetic_friction:Planar64, kinetic_friction:Planar64,
@ -263,6 +287,9 @@ impl WalkSettings{
)->Self{ )->Self{
Self{accelerate,static_friction,kinetic_friction,surf_dot} Self{accelerate,static_friction,kinetic_friction,surf_dot}
} }
pub fn into_inner(self)->(AccelerateSettings,Planar64,Planar64,Planar64){
(self.accelerate,self.static_friction,self.kinetic_friction,self.surf_dot)
}
pub fn accel(&self,target_diff:Planar64Vec3,gravity:Planar64Vec3)->Planar64{ pub fn accel(&self,target_diff:Planar64Vec3,gravity:Planar64Vec3)->Planar64{
//TODO: fallible walk accel //TODO: fallible walk accel
let diff_len=target_diff.length(); let diff_len=target_diff.length();
@ -308,13 +335,16 @@ pub struct LadderSettings{
dot:Planar64, dot:Planar64,
} }
impl LadderSettings{ impl LadderSettings{
pub fn new( pub const fn new(
accelerate:AccelerateSettings, accelerate:AccelerateSettings,
dot:Planar64, dot:Planar64,
)->Self{ )->Self{
Self{accelerate,dot} Self{accelerate,dot}
} }
pub fn accel(&self,target_diff:Planar64Vec3,gravity:Planar64Vec3)->Planar64{ pub fn into_inner(self)->(AccelerateSettings,Planar64){
(self.accelerate,self.dot)
}
pub const fn accel(&self,target_diff:Planar64Vec3,gravity:Planar64Vec3)->Planar64{
//TODO: fallible ladder accel //TODO: fallible ladder accel
self.accelerate.accel self.accelerate.accel
} }

View File

@ -14,6 +14,10 @@ impl Time{
Self(num) Self(num)
} }
#[inline] #[inline]
pub const fn get(self)->i64{
self.0
}
#[inline]
pub const 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)
} }
@ -113,6 +117,14 @@ impl Ratio64{
} }
} }
#[inline] #[inline]
pub const fn num(self)->i64{
self.num
}
#[inline]
pub const fn den(self)->u64{
self.den
}
#[inline]
pub const 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)
} }
@ -602,6 +614,10 @@ impl Planar64Vec3{
Self(glam::i64vec3(x.0,y.0,z.0)) Self(glam::i64vec3(x.0,y.0,z.0))
} }
#[inline] #[inline]
pub const fn get(self)->glam::I64Vec3{
self.0
}
#[inline]
pub const fn int(x:i32,y:i32,z:i32)->Self{ pub const fn int(x:i32,y:i32,z:i32)->Self{
Self(glam::i64vec3((x as i64)<<32,(y as i64)<<32,(z as i64)<<32)) Self(glam::i64vec3((x as i64)<<32,(y as i64)<<32,(z as i64)<<32))
} }