Skip to main content

World

Struct World 

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

A world: its component storage, its resources, the compiled payloads it loads from, and the systems that run over all three.

Constructing one and filling it with components needs no systems, so this is the whole world for any caller that only builds or inspects content. start is what gives it systems, from the table the caller hands it.

Implementations§

Source§

impl World

Source

pub fn new() -> Self

An empty world, for contexts that have no compiled payloads (e.g. unit tests, or worlds built entirely from runtime-only components).

Source

pub fn from_payloads(blob: Box<dyn PayloadStore + Send>) -> Self

A world backed by a compiled payload store.

Source

pub fn reserve_components(&mut self, counts: &[(u8, u32)])

Pre-size the component columns from the blob manifest’s per-type record counts, so the bulk add loop that follows never reallocates mid-push.

Source

pub fn add(&mut self, component: ComponentAsset) -> Entity

Add a component loaded from a blob def, returning its minted entity so the loaders can index it by name.

Source

pub fn add_component<C: RuntimeComponent>(&mut self, c: C)

Add one component to the world.

Only a RuntimeComponent can be added: a build-only asset is consumed by the cook and never reaches a world.

Source

pub fn add_mesh<M: BakedMesh>( &mut self, mesh: M, payload: Vec<u8>, ) -> MeshHandle

Add a mesh with its baked geometry payload and return the handle a Prop references it by.

The world names the mesh itself (from the minted range) and holds the payload directly, so no compiled blob is involved; handles count up in call order, after any the build assigned.

Source

pub fn add_material(&mut self, material: Material) -> MaterialHandle

Add a material and return the handle a Prop references it by. The value’s fields are clamped into their valid ranges on the way in, the same way the cook clamps an authored material.

Source

pub fn add_environment_map(&mut self, payload: Vec<u8>) -> EnvironmentMapHandle

Add a baked image-based-lighting payload (see bake::payload::environment_map) and return its handle. The renderer lights with the map at handle 0.

Source

pub fn remove_all<C: ComponentSlot>(&mut self)

Remove and drop every component of type C.

Source

pub fn is_empty(&self) -> bool

Whether the world holds neither components nor systems.

Source

pub fn component_count(&self) -> usize

Components across every typed column.

Source

pub fn query<C: ComponentSlot>(&self) -> Iter<'_, C>

Iterate every stored component of a given type. Mirrors PipelineContext::query; useful in tests that hold a World directly.

Source

pub fn query_mut<C: ComponentSlot>(&mut self) -> IterMut<'_, C>

Mutable iteration over all components of type C. Mirror of PipelineContext::query_mut for code holding a World directly rather than a per-system PipelineContext.

Source

pub fn push<C: ComponentSlot>(&mut self, c: C) -> Entity

Push a runtime-produced component into the matching typed slot, returning its minted entity. Mirror of PipelineContext::push.

Source

pub fn get<C: ComponentSlot>(&self, entity: Entity) -> Option<&C>

Borrow one entity’s component, for code holding a World directly. Mirror of PipelineContext::get.

Source

pub fn get_mut<C: ComponentSlot>(&mut self, entity: Entity) -> Option<&mut C>

Mutably borrow one entity’s component. Mirror of PipelineContext::get_mut.

Source

pub fn insert<C: ComponentSlot>(&mut self, entity: Entity, c: C)

Add a component to an existing entity. Mirror of PipelineContext::insert.

Source

pub fn replace_component( &mut self, entity: Entity, asset: ComponentAsset, ) -> bool

Overwrite an existing component with a rebuilt one, keeping the entity and its other components. false when the entity holds no component of that type. An editing tool that rebuilds one component from changed authoring data writes it back through here rather than reloading the world around it.

Source

pub fn is_alive(&self, entity: Entity) -> bool

Whether an entity is still live. Mirror of PipelineContext::is_alive; guards name-index resolves against entities despawned by the start-time drains (Window, GraphicsConfig, Scene, …).

Source

pub fn despawn(&mut self, entity: Entity)

Despawn an entity (all its components, recycling its id). Stands in for the GraphicsSystem-mediated despawn in system tests that need an entity gone before a later system step (e.g. physics-body reaping).

Source

pub fn join2<A: ComponentSlot, B: ComponentSlot>( &self, ) -> impl Iterator<Item = (Entity, &A, &B)>

Read-only join over two component types, for code holding a World directly (the decomposition round-trip tests). Mirror of PipelineContext::join2.

Source

