Skip to content

Commit 84ea563

Browse files
dgsantanaShaturUkoeHB
authored
Update to Bevy 0.13 (#198)
Co-authored-by: Hennadii Chernyshchyk <[email protected]> Co-authored-by: UkoeHB <[email protected]>
1 parent 56af700 commit 84ea563

28 files changed

+252
-282
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- Removed `Mapper` and `MapNetworkEntities` in favor of `EntityMapper` and `MapEntities` introduced in Bevy 0.13.0
11+
- Changed conditional systems to follow the new pattern, avoid returning a closure.
12+
1013
## [0.22.0] - 2024-02-17
1114

1215
### Changed

Cargo.toml

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ license = "MIT OR Apache-2.0"
1919
include = ["/benches", "/src", "/tests", "/LICENSE*"]
2020

2121
[dependencies]
22-
bevy_renet = "0.0.10"
23-
bevy = { version = "0.12.1", default-features = false, features = [
24-
"bevy_scene",
25-
] }
22+
bevy_renet = "0.0.11"
23+
bevy = { version = "0.13", default-features = false, features = ["bevy_scene"] }
2624
bincode = "1.3"
2725
serde = "1.0"
2826
varint-rs = "2.2"
@@ -36,7 +34,7 @@ spin_sleep = "1.1"
3634
anyhow = "1.0"
3735
clap = { version = "4.1", features = ["derive"] }
3836
ron = "0.8"
39-
bevy = { version = "0.12", default-features = false, features = [
37+
bevy = { version = "0.13", default-features = false, features = [
4038
"bevy_asset",
4139
"bevy_core_pipeline",
4240
"bevy_render",

deny.toml

+13-22
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,27 @@ allow-osi-fsf-free = "either"
1111
multiple-versions = "deny"
1212
wildcards = "allow"
1313
skip = [
14-
{ name = "async-channel", version = "1.9" },
15-
{ name = "async-lock", version = "2.8" },
1614
{ name = "bitflags", version = "2.0" },
1715
{ name = "event-listener", version = "<5.0" },
1816
{ name = "event-listener-strategy", version = "0.5" },
19-
{ name = "fastrand", version = "1.9" },
20-
{ name = "foreign-types", version = "0.3" },
21-
{ name = "foreign-types-shared", version = "0.1" },
22-
{ name = "futures-lite", version = "1.13" },
23-
{ name = "hashbrown", version = "0.12" },
24-
{ name = "indexmap", version = "1.0" },
25-
{ name = "libloading", version = "0.7" },
26-
{ name = "num_enum", version = "0.6" },
27-
{ name = "num_enum_derive", version = "0.5" },
17+
{ name = "objc-sys", version = "0.2.0-beta.2" },
18+
{ name = "objc2", version = "0.3.0-beta.3.patch-leaks.3" },
19+
{ name = "objc2-encode", version = "2.0.0-pre.2" },
2820
{ name = "redox_syscall", version = "0.3" },
2921
{ name = "regex-automata", version = "0.1" },
3022
{ name = "regex-syntax", version = "0.6" },
31-
{ name = "regex-syntax", version = "0.7" },
3223
{ name = "syn", version = "1.0" },
33-
{ name = "toml_edit", version = "0.19" },
3424
{ name = "tracing-log", version = "0.1" },
35-
{ name = "windows-sys", version = "0.45" },
36-
{ name = "windows-targets", version = "0.42" },
37-
{ name = "windows_aarch64_gnullvm", version = "0.42" },
38-
{ name = "windows_aarch64_msvc", version = "0.42" },
39-
{ name = "windows_i686_gnu", version = "0.42" },
40-
{ name = "windows_i686_msvc", version = "0.42" },
41-
{ name = "windows_x86_64_gnu", version = "0.42" },
42-
{ name = "windows_x86_64_gnullvm", version = "0.42" },
43-
{ name = "windows_x86_64_msvc", version = "0.42" },
25+
{ name = "windows" },
26+
{ name = "windows-sys" },
27+
{ name = "windows-targets" },
28+
{ name = "windows_aarch64_gnullvm" },
29+
{ name = "windows_aarch64_msvc" },
30+
{ name = "windows_i686_gnu" },
31+
{ name = "windows_i686_msvc" },
32+
{ name = "windows_x86_64_gnu" },
33+
{ name = "windows_x86_64_gnullvm" },
34+
{ name = "windows_x86_64_msvc" },
4435
]
4536

4637
[sources]

examples/simple_box.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl Plugin for SimpleBoxPlugin {
4343
.add_systems(
4444
Update,
4545
(
46-
Self::movement_system.run_if(has_authority()), // Runs only on the server or a single player.
47-
Self::server_event_system.run_if(resource_exists::<RenetServer>()), // Runs only on the server.
46+
Self::movement_system.run_if(has_authority), // Runs only on the server or a single player.
47+
Self::server_event_system.run_if(resource_exists::<RenetServer>), // Runs only on the server.
4848
(Self::draw_boxes_system, Self::input_system),
4949
),
5050
);
@@ -174,18 +174,18 @@ impl SimpleBoxPlugin {
174174
}
175175

176176
/// Reads player inputs and sends [`MoveCommandEvents`]
177-
fn input_system(mut move_events: EventWriter<MoveDirection>, input: Res<Input<KeyCode>>) {
177+
fn input_system(mut move_events: EventWriter<MoveDirection>, input: Res<ButtonInput<KeyCode>>) {
178178
let mut direction = Vec2::ZERO;
179-
if input.pressed(KeyCode::Right) {
179+
if input.pressed(KeyCode::ArrowRight) {
180180
direction.x += 1.0;
181181
}
182-
if input.pressed(KeyCode::Left) {
182+
if input.pressed(KeyCode::ArrowLeft) {
183183
direction.x -= 1.0;
184184
}
185-
if input.pressed(KeyCode::Up) {
185+
if input.pressed(KeyCode::ArrowUp) {
186186
direction.y += 1.0;
187187
}
188-
if input.pressed(KeyCode::Down) {
188+
if input.pressed(KeyCode::ArrowDown) {
189189
direction.y -= 1.0;
190190
}
191191
if direction != Vec2::ZERO {

examples/tic_tac_toe.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct TicTacToePlugin;
4545

4646
impl Plugin for TicTacToePlugin {
4747
fn build(&self, app: &mut App) {
48-
app.add_state::<GameState>()
48+
app.init_state::<GameState>()
4949
.init_resource::<SymbolFont>()
5050
.init_resource::<CurrentTurn>()
5151
.replicate::<Symbol>()
@@ -70,18 +70,18 @@ impl Plugin for TicTacToePlugin {
7070
.add_systems(
7171
Update,
7272
(
73-
Self::connecting_text_system.run_if(resource_added::<RenetClient>()),
74-
Self::server_waiting_text_system.run_if(resource_added::<RenetServer>()),
75-
Self::server_event_system.run_if(resource_exists::<RenetServer>()),
73+
Self::connecting_text_system.run_if(resource_added::<RenetClient>),
74+
Self::server_waiting_text_system.run_if(resource_added::<RenetServer>),
75+
Self::server_event_system.run_if(resource_exists::<RenetServer>),
7676
Self::start_game_system
77-
.run_if(client_connected())
78-
.run_if(any_component_added::<Player>()), // Wait until client replicates players before starting the game.
77+
.run_if(client_connected)
78+
.run_if(any_component_added::<Player>), // Wait until client replicates players before starting the game.
7979
(
80-
Self::cell_interatction_system.run_if(local_player_turn()),
81-
Self::picking_system.run_if(has_authority()),
80+
Self::cell_interatction_system.run_if(local_player_turn),
81+
Self::picking_system.run_if(has_authority),
8282
Self::symbol_init_system,
83-
Self::turn_advance_system.run_if(any_component_added::<CellIndex>()),
84-
Self::symbol_turn_text_system.run_if(resource_changed::<CurrentTurn>()),
83+
Self::turn_advance_system.run_if(any_component_added::<CellIndex>),
84+
Self::symbol_turn_text_system.run_if(resource_changed::<CurrentTurn>),
8585
)
8686
.run_if(in_state(GameState::InGame)),
8787
),
@@ -514,22 +514,22 @@ impl TicTacToePlugin {
514514

515515
/// Returns `true` if the local player can select cells.
516516
fn local_player_turn(
517-
) -> impl FnMut(Res<CurrentTurn>, Option<Res<NetcodeClientTransport>>, Query<(&Player, &Symbol)>) -> bool
518-
{
519-
|current_turn, client_transport, players| {
520-
let client_id = client_transport
521-
.map(|client| ClientId::from_raw(client.client_id()))
522-
.unwrap_or(SERVER_ID);
523-
524-
players
525-
.iter()
526-
.any(|(player, &symbol)| player.0 == client_id && symbol == current_turn.0)
527-
}
517+
current_turn: Res<CurrentTurn>,
518+
client_transport: Option<Res<NetcodeClientTransport>>,
519+
players: Query<(&Player, &Symbol)>,
520+
) -> bool {
521+
let client_id = client_transport
522+
.map(|client| client.client_id())
523+
.unwrap_or(SERVER_ID);
524+
525+
players
526+
.iter()
527+
.any(|(player, &symbol)| player.0 == client_id && symbol == current_turn.0)
528528
}
529529

530530
/// A condition for systems to check if any component of type `T` was added to the world.
531-
fn any_component_added<T: Component>() -> impl FnMut(Query<(), Added<T>>) -> bool {
532-
|components| !components.is_empty()
531+
fn any_component_added<T: Component>(components: Query<(), Added<T>>) -> bool {
532+
!components.is_empty()
533533
}
534534

535535
const PORT: u16 = 5000;

src/client.rs

+14-19
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ pub mod diagnostics;
33

44
use std::io::Cursor;
55

6-
use bevy::{prelude::*, utils::EntityHashMap};
6+
use bevy::{ecs::entity::EntityHashMap, prelude::*};
77
use bevy_renet::{
88
client_connected, client_just_connected, client_just_disconnected,
99
renet::{Bytes, RenetClient},
1010
transport::NetcodeClientPlugin,
11-
RenetClientPlugin,
11+
RenetClientPlugin, RenetReceive, RenetSend,
1212
};
1313
use bincode::{DefaultOptions, Options};
1414
use varint_rs::VarintReader;
@@ -32,30 +32,24 @@ impl Plugin for ClientPlugin {
3232
.configure_sets(
3333
PreUpdate,
3434
ClientSet::ResetEvents
35-
.after(NetcodeClientPlugin::update_system)
35+
.after(RenetReceive)
3636
.before(ClientSet::Receive)
37-
.run_if(client_just_connected()),
38-
)
39-
.configure_sets(
40-
PreUpdate,
41-
ClientSet::Receive.after(NetcodeClientPlugin::update_system),
37+
.run_if(client_just_connected),
4238
)
39+
.configure_sets(PreUpdate, ClientSet::Receive.after(RenetReceive))
4340
.configure_sets(
4441
PreUpdate,
4542
ClientSet::Reset
46-
.after(NetcodeClientPlugin::update_system)
47-
.run_if(client_just_disconnected()),
48-
)
49-
.configure_sets(
50-
PostUpdate,
51-
ClientSet::Send.before(NetcodeClientPlugin::send_packets),
43+
.after(RenetReceive)
44+
.run_if(client_just_disconnected),
5245
)
46+
.configure_sets(PostUpdate, ClientSet::Send.before(RenetSend))
5347
.add_systems(
5448
PreUpdate,
5549
Self::replication_receiving_system
5650
.map(Result::unwrap)
5751
.in_set(ClientSet::Receive)
58-
.run_if(client_connected()),
52+
.run_if(client_connected),
5953
)
6054
.add_systems(PreUpdate, Self::reset_system.in_set(ClientSet::Reset));
6155
}
@@ -453,14 +447,15 @@ fn apply_update_components(
453447

454448
/// Deserializes `entity` from compressed index and generation.
455449
///
456-
/// For details see [`ReplicationBuffer::write_entity`](crate::server::replication_message::replication_buffer::write_entity).
450+
/// For details see
451+
/// [`ReplicationBuffer::write_entity`](crate::server::replication_message::replication_buffer::write_entity).
457452
fn deserialize_entity(cursor: &mut Cursor<&[u8]>) -> bincode::Result<Entity> {
458453
let flagged_index: u64 = cursor.read_u64_varint()?;
459454
let has_generation = (flagged_index & 1) > 0;
460455
let generation = if has_generation {
461-
cursor.read_u32_varint()?
456+
cursor.read_u32_varint()? + 1
462457
} else {
463-
0u32
458+
1u32
464459
};
465460

466461
let bits = (generation as u64) << 32 | (flagged_index >> 1);
@@ -514,7 +509,7 @@ pub enum ClientSet {
514509
///
515510
/// If [`ClientSet::Reset`] is disabled, then this needs to be cleaned up manually.
516511
#[derive(Default, Deref, DerefMut, Resource)]
517-
pub struct ServerEntityTicks(EntityHashMap<Entity, RepliconTick>);
512+
pub struct ServerEntityTicks(EntityHashMap<RepliconTick>);
518513

519514
/// All cached buffered updates, used by the replicon client to align replication updates with initialization
520515
/// messages.

src/client/client_mapper.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
use bevy::{
2-
prelude::*,
3-
utils::{hashbrown::hash_map::Entry, EntityHashMap},
4-
};
1+
use bevy::{ecs::entity::EntityHashMap, prelude::*, utils::hashbrown::hash_map::Entry};
52

6-
use crate::replicon_core::replication_rules::{Mapper, Replication};
3+
use crate::replicon_core::replication_rules::Replication;
74

85
/// Maps server entities into client entities inside components.
96
///
107
/// Spawns new client entity if a mapping doesn't exists.
118
pub struct ClientMapper<'a> {
129
world: &'a mut World,
13-
server_to_client: &'a mut EntityHashMap<Entity, Entity>,
14-
client_to_server: &'a mut EntityHashMap<Entity, Entity>,
10+
server_to_client: &'a mut EntityHashMap<Entity>,
11+
client_to_server: &'a mut EntityHashMap<Entity>,
1512
}
1613

1714
impl<'a> ClientMapper<'a> {
@@ -25,8 +22,8 @@ impl<'a> ClientMapper<'a> {
2522
}
2623
}
2724

28-
impl Mapper for ClientMapper<'_> {
29-
fn map(&mut self, entity: Entity) -> Entity {
25+
impl EntityMapper for ClientMapper<'_> {
26+
fn map_entity(&mut self, entity: Entity) -> Entity {
3027
*self.server_to_client.entry(entity).or_insert_with(|| {
3128
let client_entity = self.world.spawn(Replication).id();
3229
self.client_to_server.insert(client_entity, entity);
@@ -41,8 +38,8 @@ impl Mapper for ClientMapper<'_> {
4138
/// via [`Self::remove_by_client`] or [`Self::clear`].
4239
#[derive(Default, Resource)]
4340
pub struct ServerEntityMap {
44-
server_to_client: EntityHashMap<Entity, Entity>,
45-
client_to_server: EntityHashMap<Entity, Entity>,
41+
server_to_client: EntityHashMap<Entity>,
42+
client_to_server: EntityHashMap<Entity>,
4643
}
4744

4845
impl ServerEntityMap {
@@ -110,12 +107,12 @@ impl ServerEntityMap {
110107
}
111108

112109
#[inline]
113-
pub fn to_client(&self) -> &EntityHashMap<Entity, Entity> {
110+
pub fn to_client(&self) -> &EntityHashMap<Entity> {
114111
&self.server_to_client
115112
}
116113

117114
#[inline]
118-
pub fn to_server(&self) -> &EntityHashMap<Entity, Entity> {
115+
pub fn to_server(&self) -> &EntityHashMap<Entity> {
119116
&self.client_to_server
120117
}
121118

0 commit comments

Comments
 (0)