From 1d559735ba59f48ca060226befadc2aee92b1fca Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 26 Dec 2022 17:15:05 +0100 Subject: Session now manages Scenes in via a stack --- kurator/src/Session.cpp | 35 ++++++++++++++++++++++++++--------- 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 +#include #include #include @@ -13,27 +14,43 @@ namespace kurator void -Session::set(std::shared_ptr _scene) +Session::set(std::shared_ptr scene) { - previous_scene = scene; - scene = _scene; + pop(); + push(std::move(scene)); +} + + +void +Session::push(std::shared_ptr 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 #include #include "Scene.h" @@ -13,14 +14,15 @@ namespace kurator class Session { public: - void set(std::shared_ptr _scene); + void set(std::shared_ptr scene); + void push(std::shared_ptr scene); + void pop(); void run(); void quit(); private: - bool keep_going = true; Window window; - std::shared_ptr scene; - std::shared_ptr previous_scene; + std::deque> scenes; + std::deque> for_removal; }; -- cgit v1.1