This commit is contained in:
Quaternions 2025-01-07 20:30:13 -08:00
parent 4c216a5b28
commit 2e88ae0612
2 changed files with 13 additions and 17 deletions

View File

@ -29,8 +29,6 @@ pub enum Instruction{
//Graphics(crate::graphics_worker::Instruction), //Graphics(crate::graphics_worker::Instruction),
} }
pub struct MouseInterpolator{ pub struct MouseInterpolator{
//"PlayerController"
user_settings:crate::settings::UserSettings,
//"MouseInterpolator" //"MouseInterpolator"
timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>, timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>,
last_mouse_time:Time,//this value is pre-transformed to simulation time last_mouse_time:Time,//this value is pre-transformed to simulation time
@ -40,27 +38,22 @@ pub struct MouseInterpolator{
} }
impl instruction::InstructionConsumer<Instruction> for MouseInterpolator{ impl instruction::InstructionConsumer<Instruction> for MouseInterpolator{
fn process_instruction(&mut self,ins:TimedInstruction<Instruction>){ fn process_instruction(&mut self,ins:TimedInstruction<Instruction>){
atomic_state_update(&mut self,ins) self.atomic_state_update(ins)
} }
} }
impl instruction::InstructionEmitter<PhysicsInputInstruction> for MouseInterpolator{ impl instruction::InstructionEmitter<PhysicsInputInstruction> for MouseInterpolator{
fn next_instruction(&self,time_limit:Time)->Option<TimedInstruction<PhysicsInputInstruction>>{ fn next_instruction(&self,time_limit:Time)->Option<TimedInstruction<PhysicsInputInstruction>>{
next_instruction_internal(&self,time_limit) self.next_instruction_internal(time_limit)
} }
} }
impl MouseInterpolator{ impl MouseInterpolator{
pub fn new( pub fn new( )->Self{
physics:crate::physics::PhysicsContext, Self{
user_settings:crate::settings::UserSettings,
)->MouseInterpolator{
MouseInterpolator{
mouse_blocking:true, mouse_blocking:true,
last_mouse_time:physics.get_next_mouse().time, last_mouse_time:physics.get_next_mouse().time,
timeline:std::collections::VecDeque::new(), timeline:std::collections::VecDeque::new(),
timer:Timer::from_state(Scaled::identity(),false), timer:Timer::from_state(Scaled::identity(),false),
physics,
user_settings,
} }
} }
fn push_mouse_instruction(&mut self,ins:&TimedInstruction<Instruction>,m:glam::IVec2){ fn push_mouse_instruction(&mut self,ins:&TimedInstruction<Instruction>,m:glam::IVec2){

View File

@ -1,26 +1,29 @@
use strafesnet_common::instruction::TimedInstruction; use crate::session::SessionState;
type TimedSessionInstruction=strafesnet_common::instruction::TimedInstruction<crate::session::Instruction>;
pub fn new<'a>( pub fn new<'a>(
mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>, mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>,
user_settings:crate::settings::UserSettings, user_settings:crate::settings::UserSettings,
)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTimeInner>>{ )->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTimeInner>>{
let physics=crate::physics::PhysicsContext::default(); let physics=crate::physics::PhysicsContext::default();
let mut interpolator=MouseInterpolator::new( let mouse_interpolator=crate::mouse_interpolator::MouseInterpolator::new();
let mut session=SessionState::new(
physics, physics,
user_settings user_settings
); );
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTimeInner>|{ crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTimeInner>|{
interpolator.handle_instruction(&ins); session.handle_instruction(&ins);
match ins.instruction{ match ins.instruction{
Instruction::Render=>{ Instruction::Render=>{
let frame_state=interpolator.get_frame_state(ins.time); let frame_state=session.get_frame_state(ins.time);
graphics_worker.send(crate::graphics_worker::Instruction::Render(frame_state)).unwrap(); graphics_worker.send(crate::graphics_worker::Instruction::Render(frame_state)).unwrap();
}, },
Instruction::Resize(size)=>{ Instruction::Resize(size)=>{
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,interpolator.user_settings().clone())).unwrap(); graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,session.user_settings().clone())).unwrap();
}, },
Instruction::ChangeMap(map)=>{ Instruction::ChangeMap(map)=>{
interpolator.change_map(ins.time,&map); session.change_map(ins.time,&map);
graphics_worker.send(crate::graphics_worker::Instruction::ChangeMap(map)).unwrap(); graphics_worker.send(crate::graphics_worker::Instruction::ChangeMap(map)).unwrap();
}, },
Instruction::Input(_)=>(), Instruction::Input(_)=>(),