This commit is contained in:
Quaternions 2025-01-07 22:36:21 -08:00
parent 36ba73a892
commit 120d8197b7
6 changed files with 57 additions and 39 deletions

View File

@ -1,5 +1,5 @@
use crate::model; use crate::model;
use crate::integer::{Time,Planar64,Planar64Vec3}; use crate::integer::{RawTime,Planar64,Planar64Vec3};
//you have this effect while in contact //you have this effect while in contact
#[derive(Clone,Hash,Eq,PartialEq)] #[derive(Clone,Hash,Eq,PartialEq)]
@ -31,7 +31,7 @@ pub enum Booster{
//Affine(crate::integer::Planar64Affine3),//capable of SetVelocity,DotVelocity,normal booster,bouncy part,redirect velocity, and much more //Affine(crate::integer::Planar64Affine3),//capable of SetVelocity,DotVelocity,normal booster,bouncy part,redirect velocity, and much more
Velocity(Planar64Vec3),//straight up boost velocity adds to your current velocity Velocity(Planar64Vec3),//straight up boost velocity adds to your current velocity
Energy{direction:Planar64Vec3,energy:Planar64},//increase energy in direction Energy{direction:Planar64Vec3,energy:Planar64},//increase energy in direction
AirTime(Time),//increase airtime, invariant across mass and gravity changes AirTime(RawTime),//increase airtime, invariant across mass and gravity changes
Height(Planar64),//increase height, invariant across mass and gravity changes Height(Planar64),//increase height, invariant across mass and gravity changes
} }
impl Booster{ impl Booster{
@ -57,13 +57,13 @@ pub enum TrajectoryChoice{
#[derive(Clone,Hash,Eq,PartialEq)] #[derive(Clone,Hash,Eq,PartialEq)]
pub enum SetTrajectory{ pub enum SetTrajectory{
//Speed-type SetTrajectory //Speed-type SetTrajectory
AirTime(Time),//air time (relative to gravity direction) is invariant across mass and gravity changes AirTime(RawTime),//air time (relative to gravity direction) is invariant across mass and gravity changes
Height(Planar64),//boost height (relative to gravity direction) is invariant across mass and gravity changes Height(Planar64),//boost height (relative to gravity direction) is invariant across mass and gravity changes
DotVelocity{direction:Planar64Vec3,dot:Planar64},//set your velocity in a specific direction without touching other directions DotVelocity{direction:Planar64Vec3,dot:Planar64},//set your velocity in a specific direction without touching other directions
//Velocity-type SetTrajectory //Velocity-type SetTrajectory
TargetPointTime{//launch on a trajectory that will land at a target point in a set amount of time TargetPointTime{//launch on a trajectory that will land at a target point in a set amount of time
target_point:Planar64Vec3, target_point:Planar64Vec3,
time:Time,//short time = fast and direct, long time = launch high in the air, negative time = wrong way time:RawTime,//short time = fast and direct, long time = launch high in the air, negative time = wrong way
}, },
TargetPointSpeed{//launch at a fixed speed and land at a target point TargetPointSpeed{//launch at a fixed speed and land at a target point
target_point:Planar64Vec3, target_point:Planar64Vec3,

View File

@ -1,7 +1,8 @@
const VALVE_SCALE:Planar64=Planar64::raw(1<<28);// 1/16 const VALVE_SCALE:Planar64=Planar64::raw(1<<28);// 1/16
use crate::integer::{int,vec3::int as int3,Time,Ratio64,Planar64,Planar64Vec3}; use crate::integer::{int,vec3::int as int3,RawTime,Ratio64,Planar64,Planar64Vec3};
use crate::controls_bitflag::Controls; use crate::controls_bitflag::Controls;
use crate::physics::Time as PhysicsTime;
#[derive(Clone,Debug)] #[derive(Clone,Debug)]
pub struct StyleModifiers{ pub struct StyleModifiers{
@ -48,7 +49,7 @@ pub enum JumpCalculation{
#[derive(Clone,Debug)] #[derive(Clone,Debug)]
pub enum JumpImpulse{ pub enum JumpImpulse{
Time(Time),//jump time is invariant across mass and gravity changes Time(RawTime),//jump time is invariant across mass and gravity changes
Height(Planar64),//jump height is invariant across mass and gravity changes Height(Planar64),//jump height is invariant across mass and gravity changes
Linear(Planar64),//jump velocity is invariant across mass and gravity changes Linear(Planar64),//jump velocity is invariant across mass and gravity changes
Energy(Planar64),// :) Energy(Planar64),// :)
@ -272,8 +273,8 @@ impl StrafeSettings{
false=>None, false=>None,
} }
} }
pub fn next_tick(&self,time:Time)->Time{ pub fn next_tick(&self,time:PhysicsTime)->PhysicsTime{
Time::from_nanos(self.tick_rate.rhs_div_int(self.tick_rate.mul_int(time.nanos())+1)) PhysicsTime::from_nanos(self.tick_rate.rhs_div_int(self.tick_rate.mul_int(time.nanos())+1))
} }
pub const fn activates(&self,controls:Controls)->bool{ pub const fn activates(&self,controls:Controls)->bool{
self.enable.activates(controls) self.enable.activates(controls)
@ -435,7 +436,7 @@ impl StyleModifiers{
enable:ControlsActivation::full_2d(), enable:ControlsActivation::full_2d(),
air_accel_limit:None, air_accel_limit:None,
mv:int(3), mv:int(3),
tick_rate:Ratio64::new(64,Time::ONE_SECOND.nanos() as u64).unwrap(), tick_rate:Ratio64::new(64,RawTime::ONE_SECOND.get() as u64).unwrap(),
}), }),
jump:Some(JumpSettings{ jump:Some(JumpSettings{
impulse:JumpImpulse::Energy(int(512)), impulse:JumpImpulse::Energy(int(512)),
@ -477,10 +478,10 @@ impl StyleModifiers{
enable:ControlsActivation::full_2d(), enable:ControlsActivation::full_2d(),
air_accel_limit:None, air_accel_limit:None,
mv:int(27)/10, mv:int(27)/10,
tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), tick_rate:Ratio64::new(100,RawTime::ONE_SECOND.get() as u64).unwrap(),
}), }),
jump:Some(JumpSettings{ jump:Some(JumpSettings{
impulse:JumpImpulse::Time(Time::from_micros(715_588)), impulse:JumpImpulse::Time(RawTime::from_micros(715_588)),
calculation:JumpCalculation::Max, calculation:JumpCalculation::Max,
limit_minimum:true, limit_minimum:true,
}), }),
@ -534,7 +535,7 @@ impl StyleModifiers{
enable:ControlsActivation::full_2d(), enable:ControlsActivation::full_2d(),
air_accel_limit:Some(Planar64::raw(150<<28)*100), air_accel_limit:Some(Planar64::raw(150<<28)*100),
mv:(Planar64::raw(30)*VALVE_SCALE).fix_1(), mv:(Planar64::raw(30)*VALVE_SCALE).fix_1(),
tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), tick_rate:Ratio64::new(100,RawTime::ONE_SECOND.get() as u64).unwrap(),
}), }),
jump:Some(JumpSettings{ jump:Some(JumpSettings{
impulse:JumpImpulse::Height((int(52)*VALVE_SCALE).fix_1()), impulse:JumpImpulse::Height((int(52)*VALVE_SCALE).fix_1()),
@ -575,7 +576,7 @@ impl StyleModifiers{
enable:ControlsActivation::full_2d(), enable:ControlsActivation::full_2d(),
air_accel_limit:Some((int(150)*66*VALVE_SCALE).fix_1()), air_accel_limit:Some((int(150)*66*VALVE_SCALE).fix_1()),
mv:(int(30)*VALVE_SCALE).fix_1(), mv:(int(30)*VALVE_SCALE).fix_1(),
tick_rate:Ratio64::new(66,Time::ONE_SECOND.nanos() as u64).unwrap(), tick_rate:Ratio64::new(66,RawTime::ONE_SECOND.get() as u64).unwrap(),
}), }),
jump:Some(JumpSettings{ jump:Some(JumpSettings{
impulse:JumpImpulse::Height((int(52)*VALVE_SCALE).fix_1()), impulse:JumpImpulse::Height((int(52)*VALVE_SCALE).fix_1()),

View File

@ -1,35 +1,41 @@
use crate::integer::Time; use crate::integer::Time;
#[derive(Debug)] #[derive(Debug)]
pub struct TimedInstruction<I>{ pub struct TimedInstruction<I,T>{
pub time:Time, pub time:Time<T>,
pub instruction:I, pub instruction:I,
} }
pub trait InstructionEmitter<I>{ pub trait InstructionEmitter{
fn next_instruction(&self,time_limit:Time)->Option<TimedInstruction<I>>; type Instruction;
type TimeInner;
fn next_instruction(&self,time_limit:Time<Self::TimeInner>)->Option<TimedInstruction<Self::Instruction,Self::TimeInner>>;
} }
pub trait InstructionConsumer<I>{ pub trait InstructionConsumer{
fn process_instruction(&mut self, instruction:TimedInstruction<I>); type Instruction;
type TimeInner;
fn process_instruction(&mut self, instruction:TimedInstruction<Self::Instruction,Self::TimeInner>);
} }
//PROPER PRIVATE FIELDS!!! //PROPER PRIVATE FIELDS!!!
pub struct InstructionCollector<I>{ pub struct InstructionCollector<I,T>{
time:Time, time:Time<T>,
instruction:Option<I>, instruction:Option<I>,
} }
impl<I> InstructionCollector<I>{ impl<I,T> InstructionCollector<I,T>
pub const fn new(time:Time)->Self{ where Time<T>:Copy+PartialOrd,
{
pub const fn new(time:Time<T>)->Self{
Self{ Self{
time, time,
instruction:None instruction:None
} }
} }
#[inline] #[inline]
pub const fn time(&self)->Time{ pub const fn time(&self)->Time<T>{
self.time self.time
} }
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){ pub fn collect(&mut self,instruction:Option<TimedInstruction<I,T>>){
match instruction{ match instruction{
Some(unwrap_instruction)=>{ Some(unwrap_instruction)=>{
if unwrap_instruction.time<self.time { if unwrap_instruction.time<self.time {
@ -40,7 +46,7 @@ impl<I> InstructionCollector<I>{
None=>(), None=>(),
} }
} }
pub fn instruction(self)->Option<TimedInstruction<I>>{ pub fn instruction(self)->Option<TimedInstruction<I,T>>{
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR //STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
match self.instruction{ match self.instruction{
Some(instruction)=>Some(TimedInstruction{ Some(instruction)=>Some(TimedInstruction{

View File

@ -1,11 +1,11 @@
use crate::integer::Time; use crate::integer::Time;
#[derive(Clone,Debug)] #[derive(Clone,Debug)]
pub struct MouseState{ pub struct MouseState<T>{
pub pos:glam::IVec2, pub pos:glam::IVec2,
pub time:Time, pub time:Time<T>,
} }
impl Default for MouseState{ impl<T> Default for MouseState<T>{
fn default()->Self{ fn default()->Self{
Self{ Self{
time:Time::ZERO, time:Time::ZERO,
@ -13,8 +13,10 @@ impl Default for MouseState{
} }
} }
} }
impl MouseState{ impl<T> MouseState<T>
pub fn lerp(&self,target:&MouseState,time:Time)->glam::IVec2{ where Time<T>:Copy,
{
pub fn lerp(&self,target:&MouseState<T>,time:Time<T>)->glam::IVec2{
let m0=self.pos.as_i64vec2(); let m0=self.pos.as_i64vec2();
let m1=target.pos.as_i64vec2(); let m1=target.pos.as_i64vec2();
//these are deltas //these are deltas

View File

@ -1,7 +1,11 @@
#[derive(Clone,Copy,Hash,Eq,PartialEq,PartialOrd,Debug)]
pub enum TimeInner{}
pub type Time=crate::integer::Time<TimeInner>;
#[derive(Clone,Debug)] #[derive(Clone,Debug)]
pub enum Instruction{ pub enum Instruction{
ReplaceMouse(crate::mouse::MouseState,crate::mouse::MouseState), ReplaceMouse(crate::mouse::MouseState<TimeInner>,crate::mouse::MouseState<TimeInner>),
SetNextMouse(crate::mouse::MouseState), SetNextMouse(crate::mouse::MouseState<TimeInner>),
SetMoveRight(bool), SetMoveRight(bool),
SetMoveUp(bool), SetMoveUp(bool),
SetMoveBack(bool), SetMoveBack(bool),

View File

@ -1,5 +1,10 @@
use crate::timer::{TimerFixed,Realtime,Paused,Unpaused}; use crate::timer::{TimerFixed,Realtime,Paused,Unpaused};
use crate::integer::Time;
use crate::physics::{TimeInner as PhysicsTimeInner,Time as PhysicsTime};
#[derive(Clone,Copy,Hash,Eq,PartialEq,PartialOrd,Debug)]
pub enum TimeInner{}
pub type Time=crate::integer::Time<TimeInner>;
#[derive(Clone,Copy,Debug)] #[derive(Clone,Copy,Debug)]
pub enum FlagReason{ pub enum FlagReason{
@ -45,8 +50,8 @@ impl std::error::Error for Error{}
#[derive(Clone,Copy,Debug)] #[derive(Clone,Copy,Debug)]
enum RunState{ enum RunState{
Created, Created,
Started{timer:TimerFixed<Realtime,Unpaused>}, Started{timer:TimerFixed<Realtime<PhysicsTimeInner,TimeInner>,Unpaused>},
Finished{timer:TimerFixed<Realtime,Paused>}, Finished{timer:TimerFixed<Realtime<PhysicsTimeInner,TimeInner>,Paused>},
} }
#[derive(Clone,Copy,Debug)] #[derive(Clone,Copy,Debug)]
@ -62,14 +67,14 @@ impl Run{
flagged:None, flagged:None,
} }
} }
pub fn time(&self,time:Time)->Time{ pub fn time(&self,time:PhysicsTime)->Time{
match &self.state{ match &self.state{
RunState::Created=>Time::ZERO, RunState::Created=>Time::ZERO,
RunState::Started{timer}=>timer.time(time), RunState::Started{timer}=>timer.time(time),
RunState::Finished{timer}=>timer.time(time), RunState::Finished{timer}=>timer.time(time),
} }
} }
pub fn start(&mut self,time:Time)->Result<(),Error>{ pub fn start(&mut self,time:PhysicsTime)->Result<(),Error>{
match &self.state{ match &self.state{
RunState::Created=>{ RunState::Created=>{
self.state=RunState::Started{ self.state=RunState::Started{
@ -81,7 +86,7 @@ impl Run{
RunState::Finished{..}=>Err(Error::AlreadyFinished), RunState::Finished{..}=>Err(Error::AlreadyFinished),
} }
} }
pub fn finish(&mut self,time:Time)->Result<(),Error>{ pub fn finish(&mut self,time:PhysicsTime)->Result<(),Error>{
//this uses Copy //this uses Copy
match &self.state{ match &self.state{
RunState::Created=>Err(Error::NotStarted), RunState::Created=>Err(Error::NotStarted),