Skip to content

Engine → Scene → scene_manager.h

scene_manager

Syntax

class CONJURE_API scene_manager

Constructors

AccessSignatureDescription
publicscene_manager( ecs::world &world, assets::asset_manager &assets);

Important

Copy constructor and assignment has been deleted.

Destructors

AccessSignatureDescription
public~scene_manager();Drops the load records (and their asset handles); the scene's entities stay in the world.

Variables

AccessNameTypeDefaultDescription
privatemAssetsassets::asset_manager *nullptr
privatemLayerslayer_table{}
privatemLoadOrderstd::vector<u32>{}
privatemNextGenerationu322
privatemNextRequestu321
privatemOnBeforeUnloadcore::event<scene_id, std::span<const ecs::entity>>{}
privatemOnLoadedcore::event<scene_id>{}
privatemOnLoadFailedcore::event<load_request_id, const core::error &>{}
privatemPendingstd::vector<pending_load>{}
privatemPendingUnloadsstd::vector<scene_id>{}
privatemRecordsstd::vector<loaded_record>{}
privatemScenescene—
privatemTransformstransform_system—
privatemWorldecs::world *nullptr

Functions

Public

active

[[nodiscard]] scene &active() noexcept;

The one scene over the world.

[[nodiscard]] const scene &active() const noexcept;

apply_pending_loads

void 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

[[nodiscard]] assets::asset_manager &assets() noexcept;

The asset manager the scene binds through and loads scene assets from.

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

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

[[nodiscard]] bool is_load_pending(
    const assets::asset_id &id) const noexcept;

True while a request for the asset waits.

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

[[nodiscard]] layer_table &layers() noexcept;

The layer names, filled by the engine from project.json.

[[nodiscard]] const layer_table &layers() const noexcept;

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

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

[[nodiscard]] std::vector<loaded_scene_info> loaded_scenes() const;

Every loaded scene in load order, with its current roots.

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

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

[[nodiscard]] core::event<scene_id> &on_loaded() noexcept;

Fires once a load (synchronous or deferred) has instantiated and ordered its roots.

pending_count

[[nodiscard]] u32 pending_count() const noexcept;

Requests not yet applied.

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

void request_unload(
    scene_id id);

Queues an unload applied at the next apply_pending_loads; unknown ids are ignored.

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

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

void 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

[[nodiscard]] u32 allocate_record();

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

void collect_owned_roots(
    scene_id id,
    std::vector<ecs::entity> &out) const;

find_record

[[nodiscard]] loaded_record *find_record(
    scene_id id) noexcept;
[[nodiscard]] const loaded_record *find_record(
    scene_id id) const noexcept;