Skip to main content

GameTransport

Trait GameTransport 

Source
pub trait GameTransport: Sync + GameTransportBounds {
    // Required methods
    fn send_unreliable<'life0, 'life1, 'async_trait>(
        &'life0 self,
        client_id: ClientId,
        data: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn send_reliable<'life0, 'life1, 'async_trait>(
        &'life0 self,
        client_id: ClientId,
        data: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn broadcast_unreliable<'life0, 'life1, 'async_trait>(
        &'life0 self,
        data: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn poll_events<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Vec<NetworkEvent>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn connected_client_count<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Abstracts the underlying network transport.

§Why this exists

In Phase 1, this wraps renet. In Phase 3, this wraps quinn directly. The game loop never knows which library is underneath.

§Reliability semantics

  • send_unreliable: Fire-and-forget. Used for position updates that are invalidated by the next tick. If the packet is lost, the client simply interpolates from the last known position.
  • send_reliable: Ordered and guaranteed delivery. Used for discrete game events (damage, death, loot) where loss would desync the client.

Required Methods§

Source

fn send_unreliable<'life0, 'life1, 'async_trait>( &'life0 self, client_id: ClientId, data: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Sends an unreliable datagram to a specific client.

Returns immediately. The transport layer may silently drop this packet under congestion — this is by design for volatile data.

§Errors

Returns TransportError::ClientNotConnected if the client_id is unknown, or TransportError::PayloadTooLarge if the packet exceeds MTU.

Source

fn send_reliable<'life0, 'life1, 'async_trait>( &'life0 self, client_id: ClientId, data: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Sends a reliable, ordered message to a specific client.

The transport guarantees delivery and ordering within a single stream. Callers must not assume delivery timing — only eventual delivery.

§Errors

Returns TransportError::ClientNotConnected if the client_id is unknown, or TransportError::Io on underlying transport failure.

Source

fn broadcast_unreliable<'life0, 'life1, 'async_trait>( &'life0 self, data: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Broadcasts an unreliable datagram to all connected clients.

Useful for world-wide events (weather changes, global announcements) where individual targeting is unnecessary.

§Errors

Returns TransportError::PayloadTooLarge if the packet exceeds MTU.

Source

fn poll_events<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Vec<NetworkEvent>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Drains all pending inbound network events since the last call.

This is called exactly once per tick at the top of the game loop. Events include: client connections, disconnections, and inbound data.

Source

fn connected_client_count<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns the number of currently connected clients.

Implementors§