pub trait DemoRunner {
// Required methods
fn run_to_end(&mut self) -> Result<(), ParserError>;
fn run_to_tick(&mut self, target_tick: u32) -> Result<(), ParserError>;
fn jump_to_tick(&mut self, target_tick: u32) -> Result<(), ParserError>;
}Expand description
Trait for controlling replay parsing execution.
Provides methods to run the parser to completion, to a specific tick, or to jump to a tick without full processing.
Required Methods§
Sourcefn run_to_end(&mut self) -> Result<(), ParserError>
fn run_to_end(&mut self) -> Result<(), ParserError>
Processes the entire replay from start to finish.
This method processes all demo commands sequentially, calling registered
observers for each event. The final packet is CDemoFileInfo.
§Errors
Returns ParserError if parsing fails.
§Examples
use source2_demo::prelude::*;
let replay = std::fs::read("replay.dem")?;
let mut parser = Parser::new(&replay)?;
parser.register_observer::<MyObserver>();
parser.run_to_end()?;Sourcefn run_to_tick(&mut self, target_tick: u32) -> Result<(), ParserError>
fn run_to_tick(&mut self, target_tick: u32) -> Result<(), ParserError>
Processes the replay up to a specific tick.
Stops parsing when the specified tick is reached. All observers are called for events up to and including the target tick.
§Arguments
target_tick- The tick to parse up to (inclusive)
§Errors
Returns ParserError if parsing fails.
§Examples
use source2_demo::prelude::*;
let replay = std::fs::File::open("replay.dem")?;
let mut parser = Parser::from_reader(&replay)?;
// Process first 5 minutes (30 ticks per second * 60 seconds * 5 minutes)
parser.run_to_tick(9000)?;Sourcefn jump_to_tick(&mut self, target_tick: u32) -> Result<(), ParserError>
fn jump_to_tick(&mut self, target_tick: u32) -> Result<(), ParserError>
Jumps to a specific tick without full processing.
This is an optimized method that seeks to the target tick without calling observers for intermediate events. Useful for jumping to a specific point in a replay quickly.
After jumping, you can continue parsing normally with observers active.
§Arguments
target_tick- The tick to jump to
§Errors
Returns ParserError if seeking fails.
§Examples
use source2_demo::prelude::*;
let replay = std::fs::File::open("replay.dem")?;
let mut parser = Parser::from_reader(&replay)?;
// Jump to 10 minutes in
parser.jump_to_tick(18000)?;
// Now register observers and continue
parser.register_observer::<MyObserver>();
parser.run_to_tick(20000)?;