Skip to main content

Replicated

Struct Replicated 

Source
pub struct Replicated { /* private fields */ }
Expand description

The replicated state of a simulation.

Implementations§

Source§

impl Replicated

Source

pub fn new() -> Self

Source

pub fn seq(&self) -> u64

The change counter. Every change raises it by one.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

pub fn store_id(&self) -> u64

This store’s process-unique id.

Source

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.

Source

pub fn get(&self, id: EntityId) -> Option<&Entity>

Source

pub fn contains(&self, id: EntityId) -> bool

Source

pub fn iter(&self) -> impl Iterator<Item = (EntityId, &Entity)>

Entities in id order.

Source

pub fn spawn(&mut self, id: EntityId, pos: [f32; 3]) -> bool

Add an entity. Returns false (and changes nothing) when the id is taken.

Source

pub fn despawn(&mut self, id: EntityId) -> bool

Remove an entity. Returns false when there was none.

Source

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.

Source

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.

Source

pub fn remove_component(&mut self, id: EntityId, component: ComponentId) -> bool

Remove a component. Returns false when the entity or component is missing.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Replicated

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Replicated

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Replicated

Stores are equal when they hold the same entities; the id and the log are bookkeeping.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.