Skip to content

Commit

Permalink
Merge branch 'main' of github.com:gschup/ggrs
Browse files Browse the repository at this point in the history
  • Loading branch information
gschup committed Feb 27, 2024
2 parents 2fe55aa + 2303ee7 commit f0c14dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ If you are interested in integrating rollback networking into your game or just

GGRS has two demo apps you can try in the browser! One written with [macroquad](https://github.com/not-fl3/macroquad), the other written with [bevy](https://bevyengine.org/). Both use [matchbox](https://github.com/johanhelsing/matchbox). Try it out with a friend! Just click the link and match with another player! (You can also open the link in two separate windows to play against yourself)

🚧 MATCHMAKING CURRENTLY OFFLINE! 🚧
- [Bevy Demo](https://gschup.github.io/bevy_ggrs_demo/) ([Repository](https://github.com/gschup/bevy_ggrs_demo))
- [Macroquad Demo](https://gschup.github.io/ggrs_demo/) ([Repository](https://github.com/gschup/ggrs_demo))

Expand Down
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 f0c14dc

Please sign in to comment.