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
impl World
Sourcepub fn new() -> Self
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).
Sourcepub fn from_payloads(blob: Box<dyn PayloadStore + Send>) -> Self
pub fn from_payloads(blob: Box<dyn PayloadStore + Send>) -> Self
A world backed by a compiled payload store.
Sourcepub fn reserve_components(&mut self, counts: &[(u8, u32)])
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.
Sourcepub fn add(&mut self, component: ComponentAsset) -> Entity
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.
Sourcepub fn add_component<C: RuntimeComponent>(&mut self, c: C)
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.
Sourcepub fn add_mesh<M: BakedMesh>(
&mut self,
mesh: M,
payload: Vec<u8>,
) -> MeshHandle
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.
Sourcepub fn add_material(&mut self, material: Material) -> MaterialHandle
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.
Sourcepub fn add_environment_map(&mut self, payload: Vec<u8>) -> EnvironmentMapHandle
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.
Sourcepub fn remove_all<C: ComponentSlot>(&mut self)
pub fn remove_all<C: ComponentSlot>(&mut self)
Remove and drop every component of type C.
Sourcepub fn component_count(&self) -> usize
pub fn component_count(&self) -> usize
Components across every typed column.
Sourcepub fn query<C: ComponentSlot>(&self) -> Iter<'_, C> ⓘ
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.
Sourcepub fn query_mut<C: ComponentSlot>(&mut self) -> IterMut<'_, C> ⓘ
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.
Sourcepub fn push<C: ComponentSlot>(&mut self, c: C) -> Entity
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.
Sourcepub fn get<C: ComponentSlot>(&self, entity: Entity) -> Option<&C>
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.
Sourcepub fn get_mut<C: ComponentSlot>(&mut self, entity: Entity) -> Option<&mut C>
pub fn get_mut<C: ComponentSlot>(&mut self, entity: Entity) -> Option<&mut C>
Mutably borrow one entity’s component. Mirror of
PipelineContext::get_mut.
Sourcepub fn insert<C: ComponentSlot>(&mut self, entity: Entity, c: C)
pub fn insert<C: ComponentSlot>(&mut self, entity: Entity, c: C)
Add a component to an existing entity. Mirror of
PipelineContext::insert.
Sourcepub fn replace_component(
&mut self,
entity: Entity,
asset: ComponentAsset,
) -> bool
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.
Sourcepub fn is_alive(&self, entity: Entity) -> bool
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, …).
Sourcepub fn despawn(&mut self, entity: Entity)
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).
Sourcepub fn join2<A: ComponentSlot, B: ComponentSlot>(
&self,
) -> impl Iterator<Item = (Entity, &A, &B)>
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.
Sourcepub fn component_census(&self) -> Vec<(u8, u32)>
pub fn component_census(&self) -> Vec<(u8, u32)>
How many components of each type the world holds, one entry per populated type.
Sourcepub fn events<E: 'static>(&self) -> Option<&Events<E>>
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).
Sourcepub fn events_mut<E: Send + 'static>(&mut self) -> &mut Events<E>
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.
Sourcepub fn insert_resource<T: Any + Send>(&mut self, value: T)
pub fn insert_resource<T: Any + Send>(&mut self, value: T)
Seed (or replace) a singleton resource that persists across steps.
Sourcepub fn resource_mut<T: Any>(&mut self) -> Option<&mut T>
pub fn resource_mut<T: Any>(&mut self) -> Option<&mut T>
Mutably borrow a published singleton resource.
Sourcepub fn remove_resource<T: Any>(&mut self) -> Option<T>
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.
Sourcepub fn profile(&self) -> &FrameProfile
pub fn profile(&self) -> &FrameProfile
Per-frame profiling data: system CPU timings and render-backend stats from the most recently completed frame.
Sourcepub fn scratch_stats(&self) -> ScratchStats
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.
Sourcepub fn context(&mut self) -> PipelineContext<'_>
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.
Sourcepub fn event_store(&mut self) -> &mut EventStore
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.
Sourcepub fn update_events(&mut self)
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.
Sourcepub fn reset_scratch(&mut self)
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.
Sourcepub fn release_payloads(&mut self) -> usize
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.
Sourcepub fn systems(&self) -> &[BuiltSystem]
pub fn systems(&self) -> &[BuiltSystem]
The world’s systems, in schedule order.
Sourcepub fn systems_mut(&mut self) -> &mut [BuiltSystem]
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).
Sourcepub fn systems_and_resources(&mut self) -> (&mut [BuiltSystem], &mut Resources)
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).
Sourcepub fn system_count(&self) -> usize
pub fn system_count(&self) -> usize
Systems built for this world.
Sourcepub fn system_manifest(&self, table: &SystemTable) -> Vec<&'static str>
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.
Sourcepub fn start(&mut self, table: &SystemTable) -> Result<(), CnResult>
pub fn start(&mut self, table: &SystemTable) -> Result<(), CnResult>
Build the systems table gates in for this world’s content and run
their init.
Sourcepub fn step(&mut self) -> StepResult
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.
Sourcepub fn take_scratch_overflows(&mut self) -> u32
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.