Skip to content

Commit

Permalink
Merge pull request #198 from naia-lib/release/0.23.0
Browse files Browse the repository at this point in the history
Release/0.23.0
  • Loading branch information
connorcarpenter authored Sep 17, 2024
2 parents 31723b9 + e084bf5 commit eb05771
Show file tree
Hide file tree
Showing 228 changed files with 7,191 additions and 2,056 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

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

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

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

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

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

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

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.22.0"
version = "0.23.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.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 }
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 }
log = { version = "0.4" }
117 changes: 82 additions & 35 deletions adapters/bevy/client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,134 +1,181 @@
use std::net::SocketAddr;
use std::{marker::PhantomData, net::SocketAddr};

use bevy_ecs::{
entity::Entity,
system::{ResMut, SystemParam},
system::{ResMut, Resource, SystemParam},
};

use naia_bevy_shared::{
Channel, EntityAndGlobalEntityConverter, EntityAuthStatus, EntityDoesNotExistError,
GlobalEntity, Message, Tick,
GlobalEntity, Message, Request, Response, ResponseReceiveKey, ResponseSendKey, Tick,
};
use naia_client::{
shared::{GameInstant, SocketConfig}, transport::Socket, Client as NaiaClient, ConnectionStatus,
NaiaClientError,
};
use naia_client::{shared::SocketConfig, transport::Socket, Client as NaiaClient, NaiaClientError};

use crate::ReplicationConfig;

#[derive(Resource)]
pub struct ClientWrapper<T: Send + Sync + 'static> {
pub client: NaiaClient<Entity>,
phantom_t: PhantomData<T>,
}

impl<T: Send + Sync + 'static> ClientWrapper<T> {
pub fn new(client: NaiaClient<Entity>) -> Self {
Self {
client,
phantom_t: PhantomData,
}
}
}

// Client
#[derive(SystemParam)]
pub struct Client<'w> {
client: ResMut<'w, NaiaClient<Entity>>,
pub struct Client<'w, T: Send + Sync + 'static> {
client: ResMut<'w, ClientWrapper<T>>,
}

impl<'w> Client<'w> {
impl<'w, T: Send + Sync + 'static> Client<'w, T> {
// Public Methods //

//// Connections ////

pub fn auth<M: Message>(&mut self, auth: M) {
self.client.auth(auth);
self.client.client.auth(auth);
}

pub fn connect<S: Into<Box<dyn Socket>>>(&mut self, socket: S) {
self.client.connect(socket);
pub fn auth_headers(&mut self, headers: Vec<(String, String)>) {
self.client.client.auth_headers(headers);
}

pub fn disconnect(&mut self) {
self.client.disconnect();
pub fn connect<S: Into<Box<dyn Socket>>>(&mut self, socket: S) {
self.client.client.connect(socket);
}

pub fn is_connected(&self) -> bool {
self.client.is_connected()
pub fn disconnect(&mut self) {
self.client.client.disconnect();
}

pub fn is_connecting(&self) -> bool {
self.client.is_connecting()
pub fn connection_status(&self) -> ConnectionStatus {
self.client.client.connection_status()
}

pub fn server_address(&self) -> Result<SocketAddr, NaiaClientError> {
self.client.server_address()
self.client.client.server_address()
}

pub fn rtt(&self) -> f32 {
self.client.rtt()
self.client.client.rtt()
}

pub fn jitter(&self) -> f32 {
self.client.jitter()
self.client.client.jitter()
}

// Config
pub fn socket_config(&self) -> &SocketConfig {
self.client.socket_config()
self.client.client.socket_config()
}

//// Messages ////
pub fn send_message<C: Channel, M: Message>(&mut self, message: &M) {
self.client.send_message::<C, M>(message);
self.client.client.send_message::<C, M>(message);
}

pub fn send_tick_buffer_message<C: Channel, M: Message>(&mut self, tick: &Tick, message: &M) {
self.client.send_tick_buffer_message::<C, M>(tick, message);
self.client
.client
.send_tick_buffer_message::<C, M>(tick, message);
}

/// Requests ///
pub fn send_request<C: Channel, Q: Request>(
&mut self,
request: &Q,
) -> Result<ResponseReceiveKey<Q::Response>, NaiaClientError> {
self.client.client.send_request::<C, Q>(request)
}

pub fn send_response<S: Response>(
&mut self,
response_key: &ResponseSendKey<S>,
response: &S,
) -> bool {
self.client.client.send_response(response_key, response)
}

pub fn receive_response<S: Response>(
&mut self,
response_key: &ResponseReceiveKey<S>,
) -> Option<S> {
self.client.client.receive_response(response_key)
}

//// Ticks ////

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

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

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

// Interpolation

pub fn client_interpolation(&self) -> Option<f32> {
self.client.client_interpolation()
self.client.client.client_interpolation()
}

pub fn server_interpolation(&self) -> Option<f32> {
self.client.server_interpolation()
self.client.client.server_interpolation()
}

// Entity Registration

pub(crate) fn enable_replication(&mut self, entity: &Entity) {
self.client.enable_entity_replication(entity);
self.client.client.enable_entity_replication(entity);
}

pub(crate) fn disable_replication(&mut self, entity: &Entity) {
self.client.disable_entity_replication(entity);
self.client.client.disable_entity_replication(entity);
}

pub(crate) fn replication_config(&self, entity: &Entity) -> Option<ReplicationConfig> {
self.client.entity_replication_config(entity)
self.client.client.entity_replication_config(entity)
}

pub(crate) fn entity_request_authority(&mut self, entity: &Entity) {
self.client.entity_request_authority(entity);
self.client.client.entity_request_authority(entity);
}

pub(crate) fn entity_release_authority(&mut self, entity: &Entity) {
self.client.entity_release_authority(entity);
self.client.client.entity_release_authority(entity);
}

pub(crate) fn entity_authority_status(&self, entity: &Entity) -> Option<EntityAuthStatus> {
self.client.entity_authority_status(entity)
self.client.client.entity_authority_status(entity)
}
}

impl<'w> EntityAndGlobalEntityConverter<Entity> for Client<'w> {
impl<'w, T: Send + Sync + 'static> EntityAndGlobalEntityConverter<Entity> for Client<'w, T> {
fn global_entity_to_entity(
&self,
global_entity: &GlobalEntity,
) -> Result<Entity, EntityDoesNotExistError> {
self.client.global_entity_to_entity(global_entity)
self.client.client.global_entity_to_entity(global_entity)
}

fn entity_to_global_entity(
&self,
entity: &Entity,
) -> Result<GlobalEntity, EntityDoesNotExistError> {
self.client.entity_to_global_entity(entity)
self.client.client.entity_to_global_entity(entity)
}
}
Loading

0 comments on commit eb05771

Please sign in to comment.