mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
usercmd parsing and writing
This commit is contained in:
parent
015bcf9c9f
commit
f253e824d2
2 changed files with 49 additions and 9 deletions
|
|
@ -25,7 +25,7 @@ pub enum Packet<'a> {
|
|||
Message(MessagePacket<'a>),
|
||||
SyncTick(SyncTickPacket),
|
||||
ConsoleCmd(ConsoleCmdPacket),
|
||||
UserCmd(UserCmdPacket<'a>),
|
||||
UserCmd(UserCmdPacket),
|
||||
DataTables(DataTablePacket),
|
||||
Stop(StopPacket),
|
||||
StringTables(StringTablePacket<'a>),
|
||||
|
|
|
|||
|
|
@ -1,12 +1,52 @@
|
|||
use crate::Stream;
|
||||
use bitbuffer::{BitRead, BitWrite, LittleEndian};
|
||||
use bitbuffer::{BitRead, BitReadStream, BitWrite, BitWriteStream, LittleEndian};
|
||||
|
||||
#[derive(Debug, BitRead, BitWrite, PartialEq)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct UserCmdPacket<'a> {
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct UserCmdPacket {
|
||||
tick: u32,
|
||||
sequence_out: u32,
|
||||
len: u32,
|
||||
#[size = "len.saturating_mul(8)"]
|
||||
data: Stream<'a>,
|
||||
cmd: UserCmd,
|
||||
}
|
||||
|
||||
impl<'a> BitRead<'a, LittleEndian> for UserCmdPacket {
|
||||
fn read(stream: &mut BitReadStream<'a, LittleEndian>) -> bitbuffer::Result<Self> {
|
||||
let tick = stream.read()?;
|
||||
let sequence_out = stream.read()?;
|
||||
let len: u32 = stream.read()?;
|
||||
let mut data = stream.read_bits(len as usize * 8)?;
|
||||
let cmd = data.read()?;
|
||||
Ok(UserCmdPacket {
|
||||
tick,
|
||||
sequence_out,
|
||||
cmd,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl BitWrite<LittleEndian> for UserCmdPacket {
|
||||
fn write(&self, stream: &mut BitWriteStream<LittleEndian>) -> bitbuffer::Result<()> {
|
||||
self.tick.write(stream)?;
|
||||
self.sequence_out.write(stream)?;
|
||||
stream.reserve_byte_length(32, |stream| self.cmd.write(stream))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, BitRead, BitWrite)]
|
||||
pub struct UserCmd {
|
||||
command_number: Option<u32>,
|
||||
tick_count: Option<u32>,
|
||||
view_angles: [Option<f32>; 3],
|
||||
movement: [Option<f32>; 3],
|
||||
buttons: Option<u32>,
|
||||
impulse: Option<u8>,
|
||||
weapon_select: Option<WeaponSelect>,
|
||||
mouse_dx: Option<u16>,
|
||||
mouse_dy: Option<u16>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, BitRead, BitWrite)]
|
||||
pub struct WeaponSelect {
|
||||
#[size = 11]
|
||||
select: u16,
|
||||
#[size = 6]
|
||||
subtype: Option<u8>,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue