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