1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 10:14:06 +02:00

clean sendprop a bit

This commit is contained in:
Robin Appelman 2019-04-28 22:38:05 +02:00
commit aeaca07588
2 changed files with 20 additions and 20 deletions

View file

@ -1,6 +1,6 @@
use bitstream_reader::BitRead; use bitstream_reader::BitRead;
use crate::demo::sendprop::{SendPropDefinition, SendPropFlag, SendPropType}; use crate::demo::sendprop::{RawSendPropDefinition, SendPropFlag, SendPropType};
use crate::{Parse, ParseError, ParserState, Result, Stream}; use crate::{Parse, ParseError, ParserState, Result, Stream};
#[derive(BitRead, Debug)] #[derive(BitRead, Debug)]
@ -13,9 +13,9 @@ pub struct ServerClass {
#[derive(Debug)] #[derive(Debug)]
pub struct SendTable { pub struct SendTable {
pub name: String, pub name: String,
pub props: Vec<SendPropDefinition>, pub props: Vec<RawSendPropDefinition>,
pub needs_decoder: bool, pub needs_decoder: bool,
pub flattened_props: Option<Vec<SendPropDefinition>>, pub flattened_props: Option<Vec<RawSendPropDefinition>>,
} }
impl Parse for SendTable { impl Parse for SendTable {
@ -28,8 +28,8 @@ impl Parse for SendTable {
let mut props = Vec::with_capacity(prop_count); let mut props = Vec::with_capacity(prop_count);
for _ in 0..prop_count { for _ in 0..prop_count {
let prop: SendPropDefinition = let prop: RawSendPropDefinition =
SendPropDefinition::read(stream)?; RawSendPropDefinition::read(stream)?;
if prop.flags.contains(SendPropFlag::InsideArray) { if prop.flags.contains(SendPropFlag::InsideArray) {
if array_element_prop.is_some() if array_element_prop.is_some()
|| prop.flags.contains(SendPropFlag::ChangesOften) || prop.flags.contains(SendPropFlag::ChangesOften)

View file

@ -8,26 +8,26 @@ use super::packet::datatable::SendTable;
use super::vector::{Vector, VectorXY}; use super::vector::{Vector, VectorXY};
#[derive(Debug)] #[derive(Debug)]
pub struct SendPropDefinition { pub struct RawSendPropDefinition {
pub prop_type: SendPropType, pub prop_type: SendPropType,
pub name: String, pub name: String,
pub flags: SendPropFlags, pub flags: SendPropFlags,
pub exclude_dt_name: Option<String>, pub table_name: Option<String>,
pub low_value: Option<f32>, pub low_value: Option<f32>,
pub high_value: Option<f32>, pub high_value: Option<f32>,
pub bit_count: Option<u32>, pub bit_count: Option<u32>,
pub original_bit_count: Option<u32>, pub original_bit_count: Option<u32>,
pub element_count: Option<u16>, pub element_count: Option<u16>,
pub array_property: Option<Box<SendPropDefinition>>, pub array_property: Option<Box<RawSendPropDefinition>>,
} }
impl SendPropDefinition { impl RawSendPropDefinition {
pub fn with_array_property(self, array_property: Self) -> Self { pub fn with_array_property(self, array_property: Self) -> Self {
SendPropDefinition { RawSendPropDefinition {
prop_type: self.prop_type, prop_type: self.prop_type,
name: self.name, name: self.name,
flags: self.flags, flags: self.flags,
exclude_dt_name: self.exclude_dt_name, table_name: self.table_name,
low_value: self.low_value, low_value: self.low_value,
high_value: self.high_value, high_value: self.high_value,
bit_count: self.bit_count, bit_count: self.bit_count,
@ -38,26 +38,26 @@ impl SendPropDefinition {
} }
} }
impl BitRead<LittleEndian> for SendPropDefinition { impl BitRead<LittleEndian> for RawSendPropDefinition {
fn read(stream: &mut Stream) -> ReadResult<Self> { fn read(stream: &mut Stream) -> ReadResult<Self> {
let prop_type = SendPropType::read(stream)?; let prop_type = SendPropType::read(stream)?;
let name = stream.read_string(None)?; let name = stream.read_string(None)?;
let flags = SendPropFlags::read(stream)?; let flags = SendPropFlags::read(stream)?;
let mut exclude_dt_name = None; let mut table_name = None;
let mut element_count = None; let mut element_count = None;
let mut low_value = None; let mut low_value = None;
let mut high_value = None; let mut high_value = None;
let mut bit_count = None; let mut bit_count = None;
if prop_type == SendPropType::DataTable { if prop_type == SendPropType::DataTable {
exclude_dt_name = Some(stream.read_string(None)?); table_name = Some(stream.read()?);
} else { } else {
if flags.contains(SendPropFlag::Exclude) { if flags.contains(SendPropFlag::Exclude) {
exclude_dt_name = Some(stream.read_string(None)?); table_name = Some(stream.read()?);
} else if prop_type == SendPropType::Array { } else if prop_type == SendPropType::Array {
element_count = Some(stream.read_int(10)?); element_count = Some(stream.read_int(10)?);
} else { } else {
low_value = Some(stream.read_float()?); low_value = Some(stream.read()?);
high_value = Some(stream.read_float()?); high_value = Some(stream.read()?);
bit_count = Some(stream.read_int(7)?); bit_count = Some(stream.read_int(7)?);
} }
} }
@ -73,11 +73,11 @@ impl BitRead<LittleEndian> for SendPropDefinition {
} }
} }
Ok(SendPropDefinition { Ok(RawSendPropDefinition {
prop_type, prop_type,
name, name,
flags, flags,
exclude_dt_name, table_name,
low_value, low_value,
high_value, high_value,
bit_count, bit_count,
@ -192,7 +192,7 @@ pub enum SendPropValue {
#[derive(Debug)] #[derive(Debug)]
pub struct SendProp { pub struct SendProp {
definition: SendPropDefinition, definition: RawSendPropDefinition,
value: SendPropValue, value: SendPropValue,
} }