diff options
Diffstat (limited to 'src/crepe/api/SceneManager.cpp')
-rw-r--r-- | src/crepe/api/SceneManager.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/crepe/api/SceneManager.cpp b/src/crepe/api/SceneManager.cpp new file mode 100644 index 0000000..08f036d --- /dev/null +++ b/src/crepe/api/SceneManager.cpp @@ -0,0 +1,34 @@ +#include "../ComponentManager.h" + +#include "SceneManager.h" + +using namespace crepe; +using namespace std; + +SceneManager::SceneManager() {} + +SceneManager & SceneManager::get_instance() { + static SceneManager instance; + return instance; +} + +// Set the next scene (this scene will be loaded at the end of the frame) +void SceneManager::set_next_scene(const std::string & name) { + next_scene = name; +} + +// Load a new scene (if there is one) +void SceneManager::load_next_scene() { + if (!next_scene.empty()) { + for (auto & scene : scenes) { + if (scene->name == next_scene) { + // Delete all components of the current scene + ComponentManager & mgr = ComponentManager::get_instance(); + mgr.delete_all_components(); + // Load the new scene + scene->load_scene(); + break; + } + } + } +} |