Skip to content

Commit

Permalink
Merge pull request #61 from alepez/bevy-0.11
Browse files Browse the repository at this point in the history
Switch to bevy 0.11
  • Loading branch information
gschup authored Jul 13, 2023
2 parents 03cf19d + 363dc8f commit cbb5e50
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 33 deletions.
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.10", default-features = false, features = ["bevy_render", "bevy_asset","bevy_scene",]}
bevy = { version = "0.11", default-features = false, features = ["bevy_render", "bevy_asset","bevy_scene",]}
bytemuck = { version = "1.7", features=["derive"]}
instant = "0.1"
log = "0.4"
Expand All @@ -27,7 +27,7 @@ parking_lot = "0.12.1"
[dev-dependencies]
structopt = "0.3"
rand = "0.8.4"
bevy = "0.10"
bevy = "0.11"
serde = "1.0.130"
serde_json = "1.0"
serial_test = "1.0.0"
Expand Down
8 changes: 4 additions & 4 deletions examples/box_game/box_game_p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}),
..default()
}))
.add_startup_system(setup_system)
.add_systems(Startup, setup_system)
// these systems will be executed as part of the advance frame update
.add_systems((move_cube_system, increase_frame_system).in_schedule(GgrsSchedule))
.add_systems(GgrsSchedule, (move_cube_system, increase_frame_system))
// add your GGRS session
.insert_resource(Session::P2P(sess))
// register a resource that will be rolled back
Expand All @@ -92,8 +92,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2.0,
TimerMode::Repeating,
)))
.add_system(print_network_stats_system)
.add_system(print_events_system)
.add_systems(Update, print_network_stats_system)
.add_systems(Update, print_events_system)
.run();

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions examples/box_game/box_game_spectator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)
.insert_resource(opt)
.add_plugins(DefaultPlugins)
.add_startup_system(setup_system)
.add_systems(Startup, setup_system)
// these systems will be executed as part of the advance frame update
.add_systems((move_cube_system, increase_frame_system).in_schedule(GgrsSchedule))
.add_systems(GgrsSchedule, (move_cube_system, increase_frame_system))
// add your GGRS session
.insert_resource(Session::Spectator(sess))
// register a resource that will be rolled back
Expand All @@ -62,8 +62,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2.0,
TimerMode::Repeating,
)))
.add_system(print_network_stats_system)
.add_system(print_events_system)
.add_systems(Update, print_network_stats_system)
.add_systems(Update, print_events_system)
.run();

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/box_game/box_game_synctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)
.insert_resource(opt)
.add_plugins(DefaultPlugins)
.add_startup_system(setup_system)
.add_systems(Startup, setup_system)
// these systems will be executed as part of the advance frame update
.add_systems((move_cube_system, increase_frame_system).in_schedule(GgrsSchedule))
.add_systems(GgrsSchedule, (move_cube_system, increase_frame_system))
// add your GGRS session
.insert_resource(Session::SyncTest(sess))
// register a resource that will be rolled back
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use std::sync::Arc;

pub use ggrs;

pub use rollback::{AddRollbackCommandExtension, AddRollbackCommand, Rollback};
pub use rollback::{AddRollbackCommand, AddRollbackCommandExtension, Rollback};

pub(crate) mod ggrs_stage;
pub(crate) mod world_snapshot;
pub(crate) mod rollback;
pub(crate) mod world_snapshot;

pub mod prelude {
pub use crate::{
Expand Down Expand Up @@ -141,7 +141,7 @@ impl<T: Config + Send + Sync> GgrsPlugin<T> {
app.add_schedule(GgrsSchedule, schedule);

stage.set_type_registry(self.type_registry);
app.add_system(GgrsStage::<T>::run.in_base_set(CoreSet::PreUpdate));
app.add_systems(PreUpdate, GgrsStage::<T>::run);
app.insert_resource(stage);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Rollback {
pub struct AddRollbackCommand;

impl EntityCommand for AddRollbackCommand {
fn write(self, id: Entity, world: &mut World) {
fn apply(self, id: Entity, world: &mut World) {
world.entity_mut(id).insert(Rollback::new(id));
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/world_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ impl WorldSnapshot {
// find the corresponding current entity or create new entity, if it doesn't exist
let entity = *rid_map
.entry(rollback_entity.rollback_id)
.or_insert_with(|| {
world
.spawn(rollback_entity.rollback_id)
.id()
});
.or_insert_with(|| world.spawn(rollback_entity.rollback_id).id());

// Add the mapping from the old entity ID to the new entity ID
entity_map.insert(rollback_entity.entity, entity);
Expand Down Expand Up @@ -252,11 +248,7 @@ impl WorldSnapshot {
// new IDs after applying the snapshot.
for registration in type_registry.iter() {
if let Some(map_entities_reflect) = registration.data::<ReflectMapEntities>() {
map_entities_reflect
.map_entities(world, &entity_map)
// This may fail if an entity is not found in the entity map, but that's fine,
// because if it's not found in the map, then the entity may remain un-mapped.
.ok();
map_entities_reflect.map_all_entities(world, &mut entity_map)
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions tests/entity_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn frame_counter(mut counter: ResMut<FrameCounter>) {
counter.0 = counter.0.wrapping_add(1);
}

#[derive(Event)]
struct DeleteChildEntityEvent;

/// This test makes sure that we correctly map entities stored in resource and components during
Expand All @@ -68,10 +69,10 @@ fn entity_mapping() {
let mut app = App::new();

app.add_plugins(MinimalPlugins)
.add_plugin(TransformPlugin)
.add_plugins(TransformPlugin)
.add_event::<DeleteChildEntityEvent>()
.init_resource::<FrameCounter>()
.add_startup_system(setup_system)
.add_systems(Startup, setup_system)
// Insert the GGRS session
.insert_resource(Session::SyncTest(
SessionBuilder::<GgrsConfig>::new()
Expand All @@ -90,11 +91,7 @@ fn entity_mapping() {
.register_rollback_component::<ParentEntity>()
.register_rollback_resource::<FrameCounter>(),
)
.add_systems(
(frame_counter, delete_child_system)
.chain()
.in_schedule(GgrsSchedule),
);
.add_systems(GgrsSchedule, (frame_counter, delete_child_system).chain());

// Sleep helper that will make sure at least one frame should be executed by the GGRS fixed
// update loop.
Expand Down

0 comments on commit cbb5e50

Please sign in to comment.