diff --git a/src/parser/src/e2e_test.rs b/src/parser/src/e2e_test.rs index 603ef241..41664653 100644 --- a/src/parser/src/e2e_test.rs +++ b/src/parser/src/e2e_test.rs @@ -1177,6 +1177,7 @@ mod tests { use crate::second_pass::variants::VarVec; use crate::second_pass::variants::VarVec::String; use crate::second_pass::variants::VarVec::*; + use crate::second_pass::variants::Variant; use ahash::AHashMap; use lazy_static::lazy_static; use memmap2::MmapOptions; @@ -1187,6 +1188,111 @@ mod tests { static ref out: (DemoOutput, PropController, BTreeMap>) = create_data(); } + #[test] + fn test_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![], + 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 = 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![], + 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> = 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_player_filter() { let huf = create_huffman_lookup_table();