diff options
-rw-r--r-- | kurator/src/Session.cpp | 35 | ||||
-rw-r--r-- | kurator/src/Session.h | 10 |
2 files changed, 32 insertions, 13 deletions
diff --git a/kurator/src/Session.cpp b/kurator/src/Session.cpp index 1d1d513..9d39d59 100644 --- a/kurator/src/Session.cpp +++ b/kurator/src/Session.cpp @@ -1,6 +1,7 @@ #include "Session.h" #include <memory> +#include <utility> #include <raylib.h> #include <rlImGui.h> @@ -13,27 +14,43 @@ namespace kurator void -Session::set(std::shared_ptr<Scene> _scene) +Session::set(std::shared_ptr<Scene> scene) { - previous_scene = scene; - scene = _scene; + pop(); + push(std::move(scene)); +} + + +void +Session::push(std::shared_ptr<Scene> scene) +{ + scenes.push_back(std::move(scene)); +} + + +void +Session::pop() +{ + if (!scenes.empty()) { + for_removal.push_back(std::move(scenes.back())); + scenes.pop_back(); + } } void Session::run() { - while (!window.should_close() && keep_going) { - if (!scene) - return; + while (!window.should_close() && !scenes.empty()) { + auto scene = scenes.back(); rlImGuiBegin(); scene->update(GetFrameTime()); BeginDrawing(); scene->draw(); rlImGuiEnd(); EndDrawing(); - if (previous_scene) - previous_scene.reset(); + if (!for_removal.empty()) + for_removal.clear(); } } @@ -41,7 +58,7 @@ Session::run() void Session::quit() { - keep_going = false; + scenes.clear(); } diff --git a/kurator/src/Session.h b/kurator/src/Session.h index 59aa597..dfc49e0 100644 --- a/kurator/src/Session.h +++ b/kurator/src/Session.h @@ -1,5 +1,6 @@ #pragma once +#include <deque> #include <memory> #include "Scene.h" @@ -13,14 +14,15 @@ namespace kurator class Session { public: - void set(std::shared_ptr<Scene> _scene); + void set(std::shared_ptr<Scene> scene); + void push(std::shared_ptr<Scene> scene); + void pop(); void run(); void quit(); private: - bool keep_going = true; Window window; - std::shared_ptr<Scene> scene; - std::shared_ptr<Scene> previous_scene; + std::deque<std::shared_ptr<Scene>> scenes; + std::deque<std::shared_ptr<Scene>> for_removal; }; |