Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Entities::Scene Class Reference

Owns scene entities, actor lifetime, and the scene graph root. More...

#include <Scene.h>

Inheritance diagram for Engine::Entities::Scene:
Collaboration diagram for Engine::Entities::Scene:

Public Member Functions

 Scene ()
 Creates a scene with an empty scene graph.
 ~Scene () override
 Cleans up all scene-owned entities and actors.
template<class T, typename... Args>
T * spawnEntity (Args &&... args)
 Creates an entity owned by this scene.
void destroyEntity (Entity *entity)
 Queues an entity for destruction.
template<class T, typename... Args>
T * spawnActor (const Ecs::Transform &spawnTransform, Args &&... args)
 Creates an actor at a world transform and calls beginPlay().
template<typename T, typename... Args>
T * spawnActorAttached (const Ecs::Transform &localTransform, Actor &parent, Args &&... args)
 Creates an actor under another actor's scene node.
template<typename T, typename... Args>
T * spawnActorAttached (const Ecs::Transform &localTransform, const std::shared_ptr< SceneNode > &parentNode, Args &&... args)
 Creates an actor under a scene node.
void destroyActor (Entities::Actor *actor)
 Queues an actor for destruction after the current tick.
void destroyActorImmediate (Entities::Actor *actor)
 Destroys an actor now and calls endPlay() if needed.
void flushPendingActorDestruction ()
 Destroys all actors queued by destroyActor().
void flushPendingEntityDestruction ()
 Destroys all entities queued for destruction.
virtual void loadContent ()
 Loads scene content. Override in derived scenes.
virtual void unloadContent ()
 Releases scene content. Override in derived scenes.
std::vector< Entities::Entity * > getEntities () const
 Returns the scene-owned entities.
template<typename Func>
void forEachEntity (Func &&func) const
 Invokes a callback for each scene-owned entity.
EntityContainer & getEntityContainer ()
 Returns the mutable scene entity container.
const EntityContainer & getEntityContainer () const
 Returns the read-only scene entity container.
void reserveActorCapacity (size_t additionalActors)
 Reserves storage for upcoming actor spawns.
void cleanup ()
 Destroys all scene-owned entities and clears pending actor destruction.
Core::SceneManager * getSceneManager () const
 Returns the scene manager from the active engine.
Core::AssetManager * getAssetManager () const
 Returns the asset manager assigned to this scene.
Core::AssetRegistry * getAssetRegistry () const
 Returns the asset registry assigned to this scene.
void setAssetManager (Core::AssetManager *manager)
 Sets the asset manager for this scene.
void setAssetRegistry (Core::AssetRegistry *registry)
 Sets the asset registry for this scene.
SceneGraph * getSceneGraph () const
 Returns the scene graph owned by this scene.
void setLightingOverride (const SceneLightingSettings &settings)
 Enables scene-specific lighting values.
void clearLightingOverride ()
 Disables scene-specific lighting and restores the global defaults.
bool hasLightingOverride () const
SceneLightingSettings * getLightingOverride ()
const SceneLightingSettings * getLightingOverride () const
Public Member Functions inherited from Engine::Core::ITickable
virtual ~ITickable ()=default
 Destroys a tickable object.
virtual void preTick ()
 Function which executes immediately before the execution of ITickable::preTick()
virtual void tick (double deltaTimeSeconds)
 Function called each frame when a tick component has been registered with EnTT Ecs::Tick.
virtual void postTick ()
 Function which executes immediately after the execution of ITickable::postTick()

Static Public Member Functions

template<typename ActorT = StaticMeshActor>
static std::vector< ActorT * > spawnAll (Scene *scene, const std::filesystem::path &gltfPath)
 Spawns one actor for each mesh node in a GLTF file.
template<typename ActorT = StaticMeshActor>
static std::vector< ActorT * > spawnAll (Scene *scene, Assets::GltfHandle gltf)
 Spawns one actor for each mesh node in a loaded GLTF asset.

