From b6206d52c8bfdfe65f00da4d85e646c4f7f42d18 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 9 Jan 2025 19:20:07 -0800 Subject: [PATCH] work --- strafe-client/src/physics_worker.rs | 36 ++++++++++++--------- strafe-client/src/session.rs | 49 ++++++++++++++++++++++++++--- strafe-client/src/window.rs | 1 - 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/strafe-client/src/physics_worker.rs b/strafe-client/src/physics_worker.rs index 8113b29..a760873 100644 --- a/strafe-client/src/physics_worker.rs +++ b/strafe-client/src/physics_worker.rs @@ -1,33 +1,39 @@ -use crate::session::SessionState; +use crate::graphics_worker::Instruction as GraphicsInstruction; +use crate::session::{Instruction as SessionInstruction,Session, Simulation}; +use strafesnet_common::physics::Time as PhysicsTime; +use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner}; +use strafesnet_common::timer::Timer; -type TimedSessionInstruction=strafesnet_common::instruction::TimedInstruction; +type TimedSessionInstruction=strafesnet_common::instruction::TimedInstruction; pub fn new<'a>( mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>, user_settings:crate::settings::UserSettings, -)->crate::compat_worker::QNWorker<'a,TimedInstruction>{ +)->crate::compat_worker::QNWorker<'a,TimedSessionInstruction>{ let physics=crate::physics::PhysicsContext::default(); + let timer=Timer::unpaused(SessionTime::ZERO,PhysicsTime::ZERO); + let simulation=Simulation::new(timer,physics); let mouse_interpolator=crate::mouse_interpolator::MouseInterpolator::new(); - let mut session=SessionState::new( - physics, - user_settings + let mut session=Session::new( + user_settings, + simulation, ); - crate::compat_worker::QNWorker::new(move |ins:TimedInstruction|{ + crate::compat_worker::QNWorker::new(move |ins:TimedSessionInstruction|{ session.handle_instruction(&ins); match ins.instruction{ - Instruction::Render=>{ + SessionInstruction::Render=>{ let frame_state=session.get_frame_state(ins.time); - graphics_worker.send(crate::graphics_worker::Instruction::Render(frame_state)).unwrap(); + graphics_worker.send(GraphicsInstruction::Render(frame_state)).unwrap(); }, - Instruction::Resize(size)=>{ - graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,session.user_settings().clone())).unwrap(); + SessionInstruction::Resize(size)=>{ + graphics_worker.send(GraphicsInstruction::Resize(size,session.user_settings().clone())).unwrap(); }, - Instruction::ChangeMap(map)=>{ + SessionInstruction::ChangeMap(map)=>{ session.change_map(ins.time,&map); - graphics_worker.send(crate::graphics_worker::Instruction::ChangeMap(map)).unwrap(); + graphics_worker.send(GraphicsInstruction::ChangeMap(map)).unwrap(); }, - Instruction::Input(_)=>(), - Instruction::SetPaused(_)=>(), + SessionInstruction::Input(_)=>(), + SessionInstruction::SetPaused(_)=>(), } }) } diff --git a/strafe-client/src/session.rs b/strafe-client/src/session.rs index 8ddaca7..b89e7c3 100644 --- a/strafe-client/src/session.rs +++ b/strafe-client/src/session.rs @@ -5,6 +5,8 @@ use strafesnet_common::timer::{Scaled,Timer}; use strafesnet_common::physics::TimeInner as PhysicsTimeInner; use strafesnet_common::session::TimeInner as SessionTimeInner; +use crate::mouse_interpolator::MouseInterpolator; + pub struct FrameState{ pub body:crate::physics::Body, pub camera:crate::physics::PhysicsCamera, @@ -15,16 +17,53 @@ pub struct Simulation{ timer:Timer>, physics:crate::physics::PhysicsContext, } - -pub struct Replay{ - instruction:Vec, - simulation:Simulation, +impl Simulation{ + pub const fn new( + timer:Timer>, + physics:crate::physics::PhysicsContext, + )->Self{ + Self{ + timer, + physics, + } + } } -pub struct SessionState{ +pub struct Replay{ + last_instruction_id:usize, + instructions:Vec, + simulation:Simulation, +} +impl Replay{ + pub const fn new( + instructions:Vec, + simulation:Simulation, + )->Self{ + Self{ + last_instruction_id:0, + instructions, + simulation, + } + } +} + +pub struct Session{ user_settings:crate::settings::UserSettings, mouse_interpolator:crate::mouse_interpolator::MouseInterpolator, //gui:GuiState simulation:Simulation, replays:Vec, } +impl Session{ + pub fn new( + user_settings:crate::settings::UserSettings, + simulation:Simulation, + )->Self{ + Self{ + user_settings, + mouse_interpolator:MouseInterpolator::new(), + simulation, + replays:Vec::new(), + } + } +} diff --git a/strafe-client/src/window.rs b/strafe-client/src/window.rs index 20a9027..b1cd42e 100644 --- a/strafe-client/src/window.rs +++ b/strafe-client/src/window.rs @@ -1,5 +1,4 @@ use crate::physics_worker::InputInstruction; -use strafesnet_common::integer; use strafesnet_common::instruction::TimedInstruction; use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};