Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ categories = ["network-programming", "game-development"]
wasm-bindgen = ["instant/wasm-bindgen", "ggrs/wasm-bindgen"]

[dependencies]
bevy = { version = "0.16", default-features = false, features = ["bevy_log"] }
bevy = { version = "0.17", default-features = false, features = ["bevy_log"] }
instant = { version = "0.1", optional = true }
log = "0.4"
#ggrs = { version= "0.11.1", features=["sync-send"]}
Expand All @@ -26,7 +26,7 @@ disqualified = "1.0.0"
serde = { version = "1", default-features = false }

[dev-dependencies]
bevy = { version = "0.16", default-features = true }
bevy = { version = "0.17", default-features = true }
clap = { version = "4.4", features = ["derive"] }
rand = "0.9"
rand_xoshiro = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion examples/box_game/box_game_p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.insert_resource(opt)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(720., 720.),
resolution: WindowResolution::new(720, 720),
title: "GGRS Box Game".to_owned(),
..default()
}),
Expand Down
2 changes: 1 addition & 1 deletion examples/stress_tests/particles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
})
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(720., 720.),
resolution: WindowResolution::new(720, 720),
title: "GGRS particles stress test".to_owned(),
..default()
}),
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use bevy::{
ecs::schedule::{ExecutorKind, LogLevel, ScheduleBuildSettings, ScheduleLabel},
input::InputSystem,
input::InputSystems,
platform::collections::HashMap,
prelude::*,
};
Expand Down Expand Up @@ -175,11 +175,11 @@ impl<C: Config> Plugin for GgrsPlugin<C> {
.add_systems(
AdvanceWorld,
(|world: &mut World| world.run_schedule(GgrsSchedule))
.in_set(AdvanceWorldSet::Main),
.in_set(AdvanceWorldSystems::Main),
)
.add_systems(
PreUpdate,
schedule_systems::run_ggrs_schedules::<C>.after(InputSystem),
schedule_systems::run_ggrs_schedules::<C>.after(InputSystems),
)
.add_plugins((ChecksumPlugin, EntityChecksumPlugin, GgrsTimePlugin));
}
Expand Down
6 changes: 3 additions & 3 deletions src/snapshot/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use bevy::prelude::*;

use crate::{SaveWorld, SaveWorldSet, checksum_hasher};
use crate::{SaveWorld, SaveWorldSystems, checksum_hasher};

/// Flags an entity as containing a checksum for a type `T`
#[derive(Component)]
Expand Down Expand Up @@ -94,8 +94,8 @@ impl Plugin for ChecksumPlugin {
app.init_resource::<Checksum>().add_systems(
SaveWorld,
Self::update
.after(SaveWorldSet::Checksum)
.before(SaveWorldSet::Snapshot),
.after(SaveWorldSystems::Checksum)
.before(SaveWorldSystems::Snapshot),
);
}
}
7 changes: 4 additions & 3 deletions src/snapshot/childof_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
GgrsComponentSnapshots, LoadWorld, LoadWorldSet, RollbackFrameCount, SaveWorld, SaveWorldSet,
GgrsComponentSnapshots, LoadWorld, LoadWorldSystems, RollbackFrameCount, SaveWorld,
SaveWorldSystems,
};
use bevy::{ecs::hierarchy::ChildOf, prelude::*};

Expand All @@ -22,9 +23,9 @@ impl Plugin for ChildOfSnapshotPlugin {
Self::save,
)
.chain()
.in_set(SaveWorldSet::Snapshot),
.in_set(SaveWorldSystems::Snapshot),
)
.add_systems(LoadWorld, Self::load.in_set(LoadWorldSet::Data));
.add_systems(LoadWorld, Self::load.in_set(LoadWorldSystems::Data));
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/snapshot/component_checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::hash::{Hash, Hasher};
use bevy::prelude::*;

