Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Commit

Permalink
fix oldest frame calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
RJ committed Oct 19, 2023
1 parent 9dcb8f4 commit fd326db
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
31 changes: 30 additions & 1 deletion src/frame_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -210,6 +210,35 @@ where
mod tests {
use super::*;

#[test]
fn test_oldest_frame() {
let mut fb = FrameBuffer::<u32>::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::<u32>::with_capacity(5, "");
Expand Down
9 changes: 6 additions & 3 deletions src/systems/prefix_start_rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,15 @@ pub(crate) fn rollback_component<T: TimewarpComponent>(
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",
Expand Down

0 comments on commit fd326db

Please sign in to comment.