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

shove changes_often into the enum

This commit is contained in:
Robin Appelman 2021-02-13 16:49:04 +01:00
commit a3fc003437
2 changed files with 35 additions and 6 deletions

View file

@ -129,7 +129,7 @@ impl ParseSendTable {
// sort often changed props before the others
let mut start = 0;
for i in 0..flat.len() {
if flat[i].changes_often {
if flat[i].parse_definition.changes_often() {
if i != start {
flat.swap(i, start);
}

View file

@ -16,7 +16,6 @@ use std::convert::{TryFrom, TryInto};
use fnv::FnvHasher;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::num::NonZeroU64;
use std::rc::Rc;
#[derive(
@ -348,7 +347,6 @@ impl FloatDefinition {
#[derive(Debug, Clone)]
pub struct SendPropDefinition {
pub changes_often: bool,
pub identifier: SendPropIdentifier,
pub parse_definition: SendPropParseDefinition,
}
@ -359,7 +357,6 @@ impl TryFrom<&RawSendPropDefinition> for SendPropDefinition {
fn try_from(definition: &RawSendPropDefinition) -> std::result::Result<Self, Self::Error> {
let parse_definition = definition.try_into()?;
Ok(SendPropDefinition {
changes_often: definition.flags.contains(SendPropFlag::ChangesOften),
parse_definition,
identifier: definition.identifier(),
})
@ -369,51 +366,80 @@ impl TryFrom<&RawSendPropDefinition> for SendPropDefinition {
#[derive(Debug, Clone)]
pub enum SendPropParseDefinition {
NormalVarInt {
changes_often: bool,
unsigned: bool,
},
UnsignedInt {
changes_often: bool,
bit_count: u8,
},
Int {
changes_often: bool,
bit_count: u8,
},
Float {
changes_often: bool,
definition: FloatDefinition,
},
String,
String {
changes_often: bool,
},
Vector {
changes_often: bool,
definition: FloatDefinition,
},
VectorXY {
changes_often: bool,
definition: FloatDefinition,
},
Array {
changes_often: bool,
inner_definition: Box<SendPropParseDefinition>,
count_bit_count: u16,
},
}
impl SendPropParseDefinition {
pub fn changes_often(&self) -> bool {
match self {
SendPropParseDefinition::NormalVarInt { changes_often, .. } => *changes_often,
SendPropParseDefinition::UnsignedInt { changes_often, .. } => *changes_often,
SendPropParseDefinition::Int { changes_often, .. } => *changes_often,
SendPropParseDefinition::Float { changes_often, .. } => *changes_often,
SendPropParseDefinition::String { changes_often, .. } => *changes_often,
SendPropParseDefinition::Vector { changes_often, .. } => *changes_often,
SendPropParseDefinition::VectorXY { changes_often, .. } => *changes_often,
SendPropParseDefinition::Array { changes_often, .. } => *changes_often,
}
}
}
impl TryFrom<&RawSendPropDefinition> for SendPropParseDefinition {
type Error = MalformedSendPropDefinitionError;
fn try_from(definition: &RawSendPropDefinition) -> std::result::Result<Self, Self::Error> {
let changes_often = definition.flags.contains(SendPropFlag::ChangesOften);
match definition.prop_type {
SendPropType::Int => {
if definition.flags.contains(SendPropFlag::NormalVarInt) {
Ok(SendPropParseDefinition::NormalVarInt {
changes_often,
unsigned: definition.flags.contains(SendPropFlag::Unsigned),
})
} else if definition.flags.contains(SendPropFlag::Unsigned) {
Ok(SendPropParseDefinition::UnsignedInt {
changes_often,
bit_count: definition.bit_count.unwrap_or(32) as u8,
})
} else {
Ok(SendPropParseDefinition::Int {
changes_often,
bit_count: definition.bit_count.unwrap_or(32) as u8,
})
}
}
SendPropType::Float => Ok(SendPropParseDefinition::Float {
changes_often,
definition: FloatDefinition::new(
definition.flags,
definition.bit_count,
@ -421,8 +447,9 @@ impl TryFrom<&RawSendPropDefinition> for SendPropParseDefinition {
definition.low_value,
)?,
}),
SendPropType::String => Ok(SendPropParseDefinition::String),
SendPropType::String => Ok(SendPropParseDefinition::String { changes_often }),
SendPropType::Vector => Ok(SendPropParseDefinition::Vector {
changes_often,
definition: FloatDefinition::new(
definition.flags,
definition.bit_count,
@ -431,6 +458,7 @@ impl TryFrom<&RawSendPropDefinition> for SendPropParseDefinition {
)?,
}),
SendPropType::VectorXY => Ok(SendPropParseDefinition::VectorXY {
changes_often,
definition: FloatDefinition::new(
definition.flags,
definition.bit_count,
@ -450,6 +478,7 @@ impl TryFrom<&RawSendPropDefinition> for SendPropParseDefinition {
.as_deref()
.ok_or(MalformedSendPropDefinitionError::UntypedArray)?;
Ok(SendPropParseDefinition::Array {
changes_often,
inner_definition: Box::new(SendPropParseDefinition::try_from(
child_definition,
)?),