pub fn component_census(&self) -> Vec<(u8, u32)>

How many components of each type the world holds, one entry per populated type.

Source

pub fn events<E: 'static>(&self) -> Option<&Events<E>>

Borrow the event queue for event type E, if any have been sent. Mirror of PipelineContext::events, for code holding a World directly (tests).

Source

pub fn events_mut<E: Send + 'static>(&mut self) -> &mut Events<E>

Mutably borrow (creating if absent) the event queue for event type E. Mirror of PipelineContext::events_mut, for code holding a World directly: tests, and the editor’s debug-driven command injection.

Source

pub fn insert_resource<T: Any + Send>(&mut self, value: T)

Seed (or replace) a singleton resource that persists across steps.

Source

pub fn resource<T: Any>(&self) -> Option<&T>

Borrow a published singleton resource.

Source

pub fn resource_mut<T: Any>(&mut self) -> Option<&mut T>

Mutably borrow a published singleton resource.

Source

pub fn remove_resource<T: Any>(&mut self) -> Option<T>

Withdraw a published singleton resource. Presence-keyed protocols turn off by removing their resource, so the reading system pays nothing beyond noticing the absence.

Source

pub fn profile(&self) -> &FrameProfile

Per-frame profiling data: system CPU timings and render-backend stats from the most recently completed frame.

Source

pub fn scratch_stats(&self) -> ScratchStats

What the frame scratch cost and whether it was big enough, for the memory query and the Health panel. peak is what sizes the reserve.

Source

pub fn context(&mut self) -> PipelineContext<'_>

The systems’ view of this world for one tick. The caller holds the returned context for the whole tick, so the borrow of self is what keeps the world’s data still while systems run over it.

Source

pub fn event_store(&mut self) -> &mut EventStore

The EventStore resource, created on first use. Every queue events_mut ever handed out (here or on a PipelineContext) lives in this one resource, so no per-type rotation list can fall out of sync.

Source

pub fn update_events(&mut self)

Advance every event queue once, before systems run, so each queue’s two-frame retention holds for readers that run after the writer.

Source

pub fn reset_scratch(&mut self)

Hand the whole frame’s scratch back. &mut self is the proof that no allocation from the last frame survives.

Source

pub fn release_payloads(&mut self) -> usize

Release every resident compiled payload, returning the bytes freed. Run once every system has inited and cached what it keeps.

Source

pub fn systems(&self) -> &[BuiltSystem]

The world’s systems, in schedule order.

Source

pub fn systems_mut(&mut self) -> &mut [BuiltSystem]

Mutable view of the active systems. Lets a caller holding the world downcast one system out of the boxed set and drive it from outside the per-system step (the cn debug hot-reload drive).

Source

pub fn systems_and_resources(&mut self) -> (&mut [BuiltSystem], &mut Resources)

Disjoint mutable borrows of the system list and the resource map, for a caller that drives a system against something parked in a resource (the cn debug hot-reload drive reaches the render backend that way).

Source

pub fn system_count(&self) -> usize

Systems built for this world.

Source

pub fn system_manifest(&self, table: &SystemTable) -> Vec<&'static str>

The system names table would build for this world’s current content, in run order. Runs the same gates start runs, so tooling that reports a world’s schedule cannot drift from the runtime; the probe constructs and discards each gated system, which is why constructors must stay cheap and side-effect-free. It reads the world as it stands: before start the table’s complete_world pass has not run, so a system only an injected default turns on is not listed yet, and after start has drained the gating components it reports the systems a rebuild of the CURRENT content would get, not the built set.

Source

pub fn start(&mut self, table: &SystemTable) -> Result<(), CnResult>

Build the systems table gates in for this world’s content and run their init.

Source

pub fn step(&mut self) -> StepResult

Tick – systems run in order, Done systems are removed. Returns Done when no systems remain, Stop on hard halt.

Source

pub fn take_scratch_overflows(&mut self) -> u32

Fold the frame’s declined scratch requests into the world’s running total, returning what this frame declined. A frame that outgrew the reserve fell back to the heap and still rendered, so nothing breaks; the count is what a host surfaces to say the reserve is undersized.

Trait Implementations§

Source§

impl Debug for World

Source§

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

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

impl Default for World

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !Freeze for World

§

impl !RefUnwindSafe for World

§

impl !Sync for World

§

impl !UnwindSafe for World

§

impl Send for World

§

impl Unpin for World

§

impl UnsafeUnpin for World

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