Scene class implements scene functionality like loading and holding game objects.
More...
#include <Scene.hpp>
|
| void | load () |
| | Loads the scene data from the file path specified in the constructor.
|
Scene class implements scene functionality like loading and holding game objects.
Definition at line 22 of file Scene.hpp.
◆ 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()
Destructor clears the current scene.
Definition at line 31 of file Scene.cpp.
◆ 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
-
| const | std::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
-
| const | std::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()
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 |
◆ load()
| void vex::Scene::load |
( |
| ) |
|
|
private |
Loads the scene data from the file path specified in the constructor.
- Reads the JSON file from the Virtual File System.
- Parses and applies Global Environment settings (Lighting, Shading, Dithering).
- Iterates through the "objects" array, creating GameObjects via GameObjectFactory.
- Loads components for each object via ComponentRegistry.
- 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
-
| const | std::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.
- Flushes the destruction queue via FlushDestructionQueue.
- Calls Update(deltaTime) on all active objects.
- Supports parallel execution for large object counts if configured.
- Parameters
-
| float | deltaTime - Delta time since last frame. |
Definition at line 219 of file Scene.cpp.
◆ m_addedObjects
| std::vector<std::shared_ptr<GameObject> > vex::Scene::m_addedObjects |
|
private |
◆ m_creatingFromScene
| bool vex::Scene::m_creatingFromScene = false |
|
private |
◆ m_engine
◆ m_objects
| std::vector<std::shared_ptr<GameObject> > vex::Scene::m_objects |
|
private |
◆ m_path
| std::string vex::Scene::m_path |
|
private |
◆ m_pendingDestruction
| std::vector<GameObject*> vex::Scene::m_pendingDestruction |
|
private |
The documentation for this class was generated from the following files: