Skip to main content

subtr_actor/collector/
mod.rs

1pub mod callback;
2pub mod decorator;
3mod frame_resolution;
4pub mod ndarray;
5pub mod replay_data;
6pub mod replay_data_heuristics;
7pub mod stats;
8pub mod stats_timeline;
9pub mod stats_timeline_types;
10
11pub use self::ndarray::*;
12pub use callback::*;
13pub use decorator::*;
14pub use frame_resolution::StatsFrameResolution;
15pub use replay_data::*;
16pub use replay_data_heuristics::*;
17pub use stats::*;
18pub use stats_timeline::*;
19pub use stats_timeline_types::*;
20
21use crate::*;
22use boxcars;
23
24/// Enum used to control the progress of time during replay processing.
25pub enum TimeAdvance {
26    /// Move forward in time by a specified amount.
27    Time(f32),
28    /// Advance to the next frame.
29    NextFrame,
30}
31
32/// Trait for types that collect data from a replay.
33///
34/// A `Collector` processes frames from a replay, potentially using a
35/// [`ReplayProcessor`] for access to additional replay data and context. It
36/// determines the pace of replay progression via the [`TimeAdvance`] return
37/// value.
38pub trait Collector {
39    /// Process a single frame from a replay.
40    ///
41    /// # Arguments
42    ///
43    /// * `processor` - The [`ReplayProcessor`] providing context for the replay.
44    /// * `frame` - The [`boxcars::Frame`] to process.
45    /// * `frame_number` - The number of the current frame.
46    /// * `current_time` - The current target time in the replay.
47    ///
48    /// # Returns
49    ///
50    /// Returns a [`TimeAdvance`] enum which determines the next step in replay
51    /// progression.
52    fn process_frame(
53        &mut self,
54        processor: &ReplayProcessor,
55        frame: &boxcars::Frame,
56        frame_number: usize,
57        current_time: f32,
58    ) -> SubtrActorResult<TimeAdvance>;
59
60    /// Process an entire replay.
61    ///
62    /// # Arguments
63    ///
64    /// * `replay` - The [`boxcars::Replay`] to process.
65    ///
66    /// # Returns
67    ///
68    /// Returns the [`Collector`] itself, potentially modified by the processing
69    /// of the replay.
70    fn process_replay(mut self, replay: &boxcars::Replay) -> SubtrActorResult<Self>
71    where
72        Self: Sized,
73    {
74        ReplayProcessor::new(replay)?.process(&mut self)?;
75        Ok(self)
76    }
77
78    /// Finalize replay-derived state after the last frame has been processed.
79    ///
80    /// Collectors that aggregate state across frame boundaries can override
81    /// this to flush any in-progress segment once replay traversal is complete.
82    fn finish_replay(&mut self, _processor: &ReplayProcessor) -> SubtrActorResult<()> {
83        Ok(())
84    }
85}
86
87impl<G> Collector for G
88where
89    G: FnMut(&ReplayProcessor, &boxcars::Frame, usize, f32) -> SubtrActorResult<TimeAdvance>,
90{
91    fn process_frame(
92        &mut self,
93        processor: &ReplayProcessor,
94        frame: &boxcars::Frame,
95        frame_number: usize,
96        current_time: f32,
97    ) -> SubtrActorResult<TimeAdvance> {
98        self(processor, frame, frame_number, current_time)
99    }
100}