summaryrefslogtreecommitdiff
path: root/kurator/src/Session.cpp
blob: 5bf405af653e18dff1bc645cd5e523767b607a5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "Session.h"

#include <memory>
#include <utility>

#include <raylib.h>
#include <rlImGui.h>

#include "Scene.h"


namespace kurator
{


std::shared_ptr<Scene>
Session::current() const
{
	return scenes.back();
}


void
Session::set(std::shared_ptr<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() && !scenes.empty()) {
		auto scene = current();
		rlImGuiBegin();
		scene->update();
		if (!scenes.empty())
			scene = current();
		BeginDrawing();
		scene->draw();
		rlImGuiEnd();
		EndDrawing();
		if (!for_removal.empty())
			for_removal.clear();
	}
}


void
Session::quit()
{
	scenes.clear();
}


}  // namespace kurator