use crate::{
ChecksumFlag, ChecksumPart, Rollback, RollbackOrdered, SaveWorld, SaveWorldSet, checksum_hasher,
ChecksumFlag, ChecksumPart, Rollback, RollbackOrdered, SaveWorld, SaveWorldSystems,
checksum_hasher,
};

/// A [`Plugin`] which will track the [`Component`] `C` on [`Rollback Entities`](`Rollback`) and ensure a
Expand Down Expand Up @@ -99,6 +100,6 @@ where
}
};

app.add_systems(SaveWorld, update.in_set(SaveWorldSet::Checksum));
app.add_systems(SaveWorld, update.in_set(SaveWorldSystems::Checksum));
}
}
4 changes: 2 additions & 2 deletions src/snapshot/component_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy::{
prelude::*,
};

use crate::{LoadWorld, LoadWorldSet, RollbackEntityMap};
use crate::{LoadWorld, LoadWorldSystems, RollbackEntityMap};

/// A [`Plugin`] which updates the state of a post-rollback [`Component`] `C` using [`MapEntities`].
///
Expand Down Expand Up @@ -86,7 +86,7 @@ where
C: Component<Mutability = Mutable> + MapEntities,
{
fn build(&self, app: &mut App) {
app.add_systems(LoadWorld, Self::update.in_set(LoadWorldSet::Mapping));
app.add_systems(LoadWorld, Self::update.in_set(LoadWorldSystems::Mapping));
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/snapshot/component_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
GgrsComponentSnapshot, GgrsComponentSnapshots, LoadWorld, LoadWorldSet, Rollback,
RollbackFrameCount, SaveWorld, SaveWorldSet, Strategy,
GgrsComponentSnapshot, GgrsComponentSnapshots, LoadWorld, LoadWorldSystems, Rollback,
RollbackFrameCount, SaveWorld, SaveWorldSystems, Strategy,
};
use bevy::{
ecs::component::{Immutable, Mutable},
Expand Down Expand Up @@ -128,9 +128,9 @@ where
Self::save,
)
.chain()
.in_set(SaveWorldSet::Snapshot),
.in_set(SaveWorldSystems::Snapshot),
);
app.add_systems(LoadWorld, Self::load.in_set(LoadWorldSet::Data));
app.add_systems(LoadWorld, Self::load.in_set(LoadWorldSystems::Data));
}
}

Expand Down Expand Up @@ -187,9 +187,9 @@ where
ComponentSnapshotPlugin::<S>::save,
)
.chain()
.in_set(SaveWorldSet::Snapshot),
.in_set(SaveWorldSystems::Snapshot),
)
.add_systems(LoadWorld, Self::load.in_set(LoadWorldSet::Data));
.add_systems(LoadWorld, Self::load.in_set(LoadWorldSystems::Data));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/snapshot/entity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
GgrsComponentSnapshot, GgrsComponentSnapshots, LoadWorld, LoadWorldSet, Rollback,
RollbackEntityMap, RollbackFrameCount, SaveWorld, SaveWorldSet,
GgrsComponentSnapshot, GgrsComponentSnapshots, LoadWorld, LoadWorldSystems, Rollback,
RollbackEntityMap, RollbackFrameCount, SaveWorld, SaveWorldSystems,
};
use bevy::{platform::collections::HashMap, prelude::*};

Expand Down Expand Up @@ -97,8 +97,8 @@ impl Plugin for EntitySnapshotPlugin {
Self::save,
)
.chain()
.in_set(SaveWorldSet::Snapshot),
.in_set(SaveWorldSystems::Snapshot),
)
.add_systems(LoadWorld, Self::load.in_set(LoadWorldSet::Entity));
.add_systems(LoadWorld, Self::load.in_set(LoadWorldSystems::Entity));
}
}
5 changes: 3 additions & 2 deletions src/snapshot/entity_checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::hash::{Hash, Hasher};
use bevy::prelude::*;

use crate::{
ChecksumFlag, ChecksumPart, Rollback, RollbackOrdered, SaveWorld, SaveWorldSet, checksum_hasher,
ChecksumFlag, ChecksumPart, Rollback, RollbackOrdered, SaveWorld, SaveWorldSystems,
checksum_hasher,
};

pub struct EntityChecksumPlugin;
Expand Down Expand Up @@ -38,6 +39,6 @@ impl EntityChecksumPlugin {

impl Plugin for EntityChecksumPlugin {
fn build(&self, app: &mut App) {
app.add_systems(SaveWorld, Self::update.in_set(SaveWorldSet::Checksum));
app.add_systems(SaveWorld, Self::update.in_set(SaveWorldSystems::Checksum));
}
}
2 changes: 1 addition & 1 deletion src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub use set::*;
pub use strategy::*;

pub mod prelude {
pub use super::{Checksum, LoadWorldSet, SaveWorldSet};
pub use super::{Checksum, LoadWorldSystems, SaveWorldSystems};
}

/// Label for the schedule which loads and overwrites a snapshot of the world.
Expand Down
4 changes: 2 additions & 2 deletions src/snapshot/resource_checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::hash::{Hash, Hasher};

use bevy::prelude::*;

use crate::{ChecksumFlag, ChecksumPart, Rollback, SaveWorld, SaveWorldSet, checksum_hasher};
use crate::{ChecksumFlag, ChecksumPart, Rollback, SaveWorld, SaveWorldSystems, checksum_hasher};

/// Plugin which will track the [`Resource`] `R` and ensure a [`ChecksumPart`] is
/// available and updated. This can be used to generate a [`Checksum`](`crate::Checksum`).
Expand Down Expand Up @@ -74,6 +74,6 @@ where
commands.spawn((result, ChecksumFlag::<R>::default()));
}
};
app.add_systems(SaveWorld, update.in_set(SaveWorldSet::Checksum));
app.add_systems(SaveWorld, update.in_set(SaveWorldSystems::Checksum));
}
}
4 changes: 2 additions & 2 deletions src/snapshot/resource_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::marker::PhantomData;

use bevy::{ecs::entity::MapEntities, prelude::*};

use crate::{LoadWorld, LoadWorldSet, RollbackEntityMap};
use crate::{LoadWorld, LoadWorldSystems, RollbackEntityMap};

/// A [`Plugin`] which updates the state of a post-rollback [`Resource`] `R` using [`MapEntities`].
///
Expand Down Expand Up @@ -81,6 +81,6 @@ where
R: Resource + MapEntities,
{
fn build(&self, app: &mut App) {
app.add_systems(LoadWorld, Self::update.in_set(LoadWorldSet::Mapping));
app.add_systems(LoadWorld, Self::update.in_set(LoadWorldSystems::Mapping));
}
}
8 changes: 4 additions & 4 deletions src/snapshot/resource_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
GgrsResourceSnapshots, LoadWorld, LoadWorldSet, RollbackFrameCount, SaveWorld, SaveWorldSet,
Strategy,
GgrsResourceSnapshots, LoadWorld, LoadWorldSystems, RollbackFrameCount, SaveWorld,
SaveWorldSystems, Strategy,
};
use bevy::prelude::*;
use std::marker::PhantomData;
Expand Down Expand Up @@ -99,8 +99,8 @@ where
Self::save,
)
.chain()
.in_set(SaveWorldSet::Snapshot),
.in_set(SaveWorldSystems::Snapshot),
)
.add_systems(LoadWorld, Self::load.in_set(LoadWorldSet::Data));
.add_systems(LoadWorld, Self::load.in_set(LoadWorldSystems::Data));
}
}
39 changes: 21 additions & 18 deletions src/snapshot/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::snapshot::{AdvanceWorld, LoadWorld, SaveWorld};
/// The most common option is [`LoadWorldSet::Data`], which is where [`Component`]
/// and [`Resource`] snapshots are loaded and applied to the [`World`].
#[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone)]
pub enum LoadWorldSet {
pub enum LoadWorldSystems {
/// Recreate the [`Entity`] graph as it was during the frame to be rolled back to.
/// When this set is complete, all entities that were alive during the snapshot
/// frame have been recreated, and any that were not have been removed. If the
Expand All @@ -32,7 +32,7 @@ pub enum LoadWorldSet {
}

#[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone)]
pub enum SaveWorldSet {
pub enum SaveWorldSystems {
/// Generate checksums for any tracked data.
///
/// Within this set, it is expected that all data which will participate in the
Expand All @@ -47,7 +47,7 @@ pub enum SaveWorldSet {
}

#[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone)]
pub enum AdvanceWorldSet {
pub enum AdvanceWorldSystems {
First,
Main,
Last,
Expand All @@ -62,40 +62,43 @@ impl Plugin for SnapshotSetPlugin {
app.configure_sets(
LoadWorld,
(
LoadWorldSet::Entity,
LoadWorldSet::EntityFlush,
LoadWorldSet::Data,
LoadWorldSet::DataFlush,
LoadWorldSet::Mapping,
LoadWorldSystems::Entity,
LoadWorldSystems::EntityFlush,
LoadWorldSystems::Data,
LoadWorldSystems::DataFlush,
LoadWorldSystems::Mapping,
)
.chain(),
)
.configure_sets(
SaveWorld,
(SaveWorldSet::Checksum, SaveWorldSet::Snapshot).chain(),
(SaveWorldSystems::Checksum, SaveWorldSystems::Snapshot).chain(),
)
.configure_sets(
AdvanceWorld,
(
AdvanceWorldSet::First,
AdvanceWorldSet::Main,
AdvanceWorldSet::Last,
AdvanceWorldSystems::First,
AdvanceWorldSystems::Main,
AdvanceWorldSystems::Last,
)
.chain(),
)
.add_systems(LoadWorld, ApplyDeferred.in_set(LoadWorldSet::EntityFlush))
.add_systems(LoadWorld, ApplyDeferred.in_set(LoadWorldSet::DataFlush))
.add_systems(
LoadWorld,
ApplyDeferred.in_set(LoadWorldSystems::EntityFlush),
)
.add_systems(LoadWorld, ApplyDeferred.in_set(LoadWorldSystems::DataFlush))
.add_systems(
AdvanceWorld,
ApplyDeferred
.after(AdvanceWorldSet::First)
.before(AdvanceWorldSet::Main),
.after(AdvanceWorldSystems::First)
.before(AdvanceWorldSystems::Main),
)
.add_systems(
AdvanceWorld,
ApplyDeferred
.after(AdvanceWorldSet::Main)
.before(AdvanceWorldSet::Last),
.after(AdvanceWorldSystems::Main)
.before(AdvanceWorldSystems::Last),
);
}
}
6 changes: 3 additions & 3 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use bevy::prelude::*;

use crate::{
AdvanceWorld, AdvanceWorldSet, CloneStrategy, DEFAULT_FPS, ResourceSnapshotPlugin,
AdvanceWorld, AdvanceWorldSystems, CloneStrategy, DEFAULT_FPS, ResourceSnapshotPlugin,
RollbackFrameCount,
};

Expand Down Expand Up @@ -92,11 +92,11 @@ impl Plugin for GgrsTimePlugin {
AdvanceWorld,
(Self::update, Self::replace_default_with_ggrs)
.chain()
.in_set(AdvanceWorldSet::First),
.in_set(AdvanceWorldSystems::First),
)
.add_systems(
AdvanceWorld,
Self::replace_default_with_virtual.in_set(AdvanceWorldSet::Last),
Self::replace_default_with_virtual.in_set(AdvanceWorldSystems::Last),
);
}
}
Loading