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

dont stop prop and table name in sendprop

This commit is contained in:
Robin Appelman 2021-02-13 14:48:55 +01:00
commit 35519d5fce
7 changed files with 215 additions and 216 deletions

View file

@ -3,13 +3,16 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
use std::fs::{self, File};
use test_case::test_case;
use fnv::FnvHashMap;
use std::collections::HashMap;
use std::io::{BufRead, BufReader};
use tf_demo_parser::demo::message::packetentities::{EntityId, PacketEntity, PVS};
use tf_demo_parser::demo::message::Message;
use tf_demo_parser::demo::packet::datatable::{ServerClass, ServerClassName};
use tf_demo_parser::demo::packet::datatable::{
ParseSendTable, SendTableName, ServerClass, ServerClassName,
};
use tf_demo_parser::demo::parser::MessageHandler;
use tf_demo_parser::demo::sendprop::SendPropValue;
use tf_demo_parser::demo::sendprop::{SendPropIdentifier, SendPropName, SendPropValue};
use tf_demo_parser::{Demo, DemoParser, MessageType, ParserState};
/// Compatible serialization with the js parser entity dumps
@ -44,7 +47,12 @@ struct EntityDump {
}
impl EntityDump {
pub fn from_entity(entity: PacketEntity, tick: u32, classes: &[ServerClass]) -> Self {
pub fn from_entity(
entity: PacketEntity,
tick: u32,
classes: &[ServerClass],
prop_names: &FnvHashMap<SendPropIdentifier, (SendTableName, SendPropName)>,
) -> Self {
EntityDump {
tick,
server_class: classes[usize::from(entity.server_class)].name.clone(),
@ -53,10 +61,8 @@ impl EntityDump {
.props
.into_iter()
.map(|prop| {
(
format!("{}.{}", prop.identifier.owner_table, prop.identifier.name),
prop.value,
)
let (table_name, prop_name) = &prop_names[&prop.index];
(format!("{}.{}", table_name, prop_name), prop.value)
})
.collect(),
pvs: entity.pvs.into(),
@ -66,12 +72,14 @@ impl EntityDump {
struct EntityDumper {
entities: Vec<(u32, PacketEntity)>,
prop_names: FnvHashMap<SendPropIdentifier, (SendTableName, SendPropName)>,
}
impl EntityDumper {
pub fn new() -> Self {
EntityDumper {
entities: Vec::with_capacity(128),
prop_names: FnvHashMap::default(),
}
}
}
@ -98,10 +106,24 @@ impl MessageHandler for EntityDumper {
}
}
fn handle_data_tables(&mut self, tables: &[ParseSendTable], _server_classes: &[ServerClass]) {
for table in tables {
for prop_def in &table.props {
self.prop_names.insert(
prop_def.identifier(),
(prop_def.owner_table.clone(), prop_def.name.clone()),
);
}
}
}
fn into_output(self, state: &ParserState) -> Self::Output {
let prop_names = self.prop_names;
self.entities
.into_iter()
.map(|(tick, entity)| EntityDump::from_entity(entity, tick, &state.server_classes))
.map(|(tick, entity)| {
EntityDump::from_entity(entity, tick, &state.server_classes, &prop_names)
})
.collect()
}
}

View file

@ -48,7 +48,7 @@ fn flatten_test(input_file: &str, snapshot_file: &str) {
table
.flatten_props(&send_tables)
.into_iter()
.map(|prop| format!("{}.{}", prop.identifier.owner_table, prop.identifier.name))
.map(|prop| format!("{}.{}", prop.owner_table, prop.name))
.collect(),
)
})