pub struct LocalWorldManager { /* private fields */ }Expand description
Unified manager for one connection’s host-side and remote-side entity state, routing commands and events between them.
Implementations§
Source§impl LocalWorldManager
impl LocalWorldManager
Sourcepub fn new(
address: &Option<SocketAddr>,
host_type: HostType,
user_key: u64,
global_world_manager: &dyn GlobalWorldManagerType,
) -> Self
pub fn new( address: &Option<SocketAddr>, host_type: HostType, user_key: u64, global_world_manager: &dyn GlobalWorldManagerType, ) -> Self
Creates a LocalWorldManager for the given address, host type, user key, and global world manager reference.
Sourcepub fn entity_converter(&self) -> &dyn LocalEntityAndGlobalEntityConverter
pub fn entity_converter(&self) -> &dyn LocalEntityAndGlobalEntityConverter
Returns a read-only entity converter backed by the internal entity map.
Sourcepub fn entity_converter_mut<'a, 'b>(
&'b mut self,
global_world_manager: &'a dyn GlobalWorldManagerType,
) -> EntityConverterMut<'a, 'b>
pub fn entity_converter_mut<'a, 'b>( &'b mut self, global_world_manager: &'a dyn GlobalWorldManagerType, ) -> EntityConverterMut<'a, 'b>
Returns a mutable entity converter that can also allocate new host entity IDs.
Sourcepub fn has_global_entity(&self, global_entity: &GlobalEntity) -> bool
pub fn has_global_entity(&self, global_entity: &GlobalEntity) -> bool
Returns true if global_entity is currently tracked by either the host or remote engine.
Sourcepub fn has_local_entity(&self, local_entity: &OwnedLocalEntity) -> bool
pub fn has_local_entity(&self, local_entity: &OwnedLocalEntity) -> bool
Returns true if local_entity is currently registered in its respective engine.
Sourcepub fn get_host_entity_channel(
&self,
entity: &HostEntity,
) -> Option<&HostEntityChannel>
pub fn get_host_entity_channel( &self, entity: &HostEntity, ) -> Option<&HostEntityChannel>
Get a reference to a HostEntityChannel (for testing)
Sourcepub fn get_host_entity_channel_mut(
&mut self,
entity: &HostEntity,
) -> Option<&mut HostEntityChannel>
pub fn get_host_entity_channel_mut( &mut self, entity: &HostEntity, ) -> Option<&mut HostEntityChannel>
Get a mutable reference to a HostEntityChannel (for testing)
Sourcepub fn has_host_entity(&self, host_entity: &HostEntity) -> bool
pub fn has_host_entity(&self, host_entity: &HostEntity) -> bool
Returns true if host_entity is currently tracked by the host engine.
Sourcepub fn host_init_entity(
&mut self,
global_entity: &GlobalEntity,
component_kinds: Vec<ComponentKind>,
component_kinds_map: &ComponentKinds,
is_static: bool,
)
pub fn host_init_entity( &mut self, global_entity: &GlobalEntity, component_kinds: Vec<ComponentKind>, component_kinds_map: &ComponentKinds, is_static: bool, )
Allocates a host entity ID and enqueues the initial spawn command(s) when global_entity enters connection scope.
Sourcepub fn migrate_entity_remote_to_host(
&mut self,
global_entity: &GlobalEntity,
) -> Result<HostEntity, String>
pub fn migrate_entity_remote_to_host( &mut self, global_entity: &GlobalEntity, ) -> Result<HostEntity, String>
BULLETPROOF: Migrate entity from remote (client) control to host (server) control
This method performs a complete, atomic migration of an entity from client control to server control, including:
- Force-draining all buffered operations
- Preserving component state
- Installing entity redirects
- Updating command references
- Cleaning up old entity channels
§Errors
This method will panic if:
- The entity doesn’t exist in the local entity map
- The entity is not currently remote-owned
- Any step of the migration process fails
§Safety
This method is designed to be atomic - either the entire migration succeeds or the system remains in a consistent state. No partial migrations are possible.
Sourcepub fn host_send_enable_delegation(&mut self, global_entity: &GlobalEntity)
pub fn host_send_enable_delegation(&mut self, global_entity: &GlobalEntity)
Sends an EnableDelegation command to the remote peer via the host engine.
Sourcepub fn host_local_enable_delegation(&mut self, host_entity: &HostEntity)
pub fn host_local_enable_delegation(&mut self, host_entity: &HostEntity)
Forces the HostEntityChannel for host_entity into the Delegated state locally without sending a wire message.
Sourcepub fn host_send_migrate_response(
&mut self,
global_entity: &GlobalEntity,
old_remote_entity: &RemoteEntity,
new_host_entity: &HostEntity,
)
pub fn host_send_migrate_response( &mut self, global_entity: &GlobalEntity, old_remote_entity: &RemoteEntity, new_host_entity: &HostEntity, )
Sends a MigrateResponse command to notify the peer that an entity has migrated to the server’s control.
Sourcepub fn host_send_set_auth(
&mut self,
global_entity: &GlobalEntity,
auth_status: EntityAuthStatus,
)
pub fn host_send_set_auth( &mut self, global_entity: &GlobalEntity, auth_status: EntityAuthStatus, )
Sends a SetAuthority command for global_entity with the given auth_status.
Sourcepub fn host_reserve_entity(
&mut self,
global_entity: &GlobalEntity,
) -> HostEntity
pub fn host_reserve_entity( &mut self, global_entity: &GlobalEntity, ) -> HostEntity
Pre-allocates a HostEntity slot for global_entity before it is sent to the peer.
Sourcepub fn host_remove_reserved_entity(
&mut self,
global_entity: &GlobalEntity,
) -> Option<HostEntity>
pub fn host_remove_reserved_entity( &mut self, global_entity: &GlobalEntity, ) -> Option<HostEntity>
Removes and returns any previously reserved HostEntity for global_entity, if one exists.
Sourcepub fn remote_entities(&self) -> Vec<GlobalEntity>
pub fn remote_entities(&self) -> Vec<GlobalEntity>
Returns the GlobalEntity list for all entities currently tracked as remote-owned.
Sourcepub fn send_enable_delegation_response(&mut self, global_entity: &GlobalEntity)
pub fn send_enable_delegation_response(&mut self, global_entity: &GlobalEntity)
Sends an EnableDelegationResponse acknowledgement to the server after receiving an EnableDelegation message.
Sourcepub fn remote_send_request_auth(&mut self, global_entity: &GlobalEntity)
pub fn remote_send_request_auth(&mut self, global_entity: &GlobalEntity)
Sends a RequestAuthority command for global_entity via the remote engine.
Sourcepub fn remote_receive_set_auth(
&mut self,
global_entity: &GlobalEntity,
auth_status: EntityAuthStatus,
)
pub fn remote_receive_set_auth( &mut self, global_entity: &GlobalEntity, auth_status: EntityAuthStatus, )
Update the RemoteEntityChannel’s AuthChannel status (used after migration)
Sourcepub fn get_remote_entity_auth_status(
&self,
global_entity: &GlobalEntity,
) -> Option<EntityAuthStatus>
pub fn get_remote_entity_auth_status( &self, global_entity: &GlobalEntity, ) -> Option<EntityAuthStatus>
Get auth status of a remote entity’s channel (for testing)
Sourcepub fn entity_waitlist_mut(&mut self) -> &mut RemoteEntityWaitlist
pub fn entity_waitlist_mut(&mut self) -> &mut RemoteEntityWaitlist
Returns a mutable reference to the entity waitlist managed by the remote engine.
Sourcepub fn receiver_buffer_message(
&mut self,
id: MessageIndex,
msg: EntityMessage<OwnedLocalEntity>,
)
pub fn receiver_buffer_message( &mut self, id: MessageIndex, msg: EntityMessage<OwnedLocalEntity>, )
Buffers an incoming entity message at the given sequence id for ordered delivery.
Sourcepub fn take_incoming_events<E: Copy + Eq + Hash + Send + Sync, W: WorldMutType<E>>(
&mut self,
spawner: &mut dyn GlobalEntitySpawner<E>,
global_world_manager: &dyn GlobalWorldManagerType,
component_kinds: &ComponentKinds,
world: &mut W,
now: &Instant,
) -> Vec<EntityEvent>
pub fn take_incoming_events<E: Copy + Eq + Hash + Send + Sync, W: WorldMutType<E>>( &mut self, spawner: &mut dyn GlobalEntitySpawner<E>, global_world_manager: &dyn GlobalWorldManagerType, component_kinds: &ComponentKinds, world: &mut W, now: &Instant, ) -> Vec<EntityEvent>
Drains all buffered incoming messages and update events, applies them to world, and returns the resulting EntityEvents.
Sourcepub fn register_authed_entity(
&mut self,
global_manager: &dyn GlobalWorldManagerType,
global_entity: &GlobalEntity,
)
pub fn register_authed_entity( &mut self, global_manager: &dyn GlobalWorldManagerType, global_entity: &GlobalEntity, )
Registers global_entity as authority-granted, enabling update tracking for its components.
Sourcepub fn deregister_authed_entity(
&mut self,
global_manager: &dyn GlobalWorldManagerType,
global_entity: &GlobalEntity,
)
pub fn deregister_authed_entity( &mut self, global_manager: &dyn GlobalWorldManagerType, global_entity: &GlobalEntity, )
Deregisters global_entity from authority, stopping update tracking for its components.
Sourcepub fn remote_spawn_entity(&mut self, global_entity: &GlobalEntity)
pub fn remote_spawn_entity(&mut self, global_entity: &GlobalEntity)
Notifies the remote waitlist that global_entity’s remote entity has been spawned.
Sourcepub fn remote_despawn_entity(&mut self, global_entity: &GlobalEntity)
pub fn remote_despawn_entity(&mut self, global_entity: &GlobalEntity)
Despawns the remote entity mapped from global_entity and cleans up the entity map.
Sourcepub fn despawn_entity(&mut self, global_entity: &GlobalEntity)
pub fn despawn_entity(&mut self, global_entity: &GlobalEntity)
Sends a Despawn command for global_entity through whichever engine owns it.
Sourcepub fn pause_entity(&mut self, global_entity: &GlobalEntity)
pub fn pause_entity(&mut self, global_entity: &GlobalEntity)
Pause replication for a ScopeExit::Persist entity that has left scope.
The entity stays in the client’s entity pool; no further updates are sent
until resume_entity is called on re-entry.
Sourcepub fn resume_entity(&mut self, global_entity: &GlobalEntity)
pub fn resume_entity(&mut self, global_entity: &GlobalEntity)
Resume replication for a paused ScopeExit::Persist entity that has re-entered scope.
Accumulated deltas will be delivered on the next update cycle.
Sourcepub fn is_entity_paused(&self, global_entity: &GlobalEntity) -> bool
pub fn is_entity_paused(&self, global_entity: &GlobalEntity) -> bool
Returns true if global_entity is currently paused (scope-exited with ScopeExit::Persist).
Sourcepub fn insert_component(
&mut self,
global_entity: &GlobalEntity,
component_kind: &ComponentKind,
)
pub fn insert_component( &mut self, global_entity: &GlobalEntity, component_kind: &ComponentKind, )
Sends an InsertComponent command for global_entity, routing through host or remote engine as appropriate.
Sourcepub fn remove_component(
&mut self,
global_entity: &GlobalEntity,
component_kind: &ComponentKind,
)
pub fn remove_component( &mut self, global_entity: &GlobalEntity, component_kind: &ComponentKind, )
Sends a RemoveComponent command for global_entity, routing through host or remote engine as appropriate.
Sourcepub fn send_publish(
&mut self,
host_type: HostType,
global_entity: &GlobalEntity,
)
pub fn send_publish( &mut self, host_type: HostType, global_entity: &GlobalEntity, )
Sends a Publish command for global_entity, routing through host or remote engine based on ownership.
Sourcepub fn send_unpublish(
&mut self,
host_type: HostType,
global_entity: &GlobalEntity,
)
pub fn send_unpublish( &mut self, host_type: HostType, global_entity: &GlobalEntity, )
Sends an Unpublish command for global_entity, routing through host or remote engine based on ownership.
Sourcepub fn send_enable_delegation(
&mut self,
host_type: HostType,
origin_is_owning_client: bool,
global_entity: &GlobalEntity,
)
pub fn send_enable_delegation( &mut self, host_type: HostType, origin_is_owning_client: bool, global_entity: &GlobalEntity, )
Sends an EnableDelegation command (with optional preceding Publish) for global_entity.
Sourcepub fn send_disable_delegation(&mut self, global_entity: &GlobalEntity)
pub fn send_disable_delegation(&mut self, global_entity: &GlobalEntity)
Sends a DisableDelegation command for global_entity via the host engine.
Sourcepub fn remote_send_release_auth(&mut self, global_entity: &GlobalEntity)
pub fn remote_send_release_auth(&mut self, global_entity: &GlobalEntity)
Sends a ReleaseAuthority command for global_entity, routing through whichever engine owns it.
Sourcepub fn collect_messages(&mut self, now: &Instant, rtt_millis: &f32)
pub fn collect_messages(&mut self, now: &Instant, rtt_millis: &f32)
Processes dropped packet TTLs and handles update-packet retransmit logic for the current tick.
Sourcepub fn take_outgoing_events<E: Copy + Eq + Hash + Send + Sync, W: WorldRefType<E>>(
&mut self,
now: &Instant,
rtt_millis: &f32,
world: &W,
converter: &dyn EntityAndGlobalEntityConverter<E>,
global_world_manager: &dyn GlobalWorldManagerType,
) -> (VecDeque<(MessageIndex, EntityCommand)>, HashMap<GlobalEntity, HashSet<ComponentKind>>)
pub fn take_outgoing_events<E: Copy + Eq + Hash + Send + Sync, W: WorldRefType<E>>( &mut self, now: &Instant, rtt_millis: &f32, world: &W, converter: &dyn EntityAndGlobalEntityConverter<E>, global_world_manager: &dyn GlobalWorldManagerType, ) -> (VecDeque<(MessageIndex, EntityCommand)>, HashMap<GlobalEntity, HashSet<ComponentKind>>)
Collects pending outbound commands and component-update events, returning them as a pair of command queue and dirty-component map.
Sourcepub fn process_delivered_commands(&mut self)
pub fn process_delivered_commands(&mut self)
Advances the delivery state machine, applying any newly acknowledged host-side commands to the delivered engine.
Sourcepub fn take_update_events<E: Copy + Eq + Hash + Send + Sync, W: WorldRefType<E>>(
&mut self,
world: &W,
world_converter: &dyn EntityAndGlobalEntityConverter<E>,
global_world_manager: &dyn GlobalWorldManagerType,
) -> HashMap<GlobalEntity, HashSet<ComponentKind>>
pub fn take_update_events<E: Copy + Eq + Hash + Send + Sync, W: WorldRefType<E>>( &mut self, world: &W, world_converter: &dyn EntityAndGlobalEntityConverter<E>, global_world_manager: &dyn GlobalWorldManagerType, ) -> HashMap<GlobalEntity, HashSet<ComponentKind>>
Builds the dirty-component map for the current tick from mutation receivers and the world state.
Sourcepub fn get_message_processor_helpers(
&mut self,
) -> (&dyn LocalEntityAndGlobalEntityConverter, &mut RemoteEntityWaitlist)
pub fn get_message_processor_helpers( &mut self, ) -> (&dyn LocalEntityAndGlobalEntityConverter, &mut RemoteEntityWaitlist)
Returns the entity converter and entity waitlist as a pair, used during message deserialization.
Sourcepub fn update_sent_command_entity_refs(
&mut self,
_global_entity: &GlobalEntity,
old_entity: OwnedLocalEntity,
new_entity: OwnedLocalEntity,
)
pub fn update_sent_command_entity_refs( &mut self, _global_entity: &GlobalEntity, old_entity: OwnedLocalEntity, new_entity: OwnedLocalEntity, )
Patches all in-flight command packets to replace old_entity references with new_entity.
Sourcepub fn extract_host_entity_commands(
&mut self,
global_entity: &GlobalEntity,
) -> Vec<EntityCommand>
pub fn extract_host_entity_commands( &mut self, global_entity: &GlobalEntity, ) -> Vec<EntityCommand>
Extracts and returns all pending EntityCommands from the host engine channel for global_entity.
Sourcepub fn extract_host_component_kinds(
&self,
global_entity: &GlobalEntity,
) -> HashSet<ComponentKind>
pub fn extract_host_component_kinds( &self, global_entity: &GlobalEntity, ) -> HashSet<ComponentKind>
Returns the set of component kinds currently registered on the host engine channel for global_entity.
Sourcepub fn remove_host_entity(&mut self, global_entity: &GlobalEntity)
pub fn remove_host_entity(&mut self, global_entity: &GlobalEntity)
Removes the host engine channel and entity map entry for global_entity.
Sourcepub fn insert_remote_entity(
&mut self,
global_entity: &GlobalEntity,
remote_entity: RemoteEntity,
component_kinds: HashSet<ComponentKind>,
)
pub fn insert_remote_entity( &mut self, global_entity: &GlobalEntity, remote_entity: RemoteEntity, component_kinds: HashSet<ComponentKind>, )
Registers a remote entity migrated from the host side into the remote engine with an initial component set.
Sourcepub fn install_entity_redirect(
&mut self,
old: OwnedLocalEntity,
new: OwnedLocalEntity,
)
pub fn install_entity_redirect( &mut self, old: OwnedLocalEntity, new: OwnedLocalEntity, )
Installs a redirect so lookups of old transparently resolve to new for a TTL period.
Sourcepub fn apply_entity_redirect(
&self,
entity: OwnedLocalEntity,
) -> OwnedLocalEntity
pub fn apply_entity_redirect( &self, entity: OwnedLocalEntity, ) -> OwnedLocalEntity
Returns the redirected entity for entity if a redirect is installed, otherwise returns entity unchanged.
Sourcepub fn replay_entity_command(
&mut self,
global_entity: &GlobalEntity,
command: EntityCommand,
)
pub fn replay_entity_command( &mut self, global_entity: &GlobalEntity, command: EntityCommand, )
Re-submits command for global_entity through the remote engine after a migration.