pub struct Client<E: Copy + Eq + Hash + Send + Sync> { /* private fields */ }Expand description
Client can send/receive messages to/from a server, and has a pool of in-scope entities/components that are synced with the server
Implementations§
Source§impl<E: Copy + Eq + Hash + Send + Sync> Client<E>
impl<E: Copy + Eq + Hash + Send + Sync> Client<E>
Sourcepub fn new<P: Into<Protocol>>(client_config: ClientConfig, protocol: P) -> Self
pub fn new<P: Into<Protocol>>(client_config: ClientConfig, protocol: P) -> Self
Create a new Client
Sourcepub fn auth<M: Message>(&mut self, auth: M)
pub fn auth<M: Message>(&mut self, auth: M)
Set the auth object to use when setting up a connection with the Server
pub fn auth_headers(&mut self, headers: Vec<(String, String)>)
Sourcepub fn connect<S: Into<Box<dyn Socket>>>(&mut self, socket: S)
pub fn connect<S: Into<Box<dyn Socket>>>(&mut self, socket: S)
Connect to the given server address
Sourcepub fn connection_status(&self) -> ConnectionStatus
pub fn connection_status(&self) -> ConnectionStatus
Returns client’s current connection status
Sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Disconnect from Server
Sourcepub fn socket_config(&self) -> &SocketConfig
pub fn socket_config(&self) -> &SocketConfig
Returns socket config
Sourcepub fn receive<W: WorldMutType<E>>(&mut self, world: W) -> Events<E>
pub fn receive<W: WorldMutType<E>>(&mut self, world: W) -> Events<E>
Must call this regularly (preferably at the beginning of every draw frame), in a loop until it returns None. Retrieves incoming update data from the server, and maintains the connection.
Sourcepub fn send_message<C: Channel, M: Message>(&mut self, message: &M)
pub fn send_message<C: Channel, M: Message>(&mut self, message: &M)
Queues up an Message to be sent to the Server
pub fn send_request<C: Channel, Q: Request>( &mut self, request: &Q, ) -> Result<ResponseReceiveKey<Q::Response>, NaiaClientError>
Sourcepub fn send_response<S: Response>(
&mut self,
response_key: &ResponseSendKey<S>,
response: &S,
) -> bool
pub fn send_response<S: Response>( &mut self, response_key: &ResponseSendKey<S>, response: &S, ) -> bool
Sends a Response for a given Request. Returns whether or not was successful.
pub fn receive_response<S: Response>( &mut self, response_key: &ResponseReceiveKey<S>, ) -> Option<S>
pub fn send_tick_buffer_message<C: Channel, M: Message>( &mut self, tick: &Tick, message: &M, )
Sourcepub fn spawn_entity<W: WorldMutType<E>>(
&mut self,
world: W,
) -> EntityMut<'_, E, W>
pub fn spawn_entity<W: WorldMutType<E>>( &mut self, world: W, ) -> EntityMut<'_, E, W>
Creates a new Entity and returns an EntityMut which can be used for further operations on the Entity
Sourcepub fn entity<W: WorldRefType<E>>(
&self,
world: W,
entity: &E,
) -> EntityRef<'_, E, W>
pub fn entity<W: WorldRefType<E>>( &self, world: W, entity: &E, ) -> EntityRef<'_, E, W>
Retrieves an EntityRef that exposes read-only operations for the given Entity. Panics if the Entity does not exist.
Sourcepub fn entity_mut<W: WorldMutType<E>>(
&mut self,
world: W,
entity: &E,
) -> EntityMut<'_, E, W>
pub fn entity_mut<W: WorldMutType<E>>( &mut self, world: W, entity: &E, ) -> EntityMut<'_, E, W>
Retrieves an EntityMut that exposes read and write operations for the Entity. Panics if the Entity does not exist.
Sourcepub fn entities<W: WorldRefType<E>>(&self, world: &W) -> Vec<E>
pub fn entities<W: WorldRefType<E>>(&self, world: &W) -> Vec<E>
Return a list of all Entities
pub fn entity_owner(&self, entity: &E) -> EntityOwner
Sourcepub fn enable_entity_replication(&mut self, entity: &E)
pub fn enable_entity_replication(&mut self, entity: &E)
This is used only for Hecs/Bevy adapter crates, do not use otherwise!
Sourcepub fn disable_entity_replication(&mut self, entity: &E)
pub fn disable_entity_replication(&mut self, entity: &E)
This is used only for Hecs/Bevy adapter crates, do not use otherwise!
Sourcepub fn entity_replication_config(&self, entity: &E) -> Option<ReplicationConfig>
pub fn entity_replication_config(&self, entity: &E) -> Option<ReplicationConfig>
This is used only for Hecs/Bevy adapter crates, do not use otherwise!
Sourcepub fn configure_entity_replication<W: WorldMutType<E>>(
&mut self,
world: &mut W,
entity: &E,
config: ReplicationConfig,
)
pub fn configure_entity_replication<W: WorldMutType<E>>( &mut self, world: &mut W, entity: &E, config: ReplicationConfig, )
This is used only for Hecs/Bevy adapter crates, do not use otherwise!
This is used only for Hecs/Bevy adapter crates, do not use otherwise!
This is used only for Hecs/Bevy adapter crates, do not use otherwise!
This is used only for Hecs/Bevy adapter crates, do not use otherwise!
Sourcepub fn server_address(&self) -> Result<SocketAddr, NaiaClientError>
pub fn server_address(&self) -> Result<SocketAddr, NaiaClientError>
Get the address currently associated with the Server
Sourcepub fn client_tick(&self) -> Option<Tick>
pub fn client_tick(&self) -> Option<Tick>
Gets the current tick of the Client
Sourcepub fn client_instant(&self) -> Option<GameInstant>
pub fn client_instant(&self) -> Option<GameInstant>
Gets the current instant of the Client
Sourcepub fn server_tick(&self) -> Option<Tick>
pub fn server_tick(&self) -> Option<Tick>
Gets the current tick of the Server
Sourcepub fn server_instant(&self) -> Option<GameInstant>
pub fn server_instant(&self) -> Option<GameInstant>
Gets the current instant of the Server
pub fn tick_to_instant(&self, tick: Tick) -> Option<GameInstant>
pub fn tick_duration(&self) -> Option<Duration>
Sourcepub fn client_interpolation(&self) -> Option<f32>
pub fn client_interpolation(&self) -> Option<f32>
Gets the interpolation tween amount for the current frame, for use by entities on the Client Tick (i.e. predicted)
Sourcepub fn server_interpolation(&self) -> Option<f32>
pub fn server_interpolation(&self) -> Option<f32>
Gets the interpolation tween amount for the current frame, for use by entities on the Server Tick (i.e. authoritative)