pub struct Replicated { /* private fields */ }Expand description
The replicated state of a simulation.
Implementations§
Source§impl Replicated
impl Replicated
pub fn new() -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn cost(&self) -> usize
pub fn cost(&self) -> usize
Approximate memory the store holds, for limits: a fixed cost per entity and per component entry (removed ones too) plus the bytes.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove every entity but keep the change counter running, so an id spawned again afterwards gets a spawn counter no reader has seen and reads as a new entity.
pub fn get(&self, id: EntityId) -> Option<&Entity>
pub fn contains(&self, id: EntityId) -> bool
Sourcepub fn spawn(&mut self, id: EntityId, pos: [f32; 3]) -> bool
pub fn spawn(&mut self, id: EntityId, pos: [f32; 3]) -> bool
Add an entity. Returns false (and changes nothing) when the id is taken.
Sourcepub fn despawn(&mut self, id: EntityId) -> bool
pub fn despawn(&mut self, id: EntityId) -> bool
Remove an entity. Returns false when there was none.
Sourcepub fn set_pos(&mut self, id: EntityId, pos: [f32; 3]) -> bool
pub fn set_pos(&mut self, id: EntityId, pos: [f32; 3]) -> bool
Move an entity. A position equal to the current one is not a change.
Sourcepub fn set_component(
&mut self,
id: EntityId,
component: ComponentId,
bytes: &[u8],
) -> bool
pub fn set_component( &mut self, id: EntityId, component: ComponentId, bytes: &[u8], ) -> bool
Set a component. Bytes equal to the current ones are not a change.
Sourcepub fn remove_component(&mut self, id: EntityId, component: ComponentId) -> bool
pub fn remove_component(&mut self, id: EntityId, component: ComponentId) -> bool
Remove a component. Returns false when the entity or component is missing.
Sourcepub fn record_changes(&mut self, on: bool)
pub fn record_changes(&mut self, on: bool)
Start or stop keeping a log of changes for Replicated::take_changes.
A WebAssembly shard module turns this on.
Sourcepub fn take_changes(&mut self) -> Vec<u8> ⓘ
pub fn take_changes(&mut self) -> Vec<u8> ⓘ
The changes since the last call, as bytes for
Replicated::apply_changes. Empty when recording is off.
Sourcepub fn full_changes(&self) -> Vec<u8> ⓘ
pub fn full_changes(&self) -> Vec<u8> ⓘ
Every entity and component as a change log that rebuilds this store from empty (spawns, then component sets).
Sourcepub fn apply_changes(&mut self, bytes: &[u8]) -> Result<(), ChangeError>
pub fn apply_changes(&mut self, bytes: &[u8]) -> Result<(), ChangeError>
Apply changes another store recorded. Stops at the first malformed or inconsistent change; the changes before it stay applied.
Sourcepub fn apply_changes_limited(
&mut self,
bytes: &[u8],
max_entities: usize,
max_cost: usize,
) -> Result<(), ChangeError>
pub fn apply_changes_limited( &mut self, bytes: &[u8], max_entities: usize, max_cost: usize, ) -> Result<(), ChangeError>
apply_changes for a log from an untrusted source: stops with an
error at the first change that would take the store past
max_entities or max_cost (see Replicated::cost). That change
and the rest do not apply.
Trait Implementations§
Source§impl Clone for Replicated
A clone is a different store: it gets its own id and no change log, so
a WebAssembly module that swaps one in (a round reset from a template, a
rollback) sends the host a full dump of it.
impl Clone for Replicated
A clone is a different store: it gets its own id and no change log, so a WebAssembly module that swaps one in (a round reset from a template, a rollback) sends the host a full dump of it.