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

SceneManager class implements scene management functionality like loading and unloading scenes, holding game objects. More...

#include <SceneManager.hpp>

Public Member Functions

void loadScene (const std::string &path, Engine &engine)
 Unloads all current scenes and loads a new one from a file.
void unloadScene (const std::string &path)
 Unloads a specific scene from memory.
void loadSceneWithoutClearing (const std::string &path, Engine &engine)
 Loads a scene from a file additively without clearing existing scenes.
void clearScenes (Engine &engine)
 Function to clear the current scene.
void scenesUpdate (float deltaTime)
 Updates all currently loaded scenes.
const std::vector< std::shared_ptr< GameObject > > & GetAllObjects (const std::string &scene) const
 Function to get all game objects.
const std::vector< std::shared_ptr< GameObject > > & GetAllAddedObjects (const std::string &scene) const
 Function to get all added game objects.
std::vector< std::string > GetAllSceneNames () const
 Retrieves the names of all currently loaded scenes.
std::string getLastSceneName () const
 Function to get last scene name.
SceneGetScene (const std::string &scene) const
 Safely retrieves a pointer to a specific Scene.

Private Attributes

std::map< std::string, std::shared_ptr< Scene > > m_scenes
std::string lastSceneName = ""
bool m_isUpdating = false
std::vector< std::function< void()> > m_pendingActions

Detailed Description

SceneManager class implements scene management functionality like loading and unloading scenes, holding game objects.

Definition at line 18 of file SceneManager.hpp.

Member Function Documentation

◆ clearScenes()

void vex::SceneManager::clearScenes ( Engine & engine)

Function to clear the current scene.

Clears also all entities in the registry without PersistentTags and MeshManager.

Clears the registry and then clears the m_scenes map.

Definition at line 239 of file SceneManager.cpp.

◆ GetAllAddedObjects()

const std::vector< std::shared_ptr< GameObject > > & vex::SceneManager::GetAllAddedObjects ( const std::string & scene) const
inline

Function to get all added game objects.

Parameters
conststd::string& scene - Name of the scene to get the game objects from.
Returns
const std::vector<std::shared_ptr<GameObject>>& - Vector of game objects.

Definition at line 58 of file SceneManager.hpp.

◆ GetAllObjects()

const std::vector< std::shared_ptr< GameObject > > & vex::SceneManager::GetAllObjects ( const std::string & scene) const
inline

Function to get all game objects.

Parameters
conststd::string& scene - Name of the scene to get the game objects from.
Returns
const std::vector<std::shared_ptr<GameObject>>& - Vector of game objects.

Definition at line 53 of file SceneManager.hpp.

◆ GetAllSceneNames()

std::vector< std::string > vex::SceneManager::GetAllSceneNames ( ) const

Retrieves the names of all currently loaded scenes.

Iterates through the internal m_scenes map keys to construct the list.

Returns
std::vector<std::string> - Vector containing the names/paths of active scenes.

Definition at line 274 of file SceneManager.cpp.

◆ getLastSceneName()

std::string vex::SceneManager::getLastSceneName ( ) const
inline

Function to get last scene name.

Returns
std::string - Last scene name.

Definition at line 67 of file SceneManager.hpp.

◆ GetScene()

Scene * vex::SceneManager::GetScene ( const std::string & scene) const
inline

Safely retrieves a pointer to a specific Scene.

Checks if the scene exists in the m_scenes map before returning.

Parameters
conststd::string& scene - Name/Path of the scene to retrieve.
Returns
Scene* - Pointer to the scene if found, otherwise nullptr.

Definition at line 73 of file SceneManager.hpp.

◆ loadScene()

void vex::SceneManager::loadScene ( const std::string & path,
Engine & engine )

Unloads all current scenes and loads a new one from a file.

Effectively resets the game state by calling clearScenes() followed by loadSceneWithoutClearing().

Parameters
conststd::string& path - Path to the scene file.
Engine&engine - Reference to the engine instance required for object creation.

Definition at line 216 of file SceneManager.cpp.

◆ loadSceneWithoutClearing()

void vex::SceneManager::loadSceneWithoutClearing ( const std::string & path,
Engine & engine )

Loads a scene from a file additively without clearing existing scenes.

  1. Updates lastSceneName to the provided path.
  2. Creates a new Scene shared pointer.
  3. Calls sceneBegin() on the newly created scene to initialize its objects.
    Parameters
    conststd::string& path - Path to the scene file.
    Engine&engine - Reference to the engine instance.

Definition at line 233 of file SceneManager.cpp.

◆ scenesUpdate()

void vex::SceneManager::scenesUpdate ( float deltaTime)

Updates all currently loaded scenes.

Iterates through the m_scenes map and calls sceneUpdate(deltaTime) on each active scene.

Parameters
floatdeltaTime - Delta time since the last frame.

Definition at line 259 of file SceneManager.cpp.

◆ unloadScene()

void vex::SceneManager::unloadScene ( const std::string & path)

Unloads a specific scene from memory.

Removes the scene from the internal m_scenes map, triggering the destructor of the Scene object.

Parameters
conststd::string& path - Path/Name of the scene to unload.

Definition at line 229 of file SceneManager.cpp.

Member Data Documentation

◆ lastSceneName

std::string vex::SceneManager::lastSceneName = ""
private

Definition at line 82 of file SceneManager.hpp.

◆ m_isUpdating

bool vex::SceneManager::m_isUpdating = false
private

Definition at line 84 of file SceneManager.hpp.

◆ m_pendingActions

std::vector<std::function<void()> > vex::SceneManager::m_pendingActions
private

Definition at line 85 of file SceneManager.hpp.

◆ m_scenes

std::map<std::string, std::shared_ptr<Scene> > vex::SceneManager::m_scenes
private

Definition at line 81 of file SceneManager.hpp.


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