sim_lib_view_agent/replay.rs
1//! Replay: reconstruct a past run visually from a recorded event stream.
2//!
3//! Because the monitor Scene is a pure function of the topology and the run
4//! state, replaying a recorded event stream reproduces the exact sequence of
5//! Scenes the operator saw live. Each frame is a Scene value, so a replay is
6//! itself data -- snapshottable, diffable, and testable headlessly.
7
8use sim_kernel::Expr;
9use sim_lib_topology::Graph;
10
11use crate::monitor::monitor_view;
12use crate::run::{RunEvent, RunState};
13
14/// Replay a recorded event stream over `graph`, returning one monitor Scene per
15/// step (including the initial empty frame). The final frame is the end state.
16pub fn replay(graph: &Graph, events: &[RunEvent]) -> Vec<Expr> {
17 let mut run = RunState::new();
18 let mut frames = Vec::with_capacity(events.len() + 1);
19 frames.push(monitor_view(graph, &run));
20 for event in events {
21 run.apply_event(event.clone());
22 frames.push(monitor_view(graph, &run));
23 }
24 frames
25}
26
27/// Reconstruct just the final run state from a recorded event stream.
28pub fn replay_final(events: &[RunEvent]) -> RunState {
29 let mut run = RunState::new();
30 for event in events {
31 run.apply_event(event.clone());
32 }
33 run
34}