progress
This commit is contained in:
parent
1fcd18bc45
commit
fe43ce9df6
strafe-client/src
@ -1,17 +1,15 @@
|
|||||||
use strafesnet_common::mouse::MouseState;
|
use strafesnet_common::mouse::MouseState;
|
||||||
use strafesnet_common::physics::{Instruction as PhysicsInputInstruction,Time as PhysicsTime,TimeInner as PhysicsTimeInner};
|
use strafesnet_common::physics::{Instruction as PhysicsInputInstruction,Time as PhysicsTime,TimeInner as PhysicsTimeInner};
|
||||||
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
|
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
|
||||||
use strafesnet_common::instruction::{self,InstructionConsumer,InstructionEmitter,TimedInstruction};
|
use strafesnet_common::instruction::{InstructionConsumer,InstructionEmitter,TimedInstruction};
|
||||||
|
|
||||||
|
use crate::session::StepInstruction as SessionInternalInstruction;
|
||||||
|
|
||||||
type TimedPhysicsInstruction=TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>;
|
type TimedPhysicsInstruction=TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>;
|
||||||
type TimedInterpolatorInstruction=TimedInstruction<Instruction,SessionTimeInner>;
|
type TimedInterpolatorInstruction=TimedInstruction<UnbufferedInputInstruction,SessionTimeInner>;
|
||||||
|
|
||||||
pub struct DropInstruction<'a>{
|
|
||||||
instruction:&'a TimedPhysicsInstruction,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum InputInstruction{
|
pub enum UnbufferedInputInstruction{
|
||||||
MoveMouse(glam::IVec2),
|
MoveMouse(glam::IVec2),
|
||||||
MoveRight(bool),
|
MoveRight(bool),
|
||||||
MoveUp(bool),
|
MoveUp(bool),
|
||||||
@ -26,52 +24,42 @@ pub enum InputInstruction{
|
|||||||
PracticeFly,
|
PracticeFly,
|
||||||
Idle,
|
Idle,
|
||||||
}
|
}
|
||||||
pub enum Instruction{
|
|
||||||
Input(InputInstruction),
|
|
||||||
//SetPaused is not an InputInstruction: the physics doesn't know that it's paused.
|
|
||||||
SetPaused(bool),
|
|
||||||
//Graphics(crate::graphics_worker::Instruction),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct MouseInterpolator{
|
pub struct MouseInterpolator{
|
||||||
session_timeline:std::collections::VecDeque<TimedInterpolatorInstruction>,
|
|
||||||
physics_timeline:std::collections::VecDeque<TimedPhysicsInstruction>,
|
physics_timeline:std::collections::VecDeque<TimedPhysicsInstruction>,
|
||||||
}
|
}
|
||||||
// Maybe MouseInterpolator manipulation is better expressed using impls
|
// Maybe MouseInterpolator manipulation is better expressed using impls
|
||||||
// and called from Instruction trait impls in session
|
// and called from Instruction trait impls in session
|
||||||
impl InstructionConsumer<Instruction> for MouseInterpolator{
|
impl InstructionConsumer<UnbufferedInputInstruction> for MouseInterpolator{
|
||||||
type TimeInner=SessionTimeInner;
|
type TimeInner=SessionTimeInner;
|
||||||
fn process_instruction(&mut self,ins:TimedInterpolatorInstruction){
|
fn process_instruction(&mut self,ins:TimedInterpolatorInstruction){
|
||||||
self.push_input(ins)
|
self.push_unbuffered_input(ins)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> InstructionConsumer<DropInstruction<'a>> for MouseInterpolator{
|
impl InstructionEmitter<SessionInternalInstruction> for MouseInterpolator{
|
||||||
type TimeInner=SessionTimeInner;
|
type TimeInner=SessionTimeInner;
|
||||||
fn process_instruction(&mut self,ins:TimedInstruction<DropInstruction<'a>,SessionTimeInner>){
|
fn next_instruction(&self,time_limit:SessionTime)->Option<TimedInstruction<SessionInternalInstruction,Self::TimeInner>>{
|
||||||
self.drop_output(ins)
|
self.buffered_instruction_with_timeout(time_limit)
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<'a> InstructionEmitter<DropInstruction<'a>> for MouseInterpolator{
|
|
||||||
type TimeInner=SessionTimeInner;
|
|
||||||
fn next_instruction(&'a self,time_limit:SessionTime)->Option<TimedInstruction<DropInstruction<'a>,Self::TimeInner>>{
|
|
||||||
self.next_output(time_limit)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl MouseInterpolator{
|
impl MouseInterpolator{
|
||||||
pub fn new()->MouseInterpolator{
|
pub fn new()->MouseInterpolator{
|
||||||
MouseInterpolator{
|
MouseInterpolator{
|
||||||
session_timeline:std::collections::VecDeque::new(),
|
|
||||||
physics_timeline:std::collections::VecDeque::new(),
|
physics_timeline:std::collections::VecDeque::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn push_input(&mut self,ins:TimedInterpolatorInstruction){
|
pub fn push_unbuffered_input(&mut self,ins:TimedInterpolatorInstruction){
|
||||||
// new input
|
// new input
|
||||||
}
|
}
|
||||||
pub fn drop_output<'a>(&mut self,ins:TimedInstruction<DropInstruction<'a>,SessionTimeInner>){
|
pub fn buffered_instruction_with_timeout(&self,time_limit:SessionTime)->Option<TimedInstruction<SessionInternalInstruction,SessionTimeInner>>{
|
||||||
|
// if the mouse has stopped moving for over 10ms, emit DoStepReplaceMouse
|
||||||
|
// if there is a mouse interpolation target, emit DoStep
|
||||||
|
// else emit None
|
||||||
|
None
|
||||||
|
}
|
||||||
|
pub fn pop_buffered_instruction(&mut self)->Option<TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>>{
|
||||||
// so the idea is that Session gets in the middle of MouseInterpolator instruction processing
|
// so the idea is that Session gets in the middle of MouseInterpolator instruction processing
|
||||||
// and injects its own side effects, notably running physics
|
// and injects its own side effects, notably running physics
|
||||||
}
|
|
||||||
pub fn next_output(&self,time_limit:SessionTime)->Option<TimedInstruction<DropInstruction<'_>,SessionTimeInner>>{
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,25 @@
|
|||||||
use strafesnet_common::instruction::{InstructionConsumer, InstructionEmitter};
|
use strafesnet_common::instruction::{InstructionConsumer, InstructionEmitter, InstructionFeedback, TimedInstruction};
|
||||||
// session represents the non-hardware state of the client.
|
// session represents the non-hardware state of the client.
|
||||||
// Ideally it is a deterministic state which is atomically updated by instructions, same as the simulation state.
|
// Ideally it is a deterministic state which is atomically updated by instructions, same as the simulation state.
|
||||||
use strafesnet_common::physics::{Instruction as PhysicsInputInstruction,Time as PhysicsTime};
|
use strafesnet_common::physics::{Instruction as PhysicsInputInstruction,TimeInner as PhysicsTimeInner,Time as PhysicsTime};
|
||||||
use strafesnet_common::timer::{Scaled,Timer};
|
use strafesnet_common::timer::{Scaled,Timer};
|
||||||
use strafesnet_common::physics::TimeInner as PhysicsTimeInner;
|
use strafesnet_common::session::{TimeInner as SessionTimeInner,Time as SessionTime};
|
||||||
use strafesnet_common::session::TimeInner as SessionTimeInner;
|
|
||||||
|
|
||||||
use crate::mouse_interpolator::MouseInterpolator;
|
use crate::mouse_interpolator::{MouseInterpolator,UnbufferedInputInstruction};
|
||||||
|
|
||||||
pub enum Instruction{
|
pub enum ExternalInstruction{
|
||||||
Input(InputInstruction),
|
ToBuffer(UnbufferedInputInstruction),
|
||||||
|
SetPaused(bool),
|
||||||
Render,
|
Render,
|
||||||
Resize(winit::dpi::PhysicalSize<u32>),
|
Resize(winit::dpi::PhysicalSize<u32>),
|
||||||
ChangeMap(strafesnet_common::map::CompleteMap),
|
ChangeMap(strafesnet_common::map::CompleteMap),
|
||||||
//SetPaused is not an InputInstruction: the physics doesn't know that it's paused.
|
|
||||||
SetPaused(bool),
|
|
||||||
//Graphics(crate::graphics_worker::Instruction),
|
//Graphics(crate::graphics_worker::Instruction),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum StepInstruction{
|
||||||
|
DoStep,
|
||||||
|
}
|
||||||
|
|
||||||
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,
|
||||||
@ -81,28 +83,49 @@ impl Session{
|
|||||||
|
|
||||||
// mouseinterpolator consumes RawInputInstruction
|
// mouseinterpolator consumes RawInputInstruction
|
||||||
// mouseinterpolator emits PhysicsInputInstruction
|
// mouseinterpolator emits PhysicsInputInstruction
|
||||||
// mouseinterpolator consumes DropInstruction to move on to the next emitted instruction
|
// mouseinterpolator consumes DoStep to move on to the next emitted instruction
|
||||||
// Session comsumes SessionInstruction -> forwards RawInputInstruction to mouseinterpolator
|
// Session comsumes SessionInstruction -> forwards RawInputInstruction to mouseinterpolator
|
||||||
// Session consumes DropInstruction -> forwards DropInstruction to mouseinterpolator
|
// Session consumes DoStep -> forwards DoStep to mouseinterpolator
|
||||||
// Session emits DropInstruction
|
// Session emits DoStep
|
||||||
|
|
||||||
impl InstructionConsumer<Instruction> for Session{
|
impl InstructionConsumer<ExternalInstruction> for Session{
|
||||||
type TimeInner=SessionTimeInner;
|
type TimeInner=SessionTimeInner;
|
||||||
fn process_instruction(&mut self,instruction:strafesnet_common::instruction::TimedInstruction<Instruction,Self::TimeInner>){
|
fn process_instruction(&mut self,ins:TimedInstruction<ExternalInstruction,Self::TimeInner>){
|
||||||
|
match ins.instruction{
|
||||||
// send it down to MouseInterpolator
|
// send it down to MouseInterpolator
|
||||||
self.mouse_interpolator.process_instruction(ins);
|
ExternalInstruction::ToBuffer(instruction)=>self.mouse_interpolator.process_instruction(TimedInstruction{
|
||||||
|
time:ins.time,
|
||||||
|
instruction,
|
||||||
|
}),
|
||||||
|
ExternalInstruction::SetPaused(paused)=>{
|
||||||
|
// don't flush the buffered instructions in the mouse interpolator
|
||||||
|
// until the mouse is confirmed to be not moving at a later time
|
||||||
|
// what if they pause for 5ms lmao
|
||||||
|
_=self.simulation.timer.set_paused(ins.time,paused);
|
||||||
|
}
|
||||||
|
ExternalInstruction::Render=>(),
|
||||||
|
ExternalInstruction::Resize(physical_size)=>(),
|
||||||
|
ExternalInstruction::ChangeMap(complete_map)=>(),
|
||||||
|
};
|
||||||
|
// run all buffered instruction produced
|
||||||
|
self.process_exhaustive(ins.time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> InstructionConsumer<DropInstruction<'a>> for Session{
|
impl InstructionConsumer<StepInstruction> for Session{
|
||||||
type TimeInner=SessionTimeInner;
|
type TimeInner=SessionTimeInner;
|
||||||
fn process_instruction(&mut self,instruction:strafesnet_common::instruction::TimedInstruction<DropInstruction,Self::TimeInner>){
|
fn process_instruction(&mut self,ins:TimedInstruction<StepInstruction,Self::TimeInner>){
|
||||||
// send it down to MouseInterpolator
|
match ins.instruction{
|
||||||
self.mouse_interpolator.process_instruction(ins);
|
StepInstruction::DoStep=>{
|
||||||
|
if let Some(instruction)=self.mouse_interpolator.pop_buffered_instruction(){
|
||||||
|
self.simulation.physics.run_input_instruction(instruction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> InstructionEmitter<DropInstruction<'a>> for Session{
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl InstructionEmitter<StepInstruction> for Session{
|
||||||
type TimeInner=SessionTimeInner;
|
type TimeInner=SessionTimeInner;
|
||||||
fn next_instruction(&self,time_limit:strafesnet_common::integer::Time<Self::TimeInner>)->Option<strafesnet_common::instruction::TimedInstruction<DropInstruction,Self::TimeInner>>{
|
fn next_instruction(&self,time_limit:SessionTime)->Option<TimedInstruction<StepInstruction,Self::TimeInner>>{
|
||||||
self.mouse_interpolator.next_instruction(time_limit)
|
self.mouse_interpolator.next_instruction(time_limit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user