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 2a2c0e4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 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
8 changes: 0 additions & 8 deletions src/systems/prefix_in_rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ pub(crate) fn rebirth_components_during_rollback<T: TimewarpComponent>(
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..
Expand All @@ -67,10 +63,6 @@ pub(crate) fn rebirth_components_during_rollback<T: TimewarpComponent>(
);
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,
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 2a2c0e4

Please sign in to comment.