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