Skip to main content

BaseConnection

Struct BaseConnection 

Source
pub struct BaseConnection {
    pub message_manager: MessageManager,
    pub world_manager: LocalWorldManager,
    /* private fields */
}
Expand description

Represents a connection to a remote host, and provides functionality to manage the connection and the communications to it

Fields§

§message_manager: MessageManager

Manages channel-routed message send/receive queues for this connection.

§world_manager: LocalWorldManager

Manages entity-level replication state for this connection.

Implementations§

Source§

impl BaseConnection

Source

pub fn new( connection_config: &ConnectionConfig, address: &Option<SocketAddr>, host_type: HostType, user_key: u64, channel_kinds: &ChannelKinds, global_world_manager: &dyn GlobalWorldManagerType, ) -> Self

Create a new BaseConnection, given the appropriate underlying managers

Source

pub fn accumulate_bandwidth(&mut self, now: &Instant)

Tick the bandwidth accumulator, adding target_bytes_per_sec × dt to the budget and refreshing the one-packet-overshoot allowance.

Source

pub fn can_spend_bandwidth(&self, estimated_bytes: u32) -> bool

Check whether a packet of estimated_bytes is permitted under the current budget. Allows one MTU-sized overshoot per tick when the budget is positive but short.

Source

pub fn spend_bandwidth(&mut self, actual_bytes: u32)

Subtract actual_bytes from the bandwidth budget after a send.

Source

pub fn bandwidth_remaining(&self) -> f64

Current remaining budget (may be negative after overshoot).

Source

pub fn bandwidth_bytes_sent_last_tick(&self) -> u64

Bytes sent during the most-recently-completed send cycle (D13 telemetry).

Source

pub fn bandwidth_packets_deferred_last_tick(&self) -> u32

Packets deferred by the budget gate during the most-recently-completed send cycle. Always 0 unless bench_instrumentation is enabled.

Source

pub fn record_bandwidth_deferred(&mut self)

Record that a packet was deferred by the budget gate this cycle. Invoked from send loops when can_spend_bandwidth returns false.

Source

pub fn mark_sent(&mut self)

Record that a message has been sent (to prevent needing to send a heartbeat)

Source

pub fn should_send_heartbeat(&self) -> bool

Returns whether a heartbeat message should be sent

Source

pub fn mark_should_send_empty_ack(&mut self)

Sets the flag requesting that an empty ack packet be sent.

Source

pub fn should_send_empty_ack(&self) -> bool

Returns true if an empty ack should be sent this tick.

Source

pub fn take_should_send_empty_ack(&mut self) -> bool

Returns the empty-ack flag and clears it atomically.

Source

pub fn process_incoming_header( &mut self, header: &StandardHeader, packet_notifiables: &mut [&mut dyn PacketNotifiable], )

Process an incoming packet, pulling out the packet index number to keep track of the current RTT, and sending the packet to the AckManager to handle packet notification events

Source

pub fn write_header( &mut self, packet_type: PacketType, writer: &mut BitWriter, ) -> StandardHeader

Given a packet payload, start tracking the packet via it’s index, attach the appropriate header, and return the packet’s resulting underlying bytes

Source

pub fn next_packet_index(&self) -> PacketIndex

Get the next outgoing packet’s index

Source

pub fn last_received_packet_index(&self) -> PacketIndex

Returns the sequence index of the last received packet from the remote.

Source

pub fn packet_loss_pct(&self) -> f32

Fraction of sent data-packets that were lost in the last 64-packet window.

Source

pub fn collect_messages(&mut self, now: &Instant, rtt_millis: &f32)

Drains pending world-manager and message-manager outbound queues into writeable packets.

Source

pub fn write_packet<E: Copy + Eq + Hash + Sync + Send, W: WorldRefType<E>>( &mut self, channel_kinds: &ChannelKinds, message_kinds: &MessageKinds, component_kinds: &ComponentKinds, now: &Instant, writer: &mut BitWriter, packet_index: PacketIndex, world: &W, entity_converter: &dyn EntityAndGlobalEntityConverter<E>, global_world_manager: &dyn GlobalWorldManagerType, has_written: &mut bool, write_world_events: bool, host_world_events: &mut VecDeque<(MessageIndex, EntityCommand)>, update_events: &mut HashMap<GlobalEntity, HashSet<ComponentKind>>, entity_priority_order: Option<&[GlobalEntity]>, )

Serializes messages and world events into writer for the outgoing packet at packet_index.

Source

pub fn read_packet( &mut self, channel_kinds: &ChannelKinds, message_kinds: &MessageKinds, component_kinds: &ComponentKinds, tick: &Tick, read_world_events: bool, reader: &mut BitReader<'_>, ) -> Result<(), SerdeErr>

Deserializes an incoming packet, routing messages and world events to their managers.

Auto Trait Implementations§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V