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
: TheHostConnectionId
of the client sending the commands.now
: The current absolute time in milliseconds precision.request
: TheClientToHostCommands
sent by the client.state_provider
: An implementation ofGameStateProvider
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> 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