nimble_host_logic

Struct HostLogic

source
pub struct HostLogic<StepT: Clone + Eq + Debug + Deserialize + Serialize + Display> { /* private fields */ }
Expand description

Core logic handler for the Nimble host.

Manages connections, game sessions, and processes client commands.

Implementations§

source§

impl<StepT: Clone + Eq + Debug + Deserialize + Serialize + Display> HostLogic<StepT>

source

pub fn new(tick_id: TickId, deterministic_simulation_version: Version) -> Self

Creates a new instance of HostLogic.

§Parameters
  • tick_id: The initial tick identifier for the game session.
  • deterministic_simulation_version: The version of the deterministic simulation.
§Returns

A new HostLogic instance.

source

pub fn create_connection(&mut self) -> Option<HostConnectionId>

Creates a new connection and returns its identifier.

Allocates a unique HostConnectionId for a new client connection.

§Returns

An Option containing the new HostConnectionId if allocation is successful, or None if the limit is reached.

source

pub fn get(&self, connection_id: HostConnectionId) -> Option<&Connection<StepT>>

Retrieves a reference to a connection by its identifier.

§Parameters
  • connection_id: The HostConnectionId of the connection to retrieve.
§Returns

An Option containing a reference to the Connection if found, or None otherwise.

source

pub fn destroy_connection( &mut self, connection_id: HostConnectionId, ) -> Result<(), HostLogicError>

Destroys a connection, freeing its identifier.

§Parameters
  • connection_id: The HostConnectionId of the connection to destroy.
§Returns

A Result indicating success or a HostLogicError if the connection ID is invalid.

§Errors

HostLogicError // TODO:

source

pub const fn session(&self) -> &GameSession<StepT>

Retrieves a reference to the current game session.

§Returns

A reference to the GameSession.

source

pub fn post_update(&mut self)

Performs post-update operations after the main update cycle.

Specifically, it triggers the production of authoritative steps within the session’s combinator.

source

pub fn update( &mut self, connection_id: HostConnectionId, now: Millis, request: &ClientToHostCommands<StepT>, state_provider: &impl GameStateProvider, ) -> Result<Vec<HostToClientCommands<Step<StepT>>>, HostLogicError>

Processes an update from a client connection.

Handles incoming client commands and updates the game state accordingly.

§Parameters
  • connection_id: The HostConnectionId of the client sending the commands.
  • now: The current absolute time in milliseconds precision.
  • request: The ClientToHostCommands sent by the client.
  • state_provider: An implementation of GameStateProvider to supply game state data.
§Returns

A Result containing a vector of HostToClientCommands to be sent back to the client, or a HostLogicError if processing fails.

§Errors

HostLogicError // TODO:

Auto Trait Implementations§

§

impl<StepT> Freeze for HostLogic<StepT>

§

impl<StepT> !RefUnwindSafe for HostLogic<StepT>

§

impl<StepT> !Send for HostLogic<StepT>

§

impl<StepT> !Sync for HostLogic<StepT>

§

impl<StepT> Unpin for HostLogic<StepT>
where StepT: Unpin,

§

impl<StepT> !UnwindSafe for HostLogic<StepT>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.