mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-04 02:24:12 +02:00
some write progress
This commit is contained in:
parent
67a4ca5744
commit
9a9bcdc9df
18 changed files with 286 additions and 90 deletions
|
|
@ -1,10 +1,10 @@
|
|||
use bitbuffer::{BitRead, LittleEndian};
|
||||
use bitbuffer::{BitRead, BitWrite, BitWriteSized, BitWriteStream, LittleEndian};
|
||||
|
||||
use crate::demo::sendprop::read_bit_coord;
|
||||
use crate::demo::sendprop::{read_bit_coord, write_bit_coord};
|
||||
use crate::demo::vector::Vector;
|
||||
use crate::{ReadResult, Stream};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct BSPDecalMessage {
|
||||
pub position: Vector,
|
||||
pub texture_index: u16,
|
||||
|
|
@ -16,9 +16,7 @@ pub struct BSPDecalMessage {
|
|||
impl BitRead<'_, LittleEndian> for BSPDecalMessage {
|
||||
fn read(stream: &mut Stream) -> ReadResult<Self> {
|
||||
let position = {
|
||||
let has_x = stream.read()?;
|
||||
let has_y = stream.read()?;
|
||||
let has_z = stream.read()?;
|
||||
let (has_x, has_y, has_z) = stream.read()?;
|
||||
|
||||
Vector {
|
||||
x: if has_x { read_bit_coord(stream)? } else { 0f32 },
|
||||
|
|
@ -44,3 +42,55 @@ impl BitRead<'_, LittleEndian> for BSPDecalMessage {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl BitWrite<LittleEndian> for BSPDecalMessage {
|
||||
fn write(&self, stream: &mut BitWriteStream<LittleEndian>) -> ReadResult<()> {
|
||||
let has_x = self.position.x != 0.0;
|
||||
let has_y = self.position.y != 0.0;
|
||||
let has_z = self.position.z != 0.0;
|
||||
(has_x, has_y, has_z).write(stream)?;
|
||||
|
||||
if has_x {
|
||||
write_bit_coord(self.position.x, stream)?;
|
||||
}
|
||||
if has_y {
|
||||
write_bit_coord(self.position.y, stream)?;
|
||||
}
|
||||
if has_z {
|
||||
write_bit_coord(self.position.z, stream)?;
|
||||
}
|
||||
self.texture_index.write_sized(stream, 9)?;
|
||||
if self.ent_index != 0 || self.model_index != 0 {
|
||||
true.write(stream)?;
|
||||
self.ent_index.write_sized(stream, 12)?;
|
||||
self.model_index.write_sized(stream, 12)?;
|
||||
} else {
|
||||
false.write(stream)?;
|
||||
}
|
||||
self.low_priority.write(stream)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decal_roundtrip() {
|
||||
crate::test_roundtrip_encode(BSPDecalMessage {
|
||||
position: Vector::default(),
|
||||
texture_index: 0,
|
||||
ent_index: 0,
|
||||
model_index: 0,
|
||||
low_priority: false,
|
||||
});
|
||||
crate::test_roundtrip_encode(BSPDecalMessage {
|
||||
position: Vector {
|
||||
x: 1.0,
|
||||
y: 0.5,
|
||||
z: 0.0,
|
||||
},
|
||||
texture_index: 12,
|
||||
ent_index: 15,
|
||||
model_index: 2,
|
||||
low_priority: true,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,38 @@
|
|||
use crate::Stream;
|
||||
/// Messages that consists only of primitives and string and can be derived
|
||||
use bitbuffer::{BitRead, LittleEndian};
|
||||
use bitbuffer::{BitRead, BitWrite, LittleEndian};
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct FileMessage {
|
||||
pub transfer_id: u32,
|
||||
pub file_name: String,
|
||||
pub requested: bool,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct NetTickMessage {
|
||||
pub tick: u32,
|
||||
pub frame_time: u16,
|
||||
pub std_dev: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct StringCmdMessage {
|
||||
pub command: String,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct SigOnStateMessage {
|
||||
pub state: u8,
|
||||
pub count: u32,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct PrintMessage {
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct ServerInfoMessage {
|
||||
pub version: u16,
|
||||
pub server_count: u32,
|
||||
|
|
@ -53,18 +53,18 @@ pub struct ServerInfoMessage {
|
|||
pub replay: bool,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct SetPauseMessage {
|
||||
pub pause: bool,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct SetViewMessage {
|
||||
#[size = 11]
|
||||
pub index: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct FixAngleMessage {
|
||||
pub relative: bool,
|
||||
pub x: u16,
|
||||
|
|
@ -72,7 +72,7 @@ pub struct FixAngleMessage {
|
|||
pub z: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct EntityMessage<'a> {
|
||||
#[size = 11]
|
||||
|
|
@ -85,13 +85,13 @@ pub struct EntityMessage<'a> {
|
|||
pub data: Stream<'a>,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct PreFetchMessage {
|
||||
#[size = 14]
|
||||
pub index: u16,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct MenuMessage<'a> {
|
||||
pub kind: u16,
|
||||
|
|
@ -100,13 +100,13 @@ pub struct MenuMessage<'a> {
|
|||
pub index: Stream<'a>,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
pub struct GetCvarValueMessage {
|
||||
pub cookie: u32,
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct CmdKeyValuesMessage<'a> {
|
||||
pub length: u32,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use bitbuffer::{BitRead, LittleEndian};
|
||||
use bitbuffer::{BitRead, BitWrite, BitWriteStream, LittleEndian};
|
||||
|
||||
use crate::{ReadResult, Stream};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct VoiceInitMessage {
|
||||
codec: String,
|
||||
quality: u8,
|
||||
|
|
@ -30,7 +30,34 @@ impl BitRead<'_, LittleEndian> for VoiceInitMessage {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(BitRead, Debug, Clone)]
|
||||
impl BitWrite<LittleEndian> for VoiceInitMessage {
|
||||
fn write(&self, stream: &mut BitWriteStream<LittleEndian>) -> ReadResult<()> {
|
||||
self.codec.write(stream)?;
|
||||
self.quality.write(stream)?;
|
||||
|
||||
if self.quality == 255 {
|
||||
self.sampling_rate.write(stream)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_voice_init_roundtrip() {
|
||||
crate::test_roundtrip_encode(VoiceInitMessage {
|
||||
codec: "foo".into(),
|
||||
quality: 0,
|
||||
sampling_rate: 0,
|
||||
});
|
||||
crate::test_roundtrip_encode(VoiceInitMessage {
|
||||
codec: "foo".into(),
|
||||
quality: 255,
|
||||
sampling_rate: 12,
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, Clone)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct VoiceDataMessage<'a> {
|
||||
client: u8,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue