Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
Scene Class Referenceabstract

Abstract base class representing a game scene, managing entity lifecycle and persistence. More...

#include <Scene.hpp>

Inheritance diagram for Scene:
Engine::DefaultScene

Public Member Functions

 Scene (Registry &registry, VulkanRenderer &renderer)
 Construct a new Scene object.
virtual ~Scene ()
 Destroy the Scene object, unloading remaining entities.
virtual void load ()=0
 Pure virtual method called to load scene assets and entities.
virtual void update (float dt)=0
 Pure virtual method called every frame to update scene logic.
virtual void unload ()
 Method called to clean up scene state and entities.
virtual bool saveToFile (const std::string &path)
 Serializes scene entities to a JSON file.
virtual bool loadFromFile (const std::string &path)
 Deserializes scene entities from a JSON file.
virtual Entity createPrimitiveEntity (const std::string &primitiveType)
 Helper to spawn primitive geometric entities.
virtual Entity createEntityOfType (const std::string &entityType)
 Helper to spawn complex predefined entities (Camera, Grid).
virtual Entity duplicateEntity (Entity entity)
 Duplicates an existing entity.
virtual bool deleteEntity (Entity entity)
 Destroys an entity and removes it from scene tracking.
Entity trackEntity (Entity entity)
 Tracks an entity under scene ownership.
void untrackEntity (Entity entity)
 Stops tracking an entity.
std::string makeUniqueEntityName (const std::string &baseName) const
 Generates a unique name for an entity by appending indices if duplicate.

Protected Member Functions

Entity findEntityByName (const std::string &name) const
 Locates an entity by its Name component.

Protected Attributes

Registry & registry
 Reference to registry.
VulkanRenderer & renderer
 Reference to Vulkan renderer.

Private Attributes

std::vector< Entity > ownedEntities
 List of entities owned by this scene.

Detailed Description

Abstract base class representing a game scene, managing entity lifecycle and persistence.

Constructor & Destructor Documentation

◆ Scene()

Scene::Scene ( Registry & registry,
VulkanRenderer & renderer )

Construct a new Scene object.

Construct a new Scene:: Scene object.

Parameters
registryReference to the ECS Registry.
rendererReference to the Vulkan Renderer.
registryReference to ECS registry.
rendererReference to renderer.

◆ ~Scene()

Scene::~Scene ( )
virtual

Destroy the Scene object, unloading remaining entities.

Destroy the Scene:: Scene object.

Member Function Documentation

◆ createEntityOfType()

Entity Scene::createEntityOfType ( const std::string & entityType)
virtual

Helper to spawn complex predefined entities (Camera, Grid).

Spawns a component helper entity ("Camera", "Grid").

Parameters
entityTypeKind of entity.
Returns
The spawned Entity.
Parameters
entityTypeType string.
Returns
Spawned entity handle.

◆ createPrimitiveEntity()

Entity Scene::createPrimitiveEntity ( const std::string & primitiveType)
virtual

Helper to spawn primitive geometric entities.

Spawns a primitive shape entity.

Parameters
primitiveTypeKind of primitive (Triangle, Cube, Quad).
Returns
The spawned Entity.
Parameters
primitiveTypeShape type string ("Triangle", "Cube", "Quad").
Returns
Spawned entity handle.

◆ deleteEntity()

bool Scene::deleteEntity ( Entity entity)
virtual

Destroys an entity and removes it from scene tracking.

Deletes and destroys the target entity.

Parameters
entityEntity to delete.
Returns
True if successfully deleted.
Parameters
entityEntity to delete.
Returns
True if successful, false otherwise.

◆ duplicateEntity()

Entity Scene::duplicateEntity ( Entity entity)
virtual

Duplicates an existing entity.

Clones the target entity.

Parameters
entityEntity to clone.
Returns
Cloned Entity.
Parameters
entityEntity to clone.
Returns
Duplicated entity handle.

◆ findEntityByName()

Entity Scene::findEntityByName ( const std::string & name) const
protected

Locates an entity by its Name component.

Resolves active entity matching name property.

Parameters
nameName string to find.
Returns
Entity handle if found, invalid Entity otherwise.
Parameters
nameSearch name query.
Returns
Entity handle.

◆ load()

virtual void Scene::load ( )
pure virtual

Pure virtual method called to load scene assets and entities.

Implemented in Engine::DefaultScene.

◆ loadFromFile()

bool Scene::loadFromFile ( const std::string & path)
virtual

Deserializes scene entities from a JSON file.

Deserializes and loads scene entities from file.

Parameters
pathSource filepath.
Returns
True if load was successful.
Parameters
pathInput path.
Returns
True if successful, false otherwise.

◆ makeUniqueEntityName()

std::string Scene::makeUniqueEntityName ( const std::string & baseName) const

Generates a unique name for an entity by appending indices if duplicate.

Creates unique suffix indices if name conflicts.

Parameters
baseNameIntended name.
Returns
Unique name.
Parameters
baseNameDesired name.
Returns
Unique name.

◆ saveToFile()

bool Scene::saveToFile ( const std::string & path)
virtual

Serializes scene entities to a JSON file.

Serializes scene entities to file.

Parameters
pathTarget filepath.
Returns
True if save was successful.
Parameters
pathOutput path.
Returns
True if successful, false otherwise.

◆ trackEntity()

Entity Scene::trackEntity ( Entity entity)

Tracks an entity under scene ownership.

Registers entity under scene tracking list.

Parameters
entityEntity to track.
Returns
Tracked entity.
Parameters
entityTarget entity.
Returns
Tracked entity.

◆ unload()

void Scene::unload ( )
virtual

Method called to clean up scene state and entities.

Destroys all entities tracked by this scene.

◆ untrackEntity()

void Scene::untrackEntity ( Entity entity)

Stops tracking an entity.

Removes entity from scene tracking list.

Parameters
entityEntity to untrack.
entityTarget entity.

◆ update()

virtual void Scene::update ( float dt)
pure virtual

Pure virtual method called every frame to update scene logic.

Parameters
dtDelta time in seconds.

Implemented in Engine::DefaultScene.

Member Data Documentation

◆ ownedEntities

std::vector<Entity> Scene::ownedEntities
private

List of entities owned by this scene.

◆ registry

Registry& Scene::registry
protected

Reference to registry.

◆ renderer

VulkanRenderer& Scene::renderer
protected

Reference to Vulkan renderer.


The documentation for this class was generated from the following files: