Skip to content

Commit

Permalink
refactor: rm "other" wanted states & prop state querying in parse eve…
Browse files Browse the repository at this point in the history
…nt(s)
  • Loading branch information
dankotov committed Sep 1, 2024
1 parent 3c3437b commit df6180f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 303 deletions.
130 changes: 9 additions & 121 deletions src/parser/src/e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ pub fn _create_ge_tests() {
parse_ents: true,
wanted_players: vec![],
wanted_ticks: (0..5).into_iter().map(|x| x * 10000).collect_vec(),
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
wanted_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand Down Expand Up @@ -682,8 +681,7 @@ pub fn _create_tests() {
parse_ents: true,
wanted_players: vec![],
wanted_ticks: (0..5).into_iter().map(|x| x * 10000).collect_vec(),
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
wanted_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand Down Expand Up @@ -1056,8 +1054,7 @@ fn create_data() -> (DemoOutput, PropController, BTreeMap<String, Vec<GameEvent>
parse_ents: true,
wanted_players: vec![],
wanted_ticks: (0..5).into_iter().map(|x| x * 10000).collect_vec(),
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
wanted_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand All @@ -1082,8 +1079,7 @@ fn create_data() -> (DemoOutput, PropController, BTreeMap<String, Vec<GameEvent>
parse_ents: true,
wanted_players: vec![],
wanted_ticks: (0..5).into_iter().map(|x| x * 10000).collect_vec(),
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
wanted_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand Down Expand Up @@ -1201,8 +1197,7 @@ mod tests {
wanted_other_props: vec![],
parse_ents: true,
wanted_ticks: vec![],
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
wanted_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand All @@ -1211,8 +1206,8 @@ mod tests {
order_by_steamid: false,
};

let mut wanted_player_prop_states: AHashMap<std::string::String, Variant> = AHashMap::default();
wanted_player_prop_states.insert(
let mut wanted_prop_states: AHashMap<std::string::String, Variant> = AHashMap::default();
wanted_prop_states.insert(
"CCSGameRulesProxy.CCSGameRules.m_bBombPlanted".to_string(),
Variant::Bool(true),
);
Expand All @@ -1224,113 +1219,7 @@ mod tests {
wanted_other_props: vec![],
parse_ents: true,
wanted_ticks: vec![],
wanted_player_prop_states: wanted_player_prop_states,
wanted_other_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
only_convars: false,
huffman_lookup_table: &huf2,
order_by_steamid: false,
};

let mut ds = Parser::new(settings, crate::parse_demo::ParsingMode::ForceMultiThreaded);
let mut ds_with_filter = Parser::new(settings_with_filter, crate::parse_demo::ParsingMode::ForceMultiThreaded);
let file = File::open("test_demo.dem").unwrap();
let mmap = unsafe { MmapOptions::new().map(&file).unwrap() };
let output = ds.parse_demo(&mmap).unwrap();
let output_with_filter = ds_with_filter.parse_demo(&mmap).unwrap();

let positions = match output
.df
.get(&PLAYER_X_ID)
.unwrap()
.data
.clone()
.unwrap_or(VarVec::F32(vec![]))
{
VarVec::F32(positions_vec) => positions_vec,
_ => vec![],
};
let bomb_prop_id = output
.prop_controller
.prop_infos
.iter()
.find(|prop| prop.prop_name == "CCSGameRulesProxy.CCSGameRules.m_bBombPlanted")
.map(|prop| prop.id)
.unwrap();
let bomb = match output
.df
.get(&bomb_prop_id)
.unwrap()
.data
.clone()
.unwrap_or(VarVec::Bool(vec![]))
{
VarVec::Bool(bomb_vec) => bomb_vec,
_ => vec![],
};
let manually_filtered_positions: Vec<Option<f32>> = positions
.iter()
.zip(bomb.iter())
.filter_map(|(xPos, bombPlanted)| match bombPlanted {
Some(true) => Some(*xPos),
_ => None,
})
.collect();
let automatically_filtered_positions = match output_with_filter
.df
.get(&PLAYER_X_ID)
.unwrap()
.data
.clone()
.unwrap_or(VarVec::F32(vec![]))
{
VarVec::F32(positions_vec) => positions_vec,
_ => vec![],
};

assert_eq!(manually_filtered_positions, automatically_filtered_positions);
}

#[test]
fn test_parse_event_prop_state_filter() {
let huf = create_huffman_lookup_table();
let huf2 = create_huffman_lookup_table();

let settings = ParserInputs {
wanted_players: vec![76561198244754626],
real_name_to_og_name: AHashMap::default(),
wanted_player_props: vec!["X".to_string(), "CCSGameRulesProxy.CCSGameRules.m_bBombPlanted".to_string()],
wanted_events: vec!["player_death".to_string()],
wanted_other_props: vec![],
parse_ents: true,
wanted_ticks: vec![],
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
only_convars: false,
huffman_lookup_table: &huf,
order_by_steamid: false,
};

let mut wanted_player_prop_states: AHashMap<std::string::String, Variant> = AHashMap::default();
wanted_player_prop_states.insert(
"CCSGameRulesProxy.CCSGameRules.m_bBombPlanted".to_string(),
Variant::Bool(true),
);
let settings_with_filter = ParserInputs {
wanted_players: vec![76561198244754626],
real_name_to_og_name: AHashMap::default(),
wanted_player_props: vec!["X".to_string()],
wanted_events: vec!["player_death".to_string()],
wanted_other_props: vec![],
parse_ents: true,
wanted_ticks: vec![],
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: wanted_player_prop_states,
wanted_prop_states: wanted_prop_states,
parse_projectiles: true,
only_header: false,
count_props: false,
Expand Down Expand Up @@ -1410,8 +1299,7 @@ mod tests {
wanted_other_props: vec!["CCSTeam.m_iScore".to_string()],
parse_ents: true,
wanted_ticks: vec![10000, 10001],
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
wanted_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand Down
12 changes: 4 additions & 8 deletions src/parser/src/first_pass/parser_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ pub struct ParserInputs<'a> {
pub wanted_players: Vec<u64>,
pub wanted_player_props: Vec<String>,
pub wanted_other_props: Vec<String>,
pub wanted_player_prop_states: AHashMap<String, Variant>,
pub wanted_other_prop_states: AHashMap<String, Variant>,
pub wanted_prop_states: AHashMap<String, Variant>,
pub wanted_ticks: Vec<i32>,
pub wanted_events: Vec<String>,
pub parse_ents: bool,
Expand Down Expand Up @@ -66,8 +65,7 @@ pub struct FirstPassParser<'a> {
pub wanted_players: AHashSet<u64, RandomState>,
pub wanted_ticks: AHashSet<i32, RandomState>,
pub wanted_other_props: Vec<String>,
pub wanted_player_prop_states: AHashMap<String, Variant>,
pub wanted_other_prop_states: AHashMap<String, Variant>,
pub wanted_prop_states: AHashMap<String, Variant>,
pub wanted_events: Vec<String>,
pub parse_entities: bool,
pub parse_projectiles: bool,
Expand Down Expand Up @@ -109,8 +107,7 @@ impl<'a> FirstPassParser<'a> {
prop_controller: PropController::new(
inputs.wanted_player_props.clone(),
inputs.wanted_other_props.clone(),
inputs.wanted_player_prop_states.clone(),
inputs.wanted_other_prop_states.clone(),
inputs.wanted_prop_states.clone(),
inputs.real_name_to_og_name.clone(),
false,
&vec!["None".to_string()],
Expand Down Expand Up @@ -138,8 +135,7 @@ impl<'a> FirstPassParser<'a> {
wanted_players: AHashSet::from_iter(inputs.wanted_players.iter().cloned()),
wanted_ticks: AHashSet::from_iter(inputs.wanted_ticks.iter().cloned()),
wanted_other_props: inputs.wanted_other_props.clone(),
wanted_player_prop_states: inputs.wanted_player_prop_states.clone(),
wanted_other_prop_states: inputs.wanted_player_prop_states.clone(),
wanted_prop_states: inputs.wanted_prop_states.clone(),
settings: &inputs,
controller_ids: SpecialIDs::new(),
id: 0,
Expand Down
45 changes: 7 additions & 38 deletions src/parser/src/first_pass/prop_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ pub struct PropController {
pub event_with_velocity: bool,
pub needs_velocity: bool,
pub path_to_name: AHashMap<[i32; 7], String>,
pub wanted_player_prop_states: AHashMap<String, Variant>,
pub wanted_other_prop_states: AHashMap<String, Variant>,
pub wanted_prop_states: AHashMap<String, Variant>,
pub wanted_prop_state_infos: Vec<WantedPropStateInfo>,
}

Expand Down Expand Up @@ -95,8 +94,7 @@ impl PropController {
pub fn new(
wanted_player_props: Vec<String>,
wanted_other_props: Vec<String>,
wanted_player_prop_states: AHashMap<String, Variant>,
wanted_other_prop_states: AHashMap<String, Variant>,
wanted_prop_states: AHashMap<String, Variant>,
real_name_to_og_name: AHashMap<String, String>,
needs_velocty: bool,
wanted_events: &[String],
Expand All @@ -115,8 +113,7 @@ impl PropController {
event_with_velocity: !wanted_events.is_empty() && needs_velocty,
path_to_name: AHashMap::default(),
needs_velocity: needs_velocty,
wanted_player_prop_states: wanted_player_prop_states,
wanted_other_prop_states: wanted_other_prop_states,
wanted_prop_states: wanted_prop_states,
wanted_prop_state_infos: vec![],
}
}
Expand All @@ -136,7 +133,7 @@ impl PropController {
});
someid += 1;
}
if let Some(wanted_state) = self.wanted_player_prop_states.get(&(bn.to_string())) {
if let Some(wanted_state) = self.wanted_prop_states.get(&(bn.to_string())) {
self.wanted_prop_state_infos.push(WantedPropStateInfo {
base: PropInfo {
id: someid2,
Expand Down Expand Up @@ -165,7 +162,7 @@ impl PropController {
is_player_prop: true,
})
}
if let Some(wanted_state) = self.wanted_player_prop_states.get(&(custom_prop_name.to_string())) {
if let Some(wanted_state) = self.wanted_prop_states.get(&(custom_prop_name.to_string())) {
self.wanted_prop_state_infos.push(WantedPropStateInfo {
base: PropInfo {
id: *custom_prop_id,
Expand All @@ -192,7 +189,7 @@ impl PropController {
is_player_prop: true,
});
}
if let Some(wanted_state) = self.wanted_player_prop_states.get(&("game_time".to_string())) {
if let Some(wanted_state) = self.wanted_prop_states.get(&("game_time".to_string())) {
self.wanted_prop_state_infos.push(WantedPropStateInfo {
base: PropInfo {
id: GAME_TIME_ID,
Expand All @@ -214,18 +211,6 @@ impl PropController {
is_player_prop: false,
});
}
if let Some(wanted_state) = self.wanted_other_prop_states.get(&("game_time".to_string())) {
self.wanted_prop_state_infos.push(WantedPropStateInfo {
base: PropInfo {
id: GAME_TIME_ID,
prop_type: PropType::GameTime,
prop_name: "game_time".to_string(),
prop_friendly_name: "game_time".to_string(),
is_player_prop: false,
},
wanted_prop_state: wanted_state.clone(),
});
}

self.prop_infos.push(PropInfo {
id: TICK_ID,
Expand Down Expand Up @@ -300,7 +285,7 @@ impl PropController {
is_player_prop: false,
})
}
if let Some(wanted_state) = self.wanted_player_prop_states.get(&prop_name.to_string()) {
if let Some(wanted_state) = self.wanted_prop_states.get(&prop_name.to_string()) {
self.wanted_prop_state_infos.push(WantedPropStateInfo {
base: PropInfo {
id: f.prop_id as u32,
Expand All @@ -316,22 +301,6 @@ impl PropController {
wanted_prop_state: wanted_state.clone(),
});
}
if let Some(wanted_state) = self.wanted_other_prop_states.get(&prop_name.to_string()) {
self.wanted_prop_state_infos.push(WantedPropStateInfo {
base: PropInfo {
id: f.prop_id as u32,
prop_type: *prop_type,
prop_name: prop_name.to_string(),
prop_friendly_name: self
.real_name_to_og_name
.get(&prop_name.to_string())
.unwrap_or(&(prop_name.to_string()))
.to_string(),
is_player_prop: false,
},
wanted_prop_state: wanted_state.clone(),
});
}
}
}
pub fn handle_prop(&mut self, full_name: &str, f: &mut ValueField, path: Vec<i32>) {
Expand Down
3 changes: 1 addition & 2 deletions src/parser/src/first_pass/sendtables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ impl<'a> FirstPassParser<'a> {
let mut prop_controller = PropController::new(
self.wanted_player_props.clone(),
self.wanted_other_props.clone(),
self.wanted_player_prop_states.clone(),
self.wanted_other_prop_states.clone(),
self.wanted_prop_states.clone(),
self.real_name_to_og_name.clone(),
needs_velocity(&self.wanted_player_props),
&self.wanted_events,
Expand Down
1 change: 0 additions & 1 deletion src/parser/src/second_pass/parser_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ impl<'a> SecondPassParser<'a> {
vec![],
AHashMap::default(),
AHashMap::default(),
AHashMap::default(),
false,
&["none".to_string()],
),
Expand Down
Loading

0 comments on commit df6180f

Please sign in to comment.