constructors for unconstructable types

This commit is contained in:
Quaternions 2024-07-23 19:04:53 -07:00
parent 0215df9f96
commit 6cd5234c91
4 changed files with 82 additions and 6 deletions

View File

@ -13,6 +13,9 @@ impl Default for Aabb {
} }
impl Aabb{ impl Aabb{
pub fn new(min:Planar64Vec3,max:Planar64Vec3)->Self{
Self{min,max}
}
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);
@ -43,4 +46,4 @@ impl Aabb{
// let d=self.max-self.min; // let d=self.max-self.min;
// d.x*d.y*d.z // d.x*d.y*d.z
// } // }
} }

View File

@ -71,7 +71,22 @@ pub struct Stage{
unordered_checkpoints:HashSet<ModelId>, unordered_checkpoints:HashSet<ModelId>,
} }
impl Stage{ impl Stage{
pub fn new(spawn:ModelId)->Self{ pub fn new(
spawn:ModelId,
ordered_checkpoints_count:u32,
unordered_checkpoints_count:u32,
ordered_checkpoints:HashMap<CheckpointId,ModelId>,
unordered_checkpoints:HashSet<ModelId>,
)->Self{
Self{
spawn,
ordered_checkpoints_count,
unordered_checkpoints_count,
ordered_checkpoints,
unordered_checkpoints,
}
}
pub fn empty(spawn:ModelId)->Self{
Self{ Self{
spawn, spawn,
ordered_checkpoints_count:0, ordered_checkpoints_count:0,
@ -136,7 +151,22 @@ pub struct Mode{
elements:HashMap<ModelId,StageElement>, elements:HashMap<ModelId,StageElement>,
} }
impl Mode{ impl Mode{
pub fn new(style:gameplay_style::StyleModifiers,start:ModelId)->Self{ pub fn new(
style:gameplay_style::StyleModifiers,
start:ModelId,
zones:HashMap<ModelId,Zone>,
stages:Vec<Stage>,
elements:HashMap<ModelId,StageElement>,
)->Self{
Self{
style,
start,
zones,
stages,
elements,
}
}
pub fn empty(style:gameplay_style::StyleModifiers,start:ModelId)->Self{
Self{ Self{
style, style,
start, start,
@ -269,4 +299,4 @@ impl Updatable<ModesUpdate> for Modes{
} }
} }
} }
} }

View File

@ -15,7 +15,7 @@ pub struct StyleModifiers{
pub rocket:Option<PropulsionSettings>, pub rocket:Option<PropulsionSettings>,
//flying //flying
//pub move_type:MoveType::Fly(FlySettings) //pub move_type:MoveType::Fly(FlySettings)
//MoveType::Physics(PhysicsSettings) -> PhysicsSettings includes gravity //MoveType::Physics(PhysicsSettings) -> PhysicsSettings (strafe,rocket,jump,walk,ladder,swim,gravity)
//jumping is allowed //jumping is allowed
pub jump:Option<JumpSettings>, pub jump:Option<JumpSettings>,
//standing & walking is allowed //standing & walking is allowed
@ -168,6 +168,14 @@ pub struct StrafeSettings{
tick_rate:Ratio64, tick_rate:Ratio64,
} }
impl StrafeSettings{ impl StrafeSettings{
pub fn new(
enable:ControlsActivation,
mv:Planar64,
air_accel_limit:Option<Planar64>,
tick_rate:Ratio64,
)->Self{
Self{enable,mv,air_accel_limit,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{
@ -191,6 +199,9 @@ pub struct PropulsionSettings{
magnitude:Planar64, magnitude:Planar64,
} }
impl PropulsionSettings{ impl PropulsionSettings{
pub fn new(magnitude:Planar64)->Self{
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
} }
@ -204,6 +215,12 @@ pub struct JumpSettings{
calculation:JumpCalculation, calculation:JumpCalculation,
} }
impl JumpSettings{ impl JumpSettings{
pub fn new(
impulse:JumpImpulse,
calculation:JumpCalculation,
)->Self{
Self{impulse,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
@ -221,6 +238,14 @@ pub struct AccelerateSettings{
accel:Planar64, accel:Planar64,
topspeed:Planar64, topspeed:Planar64,
} }
impl AccelerateSettings{
pub fn new(
accel:Planar64,
topspeed:Planar64,
)->Self{
Self{accel,topspeed}
}
}
#[derive(Clone,Debug)] #[derive(Clone,Debug)]
pub struct WalkSettings{ pub struct WalkSettings{
accelerate:AccelerateSettings, accelerate:AccelerateSettings,
@ -230,6 +255,14 @@ 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(
accelerate:AccelerateSettings,
static_friction:Planar64,
kinetic_friction:Planar64,
surf_dot:Planar64,
)->Self{
Self{accelerate,static_friction,kinetic_friction,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();
@ -275,6 +308,12 @@ pub struct LadderSettings{
dot:Planar64, dot:Planar64,
} }
impl LadderSettings{ impl LadderSettings{
pub fn new(
accelerate:AccelerateSettings,
dot:Planar64,
)->Self{
Self{accelerate,dot}
}
pub fn accel(&self,target_diff:Planar64Vec3,gravity:Planar64Vec3)->Planar64{ pub 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

@ -10,6 +10,10 @@ 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 const fn raw(num:i64)->Self{
Self(num)
}
#[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)
} }
@ -1046,4 +1050,4 @@ fn test_sqrt(){
assert_eq!(1717986918400,r.get()); assert_eq!(1717986918400,r.get());
let s=r.sqrt(); let s=r.sqrt();
assert_eq!(85899345920,s.get()); assert_eq!(85899345920,s.get());
} }