Skip to main content

World

Struct World 

Source
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: Camera

Implementations§

Source§

impl World

Source

pub fn new(camera: Camera) -> Self

Source

pub fn spawn_empty( &mut self, name: impl Into<String>, transform: Transform, ) -> Entity

Source

pub fn set_renderable(&mut self, entity: Entity, renderable: Renderable)

Source

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

Source

pub fn set_camera(&mut self, entity: Entity, component: CameraComponent)

Source

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

Source

pub fn set_persistent(&mut self, entity: Entity, persistent: bool)

Marks (or unmarks) entity as persistent — see World::persistent’s doc comment.

Source

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

Source

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

Source

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

Source

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

Source

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.

Source

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.

Source

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§

Source§

impl Clone for World

Source§

fn clone(&self) -> World

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

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> 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

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

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> Variant for T
where T: Any + Clone + SendSync,

§

fn as_any(&self) -> &(dyn Any + 'static)

Convert this [Variant] trait object to &dyn Any.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert this [Variant] trait object to &mut dyn Any.
§

fn as_boxed_any(self: Box<T>) -> Box<dyn Any>

Convert this [Variant] trait object to Box<dyn Any>.
§

fn type_name(&self) -> &'static str

Get the name of this type.
§

fn clone_object(&self) -> Box<dyn Variant>

Clone this [Variant] trait object.
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more