pub struct World {
pub transforms: ComponentStore<Transform>,
pub names: ComponentStore<Name>,
pub renderables: ComponentStore<Renderable>,
pub scripts: ComponentStore<ScriptList>,
pub cameras: ComponentStore<CameraComponent>,
pub persistent: ComponentStore<()>,
pub camera: Camera,
/* private fields */
}Expand description
A spatial container of entities, distinct from crate::scene::Scene (which means
“game state/screen” in this framework, not a place). Each entity is a Transform plus a
Renderable and an optional Name.
Clone is cheap and GPU-allocation-free: a cloned Renderable’s wgpu::Buffer/
wgpu::BindGroup handles are refcount copies of the same GPU resource, not duplicates (wgpu
itself derives Clone for both). The editor relies on this to snapshot the whole World
before entering Play and restore it wholesale on Stop.
Fields§
§transforms: ComponentStore<Transform>§names: ComponentStore<Name>§renderables: ComponentStore<Renderable>§scripts: ComponentStore<ScriptList>§cameras: ComponentStore<CameraComponent>§persistent: ComponentStore<()>Marks an entity as surviving a scene change (WorldCommand::ChangeScene) instead of being
torn down with the rest of the outgoing scene — Unity’s DontDestroyOnLoad. A plain
ComponentStore<()> marker, mirroring how CameraComponent::active flags “the” active
camera, since most entities never need it. Deliberately not part of EntityRecord/
SceneFile — like DontDestroyOnLoad itself, it’s a runtime-only script call
(entity.set_persistent(true)), not an authorable/serialized property.
camera: CameraImplementations§
Source§impl World
impl World
pub fn new(camera: Camera) -> Self
pub fn spawn_empty( &mut self, name: impl Into<String>, transform: Transform, ) -> Entity
pub fn set_renderable(&mut self, entity: Entity, renderable: Renderable)
pub fn clear_renderable(&mut self, entity: Entity)
pub fn set_camera(&mut self, entity: Entity, component: CameraComponent)
pub fn clear_camera(&mut self, entity: Entity)
Sourcepub fn set_persistent(&mut self, entity: Entity, persistent: bool)
pub fn set_persistent(&mut self, entity: Entity, persistent: bool)
Marks (or unmarks) entity as persistent — see World::persistent’s doc comment.
pub fn is_persistent(&self, entity: Entity) -> bool
pub fn despawn(&mut self, entity: Entity)
pub fn is_alive(&self, entity: Entity) -> bool
Sourcepub fn iter_entities(&self) -> impl Iterator<Item = Entity> + '_
pub fn iter_entities(&self) -> impl Iterator<Item = Entity> + '_
Every live entity (every entity has a Transform, so iterating that store enumerates
them all — unlike renderables, which only some entities have).
Sourcepub fn despawn_non_persistent(&mut self)
pub fn despawn_non_persistent(&mut self)
Despawns every entity except ones marked persistent — the “full teardown” half of a scene
change (see WorldCommand::ChangeScene’s handling in ScriptRuntime::drain_commands).
Collects into a Vec first since despawn mutates the same transforms store
iter_entities reads from.
Sourcepub fn sync_transforms(&mut self)
pub fn sync_transforms(&mut self)
Syncs every entity’s ECS Transform into its Renderable’s own GPU-facing matrix.
Call once per frame before drawing.
Sourcepub fn active_camera(&self, aspect: f32) -> Option<Camera>
pub fn active_camera(&self, aspect: f32) -> Option<Camera>
The derived Camera for whichever entity has CameraComponent::active set, if any —
what Play mode pushes to the renderer in place of the edit-mode fly camera. aspect is
threaded through rather than read off self.camera so the caller can supply the current
viewport’s aspect the same frame it’s computed.
Returns None if no entity is marked active (or the active entity’s Transform is
somehow missing) — callers should fall back to whatever camera they’d otherwise use.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for World
impl !UnwindSafe for World
impl Freeze for World
impl Send for World
impl Sync for World
impl Unpin for World
impl UnsafeUnpin for World
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Variant for T
impl<T> Variant for T
§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Variant] trait object to &mut dyn Any.§fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
Variant] trait object to Box<dyn Any>.§fn clone_object(&self) -> Box<dyn Variant>
fn clone_object(&self) -> Box<dyn Variant>
Variant] trait object.