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>
impl<StepT: Clone + Eq + Debug + Deserialize + Serialize + Display> HostLogic<StepT>
Sourcepub fn create_connection(&mut self) -> Option<HostConnectionId>
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.
Sourcepub fn get(&self, connection_id: HostConnectionId) -> Option<&Connection<StepT>>
pub fn get(&self, connection_id: HostConnectionId) -> Option<&Connection<StepT>>
Sourcepub fn destroy_connection(
&mut self,
connection_id: HostConnectionId,
) -> Result<(), HostLogicError>
pub fn destroy_connection( &mut self, connection_id: HostConnectionId, ) -> Result<(), HostLogicError>
Sourcepub const fn session(&self) -> &GameSession<StepT>
pub const fn session(&self) -> &GameSession<StepT>
Sourcepub fn post_update(&mut self)
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.
Sourcepub fn update(
&mut self,
connection_id: HostConnectionId,
now: Millis,
request: &ClientToHostCommands<StepT>,
state_provider: &impl GameStateProvider,
) -> Result<Vec<HostToClientCommands<Step<StepT>>>, HostLogicError>
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: TheHostConnectionIdof the client sending the commands.now: The current absolute time in milliseconds precision.request: TheClientToHostCommandssent by the client.state_provider: An implementation ofGameStateProviderto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more