Skip to content

Commit

Permalink
Merge pull request #202 from naia-lib/release-0.24.0
Browse files Browse the repository at this point in the history
Release 0.24.0
  • Loading branch information
connorcarpenter authored Dec 13, 2024
2 parents eb05771 + f33d580 commit f06d749
Show file tree
Hide file tree
Showing 90 changed files with 1,735 additions and 618 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions .idea/runConfigurations/Bevy_Demo_Server__RUN_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 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.23.0"
version = "0.24.0"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia_client & Bevy interop"
Expand All @@ -17,8 +17,8 @@ transport_webrtc = [ "naia-client/transport_webrtc" ]
transport_udp = [ "naia-client/transport_udp" ]

[dependencies]
naia-client = { version = "0.23", path = "../../../client", features = ["bevy_support", "wbindgen"] }
naia-bevy-shared = { version = "0.23", path = "../shared" }
bevy_app = { version = "0.14", default-features=false }
bevy_ecs = { version = "0.14", default-features=false }
naia-client = { version = "0.24", path = "../../../client", features = ["bevy_support", "wbindgen"] }
naia-bevy-shared = { version = "0.24", path = "../shared" }
bevy_app = { version = "0.15", default-features=false }
bevy_ecs = { version = "0.15", default-features=false }
log = { version = "0.4" }
19 changes: 16 additions & 3 deletions adapters/bevy/client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{marker::PhantomData, net::SocketAddr};
use std::{marker::PhantomData, net::SocketAddr, time::Duration};

use bevy_ecs::{
entity::Entity,
Expand All @@ -10,8 +10,9 @@ use naia_bevy_shared::{
GlobalEntity, Message, Request, Response, ResponseReceiveKey, ResponseSendKey, Tick,
};
use naia_client::{
shared::{GameInstant, SocketConfig}, transport::Socket, Client as NaiaClient, ConnectionStatus,
NaiaClientError,
shared::{GameInstant, SocketConfig},
transport::Socket,
Client as NaiaClient, ConnectionStatus, NaiaClientError,
};

use crate::ReplicationConfig;
Expand Down Expand Up @@ -119,14 +120,26 @@ impl<'w, T: Send + Sync + 'static> Client<'w, T> {
self.client.client.client_tick()
}

pub fn client_instant(&self) -> Option<GameInstant> {
self.client.client.client_instant()
}

pub fn server_tick(&self) -> Option<Tick> {
self.client.client.server_tick()
}

pub fn server_instant(&self) -> Option<GameInstant> {
self.client.client.server_instant()
}

pub fn tick_to_instant(&self, tick: Tick) -> Option<GameInstant> {
self.client.client.tick_to_instant(tick)
}

pub fn tick_duration(&self) -> Option<Duration> {
self.client.client.tick_duration()
}

// Interpolation

pub fn client_interpolation(&self) -> Option<f32> {
Expand Down
16 changes: 8 additions & 8 deletions adapters/bevy/client/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::marker::PhantomData;
use bevy_ecs::{
entity::Entity,
system::EntityCommands,
world::{Mut, World, Command as BevyCommand},
world::{Command as BevyCommand, Mut, World},
};

use naia_bevy_shared::{EntityAuthStatus, HostOwned, WorldMutType, WorldProxyMut};
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<'a> CommandsExt<'a> for EntityCommands<'a> {
let mut commands = self.commands();
let new_entity = commands.spawn_empty().id();
let command = LocalDuplicateComponents::new(new_entity, old_entity);
commands.add(command);
commands.queue(command);
new_entity
}

Expand All @@ -60,7 +60,7 @@ impl<'a> CommandsExt<'a> for EntityCommands<'a> {
) -> &'a mut EntityCommands<'a> {
client.enable_replication(&self.id());
self.insert(HostOwned::new::<T>());
return self;
self
}

