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

@ -13,9 +13,15 @@ impl Default for Aabb {
}
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);

View File

@ -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<CheckpointId,ModelId>,HashSet<ModelId>){
(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<ModelId,Zone>,
Vec<Stage>,
HashMap<ModelId,StageElement>,
){
(
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<Mode>,
pub modes:Vec<Mode>,
}
impl Modes{
pub fn new(modes:Vec<Mode>)->Self{
pub const fn new(modes:Vec<Mode>)->Self{
Self{
modes,
}
}
pub fn into_inner(self)->Vec<Mode>{
self.modes
}
pub fn push_mode(&mut self,mode:Mode){
self.modes.push(mode)
}

View File

@ -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<Planar64>,
@ -176,6 +185,9 @@ impl StrafeSettings{
)->Self{
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>{
let d=velocity.dot(control_dir);
match d<self.mv{
@ -199,9 +211,12 @@ pub struct PropulsionSettings{
magnitude:Planar64,
}
impl PropulsionSettings{
pub fn new(magnitude:Planar64)->Self{
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_dot<n.dot(up)/n.length()
}
impl WalkSettings{
pub fn new(
pub const fn new(
accelerate:AccelerateSettings,
static_friction:Planar64,
kinetic_friction:Planar64,
@ -263,6 +287,9 @@ impl WalkSettings{
)->Self{
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
}

View File

@ -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))
}