Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Bevy to 0.13.2 #195

Closed
wants to merge 1 commit into from
Closed
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 adapters/bevy/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ transport_udp = [ "naia-client/transport_udp" ]
[dependencies]
naia-client = { version = "0.22", path = "../../../client", features = ["bevy_support", "wbindgen"] }
naia-bevy-shared = { version = "0.22", path = "../shared" }
bevy_app = { version = "0.12.1", default-features=false }
bevy_ecs = { version = "0.12.1", default-features=false }
bevy_app = { version = "0.13.2", default-features=false }
bevy_ecs = { version = "0.13.2", default-features=false }
log = { version = "0.4" }
60 changes: 29 additions & 31 deletions adapters/bevy/client/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy_ecs::{
entity::Entity,
system::{Command as BevyCommand, EntityCommands},
system::{Command as BevyCommand, Commands, EntityCommands},
world::{Mut, World},
};

Expand All @@ -9,42 +9,40 @@ use naia_client::{Client as NaiaClient, ReplicationConfig};

use crate::Client;

pub trait CommandsExt<'w, 's> {
fn local_duplicate(&mut self, entity: Entity) -> EntityCommands;
}

impl<'w, 's> CommandsExt<'w, 's> for Commands<'w, 's> {
fn local_duplicate(&mut self, entity: Entity) -> EntityCommands {
let new_entity = self.spawn_empty().id();
let command = LocalDuplicateComponents::new(new_entity, entity);
self.add(command);

self.entity(new_entity)
}
}

