Skip to content

Commit

Permalink
refactor: split wanted_prop_states into player & other prop states
Browse files Browse the repository at this point in the history
  • Loading branch information
dankotov committed Aug 28, 2024
1 parent 8e204bb commit eb3c7c6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
15 changes: 10 additions & 5 deletions src/parser/src/e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ pub fn _create_ge_tests() {
parse_ents: true,
wanted_players: vec![],
wanted_ticks: (0..5).into_iter().map(|x| x * 10000).collect_vec(),
wanted_prop_states: AHashMap::default(),
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand Down Expand Up @@ -681,7 +682,8 @@ pub fn _create_tests() {
parse_ents: true,
wanted_players: vec![],
wanted_ticks: (0..5).into_iter().map(|x| x * 10000).collect_vec(),
wanted_prop_states: AHashMap::default(),
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand Down Expand Up @@ -1054,7 +1056,8 @@ 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_prop_states: AHashMap::default(),
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand All @@ -1079,7 +1082,8 @@ 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_prop_states: AHashMap::default(),
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand Down Expand Up @@ -1195,7 +1199,8 @@ mod tests {
wanted_other_props: vec!["CCSTeam.m_iScore".to_string()],
parse_ents: true,
wanted_ticks: vec![10000, 10001],
wanted_prop_states: AHashMap::default(),
wanted_player_prop_states: AHashMap::default(),
wanted_other_prop_states: AHashMap::default(),
parse_projectiles: true,
only_header: false,
count_props: false,
Expand Down
12 changes: 8 additions & 4 deletions src/parser/src/first_pass/parser_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub struct ParserInputs<'a> {
pub wanted_players: Vec<u64>,
pub wanted_player_props: Vec<String>,
pub wanted_other_props: Vec<String>,
pub wanted_prop_states: AHashMap<String, Variant>,
pub wanted_player_prop_states: AHashMap<String, Variant>,
pub wanted_other_prop_states: AHashMap<String, Variant>,
pub wanted_ticks: Vec<i32>,
pub wanted_events: Vec<String>,
pub parse_ents: bool,
Expand Down Expand Up @@ -65,7 +66,8 @@ pub struct FirstPassParser<'a> {
pub wanted_players: AHashSet<u64, RandomState>,
pub wanted_ticks: AHashSet<i32, RandomState>,
pub wanted_other_props: Vec<String>,
pub wanted_prop_states: AHashMap<String, Variant>,
pub wanted_player_prop_states: AHashMap<String, Variant>,
pub wanted_other_prop_states: AHashMap<String, Variant>,
pub wanted_events: Vec<String>,
pub parse_entities: bool,
pub parse_projectiles: bool,
Expand Down Expand Up @@ -107,7 +109,8 @@ impl<'a> FirstPassParser<'a> {
prop_controller: PropController::new(
inputs.wanted_player_props.clone(),
inputs.wanted_other_props.clone(),
inputs.wanted_prop_states.clone(),
inputs.wanted_player_prop_states.clone(),
inputs.wanted_other_prop_states.clone(),
inputs.real_name_to_og_name.clone(),
false,
&vec!["None".to_string()],
Expand Down Expand Up @@ -135,7 +138,8 @@ 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_prop_states: inputs.wanted_prop_states.clone(),
wanted_player_prop_states: inputs.wanted_player_prop_states.clone(),
wanted_other_prop_states: inputs.wanted_player_prop_states.clone(),
settings: &inputs,
controller_ids: SpecialIDs::new(),
id: 0,
Expand Down
47 changes: 39 additions & 8 deletions src/parser/src/first_pass/prop_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ pub struct PropController {
pub event_with_velocity: bool,
pub needs_velocity: bool,
pub path_to_name: AHashMap<[i32; 7], String>,
pub wanted_prop_states: AHashMap<String, Variant>,
pub wanted_player_prop_states: AHashMap<String, Variant>,
pub wanted_other_prop_states: AHashMap<String, Variant>,
pub wanted_prop_state_infos: Vec<WantedPropStateInfo>,
}

Expand Down Expand Up @@ -95,7 +96,8 @@ impl PropController {
pub fn new(
wanted_player_props: Vec<String>,
wanted_other_props: Vec<String>,
wanted_prop_states: AHashMap<String, Variant>,
wanted_player_prop_states: AHashMap<String, Variant>,
wanted_other_prop_states: AHashMap<String, Variant>,
real_name_to_og_name: AHashMap<String, String>,
needs_velocty: bool,
wanted_events: &[String],
Expand All @@ -114,7 +116,8 @@ impl PropController {
event_with_velocity: !wanted_events.is_empty() && needs_velocty,
path_to_name: AHashMap::default(),
needs_velocity: needs_velocty,
wanted_prop_states: wanted_prop_states,
wanted_player_prop_states: wanted_player_prop_states,
wanted_other_prop_states: wanted_other_prop_states,
wanted_prop_state_infos: vec![],
}
}
Expand All @@ -134,7 +137,7 @@ impl PropController {
});
someid += 1;
}
if let Some(wanted_state) = self.wanted_prop_states.get(&(bn.to_string())) {
if let Some(wanted_state) = self.wanted_player_prop_states.get(&(bn.to_string())) {
self.wanted_prop_state_infos.push(WantedPropStateInfo {
base: PropInfo {
id: someid2,
Expand Down Expand Up @@ -163,7 +166,7 @@ impl PropController {
is_player_prop: true,
})
}
if let Some(wanted_state) = self.wanted_prop_states.get(&(custom_prop_name.to_string())) {
if let Some(wanted_state) = self.wanted_player_prop_states.get(&(custom_prop_name.to_string())) {
self.wanted_prop_state_infos.push(WantedPropStateInfo {
base: PropInfo {
id: *custom_prop_id,
Expand All @@ -190,7 +193,7 @@ impl PropController {
is_player_prop: true,
});
}
if let Some(wanted_state) = self.wanted_prop_states.get(&("game_time".to_string())) {
if let Some(wanted_state) = self.wanted_player_prop_states.get(&("game_time".to_string())) {
self.wanted_prop_state_infos.push(WantedPropStateInfo {
base: PropInfo {
id: GAME_TIME_ID,
Expand All @@ -212,6 +215,18 @@ 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 @@ -286,7 +301,23 @@ impl PropController {
is_player_prop: false,
})
}
if let Some(wanted_state) = self.wanted_prop_states.get(&prop_name.to_string()) {
if let Some(wanted_state) = self.wanted_player_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: true,
},
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,
Expand All @@ -297,7 +328,7 @@ impl PropController {
.get(&prop_name.to_string())
.unwrap_or(&(prop_name.to_string()))
.to_string(),
is_player_prop: false, // does this actually affect anything?
is_player_prop: false,
},
wanted_prop_state: wanted_state.clone(),
});
Expand Down
3 changes: 2 additions & 1 deletion src/parser/src/first_pass/sendtables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ impl<'a> FirstPassParser<'a> {
let mut prop_controller = PropController::new(
self.wanted_player_props.clone(),
self.wanted_other_props.clone(),
self.wanted_prop_states.clone(),
self.wanted_player_prop_states.clone(),
self.wanted_other_prop_states.clone(),
self.real_name_to_og_name.clone(),
needs_velocity(&self.wanted_player_props),
&self.wanted_events,
Expand Down

0 comments on commit eb3c7c6

Please sign in to comment.