Protected Attributes

Core::AssetManager * assetManager = nullptr
 Asset manager assigned to this scene.
Core::AssetRegistry * assetRegistry = nullptr
 Asset registry assigned to this scene.

Private Attributes

std::unique_ptr< SceneGraph > sceneGraph
EntityContainer entities_
std::optional< SceneLightingSettings > lightingOverride_

Detailed Description

Owns scene entities, actor lifetime, and the scene graph root.

Derive from Scene for level-specific content. Override loadContent(), tick(), and unloadContent() as needed.

Definition at line 84 of file Scene.h.

Constructor & Destructor Documentation

◆ Scene()

Engine::Entities::Scene::Scene ( )

Creates a scene with an empty scene graph.

Referenced by spawnAll(), and spawnAll().

Here is the caller graph for this function:

◆ ~Scene()

Engine::Entities::Scene::~Scene ( )
override

Cleans up all scene-owned entities and actors.

Member Function Documentation

◆ cleanup()

void Engine::Entities::Scene::cleanup ( )

Destroys all scene-owned entities and clears pending actor destruction.

◆ clearLightingOverride()

void Engine::Entities::Scene::clearLightingOverride ( )
inline

Disables scene-specific lighting and restores the global defaults.

Definition at line 403 of file Scene.h.

References lightingOverride_.

◆ destroyActor()

void Engine::Entities::Scene::destroyActor ( Entities::Actor * actor)

Queues an actor for destruction after the current tick.

Parameters
actorScene-owned actor to destroy. Null is ignored.

◆ destroyActorImmediate()

void Engine::Entities::Scene::destroyActorImmediate ( Entities::Actor * actor)

Destroys an actor now and calls endPlay() if needed.

Parameters
actorScene-owned actor to destroy. Null is ignored.

◆ destroyEntity()

void Engine::Entities::Scene::destroyEntity ( Entity * entity)

Queues an entity for destruction.

Parameters
entityScene-owned entity to destroy. Null is ignored.

◆ flushPendingActorDestruction()

void Engine::Entities::Scene::flushPendingActorDestruction ( )

Destroys all actors queued by destroyActor().

◆ flushPendingEntityDestruction()

void Engine::Entities::Scene::flushPendingEntityDestruction ( )

Destroys all entities queued for destruction.

◆ forEachEntity()

template<typename Func>
void Engine::Entities::Scene::forEachEntity ( Func && func) const
inline

Invokes a callback for each scene-owned entity.

Template Parameters
FuncCallable type accepting Entity*.
Parameters
funcCallback invoked for each entity.

Definition at line 337 of file Scene.h.

References entities_.

◆ getAssetManager()

Core::AssetManager * Engine::Entities::Scene::getAssetManager ( ) const
nodiscard

Returns the asset manager assigned to this scene.

◆ getAssetRegistry()

Core::AssetRegistry * Engine::Entities::Scene::getAssetRegistry ( ) const
nodiscard

Returns the asset registry assigned to this scene.

Referenced by spawnAll().

Here is the caller graph for this function:

◆ getEntities()

std::vector< Entities::Entity * > Engine::Entities::Scene::getEntities ( ) const
nodiscard

Returns the scene-owned entities.

◆ getEntityContainer() [1/2]

EntityContainer & Engine::Entities::Scene::getEntityContainer ( )
nodiscard

Returns the mutable scene entity container.

◆ getEntityContainer() [2/2]

const EntityContainer & Engine::Entities::Scene::getEntityContainer ( ) const
nodiscard

Returns the read-only scene entity container.

◆ getLightingOverride() [1/2]

SceneLightingSettings * Engine::Entities::Scene::getLightingOverride ( )
inlinenodiscard

Definition at line 406 of file Scene.h.

References lightingOverride_.

◆ getLightingOverride() [2/2]

const SceneLightingSettings * Engine::Entities::Scene::getLightingOverride ( ) const
inlinenodiscard

Definition at line 410 of file Scene.h.

