VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
vex::Scene Class Reference

Scene class implements scene functionality like loading and holding game objects. More...

#include <Scene.hpp>

Public Member Functions

 Scene (const std::string &path, Engine &engine)
 Constructor creates empty scene object.
 Scene (const Scene &)=delete
Sceneoperator= (const Scene &)=delete
 Scene (Scene &&)=default
Sceneoperator= (Scene &&)=default
 ~Scene ()
 Destructor clears the current scene.
void sceneBegin ()
 Calls BeginPlay on all objects in the scene.
void sceneUpdate (float deltaTime)
 Updates all objects in the scene.
void AddGameObject (std::unique_ptr< GameObject > gameObject)
 [Deprecated] Function to add a game object to the scene.
std::vector< GameObject * > GetAllGameObjectsByName (const std::string &name)
 Function to get all game objects with a specific name.
std::vector< GameObject * > GetAllGameObjectsByClassName (const std::string &classname)
 Function to get all game objects of a specific class type.
GameObjectGetGameObjectByEntity (vex::Entity &entity)
 Function to get a game object by its entity ID.
void RegisterGameObject (GameObject *gameObject)
 Registers a game object into the scene's internal storage.
void DestroyGameObject (GameObject *gameObject)
 Marks a game object for destruction.
const std::vector< std::shared_ptr< GameObject > > & GetAllObjects () const
 Function to get all game objects in the scene.
const std::vector< std::shared_ptr< GameObject > > & GetAllAddedObjects () const
 Function to get all added game objects in the scene.
void Save (const std::string &outputPath)
 Saves the current state of the scene to a JSON file.
void AddEditorGameObject (GameObject *gameObject)
 Promotes a temporary GameObject (e.g., created by the Editor) to a persistent Scene object.
std::string GetScenePath ()
void FlushDestructionQueue ()
 Processes the queue of objects marked for destruction.

Private Member Functions

void load ()
 Loads the scene data from the file path specified in the constructor.

Private Attributes

std::vector< std::shared_ptr< GameObject > > m_objects
std::vector< std::shared_ptr< GameObject > > m_addedObjects
std::vector< GameObject * > m_pendingDestruction
std::string m_path
Enginem_engine
bool m_creatingFromScene = false

Detailed Description

Scene class implements scene functionality like loading and holding game objects.

Definition at line 22 of file Scene.hpp.

Constructor & Destructor Documentation

◆ Scene()

vex::Scene::Scene ( const std::string & path,
Engine & engine )

Constructor creates empty scene object.

Parameters
std::string&path - Path to the scene file.
Engine&engine - Reference to the engine instance.

Definition at line 26 of file Scene.cpp.

◆ ~Scene()

vex::Scene::~Scene ( )

Destructor clears the current scene.

Definition at line 31 of file Scene.cpp.

Member Function Documentation

◆ AddEditorGameObject()

void vex::Scene::AddEditorGameObject ( GameObject * gameObject)

Promotes a temporary GameObject (e.g., created by the Editor) to a persistent Scene object.

Moves the object from the temporary m_addedObjects list to the primary m_objects storage, ensuring it is saved with the scene.

Parameters
GameObject*gameObject - Pointer to the object to promote.

Definition at line 456 of file Scene.cpp.

◆ AddGameObject()

void vex::Scene::AddGameObject ( std::unique_ptr< GameObject > gameObject)

[Deprecated] Function to add a game object to the scene.

Parameters
std::unique_ptr<GameObject>gameObject - Shared pointer to the game object to add.

Definition at line 250 of file Scene.cpp.

◆ DestroyGameObject()

void vex::Scene::DestroyGameObject ( GameObject * gameObject)

Marks a game object for destruction.

Adds the object to m_pendingDestruction to be cleaned up at the start of the next sceneUpdate.

Parameters
GameObject*gameObject - Pointer to the game object to destroy.

Definition at line 267 of file Scene.cpp.

◆ FlushDestructionQueue()

void vex::Scene::FlushDestructionQueue ( )

Processes the queue of objects marked for destruction.

Waits for the GPU to finish operations via Engine::WaitForGpu to ensure safe deletion, then removes the objects from internal storage vectors.

Definition at line 275 of file Scene.cpp.

◆ GetAllAddedObjects()

const std::vector< std::shared_ptr< GameObject > > & vex::Scene::GetAllAddedObjects ( ) const
inline

Function to get all added game objects in the scene.

Returns
const std::vector<std::shared_ptr<GameObject>>& - Reference to the vector of game objects.

Definition at line 86 of file Scene.hpp.

