Engine → Scene → scene_manager.h
scene_manager
| Type | Class |
| Namespace | conjure::scene |
| Include File Path | engine/include/conjure/scene/scene_manager.h |
| Source File Path | engine/src/scene/scene_manager.cpp |
| API ↗ | Scenes, hierarchy and prefabs, Scene files, prefabs and snapshots |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | scene_manager(
ecs::world &world,
assets::asset_manager &assets); |
Important
Copy constructor and assignment has been deleted.
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~scene_manager(); | Drops the load records (and their asset handles); the scene's entities stay in the world. |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mAssets | assets::asset_manager * | nullptr | |
| private | mLayers | layer_table | {} | |
| private | mLoadOrder | std::vector<u32> | {} | |
| private | m | u32 | 2 | |
| private | mNextRequest | u32 | 1 | |
| private | m | core:: | {} | |
| private | mOnLoaded | core::event<scene_id> | {} | |
| private | m | core:: | {} | |
| private | mPending | std:: | {} | |
| private | m | std::vector<scene_id> | {} | |
| private | mRecords | std:: | {} | |
| private | mScene | scene | — | |
| private | mTransforms | transform_system | — | |
| private | mWorld | ecs::world * | nullptr |
Functions
Public
active
active[[nodiscard]] scene &active() noexcept;The one scene over the world.
[[nodiscard]] const scene &active() const noexcept;apply_pending_loads
apply_pending_loadsvoid apply_pending_loads();Body of scene.apply_pending_loads: pending unloads, then pending loads in request order (a FAILED asset drops its request with ERROR and on_load_failed; a load still in flight stops the pass).
assets
assets[[nodiscard]] assets::asset_manager &assets() noexcept;The asset manager the scene binds through and loads scene assets from.
find_loaded
find_loaded[[nodiscard]] std::optional<scene_id> find_loaded(
const assets::asset_id &asset) const noexcept;The loaded scene created from an asset, or nullopt.
info
info[[nodiscard]] std::optional<loaded_scene_info> info(
scene_id id) const;The record of a loaded scene with its current roots (gathered on each call), or nullopt.
is_load_pending
is_load_pending[[nodiscard]] bool is_load_pending(
const assets::asset_id &id) const noexcept;True while a request for the asset waits.
is_loaded
is_loaded[[nodiscard]] bool is_loaded(
scene_id id) const noexcept;True while the id names a loaded scene (unload and REPLACE loads retire ids for good).
layers
layers[[nodiscard]] layer_table &layers() noexcept;The layer names, filled by the engine from project.json.
[[nodiscard]] const layer_table &layers() const noexcept;load
load[[nodiscard]] core::result<scene_id> load(
const assets::asset_id &id,
load_mode mode = load_mode::REPLACE);Loads a scene asset synchronously (load_blocking, dependencies included) and applies it. LOAD_FAILED when the asset is not a scene or failed to load; SCENE_NOT_LOADED when an on_structure_changed handler unloads the scene before its load finishes.
load_file
load_file[[nodiscard]] core::result<scene_id> load_file(
core::vfs::file_system &fs,
std::string_view path,
load_mode mode = load_mode::REPLACE);Parses a scene file from the file system, applies it and loads the referenced assets as a batch (the record keeps the handles). SCENE_NOT_LOADED as for load.
loaded_scenes
loaded_scenes[[nodiscard]] std::vector<loaded_scene_info> loaded_scenes() const;Every loaded scene in load order, with its current roots.
on_before_unload
on_before_unload[[nodiscard]] core::event<scene_id, std::span<const ecs::entity>> &on_before_unload() noexcept;Fires before a scene's entities die with the roots about to be destroyed (scripting runs destroy_all here); unload_all fires it once more with SCENE_ID_AUTHORED and the remaining roots when any entity is left. Handlers may load scenes; one loaded during unload_all is cleared and retired with the rest.
on_load_failed
on_load_failed[[nodiscard]] core::event<load_request_id, const core::error &> &on_load_failed() noexcept;Fires when a deferred request is dropped: the asset FAILED, is not a scene, or could not be applied.
on_loaded
on_loaded[[nodiscard]] core::event<scene_id> &on_loaded() noexcept;Fires once a load (synchronous or deferred) has instantiated and ordered its roots.
request_load
request_load[[nodiscard]] load_request_id request_load(
const assets::asset_id &id,
load_mode mode = load_mode::REPLACE);Queues an asynchronous load applied by apply_pending_loads once the asset is resident. Like load and load_file it replaces the loaded scenes and the authored entities unless mode is ADDITIVE.
request_unload
request_unloadvoid request_unload(
scene_id id);Queues an unload applied at the next apply_pending_loads; unknown ids are ignored.
transforms
transforms[[nodiscard]] transform_system &transforms() noexcept;The propagation system register_systems adds to the scheduler (the engine toggles its interpolation from engine_time.interpolatePhysics).
unload
unload[[nodiscard]] core::result<void> unload(
scene_id id);Emits on_before_unload, destroys the scene's roots (reverse order), drops the asset handles and runs asset_manager::collect. SCENE_NOT_LOADED for an unknown id.
unload_all
unload_allvoid unload_all();Unloads every scene in reverse load order, then clears the remaining authored entities; unload_all fires on_before_unload once more with SCENE_ID_AUTHORED and the remaining roots when any entity is left. A scene an on_before_unload handler loads meanwhile is cleared and retired with the rest, so no scene is loaded afterwards.
Private
allocate_record
allocate_record[[nodiscard]] u32 allocate_record();apply_document
apply_document[[nodiscard]] core::result<scene_id> apply_document(
const scene_document &document,
load_mode mode,
assets::asset_load_batch batch,
const assets::asset_id &asset,
std::string path);collect_owned_roots
collect_owned_rootsvoid collect_owned_roots(
scene_id id,
std::vector<ecs::entity> &out) const;find_record
find_record[[nodiscard]] loaded_record *find_record(
scene_id id) noexcept;[[nodiscard]] const loaded_record *find_record(
scene_id id) const noexcept;