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: WorldLive entity/component storage, including runtime-only components.
settings: SceneSettingsScene lighting, physics and display configuration.
signals: SignalBusBounded next-frame script messages. Not serialized or copied into scene snapshots.
audio: AudioBusSound 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
impl Scene
Sourcepub fn to_json(&self, reg: &Registry) -> String
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.
Sourcepub fn try_to_json(&self, reg: &Registry) -> Result<String, String>
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.
Sourcepub fn from_json(
reg: &Registry,
text: &str,
) -> Result<(Scene, Vec<String>), String>
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).
Sourcepub fn add_json(
&mut self,
reg: &Registry,
text: &str,
) -> Result<Vec<String>, String>
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.
Sourcepub fn load(reg: &Registry, path: &Path) -> Result<(Scene, Vec<String>), String>
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.
Sourcepub fn save(&self, reg: &Registry, path: &Path) -> Result<(), String>
pub fn save(&self, reg: &Registry, path: &Path) -> Result<(), String>
Saves persistent scene data. Parent directories must already exist.
Sourcepub fn snapshot(&self, reg: &Registry) -> Result<(Scene, Vec<String>), String>
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.
Sourcepub fn validate(&self, reg: &Registry) -> Vec<String>
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.
Sourcepub fn spawn(&mut self, name: &str) -> Entity
pub fn spawn(&mut self, name: &str) -> Entity
Spawns a named entity with an identity local transform.
Trait Implementations§
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> 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<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>, which can then be
downcast into Box<dyn 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>, which 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.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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.