◆ GetAllGameObjectsByClassName()

std::vector< GameObject * > vex::Scene::GetAllGameObjectsByClassName ( const std::string & classname)

Function to get all game objects of a specific class type.

Parameters
conststd::string& classname - Class name in string form.
Returns
std::vector<GameObject*> - Vector of pointers to the matching game objects.

Definition at line 317 of file Scene.cpp.

◆ GetAllGameObjectsByName()

std::vector< GameObject * > vex::Scene::GetAllGameObjectsByName ( const std::string & name)

Function to get all game objects with a specific name.

Parameters
conststd::string& name - Name of the game object to get.
Returns
std::vector<GameObject*> - Vector of pointers to the matching game objects.

Definition at line 302 of file Scene.cpp.

◆ GetAllObjects()

const std::vector< std::shared_ptr< GameObject > > & vex::Scene::GetAllObjects ( ) const
inline

Function to get all game objects in the scene.

Returns
const std::vector<std::shared_ptr<GameObject>>& - Reference to the vector of game objects.

Definition at line 82 of file Scene.hpp.

◆ GetGameObjectByEntity()

GameObject * vex::Scene::GetGameObjectByEntity ( vex::Entity & entity)

Function to get a game object by its entity ID.

Parameters
vex::Entity&entity - Entity of the game object to get.
Returns
GameObject* - Pointer to the game object, or nullptr if not found.

Definition at line 332 of file Scene.cpp.

◆ GetScenePath()

std::string vex::Scene::GetScenePath ( )
inline

Definition at line 102 of file Scene.hpp.

◆ load()

void vex::Scene::load ( )
private

Loads the scene data from the file path specified in the constructor.

  1. Reads the JSON file from the Virtual File System.
  2. Parses and applies Global Environment settings (Lighting, Shading, Dithering).
  3. Iterates through the "objects" array, creating GameObjects via GameObjectFactory.
  4. Loads components for each object via ComponentRegistry.
  5. Reconstructs parent-child hierarchies based on name references.

Definition at line 36 of file Scene.cpp.

◆ RegisterGameObject()

void vex::Scene::RegisterGameObject ( GameObject * gameObject)

Registers a game object into the scene's internal storage.

Places the object into m_objects if loading from a scene file, or m_addedObjects if created at runtime.

Parameters
GameObject*gameObject - Pointer to the game object to register.

Definition at line 256 of file Scene.cpp.

◆ Save()

void vex::Scene::Save ( const std::string & outputPath)

Saves the current state of the scene to a JSON file.

Serializes:

  • Environment settings (Sun light, Ambient light, Shading artifacts).
  • All GameObjects and their components (using ComponentRegistry::saveComponent).
  • Object hierarchy (Parent/Child relationships).
  • Sorts objects to ensure parents are written before children to maintain hierarchy integrity on load.
    Parameters
    conststd::string& outputPath - The filesystem path to write the .json file to.

Definition at line 346 of file Scene.cpp.

◆ sceneBegin()

void vex::Scene::sceneBegin ( )

Calls BeginPlay on all objects in the scene.

Iterates through both main storage (m_objects) and the added queue (m_addedObjects). If VEX_USE_PARALLEL_EXECUTION is defined and object count > 50, execution is parallelized.

Definition at line 188 of file Scene.cpp.

◆ sceneUpdate()

void vex::Scene::sceneUpdate ( float deltaTime)

Updates all objects in the scene.

  1. Flushes the destruction queue via FlushDestructionQueue.
  2. Calls Update(deltaTime) on all active objects.
  3. Supports parallel execution for large object counts if configured.
    Parameters
    floatdeltaTime - Delta time since last frame.

Definition at line 219 of file Scene.cpp.

Member Data Documentation

◆ m_addedObjects

std::vector<std::shared_ptr<GameObject> > vex::Scene::m_addedObjects
private

Definition at line 122 of file Scene.hpp.

◆ m_creatingFromScene

bool vex::Scene::m_creatingFromScene = false
private

Definition at line 126 of file Scene.hpp.

◆ m_engine

Engine* vex::Scene::m_engine
private

Definition at line 125 of file Scene.hpp.

◆ m_objects

std::vector<std::shared_ptr<GameObject> > vex::Scene::m_objects
private

Definition at line 121 of file Scene.hpp.

◆ m_path

std::string vex::Scene::m_path
private

Definition at line 124 of file Scene.hpp.

◆ m_pendingDestruction

std::vector<GameObject*> vex::Scene::m_pendingDestruction
private

Definition at line 123 of file Scene.hpp.


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