pub trait WorldState: Send {
// Required methods
fn get_local_id(&self, network_id: NetworkId) -> Option<LocalId>;
fn get_network_id(&self, local_id: LocalId) -> Option<NetworkId>;
fn extract_deltas(&mut self) -> Vec<ReplicationEvent>;
fn apply_updates(&mut self, updates: &[(ClientId, ComponentUpdate)]);
fn spawn_networked(&mut self) -> NetworkId;
fn despawn_networked(
&mut self,
network_id: NetworkId,
) -> Result<(), WorldError>;
// Provided methods
fn advance_tick(&mut self) { ... }
fn simulate(&mut self) { ... }
fn spawn_networked_for(&mut self, _client_id: ClientId) -> NetworkId { ... }
fn stress_test(&mut self, _count: u16, _rotate: bool) { ... }
fn spawn_kind(
&mut self,
_kind: u16,
_x: f32,
_y: f32,
_rot: f32,
) -> NetworkId { ... }
fn clear_world(&mut self) { ... }
}Expand description
The ECS Facade. Translates between the engine’s protocol-level types and the concrete ECS’s internal representation.
§Why this exists
Bevy uses Entity, an opaque 64-bit handle with generation bits.
Our network protocol uses NetworkId, a globally unique u64.
This trait is the translation layer. The game loop never touches
a Bevy Entity directly — it only speaks NetworkId.
§Delta extraction
On every tick, modified components are detected and emitted as
ReplicationEvent items. Only changed fields are sent — never the full
component. This is the foundation of delta compression.
Required Methods§
Sourcefn get_local_id(&self, network_id: NetworkId) -> Option<LocalId>
fn get_local_id(&self, network_id: NetworkId) -> Option<LocalId>
Maps a protocol-level NetworkId to the ECS’s local entity handle.
Returns None if the entity has been despawned or never existed.
Sourcefn get_network_id(&self, local_id: LocalId) -> Option<NetworkId>
fn get_network_id(&self, local_id: LocalId) -> Option<NetworkId>
Maps a local ECS entity handle back to its protocol-level NetworkId.
Returns None if the entity is not network-replicated.
Sourcefn extract_deltas(&mut self) -> Vec<ReplicationEvent>
fn extract_deltas(&mut self) -> Vec<ReplicationEvent>
Extracts replication deltas for all components modified since the last tick.
The returned events contain only the changed fields, not full snapshots.
The caller (the game loop) never interprets these events — it passes them
directly to the Encoder for serialization.
Sourcefn apply_updates(&mut self, updates: &[(ClientId, ComponentUpdate)])
fn apply_updates(&mut self, updates: &[(ClientId, ComponentUpdate)])
Injects parsed state updates from the network into the ECS.
On the server, these are client inputs (movement commands, actions). On the client, these are authoritative state corrections from the server.
The ClientId in the update pair provides context for ownership verification
to prevent unauthorized updates from malicious clients.
Sourcefn spawn_networked(&mut self) -> NetworkId
fn spawn_networked(&mut self) -> NetworkId
Spawns a new network-replicated entity and returns its NetworkId.
Sourcefn despawn_networked(&mut self, network_id: NetworkId) -> Result<(), WorldError>
fn despawn_networked(&mut self, network_id: NetworkId) -> Result<(), WorldError>
Despawn a network-replicated entity by its NetworkId.
§Errors
Returns WorldError if the entity with the given network_id does not exist.
Provided Methods§
Sourcefn advance_tick(&mut self)
fn advance_tick(&mut self)
Advances the world change tick at the start of each server tick, before inputs are applied.
Sourcefn spawn_networked_for(&mut self, _client_id: ClientId) -> NetworkId
fn spawn_networked_for(&mut self, _client_id: ClientId) -> NetworkId
Spawns a new network-replicated entity owned by a specific client.
Sourcefn stress_test(&mut self, _count: u16, _rotate: bool)
fn stress_test(&mut self, _count: u16, _rotate: bool)
Triggers a bulk spawn of entities for stress testing.
Sourcefn spawn_kind(&mut self, _kind: u16, _x: f32, _y: f32, _rot: f32) -> NetworkId
fn spawn_kind(&mut self, _kind: u16, _x: f32, _y: f32, _rot: f32) -> NetworkId
Spawns a new network-replicated entity of a specific kind.
Sourcefn clear_world(&mut self)
fn clear_world(&mut self)
Despawns all entities from the world.