Switch to using lazy parser
This commit is contained in:
@@ -70,51 +70,48 @@ pub struct PerRound {
|
||||
|
||||
pub fn parse(buf: &[u8]) -> Result<PerRound, ()> {
|
||||
let tmp = csdemo::Container::parse(buf).map_err(|e| ())?;
|
||||
let output = csdemo::parser::parse(
|
||||
csdemo::FrameIterator::parse(tmp.inner),
|
||||
csdemo::parser::EntityFilter::all(),
|
||||
)
|
||||
.map_err(|e| ())?;
|
||||
|
||||
let output = csdemo::lazyparser::LazyParser::new(tmp);
|
||||
|
||||
let player_info = output.player_info();
|
||||
|
||||
let mut rounds: Vec<Round> = Vec::new();
|
||||
for tick in output.entity_states.ticks.iter() {
|
||||
for state in tick.states.iter() {
|
||||
let round_start_count = state
|
||||
.get_prop("CCSGameRulesProxy.CCSGameRules.m_nRoundStartCount")
|
||||
.map(|v| v.value.as_u32())
|
||||
.flatten();
|
||||
if let Some(round_start_count) = round_start_count {
|
||||
if rounds.len() < (round_start_count - 1) as usize {
|
||||
rounds.push(Round {
|
||||
winreason: WinReason::StillInProgress,
|
||||
start: tick.tick,
|
||||
end: u32::MAX,
|
||||
events: Vec::new(),
|
||||
});
|
||||
}
|
||||
for (tick, state) in output.entities().filter_map(|e| e.ok()) {
|
||||
let round_start_count = state
|
||||
.get_prop("CCSGameRulesProxy.CCSGameRules.m_nRoundStartCount")
|
||||
.map(|v| v.value.as_u32())
|
||||
.flatten();
|
||||
if let Some(round_start_count) = round_start_count {
|
||||
if rounds.len() < (round_start_count - 1) as usize {
|
||||
rounds.push(Round {
|
||||
winreason: WinReason::StillInProgress,
|
||||
start: tick,
|
||||
end: u32::MAX,
|
||||
events: Vec::new(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let round_end_count = state
|
||||
.get_prop("CCSGameRulesProxy.CCSGameRules.m_nRoundEndCount")
|
||||
.map(|v| v.value.as_u32())
|
||||
.flatten();
|
||||
if let Some(round_end_count) = round_end_count {
|
||||
if rounds.len() == (round_end_count - 1) as usize {
|
||||
rounds.last_mut().unwrap().end = tick.tick;
|
||||
}
|
||||
let round_end_count = state
|
||||
.get_prop("CCSGameRulesProxy.CCSGameRules.m_nRoundEndCount")
|
||||
.map(|v| v.value.as_u32())
|
||||
.flatten();
|
||||
if let Some(round_end_count) = round_end_count {
|
||||
if rounds.len() == (round_end_count - 1) as usize {
|
||||
rounds.last_mut().unwrap().end = tick;
|
||||
}
|
||||
}
|
||||
|
||||
if state.class.as_ref() == "CCSGameRulesProxy" {
|
||||
let round_win_reason = state
|
||||
.get_prop("CCSGameRulesProxy.CCSGameRules.m_eRoundWinReason")
|
||||
.map(|p| p.value.as_i32())
|
||||
.flatten()
|
||||
.map(|v| ROUND_WIN_REASON.get(&v))
|
||||
.flatten()
|
||||
.filter(|r| !matches!(r, WinReason::StillInProgress));
|
||||
if let Some(round_win_reason) = round_win_reason {
|
||||
rounds.last_mut().unwrap().winreason = round_win_reason.clone();
|
||||
}
|
||||
if state.class.as_ref() == "CCSGameRulesProxy" {
|
||||
let round_win_reason = state
|
||||
.get_prop("CCSGameRulesProxy.CCSGameRules.m_eRoundWinReason")
|
||||
.map(|p| p.value.as_i32())
|
||||
.flatten()
|
||||
.map(|v| ROUND_WIN_REASON.get(&v))
|
||||
.flatten()
|
||||
.filter(|r| !matches!(r, WinReason::StillInProgress));
|
||||
if let Some(round_win_reason) = round_win_reason {
|
||||
rounds.last_mut().unwrap().winreason = round_win_reason.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +120,7 @@ pub fn parse(buf: &[u8]) -> Result<PerRound, ()> {
|
||||
|
||||
let mut current_tick = 0;
|
||||
let mut current_round = rounds_iter.next().unwrap();
|
||||
'events: for event in output.events.iter() {
|
||||
'events: for event in output.events().filter_map(|e| e.ok()) {
|
||||
match event {
|
||||
csdemo::DemoEvent::Tick(tick) => {
|
||||
current_tick = tick.tick();
|
||||
@@ -154,8 +151,8 @@ pub fn parse(buf: &[u8]) -> Result<PerRound, ()> {
|
||||
None => died.clone(),
|
||||
};
|
||||
|
||||
let died_player = output.player_info.get(&died).unwrap();
|
||||
let attacker_player = output.player_info.get(&attacker).unwrap();
|
||||
let died_player = player_info.get(&died).unwrap();
|
||||
let attacker_player = player_info.get(&attacker).unwrap();
|
||||
|
||||
RoundEvent::Kill {
|
||||
attacker: attacker_player.xuid,
|
||||
|
||||
Reference in New Issue
Block a user