diff --git a/src/gameplay_style.rs b/src/gameplay_style.rs index 329e2db..1d5d814 100644 --- a/src/gameplay_style.rs +++ b/src/gameplay_style.rs @@ -1,6 +1,6 @@ const VALVE_SCALE:Planar64=Planar64::raw(1<<28);// 1/16 -use crate::integer::{Time,Ratio64,Planar64,Planar64Vec3,WideMul,WideDot}; +use crate::integer::{int,int3,Time,Ratio64,Planar64,Planar64Vec3}; use crate::controls_bitflag::Controls; #[derive(Clone,Debug)] @@ -69,10 +69,10 @@ impl JumpImpulse{ &JumpImpulse::Height(height)=>{ //height==-v.y*v.y/(2*g.y); //use energy to determine max height - let g=gravity.wide_length(); - let v_g=gravity.wide_dot(velocity); + let g=gravity.length_squared().sqrt().halve_precision(); + let v_g=gravity.dot(velocity); //do it backwards - velocity-gravity.with_length(((v_g.wide_mul(v_g)+g.wide_mul(height).wide_mul(2)).sqrt()+v_g).ratio(g)) + velocity-(*gravity*((v_g*v_g+g*height*(fixed_wide::fixed::Fixed::<2,64>::ONE*2)).sqrt().halve_precision()+v_g)/g).divide() }, &JumpImpulse::Linear(jump_speed)=>velocity+jump_dir.with_length(jump_speed), &JumpImpulse::Energy(energy)=>{ @@ -317,14 +317,14 @@ impl WalkSettings{ } let m=control_dir.length(); let n=normal.length(); - let nm=n.wide_mul(m); - let d=normal.wide_dot(control_dir); + let nm=n*m; + let d=normal.dot(control_dir); if dSelf{ Self{ - halfsize:Planar64Vec3::int(2,5,2)/2, + halfsize:int3(2,5,2)/2, mesh:HitboxMesh::Cylinder, } } pub fn source()->Self{ Self{ - halfsize:Planar64Vec3::int(33,73,33)/2*VALVE_SCALE, + halfsize:int3(33,73,33)/2*VALVE_SCALE, mesh:HitboxMesh::Box, } } @@ -424,38 +424,38 @@ impl StyleModifiers{ strafe:Some(StrafeSettings{ enable:ControlsActivation::full_2d(), air_accel_limit:None, - mv:Planar64::int(3), + mv:int(3), tick_rate:Ratio64::new(64,Time::ONE_SECOND.nanos() as u64).unwrap(), }), jump:Some(JumpSettings{ - impulse:JumpImpulse::Energy(Planar64::int(512)), + impulse:JumpImpulse::Energy(int(512)), calculation:JumpCalculation::JumpThenBoost, limit_minimum:false, }), - gravity:Planar64Vec3::int(0,-80,0), - mass:Planar64::int(1), + gravity:int3(0,-80,0), + mass:int(1), rocket:None, walk:Some(WalkSettings{ accelerate:AccelerateSettings{ - topspeed:Planar64::int(16), - accel:Planar64::int(80), + topspeed:int(16), + accel:int(80), }, - static_friction:Planar64::int(2), - kinetic_friction:Planar64::int(3),//unrealistic: kinetic friction is typically lower than static - surf_dot:Planar64::int(3)/4, + static_friction:int(2), + kinetic_friction:int(3),//unrealistic: kinetic friction is typically lower than static + surf_dot:int(3)/4, }), ladder:Some(LadderSettings{ accelerate:AccelerateSettings{ - topspeed:Planar64::int(16), - accel:Planar64::int(160), + topspeed:int(16), + accel:int(160), }, - dot:(Planar64::int(1)/2).sqrt(), + dot:(int(1)/2).sqrt(), }), swim:Some(PropulsionSettings{ - magnitude:Planar64::int(12), + magnitude:int(12), }), hitbox:Hitbox::roblox(), - camera_offset:Planar64Vec3::int(0,2,0),//4.5-2.5=2 + camera_offset:int3(0,2,0),//4.5-2.5=2 } } @@ -466,7 +466,7 @@ impl StyleModifiers{ strafe:Some(StrafeSettings{ enable:ControlsActivation::full_2d(), air_accel_limit:None, - mv:Planar64::int(27)/10, + mv:int(27)/10, tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), }), jump:Some(JumpSettings{ @@ -474,35 +474,35 @@ impl StyleModifiers{ calculation:JumpCalculation::Max, limit_minimum:true, }), - gravity:Planar64Vec3::int(0,-100,0), - mass:Planar64::int(1), + gravity:int3(0,-100,0), + mass:int(1), rocket:None, walk:Some(WalkSettings{ accelerate:AccelerateSettings{ - topspeed:Planar64::int(18), - accel:Planar64::int(90), + topspeed:int(18), + accel:int(90), }, - static_friction:Planar64::int(2), - kinetic_friction:Planar64::int(3),//unrealistic: kinetic friction is typically lower than static - surf_dot:Planar64::int(3)/4,// normal.y=0.75 + static_friction:int(2), + kinetic_friction:int(3),//unrealistic: kinetic friction is typically lower than static + surf_dot:int(3)/4,// normal.y=0.75 }), ladder:Some(LadderSettings{ accelerate:AccelerateSettings{ - topspeed:Planar64::int(18), - accel:Planar64::int(180), + topspeed:int(18), + accel:int(180), }, - dot:(Planar64::int(1)/2).sqrt(), + dot:(int(1)/2).sqrt(), }), swim:Some(PropulsionSettings{ - magnitude:Planar64::int(12), + magnitude:int(12), }), hitbox:Hitbox::roblox(), - camera_offset:Planar64Vec3::int(0,2,0),//4.5-2.5=2 + camera_offset:int3(0,2,0),//4.5-2.5=2 } } pub fn roblox_surf()->Self{ Self{ - gravity:Planar64Vec3::int(0,-50,0), + gravity:int3(0,-50,0), ..Self::roblox_bhop() } } @@ -510,7 +510,7 @@ impl StyleModifiers{ Self{ strafe:None, rocket:Some(PropulsionSettings{ - magnitude:Planar64::int(200), + magnitude:int(200), }), ..Self::roblox_bhop() } @@ -527,34 +527,34 @@ impl StyleModifiers{ tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), }), jump:Some(JumpSettings{ - impulse:JumpImpulse::Height(Planar64::int(52)*VALVE_SCALE), + impulse:JumpImpulse::Height(int(52)*VALVE_SCALE), calculation:JumpCalculation::JumpThenBoost, limit_minimum:true, }), - gravity:Planar64Vec3::int(0,-800,0)*VALVE_SCALE, - mass:Planar64::int(1), + gravity:int3(0,-800,0)*VALVE_SCALE, + mass:int(1), rocket:None, walk:Some(WalkSettings{ accelerate:AccelerateSettings{ - topspeed:Planar64::int(18),//? - accel:Planar64::int(90),//? + topspeed:int(18),//? + accel:int(90),//? }, - static_friction:Planar64::int(2),//? - kinetic_friction:Planar64::int(3),//? - surf_dot:Planar64::int(3)/4,// normal.y=0.75 + static_friction:int(2),//? + kinetic_friction:int(3),//? + surf_dot:int(3)/4,// normal.y=0.75 }), ladder:Some(LadderSettings{ accelerate:AccelerateSettings{ - topspeed:Planar64::int(18),//? - accel:Planar64::int(180),//? + topspeed:int(18),//? + accel:int(180),//? }, - dot:(Planar64::int(1)/2).sqrt(),//? + dot:(int(1)/2).sqrt(),//? }), swim:Some(PropulsionSettings{ - magnitude:Planar64::int(12),//? + magnitude:int(12),//? }), hitbox:Hitbox::source(), - camera_offset:(Planar64Vec3::int(0,64,0)-Planar64Vec3::int(0,73,0)/2)*VALVE_SCALE, + camera_offset:(int3(0,64,0)-int3(0,73,0)/2)*VALVE_SCALE, } } pub fn source_surf()->Self{ @@ -563,39 +563,39 @@ impl StyleModifiers{ controls_mask_state:Controls::all(), strafe:Some(StrafeSettings{ enable:ControlsActivation::full_2d(), - air_accel_limit:Some(Planar64::int(150)*66*VALVE_SCALE), - mv:Planar64::int(30)*VALVE_SCALE, + air_accel_limit:Some(int(150)*66*VALVE_SCALE), + mv:int(30)*VALVE_SCALE, tick_rate:Ratio64::new(66,Time::ONE_SECOND.nanos() as u64).unwrap(), }), jump:Some(JumpSettings{ - impulse:JumpImpulse::Height(Planar64::int(52)*VALVE_SCALE), + impulse:JumpImpulse::Height(int(52)*VALVE_SCALE), calculation:JumpCalculation::JumpThenBoost, limit_minimum:true, }), - gravity:Planar64Vec3::int(0,-800,0)*VALVE_SCALE, - mass:Planar64::int(1), + gravity:int3(0,-800,0)*VALVE_SCALE, + mass:int(1), rocket:None, walk:Some(WalkSettings{ accelerate:AccelerateSettings{ - topspeed:Planar64::int(18),//? - accel:Planar64::int(90),//? + topspeed:int(18),//? + accel:int(90),//? }, - static_friction:Planar64::int(2),//? - kinetic_friction:Planar64::int(3),//? - surf_dot:Planar64::int(3)/4,// normal.y=0.75 + static_friction:int(2),//? + kinetic_friction:int(3),//? + surf_dot:int(3)/4,// normal.y=0.75 }), ladder:Some(LadderSettings{ accelerate:AccelerateSettings{ - topspeed:Planar64::int(18),//? - accel:Planar64::int(180),//? + topspeed:int(18),//? + accel:int(180),//? }, - dot:(Planar64::int(1)/2).sqrt(),//? + dot:(int(1)/2).sqrt(),//? }), swim:Some(PropulsionSettings{ - magnitude:Planar64::int(12),//? + magnitude:int(12),//? }), hitbox:Hitbox::source(), - camera_offset:(Planar64Vec3::int(0,64,0)-Planar64Vec3::int(0,73,0)/2)*VALVE_SCALE, + camera_offset:(int3(0,64,0)-int3(0,73,0)/2)*VALVE_SCALE, } } } diff --git a/src/integer.rs b/src/integer.rs index d227deb..70fdbe9 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -42,7 +42,7 @@ impl Time{ impl From for Time{ #[inline] fn from(value:Planar64)->Self{ - Time(value.wide_mul(Planar64::raw(1_000_000_000)) as i64) + Time((value*Planar64::raw(1_000_000_000)).to_bits().to_bits().digits()[0] as i64) } } impl std::fmt::Display for Time{ @@ -432,10 +432,17 @@ pub type Planar64Vec3=linear_ops::types::Vector3; pub type Planar64Mat3=linear_ops::types::Matrix3; pub type Planar64Affine3=linear_ops::types::Matrix4x3; +pub fn int(value:i32)->Planar64{ + Planar64::from(value) +} +pub fn int3(x:i32,y:i32,z:i32)->Planar64Vec3{ + Planar64Vec3::new([Planar64::from(x),Planar64::from(y),Planar64::from(z)]) +} + #[test] fn test_sqrt(){ - let r=Planar64::int(400); - assert_eq!(1717986918400,r.get()); + let r=int(400); + assert_eq!(r,Planar64::raw(1717986918400)); let s=r.sqrt(); - assert_eq!(85899345920,s.get()); + assert_eq!(s,Planar64::raw(85899345920)); }