From ba00fed9b89309b19904a27720d3caa0e81911f6 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 25 Jul 2024 12:13:32 -0700 Subject: [PATCH] accessors --- src/aabb.rs | 12 +++++++++--- src/gameplay_modes.rs | 33 ++++++++++++++++++++++++++++++-- src/gameplay_style.rs | 44 ++++++++++++++++++++++++++++++++++++------- src/integer.rs | 16 ++++++++++++++++ 4 files changed, 93 insertions(+), 12 deletions(-) diff --git a/src/aabb.rs b/src/aabb.rs index 4421eef..7494fc4 100644 --- a/src/aabb.rs +++ b/src/aabb.rs @@ -6,16 +6,22 @@ pub struct Aabb{ max:Planar64Vec3, } -impl Default for Aabb { - fn default()->Self { +impl Default for Aabb{ + fn default()->Self{ Self{min:Planar64Vec3::MAX,max:Planar64Vec3::MIN} } } impl Aabb{ - pub fn new(min:Planar64Vec3,max:Planar64Vec3)->Self{ + pub const fn new(min:Planar64Vec3,max:Planar64Vec3)->Self{ 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){ self.min=self.min.min(point); self.max=self.max.max(point); diff --git a/src/gameplay_modes.rs b/src/gameplay_modes.rs index 872646e..b35acc6 100644 --- a/src/gameplay_modes.rs +++ b/src/gameplay_modes.rs @@ -100,6 +100,17 @@ impl Stage{ self.spawn } #[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,HashSet){ + (self.ordered_checkpoints,self.unordered_checkpoints) + } + #[inline] pub const fn is_empty(&self)->bool{ self.is_complete(0,0) } @@ -175,6 +186,21 @@ impl Mode{ elements:HashMap::new(), } } + pub fn into_inner(self)->( + gameplay_style::StyleModifiers, + ModelId, + HashMap, + Vec, + HashMap, + ){ + ( + self.style, + self.start, + self.zones, + self.stages, + self.elements, + ) + } pub const fn get_start(&self)->ModelId{ self.start } @@ -273,14 +299,17 @@ impl ModeUpdate{ #[derive(Default,Clone)] pub struct Modes{ - modes:Vec, + pub modes:Vec, } impl Modes{ - pub fn new(modes:Vec)->Self{ + pub const fn new(modes:Vec)->Self{ Self{ modes, } } + pub fn into_inner(self)->Vec{ + self.modes + } pub fn push_mode(&mut self,mode:Mode){ self.modes.push(mode) } diff --git a/src/gameplay_style.rs b/src/gameplay_style.rs index 14b2b7f..d28dd9e 100644 --- a/src/gameplay_style.rs +++ b/src/gameplay_style.rs @@ -94,6 +94,15 @@ impl ControlsActivation{ 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{ controls.intersection(self.controls_mask) } @@ -168,7 +177,7 @@ pub struct StrafeSettings{ tick_rate:Ratio64, } impl StrafeSettings{ - pub fn new( + pub const fn new( enable:ControlsActivation, mv:Planar64, air_accel_limit:Option, @@ -176,6 +185,9 @@ impl StrafeSettings{ )->Self{ Self{enable,mv,air_accel_limit,tick_rate} } + pub fn into_inner(self)->(ControlsActivation,Planar64,Option,Ratio64){ + (self.enable,self.mv,self.air_accel_limit,self.tick_rate) + } pub fn tick_velocity(&self,velocity:Planar64Vec3,control_dir:Planar64Vec3)->Option{ let d=velocity.dot(control_dir); match dSelf{ + pub const fn new(magnitude:Planar64)->Self{ Self{magnitude} } + pub fn magnitude(&self)->Planar64{ + self.magnitude + } pub fn acceleration(&self,control_dir:Planar64Vec3)->Planar64Vec3{ control_dir*self.magnitude } @@ -215,12 +230,15 @@ pub struct JumpSettings{ calculation:JumpCalculation, } impl JumpSettings{ - pub fn new( + pub const fn new( impulse:JumpImpulse, calculation:JumpCalculation, )->Self{ 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{ match self.calculation{ //roblox style @@ -239,12 +257,18 @@ pub struct AccelerateSettings{ topspeed:Planar64, } impl AccelerateSettings{ - pub fn new( + pub const fn new( accel:Planar64, topspeed:Planar64, )->Self{ Self{accel,topspeed} } + pub const fn accel(&self)->Planar64{ + self.accel + } + pub const fn topspeed(&self)->Planar64{ + self.topspeed + } } #[derive(Clone,Debug)] pub struct WalkSettings{ @@ -255,7 +279,7 @@ pub struct WalkSettings{ surf_dot:Planar64,//surf_dotSelf{ 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{ //TODO: fallible walk accel let diff_len=target_diff.length(); @@ -308,13 +335,16 @@ pub struct LadderSettings{ dot:Planar64, } impl LadderSettings{ - pub fn new( + pub const fn new( accelerate:AccelerateSettings, dot:Planar64, )->Self{ 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 self.accelerate.accel } diff --git a/src/integer.rs b/src/integer.rs index 1601806..824fe8a 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -14,6 +14,10 @@ impl Time{ Self(num) } #[inline] + pub const fn get(self)->i64{ + self.0 + } + #[inline] pub const fn from_secs(num:i64)->Self{ Self(Self::ONE_SECOND.0*num) } @@ -113,6 +117,14 @@ impl Ratio64{ } } #[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{ rhs*self.num/(self.den as i64) } @@ -602,6 +614,10 @@ impl Planar64Vec3{ Self(glam::i64vec3(x.0,y.0,z.0)) } #[inline] + pub const fn get(self)->glam::I64Vec3{ + self.0 + } + #[inline] 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)) }