Skip to content

Commit

Permalink
Merge pull request #66 from johanhelsing/chronological-synctest
Browse files Browse the repository at this point in the history
Report which frames checksums failed for in synctest sessions
  • Loading branch information
gschup committed Dec 8, 2023
2 parents 106ae98 + 79db831 commit 2303ee7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
13 changes: 9 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pub enum GgrsError {
/// [`SyncTestSession`]: crate::SyncTestSession
MismatchedChecksum {
/// The frame at which the mismatch occurred.
frame: Frame,
current_frame: Frame,
/// The frames with mismatched checksums (one or more)
mismatched_frames: Vec<Frame>,
},
/// The Session is not synchronized yet. Please start the session and wait a few ms to let the clients synchronize.
NotSynchronized,
Expand All @@ -47,11 +49,14 @@ impl Display for GgrsError {
"The session is not yet synchronized with all remote sessions."
)
}
GgrsError::MismatchedChecksum { frame } => {
GgrsError::MismatchedChecksum {
current_frame,
mismatched_frames,
} => {
write!(
f,
"Detected checksum mismatch during rollback on frame {}.",
frame
"Detected checksum mismatch during rollback on frame {}, mismatched frames: {:?}",
current_frame, mismatched_frames
)
}
GgrsError::SpectatorTooFarBehind => {
Expand Down
20 changes: 12 additions & 8 deletions src/sessions/sync_test_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,19 @@ impl<T: Config> SyncTestSession<T> {
let mut requests = Vec::new();

// if we advanced far enough into the game do comparisons and rollbacks
if self.check_distance > 0 && self.sync_layer.current_frame() > self.check_distance as i32 {
let current_frame = self.sync_layer.current_frame();
if self.check_distance > 0 && current_frame > self.check_distance as i32 {
// compare checksums of older frames to our checksum history (where only the first version of any checksum is recorded)
for i in 0..=self.check_distance as i32 {
let frame_to_check = self.sync_layer.current_frame() - i;
if !self.checksums_consistent(frame_to_check) {
return Err(GgrsError::MismatchedChecksum {
frame: frame_to_check,
});
}
let oldest_frame_to_check = current_frame - self.check_distance as Frame;
let mismatched_frames: Vec<_> = (oldest_frame_to_check..=current_frame)
.filter(|frame_to_check| !self.checksums_consistent(*frame_to_check))
.collect();

if !mismatched_frames.is_empty() {
return Err(GgrsError::MismatchedChecksum {
current_frame,
mismatched_frames,
});
}

// simulate rollbacks according to the check_distance
Expand Down

0 comments on commit 2303ee7

Please sign in to comment.