References lightingOverride_.

◆ getSceneGraph()

SceneGraph * Engine::Entities::Scene::getSceneGraph ( ) const
inlinenodiscard

Returns the scene graph owned by this scene.

Definition at line 393 of file Scene.h.

References sceneGraph.

◆ getSceneManager()

Core::SceneManager * Engine::Entities::Scene::getSceneManager ( ) const
nodiscard

Returns the scene manager from the active engine.

◆ hasLightingOverride()

bool Engine::Entities::Scene::hasLightingOverride ( ) const
inlinenodiscard

Definition at line 405 of file Scene.h.

References lightingOverride_.

◆ loadContent()

virtual void Engine::Entities::Scene::loadContent ( )
virtual

Loads scene content. Override in derived scenes.

◆ reserveActorCapacity()

void Engine::Entities::Scene::reserveActorCapacity ( size_t additionalActors)

Reserves storage for upcoming actor spawns.

Parameters
additionalActorsNumber of additional actors expected.

◆ setAssetManager()

void Engine::Entities::Scene::setAssetManager ( Core::AssetManager * manager)

Sets the asset manager for this scene.

Parameters
managerAsset manager pointer. May be null.

◆ setAssetRegistry()

void Engine::Entities::Scene::setAssetRegistry ( Core::AssetRegistry * registry)

Sets the asset registry for this scene.

Parameters
registryAsset registry pointer. May be null.

◆ setLightingOverride()

void Engine::Entities::Scene::setLightingOverride ( const SceneLightingSettings & settings)
inline

Enables scene-specific lighting values.

Definition at line 398 of file Scene.h.

References lightingOverride_.

◆ spawnActor()

template<class T, typename... Args>
T * Engine::Entities::Scene::spawnActor ( const Ecs::Transform & spawnTransform,
Args &&... args )
inline

Creates an actor at a world transform and calls beginPlay().

Template Parameters
TActor type. Must derive from Actor and accept SpawnContext first.
Parameters
spawnTransformInitial world transform.
argsArguments forwarded after SpawnContext.
Returns
Pointer to the created actor. The scene owns it.

Definition at line 125 of file Scene.h.

References entities_, and sceneGraph.

Referenced by spawnAll(), and spawnAll().

Here is the caller graph for this function:

◆ spawnActorAttached() [1/2]

template<typename T, typename... Args>
T * Engine::Entities::Scene::spawnActorAttached ( const Ecs::Transform & localTransform,
Actor & parent,
Args &&... args )
inline

Creates an actor under another actor's scene node.

Template Parameters
TActor type. Must derive from Actor and accept SpawnContext first.
Parameters
localTransformInitial transform relative to parent.
parentParent actor.
argsArguments forwarded after SpawnContext.
Returns
Pointer to the created actor. The scene owns it.

Definition at line 159 of file Scene.h.

References Engine::Entities::Actor::getSceneNode(), and spawnActorAttached().

Referenced by spawnActorAttached().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spawnActorAttached() [2/2]

template<typename T, typename... Args>
T * Engine::Entities::Scene::spawnActorAttached ( const Ecs::Transform & localTransform,
const std::shared_ptr< SceneNode > & parentNode,
Args &&... args )
inline

Creates an actor under a scene node.

Template Parameters
TActor type. Must derive from Actor and accept SpawnContext first.
Parameters
localTransformInitial transform relative to parentNode.
parentNodeParent scene node. Must not be null.
argsArguments forwarded after SpawnContext.
Returns
Pointer to the created actor. The scene owns it.

Definition at line 176 of file Scene.h.

References Engine::Entities::NodeFactory::createNode(), entities_, Engine::Ecs::Transform::matrix, and sceneGraph.

Here is the call graph for this function:

◆ spawnAll() [1/2]

template<typename ActorT = StaticMeshActor>
std::vector< ActorT * > Engine::Entities::Scene::spawnAll ( Scene * scene,
Assets::GltfHandle gltf )
inlinestatic

