newtypes
This commit is contained in:
parent
2c000cca67
commit
68ccee81b1
@ -6,3 +6,22 @@ pub struct TimedPhysicsInstruction{
|
|||||||
pub time:Time,
|
pub time:Time,
|
||||||
pub instruction:super::physics::PhysicsInputInstruction,
|
pub instruction:super::physics::PhysicsInputInstruction,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryInto<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
|
||||||
|
type Error=super::integer::RatioError;
|
||||||
|
fn try_into(self)->Result<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>,Self::Error>{
|
||||||
|
Ok(strafesnet_common::instruction::TimedInstruction{
|
||||||
|
time:strafesnet_common::integer::Time::raw(self.time),
|
||||||
|
instruction:self.instruction.try_into()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl TryFrom<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
|
||||||
|
type Error=super::physics::PhysicsInputInstructionError;
|
||||||
|
fn try_from(value:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<Self,Self::Error>{
|
||||||
|
Ok(Self{
|
||||||
|
time:value.time.get(),
|
||||||
|
instruction:value.instruction.try_into()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -38,6 +38,23 @@ pub struct Ratio64Vec2{
|
|||||||
pub x:Ratio64,
|
pub x:Ratio64,
|
||||||
pub y:Ratio64,
|
pub y:Ratio64,
|
||||||
}
|
}
|
||||||
|
impl TryInto<strafesnet_common::integer::Ratio64Vec2> for Ratio64Vec2{
|
||||||
|
type Error=RatioError;
|
||||||
|
fn try_into(self)->Result<strafesnet_common::integer::Ratio64Vec2,Self::Error>{
|
||||||
|
Ok(strafesnet_common::integer::Ratio64Vec2{
|
||||||
|
x:self.x.try_into()?,
|
||||||
|
y:self.y.try_into()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<strafesnet_common::integer::Ratio64Vec2> for Ratio64Vec2{
|
||||||
|
fn from(value:strafesnet_common::integer::Ratio64Vec2)->Self{
|
||||||
|
Self{
|
||||||
|
x:value.x.into(),
|
||||||
|
y:value.y.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type Angle32=i32;
|
pub type Angle32=i32;
|
||||||
pub type Planar64=i64;
|
pub type Planar64=i64;
|
||||||
|
@ -1,8 +1,37 @@
|
|||||||
use super::integer::Time;
|
use super::integer::Time;
|
||||||
|
|
||||||
|
#[binrw::binrw]
|
||||||
|
#[brw(little)]
|
||||||
|
pub enum EncodedMouseDelta{
|
||||||
|
//X did not move Y has 1 byte, time has 2 bytes
|
||||||
|
X0Y1T2{
|
||||||
|
y:i8,
|
||||||
|
t:u16,
|
||||||
|
},
|
||||||
|
X1Y1T2
|
||||||
|
}
|
||||||
|
///TODO: delta delta encoding lol
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct MouseState{
|
pub struct MouseState{
|
||||||
pub pos:[i32;2],
|
pub pos:[i32;2],
|
||||||
pub time:Time,
|
pub time:Time,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Into<strafesnet_common::mouse::MouseState> for MouseState{
|
||||||
|
fn into(self)->strafesnet_common::mouse::MouseState{
|
||||||
|
strafesnet_common::mouse::MouseState{
|
||||||
|
pos:self.pos.into(),
|
||||||
|
time:strafesnet_common::integer::Time::raw(self.time),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<strafesnet_common::mouse::MouseState> for MouseState{
|
||||||
|
fn from(value:strafesnet_common::mouse::MouseState)->Self{
|
||||||
|
Self{
|
||||||
|
pos:value.pos.to_array(),
|
||||||
|
time:value.time.get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,22 +3,92 @@ use super::common::Boolio;
|
|||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub enum PhysicsInputInstruction{
|
pub enum PhysicsInputInstruction{
|
||||||
|
#[brw(magic=0u8)]
|
||||||
ReplaceMouse(super::mouse::MouseState,super::mouse::MouseState),
|
ReplaceMouse(super::mouse::MouseState,super::mouse::MouseState),
|
||||||
|
#[brw(magic=1u8)]
|
||||||
SetNextMouse(super::mouse::MouseState),
|
SetNextMouse(super::mouse::MouseState),
|
||||||
|
#[brw(magic=2u8)]
|
||||||
SetMoveRight(Boolio),
|
SetMoveRight(Boolio),
|
||||||
|
#[brw(magic=3u8)]
|
||||||
SetMoveUp(Boolio),
|
SetMoveUp(Boolio),
|
||||||
|
#[brw(magic=4u8)]
|
||||||
SetMoveBack(Boolio),
|
SetMoveBack(Boolio),
|
||||||
|
#[brw(magic=5u8)]
|
||||||
SetMoveLeft(Boolio),
|
SetMoveLeft(Boolio),
|
||||||
|
#[brw(magic=6u8)]
|
||||||
SetMoveDown(Boolio),
|
SetMoveDown(Boolio),
|
||||||
|
#[brw(magic=7u8)]
|
||||||
SetMoveForward(Boolio),
|
SetMoveForward(Boolio),
|
||||||
|
#[brw(magic=8u8)]
|
||||||
SetJump(Boolio),
|
SetJump(Boolio),
|
||||||
|
#[brw(magic=9u8)]
|
||||||
SetZoom(Boolio),
|
SetZoom(Boolio),
|
||||||
|
#[brw(magic=10u8)]
|
||||||
Restart,
|
Restart,
|
||||||
|
#[brw(magic=11u8)]
|
||||||
Spawn(super::gameplay_modes::ModeId,super::gameplay_modes::StageId),
|
Spawn(super::gameplay_modes::ModeId,super::gameplay_modes::StageId),
|
||||||
Idle,
|
#[brw(magic=12u8)]
|
||||||
//Idle: there were no input events, but the simulation is safe to advance to this timestep
|
|
||||||
//for interpolation / networking / playback reasons, most playback heads will always want
|
|
||||||
//to be 1 instruction ahead to generate the next state for interpolation.
|
|
||||||
PracticeFly,
|
PracticeFly,
|
||||||
|
#[brw(magic=13u8)]
|
||||||
SetSensitivity(super::integer::Ratio64Vec2),
|
SetSensitivity(super::integer::Ratio64Vec2),
|
||||||
}
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum PhysicsInputInstructionError{
|
||||||
|
/// This is an instruction that can be dropped when serializing
|
||||||
|
DropInstruction,
|
||||||
|
}
|
||||||
|
impl std::fmt::Display for PhysicsInputInstructionError{
|
||||||
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
|
write!(f,"{self:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::error::Error for PhysicsInputInstructionError{}
|
||||||
|
impl TryInto<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
|
||||||
|
type Error=super::integer::RatioError;
|
||||||
|
fn try_into(self)->Result<strafesnet_common::physics::Instruction,Self::Error>{
|
||||||
|
Ok(match self{
|
||||||
|
PhysicsInputInstruction::ReplaceMouse(m0,m1)=>strafesnet_common::physics::Instruction::ReplaceMouse(m0.into(),m1.into()),
|
||||||
|
PhysicsInputInstruction::SetNextMouse(m)=>strafesnet_common::physics::Instruction::SetNextMouse(m.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveRight(state)=>strafesnet_common::physics::Instruction::SetMoveRight(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveUp(state)=>strafesnet_common::physics::Instruction::SetMoveUp(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveBack(state)=>strafesnet_common::physics::Instruction::SetMoveBack(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveLeft(state)=>strafesnet_common::physics::Instruction::SetMoveLeft(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveDown(state)=>strafesnet_common::physics::Instruction::SetMoveDown(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveForward(state)=>strafesnet_common::physics::Instruction::SetMoveForward(state.into()),
|
||||||
|
PhysicsInputInstruction::SetJump(state)=>strafesnet_common::physics::Instruction::SetJump(state.into()),
|
||||||
|
PhysicsInputInstruction::SetZoom(state)=>strafesnet_common::physics::Instruction::SetZoom(state.into()),
|
||||||
|
PhysicsInputInstruction::Restart=>strafesnet_common::physics::Instruction::Restart,
|
||||||
|
PhysicsInputInstruction::Spawn(mode_id,stage_id)=>strafesnet_common::physics::Instruction::Spawn(
|
||||||
|
strafesnet_common::gameplay_modes::ModeId::new(mode_id),
|
||||||
|
strafesnet_common::gameplay_modes::StageId::new(stage_id),
|
||||||
|
),
|
||||||
|
PhysicsInputInstruction::PracticeFly=>strafesnet_common::physics::Instruction::PracticeFly,
|
||||||
|
PhysicsInputInstruction::SetSensitivity(sensitivity)=>strafesnet_common::physics::Instruction::SetSensitivity(sensitivity.try_into()?),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl TryFrom<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
|
||||||
|
type Error=PhysicsInputInstructionError;
|
||||||
|
fn try_from(value:strafesnet_common::physics::Instruction)->Result<Self,Self::Error>{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::physics::Instruction::ReplaceMouse(m0,m1)=>Ok(PhysicsInputInstruction::ReplaceMouse(m0.into(),m1.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetNextMouse(m)=>Ok(PhysicsInputInstruction::SetNextMouse(m.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveRight(state)=>Ok(PhysicsInputInstruction::SetMoveRight(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveUp(state)=>Ok(PhysicsInputInstruction::SetMoveUp(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveBack(state)=>Ok(PhysicsInputInstruction::SetMoveBack(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveLeft(state)=>Ok(PhysicsInputInstruction::SetMoveLeft(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveDown(state)=>Ok(PhysicsInputInstruction::SetMoveDown(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveForward(state)=>Ok(PhysicsInputInstruction::SetMoveForward(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetJump(state)=>Ok(PhysicsInputInstruction::SetJump(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetZoom(state)=>Ok(PhysicsInputInstruction::SetZoom(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::Restart=>Ok(PhysicsInputInstruction::Restart),
|
||||||
|
strafesnet_common::physics::Instruction::Spawn(mode_id,stage_id)=>Ok(PhysicsInputInstruction::Spawn(
|
||||||
|
mode_id.get(),
|
||||||
|
stage_id.get(),
|
||||||
|
)),
|
||||||
|
strafesnet_common::physics::Instruction::PracticeFly=>Ok(PhysicsInputInstruction::PracticeFly),
|
||||||
|
strafesnet_common::physics::Instruction::SetSensitivity(sensitivity)=>Ok(PhysicsInputInstruction::SetSensitivity(sensitivity.into())),
|
||||||
|
strafesnet_common::physics::Instruction::Idle=>Err(PhysicsInputInstructionError::DropInstruction),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user