Compare commits

...

5 Commits

Author SHA1 Message Date
Royiex
5994b05e1f Only Vel 2024-02-13 16:55:27 +01:00
Royiex
5e6ebdf125 Fixes 2024-02-12 19:14:15 +01:00
Royiex
cda4d82236 Better Print 2024-02-12 19:13:43 +01:00
f07d9f968e Print Only Horizontal Velocity
The Speed function is unnecessary I forgot to remove it
2024-02-11 22:26:34 +00:00
2cef79da1d Something idk 2024-02-11 22:24:40 +00:00
2 changed files with 2067 additions and 2023 deletions

File diff suppressed because it is too large Load Diff

@ -1,133 +1,158 @@
use crate::physics::{MouseState,PhysicsInputInstruction}; use crate::physics::{MouseState,PhysicsInputInstruction, PhysicsState};
use strafesnet_common::integer::Time; use strafesnet_common::integer::Time;
use strafesnet_common::instruction::{TimedInstruction,InstructionConsumer}; use strafesnet_common::instruction::{TimedInstruction,InstructionConsumer};
#[derive(Debug)] use strafesnet_common::integer::{self,Planar64,Planar64Vec3,Planar64Mat3,Angle32,Ratio64,Ratio64Vec2};
pub enum InputInstruction {
MoveMouse(glam::IVec2), #[derive(Debug)]
MoveRight(bool), pub enum InputInstruction {
MoveUp(bool), MoveMouse(glam::IVec2),
MoveBack(bool), MoveRight(bool),
MoveLeft(bool), MoveUp(bool),
MoveDown(bool), MoveBack(bool),
MoveForward(bool), MoveLeft(bool),
Jump(bool), MoveDown(bool),
Zoom(bool), MoveForward(bool),
Reset, Jump(bool),
} Zoom(bool),
pub enum Instruction{ Reset,
Input(InputInstruction), }
Render, pub enum Instruction{
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings), Input(InputInstruction),
GenerateModels(crate::model::IndexedModelInstances), Render,
ClearModels, Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
//Graphics(crate::graphics_worker::Instruction), GenerateModels(crate::model::IndexedModelInstances),
} ClearModels,
//Graphics(crate::graphics_worker::Instruction),
pub fn new(mut physics:crate::physics::PhysicsState,mut graphics_worker:crate::compat_worker::INWorker<crate::graphics_worker::Instruction>)->crate::compat_worker::QNWorker<TimedInstruction<Instruction>>{ }
let mut mouse_blocking=true; pub struct Speed{
let mut last_mouse_time=physics.next_mouse.time; pub player_vel:Planar64Vec3,
let mut timeline=std::collections::VecDeque::new(); pub time:Time,
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{ pub start_time:Option<Time>,
if if let Some(phys_input)=match &ins.instruction{ }
Instruction::Input(input_instruction)=>match input_instruction{
&InputInstruction::MoveMouse(m)=>{ impl Speed{
if mouse_blocking{ pub fn new(self,player_vel:Planar64Vec3,time:Time)->Self{
//tell the game state which is living in the past about its future Self{
timeline.push_front(TimedInstruction{ player_vel,
time:last_mouse_time, time,
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:m}), start_time:None,
});
}else{ }
//mouse has just started moving again after being still for longer than 10ms. }
//replace the entire mouse interpolation state to avoid an intermediate state with identical m0.t m1.t timestamps which will divide by zero }
timeline.push_front(TimedInstruction{
time:last_mouse_time, pub fn new(mut physics:crate::physics::PhysicsState,mut graphics_worker:crate::compat_worker::INWorker<crate::graphics_worker::Instruction>)->crate::compat_worker::QNWorker<TimedInstruction<Instruction>>{
instruction:PhysicsInputInstruction::ReplaceMouse( let mut mouse_blocking=true;
MouseState{time:last_mouse_time,pos:physics.next_mouse.pos}, let mut last_mouse_time=physics.next_mouse.time;
MouseState{time:ins.time,pos:m} let mut timeline=std::collections::VecDeque::new();
), let mut next_velocity_print=std::time::Instant::now();
}); crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
//delay physics execution until we have an interpolation target if if let Some(phys_input)=match &ins.instruction{
mouse_blocking=true; Instruction::Input(input_instruction)=>match input_instruction{
} &InputInstruction::MoveMouse(m)=>{
last_mouse_time=ins.time; if mouse_blocking{
None //tell the game state which is living in the past about its future
}, timeline.push_front(TimedInstruction{
&InputInstruction::MoveForward(s)=>Some(PhysicsInputInstruction::SetMoveForward(s)), time:last_mouse_time,
&InputInstruction::MoveLeft(s)=>Some(PhysicsInputInstruction::SetMoveLeft(s)), instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:m}),
&InputInstruction::MoveBack(s)=>Some(PhysicsInputInstruction::SetMoveBack(s)), });
&InputInstruction::MoveRight(s)=>Some(PhysicsInputInstruction::SetMoveRight(s)), }else{
&InputInstruction::MoveUp(s)=>Some(PhysicsInputInstruction::SetMoveUp(s)), //mouse has just started moving again after being still for longer than 10ms.
&InputInstruction::MoveDown(s)=>Some(PhysicsInputInstruction::SetMoveDown(s)), //replace the entire mouse interpolation state to avoid an intermediate state with identical m0.t m1.t timestamps which will divide by zero
&InputInstruction::Jump(s)=>Some(PhysicsInputInstruction::SetJump(s)), timeline.push_front(TimedInstruction{
&InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)), time:last_mouse_time,
InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset), instruction:PhysicsInputInstruction::ReplaceMouse(
}, MouseState{time:last_mouse_time,pos:physics.next_mouse.pos},
Instruction::GenerateModels(_)=>Some(PhysicsInputInstruction::Idle), MouseState{time:ins.time,pos:m}
Instruction::ClearModels=>Some(PhysicsInputInstruction::Idle), ),
Instruction::Resize(_,_)=>Some(PhysicsInputInstruction::Idle), });
Instruction::Render=>Some(PhysicsInputInstruction::Idle), //delay physics execution until we have an interpolation target
}{ mouse_blocking=true;
//non-mouse event }
timeline.push_back(TimedInstruction{ last_mouse_time=ins.time;
time:ins.time, None
instruction:phys_input, },
}); &InputInstruction::MoveForward(s)=>Some(PhysicsInputInstruction::SetMoveForward(s)),
&InputInstruction::MoveLeft(s)=>Some(PhysicsInputInstruction::SetMoveLeft(s)),
if mouse_blocking{ &InputInstruction::MoveBack(s)=>Some(PhysicsInputInstruction::SetMoveBack(s)),
//assume the mouse has stopped moving after 10ms. &InputInstruction::MoveRight(s)=>Some(PhysicsInputInstruction::SetMoveRight(s)),
//shitty mice are 125Hz which is 8ms so this should cover that. &InputInstruction::MoveUp(s)=>Some(PhysicsInputInstruction::SetMoveUp(s)),
//setting this to 100us still doesn't print even though it's 10x lower than the polling rate, &InputInstruction::MoveDown(s)=>Some(PhysicsInputInstruction::SetMoveDown(s)),
//so mouse events are probably not handled separately from drawing and fire right before it :( &InputInstruction::Jump(s)=>Some(PhysicsInputInstruction::SetJump(s)),
if Time::from_millis(10)<ins.time-physics.next_mouse.time{ &InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)),
//push an event to extrapolate no movement from InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset),
timeline.push_front(TimedInstruction{ },
time:last_mouse_time, Instruction::GenerateModels(_)=>Some(PhysicsInputInstruction::Idle),
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:physics.next_mouse.pos}), Instruction::ClearModels=>Some(PhysicsInputInstruction::Idle),
}); Instruction::Resize(_,_)=>Some(PhysicsInputInstruction::Idle),
last_mouse_time=ins.time; Instruction::Render=>Some(PhysicsInputInstruction::Idle),
//stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets. }{
mouse_blocking=false; //non-mouse event
true timeline.push_back(TimedInstruction{
}else{ time:ins.time,
false instruction:phys_input,
} });
}else{
//keep this up to date so that it can be used as a known-timestamp if mouse_blocking{
//that the mouse was not moving when the mouse starts moving again //assume the mouse has stopped moving after 10ms.
last_mouse_time=ins.time; //shitty mice are 125Hz which is 8ms so this should cover that.
true //setting this to 100us still doesn't print even though it's 10x lower than the polling rate,
} //so mouse events are probably not handled separately from drawing and fire right before it :(
}else{ if Time::from_millis(10)<ins.time-physics.next_mouse.time{
//mouse event //push an event to extrapolate no movement from
true timeline.push_front(TimedInstruction{
}{ time:last_mouse_time,
//empty queue instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:physics.next_mouse.pos}),
while let Some(instruction)=timeline.pop_front(){ });
physics.run(instruction.time); last_mouse_time=ins.time;
physics.process_instruction(TimedInstruction{ //stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets.
time:instruction.time, mouse_blocking=false;
instruction:crate::physics::PhysicsInstruction::Input(instruction.instruction), true
}); }else{
} false
} }
match ins.instruction{ }else{
Instruction::Render=>{ //keep this up to date so that it can be used as a known-timestamp
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.next_mouse.pos)).unwrap(); //that the mouse was not moving when the mouse starts moving again
}, last_mouse_time=ins.time;
Instruction::Resize(size,user_settings)=>{ true
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap(); }
}, }else{
Instruction::GenerateModels(indexed_model_instances)=>{ //mouse event
physics.generate_models(&indexed_model_instances); true
physics.spawn(indexed_model_instances.spawn_point); }{
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(indexed_model_instances)).unwrap(); //empty queue
}, while let Some(instruction)=timeline.pop_front(){
Instruction::ClearModels=>{ physics.run(instruction.time);
physics.clear(); physics.process_instruction(TimedInstruction{
graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap(); time:instruction.time,
}, instruction:crate::physics::PhysicsInstruction::Input(instruction.instruction),
_=>(), });
} }
}) //some random print stuff
if 3.0/5.0<next_velocity_print.elapsed().as_secs_f64(){
next_velocity_print=next_velocity_print+std::time::Duration::from_secs_f64(1.0/10.0);
println!("xz Velocity: {} u/s", (Planar64Vec3::new(physics.body.velocity.x(), Planar64::int(0), physics.body.velocity.z())).length());
}
}
match ins.instruction{
Instruction::Render=>{
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.next_mouse.pos)).unwrap();
},
Instruction::Resize(size,user_settings)=>{
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
},
Instruction::GenerateModels(indexed_model_instances)=>{
physics.generate_models(&indexed_model_instances);
physics.spawn(indexed_model_instances.spawn_point);
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(indexed_model_instances)).unwrap();
},
Instruction::ClearModels=>{
physics.clear();
graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap();
},
_=>(),
}
})
} }