// Bevy Commands Extension
pub trait CommandsExt<'w, 's, 'a> {
fn local_duplicate(&'a mut self) -> EntityCommands<'w, 's, 'a>;
fn enable_replication(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'w, 's, 'a>;
fn disable_replication(&'a mut self, client: &mut Client)
-> &'a mut EntityCommands<'w, 's, 'a>;
fn configure_replication(
&'a mut self,
config: ReplicationConfig,
) -> &'a mut EntityCommands<'w, 's, 'a>;
pub trait EntityCommandsExt<'a> {
fn enable_replication(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'a>;
fn disable_replication(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'a>;
fn configure_replication(&'a mut self, config: ReplicationConfig)
-> &'a mut EntityCommands<'a>;
fn replication_config(&'a self, client: &Client) -> Option<ReplicationConfig>;
fn request_authority(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'w, 's, 'a>;
fn release_authority(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'w, 's, 'a>;
fn request_authority(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'a>;
fn release_authority(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'a>;
fn authority(&'a self, client: &Client) -> Option<EntityAuthStatus>;
}

impl<'w, 's, 'a> CommandsExt<'w, 's, 'a> for EntityCommands<'w, 's, 'a> {
fn local_duplicate(&'a mut self) -> EntityCommands<'w, 's, 'a> {
let old_entity = self.id();
let commands = self.commands();
let new_entity = commands.spawn_empty().id();
let command = LocalDuplicateComponents::new(new_entity, old_entity);
commands.add(command);
commands.entity(new_entity)
}

fn enable_replication(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'w, 's, 'a> {
impl<'a> EntityCommandsExt<'a> for EntityCommands<'a> {
fn enable_replication(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'a> {
client.enable_replication(&self.id());
self.insert(HostOwned);
return self;
}

fn disable_replication(
&'a mut self,
client: &mut Client,
) -> &'a mut EntityCommands<'w, 's, 'a> {
fn disable_replication(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'a> {
client.disable_replication(&self.id());
self.remove::<HostOwned>();
return self;
Expand All @@ -53,9 +51,9 @@ impl<'w, 's, 'a> CommandsExt<'w, 's, 'a> for EntityCommands<'w, 's, 'a> {
fn configure_replication(
&'a mut self,
config: ReplicationConfig,
) -> &'a mut EntityCommands<'w, 's, 'a> {
) -> &'a mut EntityCommands<'a> {
let entity = self.id();
let commands = self.commands();
let mut commands = self.commands();
let command = ConfigureReplicationCommand::new(entity, config);
commands.add(command);
return self;
Expand All @@ -65,12 +63,12 @@ impl<'w, 's, 'a> CommandsExt<'w, 's, 'a> for EntityCommands<'w, 's, 'a> {
client.replication_config(&self.id())
}

fn request_authority(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'w, 's, 'a> {
fn request_authority(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'a> {
client.entity_request_authority(&self.id());
return self;
}

fn release_authority(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'w, 's, 'a> {
fn release_authority(&'a mut self, client: &mut Client) -> &'a mut EntityCommands<'a> {
client.entity_release_authority(&self.id());
return self;
}
Expand Down
1 change: 1 addition & 0 deletions adapters/bevy/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ mod systems;

pub use client::Client;
pub use commands::CommandsExt;
pub use commands::EntityCommandsExt;
pub use components::{ClientOwned, ServerOwned};
pub use plugin::Plugin;
4 changes: 2 additions & 2 deletions adapters/bevy/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ transport_udp = [ "naia-server/transport_udp" ]
[dependencies]
naia-server = { version = "0.22", path = "../../../server", features = ["bevy_support"] }
naia-bevy-shared = { version = "0.22", path = "../shared" }
bevy_app = { version = "0.12.1", default-features=false }
bevy_ecs = { version = "0.12.1", default-features=false }
bevy_app = { version = "0.13.2", default-features=false }
bevy_ecs = { version = "0.13.2", default-features=false }
log = { version = "0.4" }
42 changes: 18 additions & 24 deletions adapters/bevy/server/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,31 @@ use naia_server::{ReplicationConfig, Server as NaiaServer, UserKey};
use crate::Server;

// Bevy Commands Extension
pub trait CommandsExt<'w, 's, 'a> {
fn enable_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'w, 's, 'a>;
fn disable_replication(&'a mut self, server: &mut Server)
-> &'a mut EntityCommands<'w, 's, 'a>;
fn configure_replication(
&'a mut self,
config: ReplicationConfig,
) -> &'a mut EntityCommands<'w, 's, 'a>;
pub trait EntityCommandsExt<'a> {
fn enable_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a>;
fn disable_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a>;
fn configure_replication(&'a mut self, config: ReplicationConfig)
-> &'a mut EntityCommands<'a>;
fn replication_config(&'a self, server: &Server) -> Option<ReplicationConfig>;
fn give_authority(
&'a mut self,
server: &mut Server,
user_key: &UserKey,
) -> &'a mut EntityCommands<'w, 's, 'a>;
fn take_authority(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'w, 's, 'a>;
) -> &'a mut EntityCommands<'a>;
fn take_authority(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a>;
fn authority(&'a self, server: &Server) -> Option<EntityAuthStatus>;
fn pause_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'w, 's, 'a>;
fn resume_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'w, 's, 'a>;
fn pause_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a>;
fn resume_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a>;
}

impl<'w, 's, 'a> CommandsExt<'w, 's, 'a> for EntityCommands<'w, 's, 'a> {
fn enable_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'w, 's, 'a> {
impl<'a> EntityCommandsExt<'a> for EntityCommands<'a> {
fn enable_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a> {
server.enable_replication(&self.id());
self.insert(HostOwned);
return self;
}

fn disable_replication(
&'a mut self,
server: &mut Server,
) -> &'a mut EntityCommands<'w, 's, 'a> {
fn disable_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a> {
server.disable_replication(&self.id());
self.remove::<HostOwned>();
return self;
Expand All @@ -49,9 +43,9 @@ impl<'w, 's, 'a> CommandsExt<'w, 's, 'a> for EntityCommands<'w, 's, 'a> {
fn configure_replication(
&'a mut self,
config: ReplicationConfig,
) -> &'a mut EntityCommands<'w, 's, 'a> {
) -> &'a mut EntityCommands<'a> {
let entity = self.id();
let commands = self.commands();
let mut commands = self.commands();
let command = ConfigureReplicationCommand::new(entity, config);
commands.add(command);
return self;
Expand All @@ -65,11 +59,11 @@ impl<'w, 's, 'a> CommandsExt<'w, 's, 'a> for EntityCommands<'w, 's, 'a> {
&'a mut self,
_server: &mut Server,
_user_key: &UserKey,
) -> &'a mut EntityCommands<'w, 's, 'a> {
) -> &'a mut EntityCommands<'a> {
todo!()
}

fn take_authority(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'w, 's, 'a> {
fn take_authority(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a> {
server.entity_take_authority(&self.id());
return self;
}
Expand All @@ -78,12 +72,12 @@ impl<'w, 's, 'a> CommandsExt<'w, 's, 'a> for EntityCommands<'w, 's, 'a> {
server.entity_authority_status(&self.id())
}

fn pause_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'w, 's, 'a> {
fn pause_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a> {
server.pause_replication(&self.id());
return self;
}

fn resume_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'w, 's, 'a> {
fn resume_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a> {
server.resume_replication(&self.id());
return self;
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/bevy/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod plugin;
mod server;
mod systems;

pub use commands::CommandsExt;
pub use commands::EntityCommandsExt;
pub use components::{ClientOwned, ServerOwned};
pub use plugin::Plugin;
pub use server::Server;
5 changes: 2 additions & 3 deletions adapters/bevy/server/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use crate::{ClientOwned, EntityAuthStatus};
mod naia_events {
pub use naia_server::{
ConnectEvent, DelegateEntityEvent, DespawnEntityEvent, DisconnectEvent,
EntityAuthGrantEvent, EntityAuthResetEvent, ErrorEvent, InsertComponentEvent,
PublishEntityEvent, RemoveComponentEvent, SpawnEntityEvent, TickEvent,
UnpublishEntityEvent, UpdateComponentEvent,
EntityAuthGrantEvent, EntityAuthResetEvent, ErrorEvent, PublishEntityEvent,
SpawnEntityEvent, TickEvent, UnpublishEntityEvent,
};
}

Expand Down
4 changes: 2 additions & 2 deletions adapters/bevy/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ maintenance = { status = "actively-developed" }

[dependencies]
naia-shared = { version = "0.22", path = "../../../shared", features = ["bevy_support", "wbindgen"] }
bevy_app = { version = "0.12.1", default-features=false }
bevy_ecs = { version = "0.12.1", default-features=false }
bevy_app = { version = "0.13.2", default-features=false }
bevy_ecs = { version = "0.13.2", default-features=false }
log = { version = "0.4" }
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ transport_udp = [ "local_ipaddress" ]
[dependencies]
naia-shared = { version = "0.22", path = "../shared" }
naia-client-socket = { version = "0.22", path = "../socket/client", optional = true }
bevy_ecs = { version = "0.12.1", default_features = false, optional = true }
bevy_ecs = { version = "0.13.2", 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.12.1", default_features = false, features = [ "bevy_asset", "bevy_winit", "bevy_core_pipeline", "bevy_render", "bevy_sprite", "x11", "webgl2"] }
bevy = { version = "0.13.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
9 changes: 5 additions & 4 deletions demos/bevy/client/src/systems/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use naia_bevy_client::{
MessageEvents, PublishEntityEvent, RejectEvent, RemoveComponentEvents, SpawnEntityEvent,
UnpublishEntityEvent, UpdateComponentEvents,
},
sequence_greater_than, Client, CommandsExt, Random, Replicate, Tick,
sequence_greater_than, Client, CommandsExt, EntityCommandsExt, Random, Replicate, Tick,
};
use naia_bevy_demo_shared::{
behavior as shared_behavior,
Expand Down Expand Up @@ -99,8 +99,8 @@ pub fn message_events(
// Here we create a local copy of the Player entity, to use for client-side prediction
if let Ok(position) = position_query.get(entity) {
let prediction_entity = commands
.entity(entity)
.local_duplicate() // copies all Replicate components as well
.local_duplicate(entity)
// copies all Replicate components as well
.insert(SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::new(SQUARE_SIZE, SQUARE_SIZE)),
Expand Down Expand Up @@ -348,7 +348,8 @@ pub fn tick_events(
let Some(predicted_entity) = global
.owned_entity
.as_ref()
.map(|owned_entity| owned_entity.predicted) else {
.map(|owned_entity| owned_entity.predicted)
else {
// No owned Entity
return;
};
Expand Down
7 changes: 4 additions & 3 deletions demos/bevy/client/src/systems/init.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::{
info, shape, Assets, Camera2dBundle, Color, ColorMaterial, Commands, Mesh, ResMut,
use bevy::{
math::primitives,
prelude::{info, Assets, Camera2dBundle, Color, ColorMaterial, Commands, Mesh, ResMut},
};

use naia_bevy_client::{transport::webrtc, Client};
Expand Down Expand Up @@ -36,7 +37,7 @@ pub fn init(
global.aqua = materials.add(ColorMaterial::from(Color::AQUAMARINE));

// Load shapes
global.circle = meshes.add(shape::Circle::new(6.).into());
global.circle = meshes.add(primitives::Circle::new(6.));

// Insert Global Resource
commands.insert_resource(global);
Expand Down
22 changes: 12 additions & 10 deletions demos/bevy/client/src/systems/input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use bevy::prelude::{Commands, Input, KeyCode, Query, Res, ResMut, Vec2, Window};

use naia_bevy_client::{Client, CommandsExt, ReplicationConfig};
use bevy::{
input::ButtonInput,
prelude::{Commands, KeyCode, Query, Res, ResMut, Vec2, Window},
};
use naia_bevy_client::{Client, EntityCommandsExt, ReplicationConfig};
use naia_bevy_demo_shared::{components::Position, messages::KeyCommand};

use crate::resources::Global;
Expand All @@ -9,13 +11,13 @@ pub fn key_input(
client: Client,
mut commands: Commands,
mut global: ResMut<Global>,
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
) {
let w = keyboard_input.pressed(KeyCode::W);
let s = keyboard_input.pressed(KeyCode::S);
let a = keyboard_input.pressed(KeyCode::A);
let d = keyboard_input.pressed(KeyCode::D);
let x = keyboard_input.pressed(KeyCode::X);
let w = keyboard_input.pressed(KeyCode::KeyW);
let s = keyboard_input.pressed(KeyCode::KeyS);
let a = keyboard_input.pressed(KeyCode::KeyA);
let d = keyboard_input.pressed(KeyCode::KeyD);
let x = keyboard_input.pressed(KeyCode::KeyX);

if let Some(command) = &mut global.queued_command {
if w {
Expand Down Expand Up @@ -68,7 +70,7 @@ pub fn cursor_input(

fn window_relative_mouse_position(window: &Window) -> Option<Vec2> {
let Some(cursor_pos) = window.cursor_position() else {
return None
return None;
};

Some(Vec2::new(
Expand Down
8 changes: 4 additions & 4 deletions demos/bevy/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
[dependencies]
naia-bevy-demo-shared = { path = "../shared" }
naia-bevy-server = { path = "../../../adapters/bevy/server", features = [ "transport_webrtc" ] }
bevy_app = { version = "0.12.1", default-features=false }
bevy_core = { version = "0.12.1", default-features=false }
bevy_ecs = { version = "0.12.1", default-features=false }
bevy_log = { version = "0.12.1", default-features=false }
bevy_app = { version = "0.13.2", default-features=false }
bevy_core = { version = "0.13.2", default-features=false }
bevy_ecs = { version = "0.13.2", default-features=false }
bevy_log = { version = "0.13.2", default-features=false }
2 changes: 1 addition & 1 deletion demos/bevy/server/src/systems/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use naia_bevy_server::{
InsertComponentEvents, PublishEntityEvent, RemoveComponentEvents, SpawnEntityEvent,
TickEvent, UnpublishEntityEvent, UpdateComponentEvents,
},
CommandsExt, Random, ReplicationConfig, Server,
EntityCommandsExt, Random, ReplicationConfig, Server,
};

use naia_bevy_demo_shared::{
Expand Down
2 changes: 1 addition & 1 deletion demos/bevy/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ publish = false

[dependencies]
naia-bevy-shared = { path = "../../../adapters/bevy/shared" }
bevy_ecs = { version = "0.12.1", default-features=false}
bevy_ecs = { version = "0.13.2", default-features=false}
cfg-if = { version = "1.0" }
log = { version = "0.4" }
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ transport_udp = []
[dependencies]
naia-shared = { version = "0.22", path = "../shared" }
naia-server-socket = { version = "0.22", path = "../socket/server", optional = true }
bevy_ecs = { version = "0.12.1", default_features = false, optional = true }
bevy_ecs = { version = "0.13.2", default_features = false, optional = true }
cfg-if = { version = "1.0" }
log = { version = "0.4" }
ring = { version = "0.16.15" }
Expand Down
Loading