mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +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));
|
let mut props = Vec::with_capacity(min(prop_count, 128));
|
||||||
|
|
||||||
for _ in 0..prop_count {
|
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 prop.flags.contains(SendPropFlag::InsideArray) {
|
||||||
if array_element_prop.is_some() || prop.flags.contains(SendPropFlag::ChangesOften) {
|
if array_element_prop.is_some() || prop.flags.contains(SendPropFlag::ChangesOften) {
|
||||||
return Err(MalformedSendPropDefinitionError::ArrayChangesOften.into());
|
return Err(MalformedSendPropDefinitionError::ArrayChangesOften.into());
|
||||||
|
|
@ -179,7 +179,7 @@ fn test_parse_send_table_roundtrip() {
|
||||||
RawSendPropDefinition {
|
RawSendPropDefinition {
|
||||||
prop_type: SendPropType::Float,
|
prop_type: SendPropType::Float,
|
||||||
name: "prop1".into(),
|
name: "prop1".into(),
|
||||||
owner_table: "table1".into(),
|
identifier: SendPropIdentifier::new("table1", "prop1"),
|
||||||
flags: SendPropFlags::default() | SendPropFlag::ChangesOften,
|
flags: SendPropFlags::default() | SendPropFlag::ChangesOften,
|
||||||
table_name: None,
|
table_name: None,
|
||||||
low_value: Some(0.0),
|
low_value: Some(0.0),
|
||||||
|
|
@ -191,7 +191,7 @@ fn test_parse_send_table_roundtrip() {
|
||||||
RawSendPropDefinition {
|
RawSendPropDefinition {
|
||||||
prop_type: SendPropType::Array,
|
prop_type: SendPropType::Array,
|
||||||
name: "prop2".into(),
|
name: "prop2".into(),
|
||||||
owner_table: "table1".into(),
|
identifier: SendPropIdentifier::new("table1", "prop2"),
|
||||||
flags: SendPropFlags::default(),
|
flags: SendPropFlags::default(),
|
||||||
table_name: None,
|
table_name: None,
|
||||||
low_value: None,
|
low_value: None,
|
||||||
|
|
@ -201,7 +201,7 @@ fn test_parse_send_table_roundtrip() {
|
||||||
array_property: Some(Box::new(RawSendPropDefinition {
|
array_property: Some(Box::new(RawSendPropDefinition {
|
||||||
prop_type: SendPropType::Int,
|
prop_type: SendPropType::Int,
|
||||||
name: "prop3".into(),
|
name: "prop3".into(),
|
||||||
owner_table: "table1".into(),
|
identifier: SendPropIdentifier::new("table1", "prop3"),
|
||||||
flags: SendPropFlags::default()
|
flags: SendPropFlags::default()
|
||||||
| SendPropFlag::InsideArray
|
| SendPropFlag::InsideArray
|
||||||
| SendPropFlag::NoScale,
|
| SendPropFlag::NoScale,
|
||||||
|
|
@ -216,7 +216,7 @@ fn test_parse_send_table_roundtrip() {
|
||||||
RawSendPropDefinition {
|
RawSendPropDefinition {
|
||||||
prop_type: SendPropType::DataTable,
|
prop_type: SendPropType::DataTable,
|
||||||
name: "prop1".into(),
|
name: "prop1".into(),
|
||||||
owner_table: "table1".into(),
|
identifier: SendPropIdentifier::new("table1", "prop1"),
|
||||||
flags: SendPropFlags::default() | SendPropFlag::Exclude,
|
flags: SendPropFlags::default() | SendPropFlag::Exclude,
|
||||||
table_name: Some("table2".into()),
|
table_name: Some("table2".into()),
|
||||||
low_value: None,
|
low_value: None,
|
||||||
|
|
@ -388,7 +388,7 @@ fn test_data_table_packet_roundtrip() {
|
||||||
RawSendPropDefinition {
|
RawSendPropDefinition {
|
||||||
prop_type: SendPropType::Float,
|
prop_type: SendPropType::Float,
|
||||||
name: "prop1".into(),
|
name: "prop1".into(),
|
||||||
owner_table: "table1".into(),
|
identifier: SendPropIdentifier::new("table1", "prop1"),
|
||||||
flags: SendPropFlags::default() | SendPropFlag::ChangesOften,
|
flags: SendPropFlags::default() | SendPropFlag::ChangesOften,
|
||||||
table_name: None,
|
table_name: None,
|
||||||
low_value: Some(0.0),
|
low_value: Some(0.0),
|
||||||
|
|
@ -400,7 +400,7 @@ fn test_data_table_packet_roundtrip() {
|
||||||
RawSendPropDefinition {
|
RawSendPropDefinition {
|
||||||
prop_type: SendPropType::Array,
|
prop_type: SendPropType::Array,
|
||||||
name: "prop2".into(),
|
name: "prop2".into(),
|
||||||
owner_table: "table1".into(),
|
identifier: SendPropIdentifier::new("table1", "prop2"),
|
||||||
flags: SendPropFlags::default(),
|
flags: SendPropFlags::default(),
|
||||||
table_name: None,
|
table_name: None,
|
||||||
low_value: None,
|
low_value: None,
|
||||||
|
|
@ -410,7 +410,7 @@ fn test_data_table_packet_roundtrip() {
|
||||||
array_property: Some(Box::new(RawSendPropDefinition {
|
array_property: Some(Box::new(RawSendPropDefinition {
|
||||||
prop_type: SendPropType::Int,
|
prop_type: SendPropType::Int,
|
||||||
name: "prop3".into(),
|
name: "prop3".into(),
|
||||||
owner_table: "table1".into(),
|
identifier: SendPropIdentifier::new("table1", "prop3"),
|
||||||
flags: SendPropFlags::default()
|
flags: SendPropFlags::default()
|
||||||
| SendPropFlag::InsideArray
|
| SendPropFlag::InsideArray
|
||||||
| SendPropFlag::NoScale,
|
| SendPropFlag::NoScale,
|
||||||
|
|
@ -425,7 +425,7 @@ fn test_data_table_packet_roundtrip() {
|
||||||
RawSendPropDefinition {
|
RawSendPropDefinition {
|
||||||
prop_type: SendPropType::DataTable,
|
prop_type: SendPropType::DataTable,
|
||||||
name: "prop1".into(),
|
name: "prop1".into(),
|
||||||
owner_table: "table1".into(),
|
identifier: SendPropIdentifier::new("table1", "prop1"),
|
||||||
flags: SendPropFlags::default() | SendPropFlag::Exclude,
|
flags: SendPropFlags::default() | SendPropFlag::Exclude,
|
||||||
table_name: Some("table2".into()),
|
table_name: Some("table2".into()),
|
||||||
low_value: None,
|
low_value: None,
|
||||||
|
|
@ -442,7 +442,7 @@ fn test_data_table_packet_roundtrip() {
|
||||||
props: vec![RawSendPropDefinition {
|
props: vec![RawSendPropDefinition {
|
||||||
prop_type: SendPropType::Float,
|
prop_type: SendPropType::Float,
|
||||||
name: "prop1".into(),
|
name: "prop1".into(),
|
||||||
owner_table: "table2".into(),
|
identifier: SendPropIdentifier::new("table2", "prop1"),
|
||||||
flags: SendPropFlags::default() | SendPropFlag::ChangesOften,
|
flags: SendPropFlags::default() | SendPropFlag::ChangesOften,
|
||||||
table_name: None,
|
table_name: None,
|
||||||
low_value: Some(0.0),
|
low_value: Some(0.0),
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ impl MessageHandler for GameStateAnalyser {
|
||||||
for prop_def in &table.props {
|
for prop_def in &table.props {
|
||||||
self.prop_names.insert(
|
self.prop_names.insert(
|
||||||
prop_def.identifier(),
|
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 struct RawSendPropDefinition {
|
||||||
pub prop_type: SendPropType,
|
pub prop_type: SendPropType,
|
||||||
pub name: SendPropName,
|
pub name: SendPropName,
|
||||||
pub owner_table: SendTableName,
|
pub identifier: SendPropIdentifier,
|
||||||
pub flags: SendPropFlags,
|
pub flags: SendPropFlags,
|
||||||
pub table_name: Option<SendTableName>,
|
pub table_name: Option<SendTableName>,
|
||||||
pub low_value: Option<f32>,
|
pub low_value: Option<f32>,
|
||||||
|
|
@ -83,8 +83,7 @@ impl fmt::Display for RawSendPropDefinition {
|
||||||
match self.prop_type {
|
match self.prop_type {
|
||||||
SendPropType::Vector | SendPropType::VectorXY => write!(
|
SendPropType::Vector | SendPropType::VectorXY => write!(
|
||||||
f,
|
f,
|
||||||
"{}::{}({})(flags: {}, low: {}, high: {}, bits: {})",
|
"{}({})(flags: {}, low: {}, high: {}, bits: {})",
|
||||||
self.owner_table,
|
|
||||||
self.name,
|
self.name,
|
||||||
self.prop_type,
|
self.prop_type,
|
||||||
self.flags,
|
self.flags,
|
||||||
|
|
@ -94,8 +93,7 @@ impl fmt::Display for RawSendPropDefinition {
|
||||||
),
|
),
|
||||||
SendPropType::Float => write!(
|
SendPropType::Float => write!(
|
||||||
f,
|
f,
|
||||||
"{}::{}({})(flags: {}, low: {}, high: {}, bits: {})",
|
"{}({})(flags: {}, low: {}, high: {}, bits: {})",
|
||||||
self.owner_table,
|
|
||||||
self.name,
|
self.name,
|
||||||
self.prop_type,
|
self.prop_type,
|
||||||
self.flags,
|
self.flags,
|
||||||
|
|
@ -105,21 +103,19 @@ impl fmt::Display for RawSendPropDefinition {
|
||||||
),
|
),
|
||||||
SendPropType::Int => write!(
|
SendPropType::Int => write!(
|
||||||
f,
|
f,
|
||||||
"{}::{}({})(flags: {}, bits: {})",
|
"{}({})(flags: {}, bits: {})",
|
||||||
self.owner_table,
|
|
||||||
self.name,
|
self.name,
|
||||||
self.prop_type,
|
self.prop_type,
|
||||||
self.flags,
|
self.flags,
|
||||||
self.bit_count.unwrap_or(32)
|
self.bit_count.unwrap_or(32)
|
||||||
),
|
),
|
||||||
SendPropType::String => {
|
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 {
|
SendPropType::Array => match &self.array_property {
|
||||||
Some(array_prop) => write!(
|
Some(array_prop) => write!(
|
||||||
f,
|
f,
|
||||||
"{}::{}([{}({})] * {})",
|
"{}([{}({})] * {})",
|
||||||
self.owner_table,
|
|
||||||
self.name,
|
self.name,
|
||||||
array_prop.prop_type,
|
array_prop.prop_type,
|
||||||
array_prop.flags,
|
array_prop.flags,
|
||||||
|
|
@ -128,15 +124,11 @@ impl fmt::Display for RawSendPropDefinition {
|
||||||
None => write!(f, "{}(Malformed array)", self.name),
|
None => write!(f, "{}(Malformed array)", self.name),
|
||||||
},
|
},
|
||||||
SendPropType::DataTable => match &self.table_name {
|
SendPropType::DataTable => match &self.table_name {
|
||||||
Some(sub_table) => write!(
|
Some(sub_table) => write!(f, "{}(DataTable = {})", self.name, sub_table),
|
||||||
f,
|
|
||||||
"{}::{}(DataTable = {})",
|
|
||||||
self.owner_table, self.name, sub_table
|
|
||||||
),
|
|
||||||
None => write!(f, "{}(Malformed DataTable)", self.name),
|
None => write!(f, "{}(Malformed DataTable)", self.name),
|
||||||
},
|
},
|
||||||
SendPropType::NumSendPropTypes => {
|
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 {
|
impl RawSendPropDefinition {
|
||||||
pub fn identifier(&self) -> SendPropIdentifier {
|
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 {
|
pub fn with_array_property(self, array_property: Self) -> Self {
|
||||||
RawSendPropDefinition {
|
RawSendPropDefinition {
|
||||||
prop_type: self.prop_type,
|
prop_type: self.prop_type,
|
||||||
owner_table: self.owner_table,
|
identifier: self.identifier,
|
||||||
name: self.name,
|
name: self.name,
|
||||||
flags: self.flags,
|
flags: self.flags,
|
||||||
table_name: self.table_name,
|
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 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 flags = SendPropFlags::read(stream)?;
|
||||||
let mut table_name = None;
|
let mut table_name = None;
|
||||||
let mut element_count = None;
|
let mut element_count = None;
|
||||||
|
|
@ -207,7 +200,7 @@ impl RawSendPropDefinition {
|
||||||
Ok(RawSendPropDefinition {
|
Ok(RawSendPropDefinition {
|
||||||
prop_type,
|
prop_type,
|
||||||
name,
|
name,
|
||||||
owner_table,
|
identifier,
|
||||||
flags,
|
flags,
|
||||||
table_name,
|
table_name,
|
||||||
low_value,
|
low_value,
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ impl MessageHandler for EntityDumper {
|
||||||
for prop_def in &table.props {
|
for prop_def in &table.props {
|
||||||
self.prop_names.insert(
|
self.prop_names.insert(
|
||||||
prop_def.identifier(),
|
prop_def.identifier(),
|
||||||
(prop_def.owner_table.clone(), prop_def.name.clone()),
|
(table.name.clone(), prop_def.name.clone()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ impl MessageHandler for SendPropAnalyser {
|
||||||
for prop_def in &table.props {
|
for prop_def in &table.props {
|
||||||
self.prop_names.insert(
|
self.prop_names.insert(
|
||||||
prop_def.identifier(),
|
prop_def.identifier(),
|
||||||
(prop_def.owner_table.clone(), prop_def.name.clone()),
|
(table.name.clone(), prop_def.name.clone()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue