Skip to main content

Scene

Struct Scene 

Source
pub struct Scene {
    pub world: World,
    pub settings: SceneSettings,
    pub signals: SignalBus,
    pub audio: AudioBus,
    pub globals: BTreeMap<String, Value>,
}
Expand description

ECS world plus environment settings. Default registers every built-in component.

Serialized scenes omit transient entities and rebuild world transforms on load. Entity handles are remapped on load and must not be persisted outside the scene.

Fields§

§world: World

Live entity/component storage, including runtime-only components.

§settings: SceneSettings

Scene lighting, physics and display configuration.

§signals: SignalBus

Bounded next-frame script messages. Not serialized or copied into scene snapshots.

§audio: AudioBus

Sound requests for the shell’s audio backend. Not serialized.

§globals: BTreeMap<String, Value>

Named values shared by all scripts (score, difficulty…). Not serialized; see Ctx::set_global.

Implementations§

Source§

impl Scene

Source

pub fn to_json(&self, reg: &Registry) -> String

Serializes persistent entities and registered components as pretty JSON. Runtime-only state is omitted. Prefer Self::try_to_json when saving files.

Source

pub fn try_to_json(&self, reg: &Registry) -> Result<String, String>

Serializes a scene, reporting JSON encoding errors instead of returning an empty string. Component serializers in the registry may omit components they cannot encode.

Source

pub fn from_json( reg: &Registry, text: &str, ) -> Result<(Scene, Vec<String>), String>

Returns the scene and any non-fatal warnings (unknown or malformed components).

Source

pub fn add_json( &mut self, reg: &Registry, text: &str, ) -> Result<Vec<String>, String>

Adds every object of a scene file to this scene (its settings are ignored). Returns the warnings of the load; the new root objects keep their places.

Source

pub fn load(reg: &Registry, path: &Path) -> Result<(Scene, Vec<String>), String>

Loads a UTF-8 JSON scene from disk, preserving non-fatal component/hierarchy warnings.

Source

pub fn save(&self, reg: &Registry, path: &Path) -> Result<(), String>

Saves persistent scene data. Parent directories must already exist.

Source

pub fn snapshot(&self, reg: &Registry) -> Result<(Scene, Vec<String>), String>

Creates an independent persistent snapshot, omitting transient/runtime-only state. Returns the same warnings as loading the serialized scene.

Source

pub fn validate(&self, reg: &Registry) -> Vec<String>

Reports persistence errors, dangling parents and hierarchy cycles without mutation. Missing transforms are allowed by the ECS but reported here for editor-visible entities. This explicit diagnostic pass does not run automatically on every gameplay tick.

Source

pub fn spawn(&mut self, name: &str) -> Entity

Spawns a named entity with an identity local transform.

Source

pub fn find(&self, name: &str) -> Option<Entity>

First exact name match, if present. Entity names need not be unique.

Source

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

Removes an entity and its complete subtree, including transient children.

Trait Implementations§

Source§

impl Default for Scene

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Scene

§

impl !Send for Scene

§

impl !Sync for Scene

§

impl !UnwindSafe for Scene

§

impl Freeze for Scene

§

impl Unpin for Scene

§

impl UnsafeUnpin for Scene

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<T> Downcast for T
where T: Any,

§

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

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

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

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

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.