Skip to content

Commit

Permalink
Release/0.21.1 (#189)
Browse files Browse the repository at this point in the history
* Update to Bevy 0.11
* Update demo to Bevy 0.11 too
- update bevy_derive to use syn 2.0
* - correct bevy demo's window coordinates
* - add 'webgl2' flag to bevy dependency

---------

Co-authored-by: Ellie Leela Ang <[email protected]>
  • Loading branch information
connorcarpenter and aurelilia authored Aug 25, 2023
1 parent b1bcc4c commit 5a16949
Show file tree
Hide file tree
Showing 23 changed files with 95 additions and 67 deletions.
8 changes: 4 additions & 4 deletions adapters/bevy/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "naia-bevy-client"
version = "0.21.0"
version = "0.21.1"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia_client & Bevy interop"
Expand All @@ -17,7 +17,7 @@ transport_webrtc = [ "naia-client/transport_webrtc" ]
transport_udp = [ "naia-client/transport_udp" ]

[dependencies]
naia-client = { version = "0.21.0", path = "../../../client", features = ["bevy_support", "wbindgen"] }
naia-client = { version = "0.21", path = "../../../client", features = ["bevy_support", "wbindgen"] }
naia-bevy-shared = { version = "0.21", path = "../shared" }
bevy_app = { version = "0.10", default-features=false }
bevy_ecs = { version = "0.10", default-features=false }
bevy_app = { version = "0.11", default-features=false }
bevy_ecs = { version = "0.11", default-features=false }
2 changes: 1 addition & 1 deletion adapters/bevy/client/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl DuplicateComponents {
}

impl BevyCommand for DuplicateComponents {
fn write(self, world: &mut World) {
fn apply(self, world: &mut World) {
WorldMutType::<Entity>::duplicate_components(
&mut world.proxy_mut(),
&self.mutable_entity,
Expand Down
14 changes: 13 additions & 1 deletion adapters/bevy/client/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{any::Any, collections::HashMap};

use bevy_ecs::entity::Entity;
use bevy_ecs::{entity::Entity, prelude::Event};

use naia_client::{Events, NaiaClientError};

Expand All @@ -9,18 +9,23 @@ use naia_bevy_shared::{
};

// ConnectEvent
#[derive(Event)]
pub struct ConnectEvent;

// DisconnectEvent
#[derive(Event)]
pub struct DisconnectEvent;

// RejectEvent
#[derive(Event)]
pub struct RejectEvent;

// ErrorEvent
#[derive(Event)]
pub struct ErrorEvent(pub NaiaClientError);

// MessageEvents
#[derive(Event)]
pub struct MessageEvents {
inner: HashMap<ChannelKind, HashMap<MessageKind, Vec<MessageContainer>>>,
}
Expand Down Expand Up @@ -57,18 +62,23 @@ impl MessageEvents {
}

// ClientTickEvent
#[derive(Event)]
pub struct ClientTickEvent(pub Tick);

// ServerTickEvent
#[derive(Event)]
pub struct ServerTickEvent(pub Tick);

// SpawnEntityEvent
#[derive(Event)]
pub struct SpawnEntityEvent(pub Entity);

// DespawnEntityEvent
#[derive(Event)]
pub struct DespawnEntityEvent(pub Entity);

// InsertComponentEvent
#[derive(Event)]
pub struct InsertComponentEvents {
inner: HashMap<ComponentKind, Vec<Entity>>,
}
Expand All @@ -88,6 +98,7 @@ impl InsertComponentEvents {
}

// UpdateComponentEvents
#[derive(Event)]
pub struct UpdateComponentEvents {
inner: HashMap<ComponentKind, Vec<(Tick, Entity)>>,
}
Expand All @@ -108,6 +119,7 @@ impl UpdateComponentEvents {
}

// RemoveComponentEvents
#[derive(Event)]
pub struct RemoveComponentEvents {
inner: HashMap<ComponentKind, Vec<(Entity, Box<dyn Replicate>)>>,
}
Expand Down
8 changes: 4 additions & 4 deletions adapters/bevy/client/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{ops::DerefMut, sync::Mutex};

use bevy_app::{App, Plugin as PluginType};
use bevy_ecs::{entity::Entity, schedule::IntoSystemConfig};
use bevy_app::{App, Plugin as PluginType, Update};
use bevy_ecs::{entity::Entity, schedule::IntoSystemConfigs};

use naia_bevy_shared::{BeforeReceiveEvents, Protocol, SharedPlugin};
use naia_client::{Client, ClientConfig};
Expand Down Expand Up @@ -54,7 +54,7 @@ impl PluginType for Plugin {

app
// SHARED PLUGIN //
.add_plugin(SharedPlugin)
.add_plugins(SharedPlugin)
// RESOURCES //
.insert_resource(client)
// EVENTS //
Expand All @@ -71,6 +71,6 @@ impl PluginType for Plugin {
.add_event::<UpdateComponentEvents>()
.add_event::<RemoveComponentEvents>()
// SYSTEMS //
.add_system(before_receive_events.in_set(BeforeReceiveEvents));
.add_systems(Update, before_receive_events.in_set(BeforeReceiveEvents));
}
}
6 changes: 3 additions & 3 deletions adapters/bevy/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "naia-bevy-server"
version = "0.21.0"
version = "0.21.1"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia_server & Bevy interop"
Expand All @@ -19,5 +19,5 @@ transport_udp = [ "naia-server/transport_udp" ]
[dependencies]
naia-server = { version = "0.21", path = "../../../server", features = ["bevy_support"] }
naia-bevy-shared = { version = "0.21", path = "../shared" }
bevy_app = { version = "0.10", default-features=false }
bevy_ecs = { version = "0.10", default-features=false }
bevy_app = { version = "0.11", default-features=false }
bevy_ecs = { version = "0.11", default-features=false }
13 changes: 12 additions & 1 deletion adapters/bevy/server/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
use std::{any::Any, collections::HashMap};

use bevy_ecs::entity::Entity;
use bevy_ecs::{entity::Entity, prelude::Event};

use naia_bevy_shared::{
Channel, ChannelKind, ComponentKind, Message, MessageContainer, MessageKind, Replicate, Tick,
};
use naia_server::{Events, NaiaServerError, User, UserKey};

// ConnectEvent
#[derive(Event)]
pub struct ConnectEvent(pub UserKey);

// DisconnectEvent
#[derive(Event)]
pub struct DisconnectEvent(pub UserKey, pub User);

// ErrorEvent
#[derive(Event)]
pub struct ErrorEvent(pub NaiaServerError);

// TickEvent
#[derive(Event)]
pub struct TickEvent(pub Tick);

// AuthEvents
#[derive(Event)]
pub struct AuthEvents {
inner: HashMap<MessageKind, Vec<(UserKey, MessageContainer)>>,
}
Expand All @@ -45,6 +50,7 @@ impl AuthEvents {
}

// MessageEvents
#[derive(Event)]
pub struct MessageEvents {
inner: HashMap<ChannelKind, HashMap<MessageKind, Vec<(UserKey, MessageContainer)>>>,
}
Expand Down Expand Up @@ -88,12 +94,15 @@ fn convert_messages<M: Message>(
}

// SpawnEntityEvent
#[derive(Event)]
pub struct SpawnEntityEvent(pub UserKey, pub Entity);

// DespawnEntityEvent
#[derive(Event)]
pub struct DespawnEntityEvent(pub UserKey, pub Entity);

// InsertComponentEvent
#[derive(Event)]
pub struct InsertComponentEvents {
inner: HashMap<ComponentKind, Vec<(UserKey, Entity)>>,
}
Expand All @@ -113,6 +122,7 @@ impl InsertComponentEvents {
}

// UpdateComponentEvents
#[derive(Event)]
pub struct UpdateComponentEvents {
inner: HashMap<ComponentKind, Vec<(UserKey, Entity)>>,
}
Expand All @@ -133,6 +143,7 @@ impl UpdateComponentEvents {
}

// RemoveComponentEvents
#[derive(Event)]
pub struct RemoveComponentEvents {
inner: HashMap<ComponentKind, Vec<(UserKey, Entity, Box<dyn Replicate>)>>,
}
Expand Down
8 changes: 4 additions & 4 deletions adapters/bevy/server/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{ops::DerefMut, sync::Mutex};

use bevy_app::{App, Plugin as PluginType};
use bevy_ecs::{entity::Entity, schedule::IntoSystemConfig};
use bevy_app::{App, Plugin as PluginType, Update};
use bevy_ecs::{entity::Entity, schedule::IntoSystemConfigs};

use naia_bevy_shared::{BeforeReceiveEvents, Protocol, SharedPlugin};
use naia_server::{Server, ServerConfig};
Expand Down Expand Up @@ -54,7 +54,7 @@ impl PluginType for Plugin {

app
// SHARED PLUGIN //
.add_plugin(SharedPlugin)
.add_plugins(SharedPlugin)
// RESOURCES //
.insert_resource(server)
// EVENTS //
Expand All @@ -70,6 +70,6 @@ impl PluginType for Plugin {
.add_event::<UpdateComponentEvents>()
.add_event::<RemoveComponentEvents>()
// SYSTEMS //
.add_system(before_receive_events.in_set(BeforeReceiveEvents));
.add_systems(Update, before_receive_events.in_set(BeforeReceiveEvents));
}
}
6 changes: 3 additions & 3 deletions adapters/bevy/shared/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "naia-bevy-shared"
version = "0.21.0"
version = "0.21.1"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia & Bevy interop, functionality shared by client & server versions"
Expand All @@ -16,5 +16,5 @@ maintenance = { status = "actively-developed" }

[dependencies]
naia-shared = { version = "0.21", path = "../../../shared", features = ["bevy_support", "wbindgen"] }
bevy_app = { version = "0.10", default-features=false }
bevy_ecs = { version = "0.10", default-features=false }
bevy_app = { version = "0.11", default-features=false }
bevy_ecs = { version = "0.11", default-features=false }
2 changes: 2 additions & 0 deletions adapters/bevy/shared/src/change_detection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy_ecs::{
entity::Entity,
event::EventWriter,
prelude::Event,
query::{Added, With},
removal_detection::RemovedComponents,
system::Query,
Expand All @@ -10,6 +11,7 @@ use naia_shared::{ComponentKind, Replicate};

use crate::HostOwned;

#[derive(Event)]
pub enum HostSyncEvent {
Insert(Entity, ComponentKind),
Remove(Entity, ComponentKind),
Expand Down
4 changes: 3 additions & 1 deletion adapters/bevy/shared/src/component_access.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{any::Any, marker::PhantomData};

use bevy_app::App;
use bevy_app::{App, Update};
use bevy_ecs::{entity::Entity, schedule::IntoSystemConfigs, world::World};

use naia_shared::{ReplicaDynMutWrapper, ReplicaDynRefWrapper, Replicate};
Expand Down Expand Up @@ -51,6 +51,7 @@ impl<R: Replicate> ComponentAccessor<R> {
impl<R: Replicate> ComponentAccess for ComponentAccessor<R> {
fn add_systems(&self, app: &mut App) {
app.add_systems(
Update,
(on_component_added::<R>, on_component_removed::<R>)
.chain()
.in_set(HostSyncChangeTracking),
Expand Down Expand Up @@ -97,6 +98,7 @@ impl<R: Replicate> ComponentAccess for ComponentAccessor<R> {
) {
let mut query = world.query::<&mut R>();
unsafe {
let world = world.as_unsafe_world_cell();
if let Ok(immutable_component) = query.get_unchecked(world, *immutable_entity) {
if let Ok(mut mutable_component) = query.get_unchecked(world, *mutable_entity) {
let some_r: &R = &immutable_component;
Expand Down
1 change: 1 addition & 0 deletions adapters/bevy/shared/src/component_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct ComponentDynRef<'a, T>(pub &'a T);

impl<'a, R: Replicate> ReplicaDynRefTrait for ComponentDynRef<'a, R> {
fn to_dyn_ref(&self) -> &dyn Replicate {
#![allow(suspicious_double_ref_op)]
self.0.deref()
}
}
Expand Down
10 changes: 5 additions & 5 deletions adapters/bevy/shared/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy_app::{App, Plugin as PluginType};
use bevy_ecs::schedule::{IntoSystemConfig, IntoSystemSetConfig};
use bevy_app::{App, Plugin as PluginType, Update};
use bevy_ecs::schedule::{IntoSystemConfigs, IntoSystemSetConfig};

use crate::{
change_detection::{on_despawn, HostSyncEvent},
Expand All @@ -15,9 +15,9 @@ impl PluginType for SharedPlugin {
// EVENTS //
.add_event::<HostSyncEvent>()
// SYSTEM SETS //
.configure_set(HostSyncChangeTracking.before(BeforeReceiveEvents))
.configure_set(BeforeReceiveEvents.before(ReceiveEvents))
.configure_set(Update, HostSyncChangeTracking.before(BeforeReceiveEvents))
.configure_set(Update, BeforeReceiveEvents.before(ReceiveEvents))
// SYSTEMS //
.add_system(on_despawn.in_set(HostSyncChangeTracking));
.add_systems(Update, on_despawn.in_set(HostSyncChangeTracking));
}
}
4 changes: 2 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "naia-client"
version = "0.21.0"
version = "0.21.1"
authors = ["connorcarpenter <[email protected]>"]
workspace = ".."
description = "Provides a cross-platform client that can send/receive messages to/from a server, and has a pool of in-scope entities/components that is synced with the server."
Expand All @@ -27,7 +27,7 @@ transport_udp = [ "local_ipaddress" ]
[dependencies]
naia-shared = { version = "0.21", path = "../shared" }
naia-client-socket = { version = "0.20", path = "../socket/client", optional = true }
bevy_ecs = { version = "0.10", default_features = false, optional = true }
bevy_ecs = { version = "0.11", default_features = false, optional = true }
local_ipaddress = { version = "0.1", optional = true }
cfg-if = { version = "1.0" }
log = { version = "0.4" }
2 changes: 1 addition & 1 deletion demos/bevy/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ crate-type = ["cdylib", "rlib"]
naia-bevy-client = { path = "../../../adapters/bevy/client", features = ["transport_webrtc"] }
naia-bevy-demo-shared = { path = "../shared" }

bevy = { version = "0.10.1", default_features = false, features = [ "bevy_asset", "bevy_winit", "bevy_core_pipeline", "bevy_render", "bevy_sprite", "x11"] }
bevy = { version = "0.11.2", default_features = false, features = [ "bevy_asset", "bevy_winit", "bevy_core_pipeline", "bevy_render", "bevy_sprite", "x11", "webgl2"] }

cfg-if = { version = "1.0" }

Expand Down
14 changes: 8 additions & 6 deletions demos/bevy/client/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{
prelude::{
App, ClearColor, Color, IntoSystemConfig, IntoSystemConfigs, IntoSystemSetConfig, SystemSet,
App, ClearColor, Color, IntoSystemConfigs, IntoSystemSetConfig, SystemSet, Startup, Update,
},
DefaultPlugins,
};
Expand All @@ -21,13 +21,14 @@ pub fn run() {
// Bevy Plugins
.add_plugins(DefaultPlugins)
// Add Naia Client Plugin
.add_plugin(ClientPlugin::new(ClientConfig::default(), protocol()))
.add_plugins(ClientPlugin::new(ClientConfig::default(), protocol()))
// Background Color
.insert_resource(ClearColor(Color::BLACK))
// Startup System
.add_startup_system(init)
.add_systems(Startup, init)
// Receive Client Events
.add_systems(
Update,
(
events::connect_events,
events::disconnect_events,
Expand All @@ -43,11 +44,12 @@ pub fn run() {
.in_set(ReceiveEvents),
)
// Tick Event
.configure_set(Tick.after(ReceiveEvents))
.add_system(events::tick_events.in_set(Tick))
.configure_set(Update, Tick.after(ReceiveEvents))
.add_systems(Update, events::tick_events.in_set(Tick))
// Realtime Gameplay Loop
.configure_set(MainLoop.after(Tick))
.configure_set(Update, MainLoop.after(Tick))
.add_systems(
Update,
(
input::key_input,
input::cursor_input,
Expand Down
Loading

0 comments on commit 5a16949

Please sign in to comment.