This commit is contained in:
Quaternions 2025-01-09 19:20:07 -08:00
parent 498c628280
commit b6206d52c8
3 changed files with 65 additions and 21 deletions

View File

@ -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<crate::session::Instruction>; type TimedSessionInstruction=strafesnet_common::instruction::TimedInstruction<SessionInstruction,SessionTimeInner>;
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,TimedSessionInstruction>{
let physics=crate::physics::PhysicsContext::default(); 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 mouse_interpolator=crate::mouse_interpolator::MouseInterpolator::new();
let mut session=SessionState::new( let mut session=Session::new(
physics, user_settings,
user_settings simulation,
); );
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTimeInner>|{ crate::compat_worker::QNWorker::new(move |ins:TimedSessionInstruction|{
session.handle_instruction(&ins); session.handle_instruction(&ins);
match ins.instruction{ match ins.instruction{
Instruction::Render=>{ SessionInstruction::Render=>{
let frame_state=session.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(GraphicsInstruction::Render(frame_state)).unwrap();
}, },
Instruction::Resize(size)=>{ SessionInstruction::Resize(size)=>{
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,session.user_settings().clone())).unwrap(); graphics_worker.send(GraphicsInstruction::Resize(size,session.user_settings().clone())).unwrap();
}, },
Instruction::ChangeMap(map)=>{ SessionInstruction::ChangeMap(map)=>{
session.change_map(ins.time,&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(_)=>(), SessionInstruction::Input(_)=>(),
Instruction::SetPaused(_)=>(), SessionInstruction::SetPaused(_)=>(),
} }
}) })
} }

View File

@ -5,6 +5,8 @@ use strafesnet_common::timer::{Scaled,Timer};
use strafesnet_common::physics::TimeInner as PhysicsTimeInner; use strafesnet_common::physics::TimeInner as PhysicsTimeInner;
use strafesnet_common::session::TimeInner as SessionTimeInner; use strafesnet_common::session::TimeInner as SessionTimeInner;
use crate::mouse_interpolator::MouseInterpolator;
pub struct FrameState{ pub struct FrameState{
pub body:crate::physics::Body, pub body:crate::physics::Body,
pub camera:crate::physics::PhysicsCamera, pub camera:crate::physics::PhysicsCamera,
@ -15,16 +17,53 @@ pub struct Simulation{
timer:Timer<Scaled<SessionTimeInner,PhysicsTimeInner>>, timer:Timer<Scaled<SessionTimeInner,PhysicsTimeInner>>,
physics:crate::physics::PhysicsContext, physics:crate::physics::PhysicsContext,
} }
impl Simulation{
pub struct Replay{ pub const fn new(
instruction:Vec<PhysicsInputInstruction>, timer:Timer<Scaled<SessionTimeInner,PhysicsTimeInner>>,
simulation:Simulation, physics:crate::physics::PhysicsContext,
)->Self{
Self{
timer,
physics,
}
}
} }
pub struct SessionState{ pub struct Replay{
last_instruction_id:usize,
instructions:Vec<PhysicsInputInstruction>,
simulation:Simulation,
}
impl Replay{
pub const fn new(
instructions:Vec<PhysicsInputInstruction>,
simulation:Simulation,
)->Self{
Self{
last_instruction_id:0,
instructions,
simulation,
}
}
}
pub struct Session{
user_settings:crate::settings::UserSettings, user_settings:crate::settings::UserSettings,
mouse_interpolator:crate::mouse_interpolator::MouseInterpolator, mouse_interpolator:crate::mouse_interpolator::MouseInterpolator,
//gui:GuiState //gui:GuiState
simulation:Simulation, simulation:Simulation,
replays:Vec<Replay>, replays:Vec<Replay>,
} }
impl Session{
pub fn new(
user_settings:crate::settings::UserSettings,
simulation:Simulation,
)->Self{
Self{
user_settings,
mouse_interpolator:MouseInterpolator::new(),
simulation,
replays:Vec::new(),
}
}
}

View File

@ -1,5 +1,4 @@
use crate::physics_worker::InputInstruction; use crate::physics_worker::InputInstruction;
use strafesnet_common::integer;
use strafesnet_common::instruction::TimedInstruction; use strafesnet_common::instruction::TimedInstruction;
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner}; use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};