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: MessageManagerManages channel-routed message send/receive queues for this connection.
world_manager: LocalWorldManagerManages entity-level replication state for this connection.
Implementations§
Source§impl BaseConnection
impl BaseConnection
Sourcepub fn new(
connection_config: &ConnectionConfig,
address: &Option<SocketAddr>,
host_type: HostType,
user_key: u64,
channel_kinds: &ChannelKinds,
global_world_manager: &dyn GlobalWorldManagerType,
) -> Self
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
Sourcepub fn accumulate_bandwidth(&mut self, now: &Instant)
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.
Sourcepub fn can_spend_bandwidth(&self, estimated_bytes: u32) -> bool
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.
Sourcepub fn spend_bandwidth(&mut self, actual_bytes: u32)
pub fn spend_bandwidth(&mut self, actual_bytes: u32)
Subtract actual_bytes from the bandwidth budget after a send.
Sourcepub fn bandwidth_remaining(&self) -> f64
pub fn bandwidth_remaining(&self) -> f64
Current remaining budget (may be negative after overshoot).
Sourcepub fn bandwidth_bytes_sent_last_tick(&self) -> u64
pub fn bandwidth_bytes_sent_last_tick(&self) -> u64
Bytes sent during the most-recently-completed send cycle (D13 telemetry).
Sourcepub fn bandwidth_packets_deferred_last_tick(&self) -> u32
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.
Sourcepub fn record_bandwidth_deferred(&mut self)
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.
Sourcepub fn mark_sent(&mut self)
pub fn mark_sent(&mut self)
Record that a message has been sent (to prevent needing to send a heartbeat)
Sourcepub fn should_send_heartbeat(&self) -> bool
pub fn should_send_heartbeat(&self) -> bool
Returns whether a heartbeat message should be sent
Sourcepub fn mark_should_send_empty_ack(&mut self)
pub fn mark_should_send_empty_ack(&mut self)
Sets the flag requesting that an empty ack packet be sent.
Sourcepub fn should_send_empty_ack(&self) -> bool
pub fn should_send_empty_ack(&self) -> bool
Returns true if an empty ack should be sent this tick.
Sourcepub fn take_should_send_empty_ack(&mut self) -> bool
pub fn take_should_send_empty_ack(&mut self) -> bool
Returns the empty-ack flag and clears it atomically.
Sourcepub fn process_incoming_header(
&mut self,
header: &StandardHeader,
packet_notifiables: &mut [&mut dyn PacketNotifiable],
)
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
Sourcepub fn write_header(
&mut self,
packet_type: PacketType,
writer: &mut BitWriter,
) -> StandardHeader
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
Sourcepub fn next_packet_index(&self) -> PacketIndex
pub fn next_packet_index(&self) -> PacketIndex
Get the next outgoing packet’s index
Sourcepub fn last_received_packet_index(&self) -> PacketIndex
pub fn last_received_packet_index(&self) -> PacketIndex
Returns the sequence index of the last received packet from the remote.
Sourcepub fn packet_loss_pct(&self) -> f32
pub fn packet_loss_pct(&self) -> f32
Fraction of sent data-packets that were lost in the last 64-packet window.
Sourcepub fn collect_messages(&mut self, now: &Instant, rtt_millis: &f32)
pub fn collect_messages(&mut self, now: &Instant, rtt_millis: &f32)
Drains pending world-manager and message-manager outbound queues into writeable packets.
Sourcepub 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]>,
)
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.
Sourcepub 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>
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.