fn disable_replication<T: Send + Sync + 'static>(
Expand All @@ -69,7 +69,7 @@ impl<'a> CommandsExt<'a> for EntityCommands<'a> {
) -> &'a mut EntityCommands<'a> {
client.disable_replication(&self.id());
self.remove::<HostOwned>();
return self;
self
}

fn configure_replication<T: Send + Sync + 'static>(
Expand All @@ -79,8 +79,8 @@ impl<'a> CommandsExt<'a> for EntityCommands<'a> {
let entity = self.id();
let mut commands = self.commands();
let command = ConfigureReplicationCommand::<T>::new(entity, config);
commands.add(command);
return self;
commands.queue(command);
self
}

fn replication_config<T: Send + Sync + 'static>(
Expand All @@ -95,15 +95,15 @@ impl<'a> CommandsExt<'a> for EntityCommands<'a> {
client: &mut Client<T>,
) -> &'a mut EntityCommands<'a> {
client.entity_request_authority(&self.id());
return self;
self
}

fn release_authority<T: Send + Sync + 'static>(
&'a mut self,
client: &mut Client<T>,
) -> &'a mut EntityCommands<'a> {
client.entity_release_authority(&self.id());
return self;
self
}

fn authority<T: Send + Sync + 'static>(
Expand Down
4 changes: 2 additions & 2 deletions adapters/bevy/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use naia_bevy_shared::{
sequence_greater_than, wrapping_diff, EntityAuthStatus, Random, ReceiveEvents, Replicate,
ResponseSendKey, Tick, Timer, GameInstant,
sequence_greater_than, sequence_less_than, wrapping_diff, EntityAuthStatus, GameInstant,
Random, ReceiveEvents, Replicate, ResponseSendKey, Tick, Timer,
};
pub use naia_client::{
shared::{default_channels, Instant, Message, ResponseReceiveKey},
Expand Down
4 changes: 2 additions & 2 deletions adapters/bevy/client/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub fn before_receive_events<T: Send + Sync + 'static>(world: &mut World) {
event_writer.send(bevy_events::EntityAuthGrantedEvent::<T>::new(entity));
}
for entity in auth_granted_entities {
if world.get_entity(entity).is_some() {
if world.get_entity(entity).is_ok() {
world.entity_mut(entity).insert(HostOwned::new::<T>());
} else {
warn!(
Expand Down Expand Up @@ -244,7 +244,7 @@ pub fn before_receive_events<T: Send + Sync + 'static>(world: &mut World) {
event_writer.send(bevy_events::EntityAuthResetEvent::<T>::new(entity));
}
for entity in auth_reset_entities {
if world.get_entity(entity).is_some() {
if world.get_entity(entity).is_ok() {
world.entity_mut(entity).remove::<HostOwned>();
} else {
warn!(
Expand Down
10 changes: 5 additions & 5 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.23.0"
version = "0.24.0"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia_server & Bevy interop"
Expand All @@ -17,8 +17,8 @@ transport_webrtc = [ "naia-server/transport_webrtc" ]
transport_udp = [ "naia-server/transport_udp" ]

[dependencies]
naia-server = { version = "0.23", path = "../../../server", features = ["bevy_support"] }
naia-bevy-shared = { version = "0.23", path = "../shared" }
bevy_app = { version = "0.14", default-features=false }
bevy_ecs = { version = "0.14", default-features=false }
naia-server = { version = "0.24", path = "../../../server", features = ["bevy_support"] }
naia-bevy-shared = { version = "0.24", path = "../shared" }
bevy_app = { version = "0.15", default-features=false }
bevy_ecs = { version = "0.15", default-features=false }
log = { version = "0.4" }
12 changes: 6 additions & 6 deletions adapters/bevy/server/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use bevy_ecs::{
entity::Entity,
system::EntityCommands,
world::{Mut, World, Command as BevyCommand},
world::{Command as BevyCommand, Mut, World},
};

use naia_bevy_shared::{EntityAuthStatus, HostOwned, WorldProxyMut};
use naia_server::{ReplicationConfig, UserKey};

use crate::{server::ServerWrapper, Server, plugin::Singleton};
use crate::{plugin::Singleton, server::ServerWrapper, Server};

// Bevy Commands Extension
pub trait CommandsExt<'a> {
Expand All @@ -31,13 +31,13 @@ impl<'a> CommandsExt<'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::new::<Singleton>());
return self;
self
}

fn disable_replication(&'a mut self, server: &mut Server) -> &'a mut EntityCommands<'a> {
server.disable_replication(&self.id());
self.remove::<HostOwned>();
return self;
self
}

fn configure_replication(
Expand All @@ -47,8 +47,8 @@ impl<'a> CommandsExt<'a> for EntityCommands<'a> {
let entity = self.id();
let mut commands = self.commands();
let command = ConfigureReplicationCommand::new(entity, config);
commands.add(command);
return self;
commands.queue(command);
self
}

fn replication_config(&'a self, server: &Server) -> Option<ReplicationConfig> {
Expand Down
13 changes: 12 additions & 1 deletion adapters/bevy/server/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use std::{any::Any, collections::HashMap};

use bevy_ecs::{entity::Entity, prelude::Event};
use bevy_ecs::{
entity::Entity,
event::EventReader,
prelude::{Event, Resource},
system::SystemState,
};

use naia_bevy_shared::{
Channel, ChannelKind, ComponentKind, Message, MessageContainer, MessageKind, Replicate,
Expand All @@ -20,6 +25,12 @@ pub struct DisconnectEvent(pub UserKey, pub User);
#[derive(Event)]
pub struct ErrorEvent(pub NaiaServerError);

// TickEventReader
#[derive(Resource)]
pub(crate) struct CachedTickEventsState {
pub(crate) event_state: SystemState<EventReader<'static, 'static, TickEvent>>,
}

// TickEvent
#[derive(Event)]
pub struct TickEvent(pub Tick);
Expand Down
12 changes: 8 additions & 4 deletions adapters/bevy/server/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{ops::DerefMut, sync::Mutex};

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

use naia_bevy_shared::{BeforeReceiveEvents, Protocol, SharedPlugin};
use naia_bevy_shared::{BeforeReceiveEvents, Protocol, SendPackets, SharedPlugin};
use naia_server::{Server, ServerConfig};

use super::{
Expand All @@ -13,7 +13,7 @@ use super::{
RequestEvents, SpawnEntityEvent, TickEvent, UnpublishEntityEvent, UpdateComponentEvents,
},
server::ServerWrapper,
systems::before_receive_events,
systems::{before_receive_events, send_packets, send_packets_init},
};

struct PluginConfig {
Expand Down Expand Up @@ -77,7 +77,11 @@ impl PluginType for Plugin {
.add_event::<InsertComponentEvents>()
.add_event::<UpdateComponentEvents>()
.add_event::<RemoveComponentEvents>()
// SYSTEM SETS //
.configure_sets(Last, SendPackets)
// SYSTEMS //
.add_systems(Update, before_receive_events.in_set(BeforeReceiveEvents));
.add_systems(Update, before_receive_events.in_set(BeforeReceiveEvents))
.add_systems(Startup, send_packets_init)
.add_systems(Update, send_packets.in_set(SendPackets));
}
}
10 changes: 10 additions & 0 deletions adapters/bevy/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ impl<'w> Server<'w> {
self.server.0.average_tick_duration()
}

//// Network Conditions ////

pub fn jitter(&self, user_key: &UserKey) -> Option<f32> {
self.server.0.jitter(user_key)
}

pub fn rtt(&self, user_key: &UserKey) -> Option<f32> {
self.server.0.rtt(user_key)
}

// Entity Replication

pub(crate) fn enable_replication(&mut self, entity: &Entity) {
Expand Down
Loading

0 comments on commit f06d749

Please sign in to comment.