From 2a2c0e48290c1f71a08a34d48173fd8d7bccff0f Mon Sep 17 00:00:00 2001 From: RJ Date: Thu, 19 Oct 2023 22:18:32 +0100 Subject: [PATCH] fix oldest frame calculation --- src/frame_buffer.rs | 31 +++++++++++++++++++++++++++- src/systems/prefix_in_rollback.rs | 8 ------- src/systems/prefix_start_rollback.rs | 9 +++++--- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/frame_buffer.rs b/src/frame_buffer.rs index 2a15f9d..158dc2e 100644 --- a/src/frame_buffer.rs +++ b/src/frame_buffer.rs @@ -69,7 +69,7 @@ where /// Theoretically.. value could be None if not inserted yet. pub fn oldest_frame(&self) -> FrameNumber { self.front_frame - .saturating_sub(self.capacity as FrameNumber + 1) + .saturating_sub(self.entries.len().saturating_sub(1) as FrameNumber) } /// removes entries for frames larger than `frame` @@ -210,6 +210,35 @@ where mod tests { use super::*; + #[test] + fn test_oldest_frame() { + let mut fb = FrameBuffer::::with_capacity(5, ""); + assert_eq!(fb.oldest_frame(), 0); + fb.insert(1, 1).unwrap(); + assert_eq!(fb.get(1), Some(&1)); + assert_eq!(fb.oldest_frame(), 1); + + fb.insert(2, 2).unwrap(); + assert_eq!(fb.get(2), Some(&2)); + assert_eq!(fb.oldest_frame(), 1); + + fb.insert(3, 3).unwrap(); + assert_eq!(fb.get(3), Some(&3)); + assert_eq!(fb.oldest_frame(), 1); + + fb.insert(4, 4).unwrap(); + assert_eq!(fb.get(4), Some(&4)); + assert_eq!(fb.oldest_frame(), 1); + + fb.insert(5, 5).unwrap(); + assert_eq!(fb.get(5), Some(&5)); + assert_eq!(fb.oldest_frame(), 1); + + fb.insert(6, 6).unwrap(); + assert_eq!(fb.get(6), Some(&6)); + assert_eq!(fb.oldest_frame(), 2); + } + #[test] fn test_frame_buffer() { let mut fb = FrameBuffer::::with_capacity(5, ""); diff --git a/src/systems/prefix_in_rollback.rs b/src/systems/prefix_in_rollback.rs index 7234485..d9d25cd 100644 --- a/src/systems/prefix_in_rollback.rs +++ b/src/systems/prefix_in_rollback.rs @@ -40,10 +40,6 @@ pub(crate) fn rebirth_components_during_rollback( for (entity, comp_history) in q.iter() { let target_frame = game_clock.frame(); if comp_history.alive_at_frame(target_frame) { - info!( - "CHecking if {entity:?} {} alive at {game_clock:?} - YES ", - comp_history.type_name() - ); // we could go fishing in SS for this, but it should be here if its alive. // i think i'm only hitting this with rollback underflows though, during load? // need more investigation and to figure out a test case.. @@ -67,10 +63,6 @@ pub(crate) fn rebirth_components_during_rollback( ); commands.entity(entity).insert(comp_val.clone()); } else { - info!( - "CHecking if {entity:?} {} alive at {game_clock:?} - NO ", - comp_history.type_name() - ); trace!( "comp not alive at {game_clock:?} for {entity:?} {:?} {}", comp_history.alive_ranges, diff --git a/src/systems/prefix_start_rollback.rs b/src/systems/prefix_start_rollback.rs index 1bd6109..cad30e3 100644 --- a/src/systems/prefix_start_rollback.rs +++ b/src/systems/prefix_start_rollback.rs @@ -150,12 +150,15 @@ pub(crate) fn rollback_component( let oldest_frame = comp_hist.values.oldest_frame(); error!( - "HMMMM f @ oldest_frame ({oldest_frame}) comp_val = {:?}", + "HMMMM {entity:?} f @ oldest_frame ({oldest_frame}) comp_val = {:?}", comp_hist.at_frame(oldest_frame) ); - error!("HMMMM {game_clock:?} OPT_COMP = {opt_comp:?}"); + error!("HMMMM {entity:?} {game_clock:?} OPT_COMP = {opt_comp:?}"); for f in (rollback_frame - 2)..=(rollback_frame + 2) { - error!("HMMMM f={f} comp_val = {:?}", comp_hist.at_frame(f)); + error!( + "HMMMM {entity:?} f={f} comp_val = {:?}", + comp_hist.at_frame(f) + ); } panic!("{prefix} {game_clock:?} {entity:?} {provenance:?} {} rollback_frame: {rollback_frame} alive_ranges:{:?} rb:{rb:?} oldest value in comp_hist: {oldest_frame} occ:{:?}\n",