mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-04 02:24:12 +02:00
entity write fixes
This commit is contained in:
parent
6f80468b6d
commit
577a998baa
17 changed files with 129 additions and 35 deletions
|
|
@ -2,7 +2,7 @@ use bitbuffer::{BitRead, BitWrite, BitWriteSized, LittleEndian};
|
|||
|
||||
use crate::{ReadResult, Stream};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct ConsoleCmdPacket {
|
||||
tick: u32,
|
||||
command: String,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::demo::parser::Encode;
|
|||
use crate::demo::vector::Vector;
|
||||
use crate::{Parse, ParserState, ReadResult, Result, Stream};
|
||||
|
||||
#[derive(Debug, BitRead, BitWrite)]
|
||||
#[derive(Debug, BitRead, BitWrite, PartialEq)]
|
||||
pub struct MessagePacketMeta {
|
||||
pub flags: u32, // TODO
|
||||
pub view_angles: ViewAngles,
|
||||
|
|
@ -15,11 +15,11 @@ pub struct MessagePacketMeta {
|
|||
pub sequence_out: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct MessagePacket<'a> {
|
||||
pub tick: u32,
|
||||
pub messages: Vec<Message<'a>>,
|
||||
pub meta: LazyBitRead<'a, MessagePacketMeta, LittleEndian>,
|
||||
pub meta: MessagePacketMeta,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
|
@ -119,7 +119,7 @@ impl<'a> Parse<'a> for MessagePacket<'a> {
|
|||
|
||||
let mut messages = Vec::with_capacity(8);
|
||||
while packet_data.bits_left() > 6 {
|
||||
let message_type = MessageType::parse(&mut packet_data, state)?;
|
||||
let message_type = MessageType::read(&mut packet_data)?;
|
||||
|
||||
if state.should_parse_message(message_type) {
|
||||
messages.push(Message::from_type(message_type, &mut packet_data, state)?);
|
||||
|
|
@ -140,7 +140,7 @@ impl<'a> Parse<'a> for MessagePacket<'a> {
|
|||
impl Encode for MessagePacket<'_> {
|
||||
fn encode(&self, stream: &mut BitWriteStream<LittleEndian>, state: &ParserState) -> Result<()> {
|
||||
self.tick.write(stream)?;
|
||||
self.meta.read()?.write(stream)?;
|
||||
self.meta.write(stream)?;
|
||||
stream.reserve_byte_length(32, |stream| {
|
||||
for message in self.messages.iter() {
|
||||
message.get_message_type().write(stream)?;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ pub mod stringtable;
|
|||
pub mod synctick;
|
||||
pub mod usercmd;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Packet<'a> {
|
||||
Sigon(MessagePacket<'a>),
|
||||
Message(MessagePacket<'a>),
|
||||
|
|
@ -32,7 +32,7 @@ pub enum Packet<'a> {
|
|||
StringTables(StringTablePacket<'a>),
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, TryFromPrimitive, Debug, Clone, Copy)]
|
||||
#[derive(BitRead, BitWrite, TryFromPrimitive, Debug, Clone, Copy, Eq, PartialEq)]
|
||||
#[discriminant_bits = 8]
|
||||
#[repr(u8)]
|
||||
pub enum PacketType {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use bitbuffer::{BitRead, BitWrite};
|
||||
|
||||
#[derive(Debug, BitRead, BitWrite)]
|
||||
#[derive(Debug, BitRead, BitWrite, PartialEq)]
|
||||
pub struct StopPacket;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ pub struct FixedUserDataSize {
|
|||
pub bits: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug)]
|
||||
pub struct StringTable<'a> {
|
||||
pub name: Cow<'a, str>,
|
||||
pub entries: Vec<(u16, StringTableEntry<'a>)>,
|
||||
|
|
@ -26,6 +26,17 @@ pub struct StringTable<'a> {
|
|||
pub compressed: bool,
|
||||
}
|
||||
|
||||
impl PartialEq for StringTable<'_> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
// ignore `compresses` until we encode compressed
|
||||
self.name.eq(&other.name)
|
||||
&& (self.entries.eq(&other.entries))
|
||||
&& (self.max_entries.eq(&other.max_entries))
|
||||
&& (self.fixed_user_data_size.eq(&other.fixed_user_data_size))
|
||||
&& (self.client_entries.eq(&other.client_entries))
|
||||
}
|
||||
}
|
||||
|
||||
impl StringTable<'_> {
|
||||
pub fn get_table_meta(&self) -> StringTableMeta {
|
||||
StringTableMeta {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use bitbuffer::{BitRead, BitWrite};
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug)]
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct SyncTickPacket {
|
||||
pub tick: u32,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::Stream;
|
||||
use bitbuffer::{BitRead, BitWrite, LittleEndian};
|
||||
|
||||
#[derive(Debug, BitRead, BitWrite)]
|
||||
#[derive(Debug, BitRead, BitWrite, PartialEq)]
|
||||
#[endianness = "LittleEndian"]
|
||||
pub struct UserCmdPacket<'a> {
|
||||
tick: u32,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue