summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-26 17:15:05 +0100
committerAki <please@ignore.pl>2022-12-26 17:15:05 +0100
commit1d559735ba59f48ca060226befadc2aee92b1fca (patch)
tree4ff6eb5b6ea17f41566abdfa90dda23390ad54dd
parente27a9ba4f7ab3b8937a9b36c432332698413d00a (diff)
downloadkurator-1d559735ba59f48ca060226befadc2aee92b1fca.zip
kurator-1d559735ba59f48ca060226befadc2aee92b1fca.tar.gz
kurator-1d559735ba59f48ca060226befadc2aee92b1fca.tar.bz2
Session now manages Scenes in via a stack
-rw-r--r--kurator/src/Session.cpp35
-rw-r--r--kurator/src/Session.h10
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;
};