Spawns one actor for each mesh node in a loaded GLTF asset.

Template Parameters
ActorTActor type to spawn. Defaults to StaticMeshActor.
Parameters
sceneScene that owns the spawned actors and provides the asset registry.
gltfLoaded GLTF asset handle.
Returns
Spawned actors in mesh-node order, or an empty vector when the handle cannot be resolved.

Definition at line 251 of file Scene.h.

References Engine::Entities::detail::applyGltfNodeExtensions(), Engine::Entities::detail::GltfSpawnNode::geometryMesh, Engine::Entities::detail::GltfSpawnPlan::meshNodes, Engine::Entities::detail::GltfSpawnNode::meshPath, Engine::Entities::detail::prepareGltfSpawnPlan(), Engine::Entities::detail::GltfSpawnNode::renderable, Scene(), spawnActor(), and Engine::Entities::detail::GltfSpawnNode::transform.

Here is the call graph for this function:

◆ spawnAll() [2/2]

template<typename ActorT = StaticMeshActor>
std::vector< ActorT * > Engine::Entities::Scene::spawnAll ( Scene * scene,
const std::filesystem::path & gltfPath )
inlinestatic

Spawns one actor for each mesh node in a GLTF file.

Each actor receives the mesh node's world transform. GLTF light, collision, and probe extensions are applied when present.

Template Parameters
ActorTActor type to spawn. Defaults to StaticMeshActor.
Parameters
sceneNon-null scene that owns the spawned actors.
gltfPathPath to the GLTF/GLB asset.
Returns
Spawned actors in mesh-node order.

Definition at line 219 of file Scene.h.

References Engine::Entities::detail::applyGltfNodeExtensions(), getAssetRegistry(), Engine::Core::AssetRegistry::gltfs(), Engine::Core::GltfStore::load(), Engine::Entities::detail::GltfSpawnPlan::meshNodes, Engine::Entities::detail::GltfSpawnNode::meshPath, Engine::Entities::detail::prepareGltfSpawnPlan(), Scene(), spawnActor(), spawnAll(), and Engine::Entities::detail::GltfSpawnNode::transform.

Referenced by Engine::Entities::GltfSpawner::spawnAll(), Engine::Entities::GltfSpawner::spawnAll(), and spawnAll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spawnEntity()

template<class T, typename... Args>
T * Engine::Entities::Scene::spawnEntity ( Args &&... args)
inline

Creates an entity owned by this scene.

Template Parameters
TEntity type. Must derive from Entity.
Parameters
argsArguments forwarded to T's constructor.
Returns
Pointer to the created entity. Do not delete it directly.

Definition at line 103 of file Scene.h.

References entities_.

◆ unloadContent()

virtual void Engine::Entities::Scene::unloadContent ( )
virtual

Releases scene content. Override in derived scenes.

Member Data Documentation

◆ assetManager

Core::AssetManager* Engine::Entities::Scene::assetManager = nullptr
protected

Asset manager assigned to this scene.

Definition at line 416 of file Scene.h.

◆ assetRegistry

Core::AssetRegistry* Engine::Entities::Scene::assetRegistry = nullptr
protected

Asset registry assigned to this scene.

Definition at line 417 of file Scene.h.

◆ entities_

EntityContainer Engine::Entities::Scene::entities_
private

Definition at line 422 of file Scene.h.

Referenced by forEachEntity(), spawnActor(), spawnActorAttached(), and spawnEntity().

◆ lightingOverride_

std::optional<SceneLightingSettings> Engine::Entities::Scene::lightingOverride_
private

◆ sceneGraph

std::unique_ptr<SceneGraph> Engine::Entities::Scene::sceneGraph
private

Definition at line 420 of file Scene.h.

Referenced by getSceneGraph(), spawnActor(), and spawnActorAttached().


The documentation for this class was generated from the following file:
  • /workspace/magerbeton/gl3-vulkan/code/Engine/include/Engine/Entity/Scene.h