SceneBridge class
#include <engine/scene/bridge.hpp>
Bridge which loads and saves Scene assets.
Scenes are stored as JSON files with two top-level objects:
- "imports" - a dictionary of names to asset IDs of other scenes to import.
- "entities" - a dictionary of names to serialized entities.
Entities imported from sub-scenes can be overriden by defining them in the current scene. For example:
{ "imports": { "foo": "6f42ae5a-59d1-5df3-8720-83b8df6dd536" }, "entities": { "baz": { "cubos::engine::Position": { "x": 10 } }, "foo.bar": { "Parent": "baz", } } }
This scene will import the sub-scene with ID 6f42ae5a-59d1-5df3-8720-83b8df6dd536, and prefix all of its entities with foo.. The entity foo.bar will override the entity bar from the imported scene, while the entity baz will be added to the scene.
Base classes
- class FileBridge
- Abstract bridge type defined to reduce boilerplate code in bridge implementations which open a single file to load and save assets.
Constructors, destructors, conversion operators
-
SceneBridge(core::
reflection:: TypeRegistry components, core:: reflection:: TypeRegistry relations) - Constructs a bridge.
Public functions
-
auto components() -> core::
reflection:: TypeRegistry& - Returns the type registry used to deserialize components.
-
auto relations() -> core::
reflection:: TypeRegistry& - Returns the type registry used to deserialize relations.
Protected functions
-
auto loadFromFile(Assets& assets,
const AnyAsset& handle,
core::
memory:: Stream& stream) -> bool override - Loads an asset from a file stream.
-
auto saveToFile(const Assets& assets,
const AnyAsset& handle,
core::
memory:: Stream& stream) -> bool override - Saves an asset to a file stream.
Function documentation
cubos:: engine:: SceneBridge:: SceneBridge(core:: reflection:: TypeRegistry components,
core:: reflection:: TypeRegistry relations)
Constructs a bridge.
| Parameters | |
|---|---|
| components | Component type registry. |
| relations | Relation type registry. |
core:: reflection:: TypeRegistry& cubos:: engine:: SceneBridge:: components()
Returns the type registry used to deserialize components.
| Returns | Component type registry. |
|---|
core:: reflection:: TypeRegistry& cubos:: engine:: SceneBridge:: relations()
Returns the type registry used to deserialize relations.
| Returns | Relations type registry. |
|---|
bool cubos:: engine:: SceneBridge:: loadFromFile(Assets& assets,
const AnyAsset& handle,
core:: memory:: Stream& stream) override protected
Loads an asset from a file stream.
| Parameters | |
|---|---|
| assets | Manager to write into. |
| handle | Handle of the asset being loaded. |
| stream | File stream. |
| Returns | Whether the asset was successfully loaded. |
bool cubos:: engine:: SceneBridge:: saveToFile(const Assets& assets,
const AnyAsset& handle,
core:: memory:: Stream& stream) override protected
Saves an asset to a file stream.
| Parameters | |
|---|---|
| assets | Manager to read from. |
| handle | Handle of the asset being saved. |
| stream | File stream. |
| Returns | Whether the asset was successfully saved. |