mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
dont store table name as string in sendpropdefinition
This commit is contained in:
parent
02819d59ec
commit
7fe9fd0fce
5 changed files with 27 additions and 34 deletions
|
|
@ -107,7 +107,7 @@ impl Parse<'_> for ParseSendTable {
|
|||
let mut props = Vec::with_capacity(min(prop_count, 128));
|
||||
|
||||
for _ in 0..prop_count {
|
||||
let prop: RawSendPropDefinition = RawSendPropDefinition::read(stream, name.clone())?;
|
||||
let prop: RawSendPropDefinition = RawSendPropDefinition::read(stream, &name)?;
|
||||
if prop.flags.contains(SendPropFlag::InsideArray) {
|
||||
if array_element_prop.is_some() || prop.flags.contains(SendPropFlag::ChangesOften) {
|
||||
return Err(MalformedSendPropDefinitionError::ArrayChangesOften.into());
|
||||
|
|
@ -179,7 +179,7 @@ fn test_parse_send_table_roundtrip() {
|
|||
RawSendPropDefinition {
|
||||
prop_type: SendPropType::Float,
|
||||
name: "prop1".into(),
|
||||
owner_table: "table1".into(),
|
||||
identifier: SendPropIdentifier::new("table1", "prop1"),
|
||||
flags: SendPropFlags::default() | SendPropFlag::ChangesOften,
|
||||
table_name: None,
|
||||
low_value: Some(0.0),
|
||||
|
|
@ -191,7 +191,7 @@ fn test_parse_send_table_roundtrip() {
|
|||
RawSendPropDefinition {
|
||||
prop_type: SendPropType::Array,
|
||||
name: "prop2".into(),
|
||||
owner_table: "table1".into(),
|
||||
identifier: SendPropIdentifier::new("table1", "prop2"),
|
||||
flags: SendPropFlags::default(),
|
||||
table_name: None,
|
||||
low_value: None,
|
||||
|
|
@ -201,7 +201,7 @@ fn test_parse_send_table_roundtrip() {
|
|||
array_property: Some(Box::new(RawSendPropDefinition {
|
||||
prop_type: SendPropType::Int,
|
||||
name: "prop3".into(),
|
||||
owner_table: "table1".into(),
|
||||
identifier: SendPropIdentifier::new("table1", "prop3"),
|
||||
flags: SendPropFlags::default()
|
||||
| SendPropFlag::InsideArray
|
||||
| SendPropFlag::NoScale,
|
||||
|
|
@ -216,7 +216,7 @@ fn test_parse_send_table_roundtrip() {
|
|||
RawSendPropDefinition {
|
||||
prop_type: SendPropType::DataTable,
|
||||
name: "prop1".into(),
|
||||
owner_table: "table1".into(),
|
||||
identifier: SendPropIdentifier::new("table1", "prop1"),
|
||||
flags: SendPropFlags::default() | SendPropFlag::Exclude,
|
||||
table_name: Some("table2".into()),
|
||||
low_value: None,
|
||||
|
|
@ -388,7 +388,7 @@ fn test_data_table_packet_roundtrip() {
|
|||
RawSendPropDefinition {
|
||||
prop_type: SendPropType::Float,
|
||||
name: "prop1".into(),
|
||||
owner_table: "table1".into(),
|
||||
identifier: SendPropIdentifier::new("table1", "prop1"),
|
||||
flags: SendPropFlags::default() | SendPropFlag::ChangesOften,
|
||||
table_name: None,
|
||||
low_value: Some(0.0),
|
||||
|
|
@ -400,7 +400,7 @@ fn test_data_table_packet_roundtrip() {
|
|||
RawSendPropDefinition {
|
||||
prop_type: SendPropType::Array,
|
||||
name: "prop2".into(),
|
||||
owner_table: "table1".into(),
|
||||
identifier: SendPropIdentifier::new("table1", "prop2"),
|
||||
flags: SendPropFlags::default(),
|
||||
table_name: None,
|
||||
low_value: None,
|
||||
|
|
@ -410,7 +410,7 @@ fn test_data_table_packet_roundtrip() {
|
|||
array_property: Some(Box::new(RawSendPropDefinition {
|
||||
prop_type: SendPropType::Int,
|
||||
name: "prop3".into(),
|
||||
owner_table: "table1".into(),
|
||||
identifier: SendPropIdentifier::new("table1", "prop3"),
|
||||
flags: SendPropFlags::default()
|
||||
| SendPropFlag::InsideArray
|
||||
| SendPropFlag::NoScale,
|
||||
|
|
@ -425,7 +425,7 @@ fn test_data_table_packet_roundtrip() {
|
|||
RawSendPropDefinition {
|
||||
prop_type: SendPropType::DataTable,
|
||||
name: "prop1".into(),
|
||||
owner_table: "table1".into(),
|
||||
identifier: SendPropIdentifier::new("table1", "prop1"),
|
||||
flags: SendPropFlags::default() | SendPropFlag::Exclude,
|
||||
table_name: Some("table2".into()),
|
||||
low_value: None,
|
||||
|
|
@ -442,7 +442,7 @@ fn test_data_table_packet_roundtrip() {
|
|||
props: vec![RawSendPropDefinition {
|
||||
prop_type: SendPropType::Float,
|
||||
name: "prop1".into(),
|
||||
owner_table: "table2".into(),
|
||||
identifier: SendPropIdentifier::new("table2", "prop1"),
|
||||
flags: SendPropFlags::default() | SendPropFlag::ChangesOften,
|
||||
table_name: None,
|
||||
low_value: Some(0.0),
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ impl MessageHandler for GameStateAnalyser {
|
|||
for prop_def in &table.props {
|
||||
self.prop_names.insert(
|
||||
prop_def.identifier(),
|
||||
(prop_def.owner_table.clone(), prop_def.name.clone()),
|
||||
(table.name.clone(), prop_def.name.clone()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ impl From<&str> for SendPropName {
|
|||
pub struct RawSendPropDefinition {
|
||||
pub prop_type: SendPropType,
|
||||
pub name: SendPropName,
|
||||
pub owner_table: SendTableName,
|
||||
pub identifier: SendPropIdentifier,
|
||||
pub flags: SendPropFlags,
|
||||
pub table_name: Option<SendTableName>,
|
||||
pub low_value: Option<f32>,
|
||||
|
|
@ -83,8 +83,7 @@ impl fmt::Display for RawSendPropDefinition {
|
|||
match self.prop_type {
|
||||
SendPropType::Vector | SendPropType::VectorXY => write!(
|
||||
f,
|
||||
"{}::{}({})(flags: {}, low: {}, high: {}, bits: {})",
|
||||
self.owner_table,
|
||||
"{}({})(flags: {}, low: {}, high: {}, bits: {})",
|
||||
self.name,
|
||||
self.prop_type,
|
||||
self.flags,
|
||||
|
|
@ -94,8 +93,7 @@ impl fmt::Display for RawSendPropDefinition {
|
|||
),
|
||||
SendPropType::Float => write!(
|
||||
f,
|
||||
"{}::{}({})(flags: {}, low: {}, high: {}, bits: {})",
|
||||
self.owner_table,
|
||||
"{}({})(flags: {}, low: {}, high: {}, bits: {})",
|
||||
self.name,
|
||||
self.prop_type,
|
||||
self.flags,
|
||||
|
|
@ -105,21 +103,19 @@ impl fmt::Display for RawSendPropDefinition {
|
|||
),
|
||||
SendPropType::Int => write!(
|
||||
f,
|
||||
"{}::{}({})(flags: {}, bits: {})",
|
||||
self.owner_table,
|
||||
"{}({})(flags: {}, bits: {})",
|
||||
self.name,
|
||||
self.prop_type,
|
||||
self.flags,
|
||||
self.bit_count.unwrap_or(32)
|
||||
),
|
||||
SendPropType::String => {
|
||||
write!(f, "{}::{}({})", self.owner_table, self.name, self.prop_type)
|
||||
write!(f, "{}({})", self.name, self.prop_type)
|
||||
}
|
||||
SendPropType::Array => match &self.array_property {
|
||||
Some(array_prop) => write!(
|
||||
f,
|
||||
"{}::{}([{}({})] * {})",
|
||||
self.owner_table,
|
||||
"{}([{}({})] * {})",
|
||||
self.name,
|
||||
array_prop.prop_type,
|
||||
array_prop.flags,
|
||||
|
|
@ -128,15 +124,11 @@ impl fmt::Display for RawSendPropDefinition {
|
|||
None => write!(f, "{}(Malformed array)", self.name),
|
||||
},
|
||||
SendPropType::DataTable => match &self.table_name {
|
||||
Some(sub_table) => write!(
|
||||
f,
|
||||
"{}::{}(DataTable = {})",
|
||||
self.owner_table, self.name, sub_table
|
||||
),
|
||||
Some(sub_table) => write!(f, "{}(DataTable = {})", self.name, sub_table),
|
||||
None => write!(f, "{}(Malformed DataTable)", self.name),
|
||||
},
|
||||
SendPropType::NumSendPropTypes => {
|
||||
write!(f, "{}::{}(NumSendPropTypes)", self.owner_table, self.name)
|
||||
write!(f, "{}(NumSendPropTypes)", self.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -144,13 +136,13 @@ impl fmt::Display for RawSendPropDefinition {
|
|||
|
||||
impl RawSendPropDefinition {
|
||||
pub fn identifier(&self) -> SendPropIdentifier {
|
||||
SendPropIdentifier::new(self.owner_table.as_str(), self.name.as_str())
|
||||
self.identifier
|
||||
}
|
||||
|
||||
pub fn with_array_property(self, array_property: Self) -> Self {
|
||||
RawSendPropDefinition {
|
||||
prop_type: self.prop_type,
|
||||
owner_table: self.owner_table,
|
||||
identifier: self.identifier,
|
||||
name: self.name,
|
||||
flags: self.flags,
|
||||
table_name: self.table_name,
|
||||
|
|
@ -175,9 +167,10 @@ impl RawSendPropDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read(stream: &mut Stream, owner_table: SendTableName) -> ReadResult<Self> {
|
||||
pub fn read(stream: &mut Stream, owner_table: &SendTableName) -> ReadResult<Self> {
|
||||
let prop_type = SendPropType::read(stream)?;
|
||||
let name = stream.read_string(None)?.to_string().into();
|
||||
let name: SendPropName = stream.read()?;
|
||||
let identifier = SendPropIdentifier::new(owner_table.as_str(), name.as_str());
|
||||
let flags = SendPropFlags::read(stream)?;
|
||||
let mut table_name = None;
|
||||
let mut element_count = None;
|
||||
|
|
@ -207,7 +200,7 @@ impl RawSendPropDefinition {
|
|||
Ok(RawSendPropDefinition {
|
||||
prop_type,
|
||||
name,
|
||||
owner_table,
|
||||
identifier,
|
||||
flags,
|
||||
table_name,
|
||||
low_value,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue