diff --git a/Cargo.toml b/Cargo.toml index 5760e42..513d02f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"]} @@ -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" diff --git a/examples/box_game/box_game_p2p.rs b/examples/box_game/box_game_p2p.rs index 6898a69..e39efee 100644 --- a/examples/box_game/box_game_p2p.rs +++ b/examples/box_game/box_game_p2p.rs @@ -73,7 +73,7 @@ fn main() -> Result<(), Box> { .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() }), diff --git a/examples/stress_tests/particles.rs b/examples/stress_tests/particles.rs index 2f90c20..14a1cbe 100644 --- a/examples/stress_tests/particles.rs +++ b/examples/stress_tests/particles.rs @@ -219,7 +219,7 @@ fn main() -> Result<(), Box> { }) .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() }), diff --git a/src/lib.rs b/src/lib.rs index 6165d8e..e50634b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ use bevy::{ ecs::schedule::{ExecutorKind, LogLevel, ScheduleBuildSettings, ScheduleLabel}, - input::InputSystem, + input::InputSystems, platform::collections::HashMap, prelude::*, }; @@ -175,11 +175,11 @@ impl Plugin for GgrsPlugin { .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::.after(InputSystem), + schedule_systems::run_ggrs_schedules::.after(InputSystems), ) .add_plugins((ChecksumPlugin, EntityChecksumPlugin, GgrsTimePlugin)); } diff --git a/src/snapshot/checksum.rs b/src/snapshot/checksum.rs index a18ab0b..e9a6ee6 100644 --- a/src/snapshot/checksum.rs +++ b/src/snapshot/checksum.rs @@ -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)] @@ -94,8 +94,8 @@ impl Plugin for ChecksumPlugin { app.init_resource::().add_systems( SaveWorld, Self::update - .after(SaveWorldSet::Checksum) - .before(SaveWorldSet::Snapshot), + .after(SaveWorldSystems::Checksum) + .before(SaveWorldSystems::Snapshot), ); } } diff --git a/src/snapshot/childof_snapshot.rs b/src/snapshot/childof_snapshot.rs index 82f7187..9ad61ce 100644 --- a/src/snapshot/childof_snapshot.rs +++ b/src/snapshot/childof_snapshot.rs @@ -1,5 +1,6 @@ use crate::{ - GgrsComponentSnapshots, LoadWorld, LoadWorldSet, RollbackFrameCount, SaveWorld, SaveWorldSet, + GgrsComponentSnapshots, LoadWorld, LoadWorldSystems, RollbackFrameCount, SaveWorld, + SaveWorldSystems, }; use bevy::{ecs::hierarchy::ChildOf, prelude::*}; @@ -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)); } } diff --git a/src/snapshot/component_checksum.rs b/src/snapshot/component_checksum.rs index 1f1dc64..5329208 100644 --- a/src/snapshot/component_checksum.rs +++ b/src/snapshot/component_checksum.rs @@ -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 @@ -99,6 +100,6 @@ where } }; - app.add_systems(SaveWorld, update.in_set(SaveWorldSet::Checksum)); + app.add_systems(SaveWorld, update.in_set(SaveWorldSystems::Checksum)); } } diff --git a/src/snapshot/component_map.rs b/src/snapshot/component_map.rs index 4beaf19..f730971 100644 --- a/src/snapshot/component_map.rs +++ b/src/snapshot/component_map.rs @@ -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`]. /// @@ -86,7 +86,7 @@ where C: Component + 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)); } } diff --git a/src/snapshot/component_snapshot.rs b/src/snapshot/component_snapshot.rs index 72593c0..bfaed6a 100644 --- a/src/snapshot/component_snapshot.rs +++ b/src/snapshot/component_snapshot.rs @@ -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}, @@ -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)); } } @@ -187,9 +187,9 @@ where ComponentSnapshotPlugin::::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)); } } diff --git a/src/snapshot/entity.rs b/src/snapshot/entity.rs index 2a9eca4..7592a7c 100644 --- a/src/snapshot/entity.rs +++ b/src/snapshot/entity.rs @@ -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::*}; @@ -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)); } } diff --git a/src/snapshot/entity_checksum.rs b/src/snapshot/entity_checksum.rs index 35d4ef4..c9f8a17 100644 --- a/src/snapshot/entity_checksum.rs +++ b/src/snapshot/entity_checksum.rs @@ -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; @@ -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)); } } diff --git a/src/snapshot/mod.rs b/src/snapshot/mod.rs index 0415db3..98593ca 100644 --- a/src/snapshot/mod.rs +++ b/src/snapshot/mod.rs @@ -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. diff --git a/src/snapshot/resource_checksum.rs b/src/snapshot/resource_checksum.rs index b4ad85f..0852344 100644 --- a/src/snapshot/resource_checksum.rs +++ b/src/snapshot/resource_checksum.rs @@ -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`). @@ -74,6 +74,6 @@ where commands.spawn((result, ChecksumFlag::::default())); } }; - app.add_systems(SaveWorld, update.in_set(SaveWorldSet::Checksum)); + app.add_systems(SaveWorld, update.in_set(SaveWorldSystems::Checksum)); } } diff --git a/src/snapshot/resource_map.rs b/src/snapshot/resource_map.rs index c917506..3e0aec2 100644 --- a/src/snapshot/resource_map.rs +++ b/src/snapshot/resource_map.rs @@ -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`]. /// @@ -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)); } } diff --git a/src/snapshot/resource_snapshot.rs b/src/snapshot/resource_snapshot.rs index 88af9b6..9b18f5c 100644 --- a/src/snapshot/resource_snapshot.rs +++ b/src/snapshot/resource_snapshot.rs @@ -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; @@ -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)); } } diff --git a/src/snapshot/set.rs b/src/snapshot/set.rs index ae64a73..e9974a9 100644 --- a/src/snapshot/set.rs +++ b/src/snapshot/set.rs @@ -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 @@ -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 @@ -47,7 +47,7 @@ pub enum SaveWorldSet { } #[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone)] -pub enum AdvanceWorldSet { +pub enum AdvanceWorldSystems { First, Main, Last, @@ -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), ); } } diff --git a/src/time.rs b/src/time.rs index 8373f66..73ec28e 100644 --- a/src/time.rs +++ b/src/time.rs @@ -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, }; @@ -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), ); } } diff --git a/tests/hierarchy.rs b/tests/hierarchy.rs index 49762ab..3bc7927 100644 --- a/tests/hierarchy.rs +++ b/tests/hierarchy.rs @@ -19,7 +19,10 @@ struct ParentEntity; #[derive(Reflect, Resource, Default, Debug)] struct FrameCounter(u16); -fn input_system(mut commands: Commands, mut delete_events: EventReader) { +fn input_system( + mut commands: Commands, + mut delete_events: MessageReader, +) { let should_delete = u8::from(delete_events.read().count() > 0); let mut local_inputs = HashMap::new(); @@ -63,8 +66,8 @@ fn frame_counter(mut counter: ResMut) { counter.0 = counter.0.wrapping_add(1); } -#[derive(Event)] -struct DeleteChildEntityEvent; +#[derive(Message)] +struct DeleteChildEntityMessage; /// This test makes sure that the hiearchy of entities is correctly restored when rolling back. #[test] @@ -73,7 +76,7 @@ fn hierarchy() { app.add_plugins(MinimalPlugins) .add_plugins(TransformPlugin) - .add_event::() + .add_message::() .init_resource::() .add_systems(Startup, setup_system) // Insert the GGRS session @@ -120,10 +123,10 @@ fn hierarchy() { sleep(); app.update(); - // Send the event to delete the child entity + // Send the message to delete the child entity app.world_mut() - .resource_mut::>() - .send(DeleteChildEntityEvent); + .resource_mut::>() + .write(DeleteChildEntityMessage); // Run for a number of times to make sure we get some rollbacks to happen for _ in 0..5 { diff --git a/tests/integration.rs b/tests/integration.rs index 7762c38..318d24b 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -162,7 +162,7 @@ pub fn increase_frame_system(mut frame_count: ResMut) { } fn press_key(app: &mut App, key: KeyCode) { - app.world_mut().send_event(KeyboardInput { + app.world_mut().write_message(KeyboardInput { logical_key: Key::Character("w".into()), key_code: key, state: ButtonState::Pressed,