forked from StrafesNET/strafe-client
lol idk #1
@ -798,7 +798,7 @@ impl GraphicsState{
|
|||||||
});
|
});
|
||||||
|
|
||||||
let camera=GraphicsCamera::default();
|
let camera=GraphicsCamera::default();
|
||||||
let camera_uniforms=camera.to_uniform_data(crate::physics::PhysicsOutputState::default().extrapolate(glam::IVec2::ZERO,integer::Time::ZERO));
|
let camera_uniforms=camera.to_uniform_data(crate::physics::PhysicsOutputState::default().extrapolate(crate::physics::MouseState::default()));
|
||||||
let camera_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
let camera_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
||||||
label:Some("Camera"),
|
label:Some("Camera"),
|
||||||
contents:bytemuck::cast_slice(&camera_uniforms),
|
contents:bytemuck::cast_slice(&camera_uniforms),
|
||||||
@ -875,7 +875,7 @@ impl GraphicsState{
|
|||||||
let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
|
let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
|
||||||
|
|
||||||
// update rotation
|
// update rotation
|
||||||
let camera_uniforms=self.camera.to_uniform_data(physics_output.extrapolate(mouse_pos,predicted_time));
|
let camera_uniforms=self.camera.to_uniform_data(physics_output.extrapolate(crate::physics::MouseState{pos:mouse_pos,time:predicted_time}));
|
||||||
self.staging_belt
|
self.staging_belt
|
||||||
.write_buffer(
|
.write_buffer(
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
|
842
src/physics.rs
842
src/physics.rs
File diff suppressed because it is too large
Load Diff
@ -13,6 +13,7 @@ pub enum InputInstruction{
|
|||||||
Jump(bool),
|
Jump(bool),
|
||||||
Zoom(bool),
|
Zoom(bool),
|
||||||
Reset,
|
Reset,
|
||||||
|
PracticeFly,
|
||||||
}
|
}
|
||||||
pub enum Instruction{
|
pub enum Instruction{
|
||||||
Input(InputInstruction),
|
Input(InputInstruction),
|
||||||
@ -25,7 +26,7 @@ pub enum Instruction{
|
|||||||
|
|
||||||
pub fn new(mut physics:crate::physics::PhysicsContext,mut graphics_worker:crate::compat_worker::INWorker<crate::graphics_worker::Instruction>)->crate::compat_worker::QNWorker<TimedInstruction<Instruction>>{
|
pub fn new(mut physics:crate::physics::PhysicsContext,mut graphics_worker:crate::compat_worker::INWorker<crate::graphics_worker::Instruction>)->crate::compat_worker::QNWorker<TimedInstruction<Instruction>>{
|
||||||
let mut mouse_blocking=true;
|
let mut mouse_blocking=true;
|
||||||
let mut last_mouse_time=physics.state.next_mouse.time;
|
let mut last_mouse_time=physics.get_next_mouse().time;
|
||||||
let mut timeline=std::collections::VecDeque::new();
|
let mut timeline=std::collections::VecDeque::new();
|
||||||
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
|
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
|
||||||
if if let Some(phys_input)=match &ins.instruction{
|
if if let Some(phys_input)=match &ins.instruction{
|
||||||
@ -43,7 +44,7 @@ pub enum Instruction{
|
|||||||
timeline.push_front(TimedInstruction{
|
timeline.push_front(TimedInstruction{
|
||||||
time:last_mouse_time,
|
time:last_mouse_time,
|
||||||
instruction:PhysicsInputInstruction::ReplaceMouse(
|
instruction:PhysicsInputInstruction::ReplaceMouse(
|
||||||
MouseState{time:last_mouse_time,pos:physics.state.next_mouse.pos},
|
MouseState{time:last_mouse_time,pos:physics.get_next_mouse().pos},
|
||||||
MouseState{time:ins.time,pos:m}
|
MouseState{time:ins.time,pos:m}
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
@ -62,6 +63,7 @@ pub enum Instruction{
|
|||||||
&InputInstruction::Jump(s)=>Some(PhysicsInputInstruction::SetJump(s)),
|
&InputInstruction::Jump(s)=>Some(PhysicsInputInstruction::SetJump(s)),
|
||||||
&InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)),
|
&InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)),
|
||||||
InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset),
|
InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset),
|
||||||
|
InputInstruction::PracticeFly=>Some(PhysicsInputInstruction::PracticeFly),
|
||||||
},
|
},
|
||||||
Instruction::GenerateModels(_)=>Some(PhysicsInputInstruction::Idle),
|
Instruction::GenerateModels(_)=>Some(PhysicsInputInstruction::Idle),
|
||||||
Instruction::ClearModels=>Some(PhysicsInputInstruction::Idle),
|
Instruction::ClearModels=>Some(PhysicsInputInstruction::Idle),
|
||||||
@ -79,11 +81,11 @@ pub enum Instruction{
|
|||||||
//shitty mice are 125Hz which is 8ms so this should cover that.
|
//shitty mice are 125Hz which is 8ms so this should cover that.
|
||||||
//setting this to 100us still doesn't print even though it's 10x lower than the polling rate,
|
//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 :(
|
//so mouse events are probably not handled separately from drawing and fire right before it :(
|
||||||
if Time::from_millis(10)<ins.time-physics.state.next_mouse.time{
|
if Time::from_millis(10)<ins.time-physics.get_next_mouse().time{
|
||||||
//push an event to extrapolate no movement from
|
//push an event to extrapolate no movement from
|
||||||
timeline.push_front(TimedInstruction{
|
timeline.push_front(TimedInstruction{
|
||||||
time:last_mouse_time,
|
time:last_mouse_time,
|
||||||
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:physics.state.next_mouse.pos}),
|
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:physics.get_next_mouse().pos}),
|
||||||
});
|
});
|
||||||
last_mouse_time=ins.time;
|
last_mouse_time=ins.time;
|
||||||
//stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets.
|
//stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets.
|
||||||
@ -104,16 +106,12 @@ pub enum Instruction{
|
|||||||
}{
|
}{
|
||||||
//empty queue
|
//empty queue
|
||||||
while let Some(instruction)=timeline.pop_front(){
|
while let Some(instruction)=timeline.pop_front(){
|
||||||
physics.run(instruction.time);
|
physics.run_input_instruction(instruction);
|
||||||
physics.process_instruction(TimedInstruction{
|
|
||||||
time:instruction.time,
|
|
||||||
instruction:crate::physics::PhysicsInstruction::Input(instruction.instruction),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match ins.instruction{
|
match ins.instruction{
|
||||||
Instruction::Render=>{
|
Instruction::Render=>{
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.state.output(),ins.time,physics.state.next_mouse.pos)).unwrap();
|
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.get_next_mouse().pos)).unwrap();
|
||||||
},
|
},
|
||||||
Instruction::Resize(size,user_settings)=>{
|
Instruction::Resize(size,user_settings)=>{
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
|
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
|
||||||
@ -124,7 +122,7 @@ pub enum Instruction{
|
|||||||
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map)).unwrap();
|
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map)).unwrap();
|
||||||
},
|
},
|
||||||
Instruction::ClearModels=>{
|
Instruction::ClearModels=>{
|
||||||
physics.state.clear();
|
physics.clear();
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap();
|
graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap();
|
||||||
},
|
},
|
||||||
_=>(),
|
_=>(),
|
||||||
|
@ -108,6 +108,7 @@ impl WindowContext<'_>{
|
|||||||
"q"=>Some(InputInstruction::MoveDown(s)),
|
"q"=>Some(InputInstruction::MoveDown(s)),
|
||||||
"z"=>Some(InputInstruction::Zoom(s)),
|
"z"=>Some(InputInstruction::Zoom(s)),
|
||||||
"r"=>if s{Some(InputInstruction::Reset)}else{None},
|
"r"=>if s{Some(InputInstruction::Reset)}else{None},
|
||||||
|
"f"=>if s{Some(InputInstruction::PracticeFly)}else{None},
|
||||||
_=>None,
|
_=>None,
|
||||||
},
|
},
|
||||||
_=>None,
|
_=>None,
|
||||||
@ -173,7 +174,7 @@ impl<'a> WindowContextSetup<'a>{
|
|||||||
let user_settings=crate::settings::read_user_settings();
|
let user_settings=crate::settings::read_user_settings();
|
||||||
|
|
||||||
let mut physics=crate::physics::PhysicsContext::default();
|
let mut physics=crate::physics::PhysicsContext::default();
|
||||||
physics.state.load_user_settings(&user_settings);
|
physics.load_user_settings(&user_settings);
|
||||||
|
|
||||||
let mut graphics=crate::graphics::GraphicsState::new(&context.device,&context.queue,&context.config);
|
let mut graphics=crate::graphics::GraphicsState::new(&context.device,&context.queue,&context.config);
|
||||||
graphics.load_user_settings(&user_settings);
|
graphics.load_user_settings(&user_settings);
|
||||||
|
Loading…
Reference in New Issue
Block a user