Record unit decisions and show their replay moments (#153)

This commit is contained in:
2026-12-02 00:01:03 +03:00
parent b882dc3c2b
commit dfb306edd7
7 changed files with 513 additions and 16 deletions
+6 -2
View File
@@ -168,6 +168,7 @@ impl Recording {
index: HashMap::new(),
events: Vec::new(),
scene: None,
decisions: decision::History::default(),
tally: Tally::default(),
sams: Vec::new(),
objects: Vec::new(),
@@ -584,6 +585,7 @@ pub struct Recording {
pub events: Vec<Event>,
/// None is the legacy event/track-only format.
pub scene: Option<SceneJournal>,
pub decisions: decision::History,
/// The failures counted during the raid.
pub tally: Tally,
/// The systems and objects as they stood: (id, kind, where).
@@ -834,6 +836,7 @@ impl Recording {
index: HashMap::new(),
events: Vec::new(),
scene: Some(SceneJournal::default()),
decisions: decision::History::default(),
tally: Tally::default(),
sams: sim.sams.iter().map(|s| (s.id, s.kind, s.pos)).collect(),
objects: sim.targets.clone(),
@@ -859,6 +862,7 @@ impl Recording {
/// `Sim` calls this once the raid is over; its own events are always appended in time order
/// (ties in the order they happened), so the index is only built for a journal altered later.
pub fn close(&mut self) {
self.decisions.close();
self.closed = true;
if self.events.windows(2).all(|w| w[0].at <= w[1].at) {
self.time_order = None;
@@ -976,7 +980,7 @@ impl Recording {
let tracks = vec_bytes(&self.tracks)
+ self.tracks.iter().map(|t| vec_bytes(&t.points)).sum::<usize>()
+ map_bytes(self.index.len(), std::mem::size_of::<u32>() + std::mem::size_of::<usize>());
let mut journal = vec_bytes(&self.events);
let mut journal = vec_bytes(&self.events) + self.decisions.bytes();
if let Some(scene) = &self.scene {
journal += vec_bytes(&scene.events)
+ map_bytes(scene.tracks.len(), std::mem::size_of::<(u32, u32)>() + std::mem::size_of::<(bool, bool, DVec3)>())
@@ -1517,7 +1521,7 @@ impl Sim {
}
done.len = done.len.saturating_sub(done.quiet.saturating_sub(40));
done.close();
if !done.events.is_empty() || done.scene.as_ref().is_some_and(|s| !s.events.is_empty()) {
if !done.events.is_empty() || done.scene.as_ref().is_some_and(|s| !s.events.is_empty()) || done.decisions.entries().next().is_some() {
self.replays.push(done);
if self.replays.len() > KEPT {
self.replays.remove(0);