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{
pub fn new(min:Planar64Vec3,max:Planar64Vec3)->Self{
Self{min,max}
}
pub fn grow(&mut self,point:Planar64Vec3){
self.min=self.min.min(point);
self.max=self.max.max(point);

View File

@ -71,7 +71,22 @@ pub struct Stage{
unordered_checkpoints:HashSet<ModelId>,
}
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{
spawn,
ordered_checkpoints_count:0,
@ -136,7 +151,22 @@ pub struct Mode{
elements:HashMap<ModelId,StageElement>,
}
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{
style,
start,

View File

@ -15,7 +15,7 @@ pub struct StyleModifiers{
pub rocket:Option<PropulsionSettings>,
//flying
//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
pub jump:Option<JumpSettings>,
//standing & walking is allowed
@ -168,6 +168,14 @@ pub struct StrafeSettings{
tick_rate:Ratio64,
}
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>{
let d=velocity.dot(control_dir);
match d<self.mv{
@ -191,6 +199,9 @@ pub struct PropulsionSettings{
magnitude:Planar64,
}
impl PropulsionSettings{
pub fn new(magnitude:Planar64)->Self{
Self{magnitude}
}
pub fn acceleration(&self,control_dir:Planar64Vec3)->Planar64Vec3{
control_dir*self.magnitude
}
@ -204,6 +215,12 @@ pub struct JumpSettings{
calculation:JumpCalculation,
}
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{
match self.calculation{
//roblox style
@ -221,6 +238,14 @@ pub struct AccelerateSettings{
accel:Planar64,
topspeed:Planar64,
}
impl AccelerateSettings{
pub fn new(
accel:Planar64,
topspeed:Planar64,
)->Self{
Self{accel,topspeed}
}
}
#[derive(Clone,Debug)]
pub struct WalkSettings{
accelerate:AccelerateSettings,
@ -230,6 +255,14 @@ pub struct WalkSettings{
surf_dot:Planar64,//surf_dot<n.dot(up)/n.length()
}
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{
//TODO: fallible walk accel
let diff_len=target_diff.length();
@ -275,6 +308,12 @@ pub struct LadderSettings{
dot:Planar64,
}
impl LadderSettings{
pub fn new(
accelerate:AccelerateSettings,
dot:Planar64,
)->Self{
Self{accelerate,dot}
}
pub fn accel(&self,target_diff:Planar64Vec3,gravity:Planar64Vec3)->Planar64{
//TODO: fallible ladder accel
self.accelerate.accel

View File

@ -10,6 +10,10 @@ impl Time{
pub const ONE_MICROSECOND:Self=Self(1_000);
pub const ONE_NANOSECOND:Self=Self(1);
#[inline]
pub const fn raw(num:i64)->Self{
Self(num)
}
#[inline]
pub const fn from_secs(num:i64)->Self{
Self(Self::ONE_SECOND.0*num)
}