diff --git a/src/v1.rs b/src/v1.rs index 762c0af..d839554 100644 --- a/src/v1.rs +++ b/src/v1.rs @@ -33,11 +33,48 @@ pub struct Vector3{ pub z:f32, } +bitflags::bitflags!{ + pub struct GameControls:u32{ + const MoveForward=1<<0; + const MoveLeft=1<<1; + const MoveBack=1<<2; + const MoveRight=1<<3; + const MoveUp=1<<4; + const MoveDown=1<<5; + const LookUp=1<<6; + const LookLeft=1<<7; + const LookDown=1<<8; + const LookRight=1<<9; + const Jump=1<<10; + const Crouch=1<<11; + const Sprint=1<<12; + const Zoom=1<<13; + const Use=1<<14; + const Action1=1<<15; + const Action2=1<<16; + } +} +#[derive(Debug)] +pub struct GameControlsError; +impl std::fmt::Display for GameControlsError{ + fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ + write!(f,"{self:?}") + } +} +impl std::error::Error for GameControlsError{} +impl GameControls{ + fn try_from_bits(bits:u32)->Result{ + Self::from_bits(bits).ok_or(GameControlsError) + } +} + // input #[binrw] #[brw(little)] pub struct InputEvent{ - pub game_controls:u32, + #[br(try_map=GameControls::try_from_bits)] + #[bw(map=GameControls::bits)] + pub game_controls:GameControls, pub mouse_pos:Vector2, } #[binrw] @@ -49,10 +86,33 @@ pub struct TimedInputEvent{ } // output +bitflags::bitflags!{ + pub struct TickInfo:u32{ + const TickEnd=1<<0; + const Jump=1<<1; + const Strafe=1<<2; + const Touching=1<<3; + } +} +#[derive(Debug)] +pub struct TickInfoError; +impl std::fmt::Display for TickInfoError{ + fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ + write!(f,"{self:?}") + } +} +impl std::error::Error for TickInfoError{} +impl TickInfo{ + fn try_from_bits(bits:u32)->Result{ + Self::from_bits(bits).ok_or(TickInfoError) + } +} #[binrw] #[brw(little)] pub struct OutputEvent{ - pub tick_info:u32, + #[br(try_map=TickInfo::try_from_bits)] + #[bw(map=TickInfo::bits)] + pub tick_info:TickInfo, pub angles:Vector3, pub position:Vector3, pub velocity:Vector3,