-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorRuntime.cpp
More file actions
200 lines (168 loc) · 3.46 KB
/
Copy pathEditorRuntime.cpp
File metadata and controls
200 lines (168 loc) · 3.46 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
*
* @file EditorRuntime.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira.
* All rights reserved.
* https://github.com/vixcpp/game
*
* Use of this source code is governed by a MIT license
* that can be found in the LICENSE file.
*
* Vix.cpp
*
*/
#include <vix/game/EditorRuntime.hpp>
#include <vix/game/GameError.hpp>
#include <vix/game/Registry.hpp>
#include <vix/game/SceneData.hpp>
namespace vix::game
{
EditorRuntime::EditorRuntime(GameRuntime &runtime) noexcept
: runtime_(&runtime),
context_(runtime.context()),
initialized_(false)
{
}
EditorRuntime &EditorRuntime::attach(GameRuntime &runtime) noexcept
{
runtime_ = &runtime;
context_.attach(runtime.context());
return *this;
}
void EditorRuntime::detach() noexcept
{
shutdown();
context_.detach();
runtime_ = nullptr;
}
bool EditorRuntime::attached() const noexcept
{
return runtime_ != nullptr && context_.attached();
}
GameBoolResult EditorRuntime::init()
{
if (initialized_)
{
return true;
}
if (!attached())
{
return make_game_error(
GameErrorCode::InvalidState,
"editor runtime is not attached to a game runtime");
}
if (!runtime_->initialized())
{
auto runtime_init = runtime_->init();
if (!runtime_init)
{
return runtime_init.error();
}
}
context_.enter_edit_mode();
initialized_ = true;
return true;
}
void EditorRuntime::shutdown() noexcept
{
if (!initialized_)
{
return;
}
context_.clear();
initialized_ = false;
}
bool EditorRuntime::initialized() const noexcept
{
return initialized_;
}
void EditorRuntime::begin_frame(const Frame &frame)
{
if (runtime_)
{
runtime_->begin_frame(frame);
}
}
void EditorRuntime::update(const Frame &frame)
{
if (!runtime_)
{
return;
}
if (context_.play_mode())
{
runtime_->update(frame);
return;
}
(void)frame;
}
void EditorRuntime::render(const Frame &frame)
{
if (runtime_)
{
runtime_->render(frame);
}
}
void EditorRuntime::end_frame(const Frame &frame)
{
if (runtime_)
{
runtime_->end_frame(frame);
}
}
void EditorRuntime::enter_edit_mode() noexcept
{
context_.enter_edit_mode();
}
void EditorRuntime::enter_play_mode() noexcept
{
context_.enter_play_mode();
}
EditorContext &EditorRuntime::context() noexcept
{
return context_;
}
const EditorContext &EditorRuntime::context() const noexcept
{
return context_;
}
GameRuntime &EditorRuntime::game_runtime()
{
return *runtime_;
}
const GameRuntime &EditorRuntime::game_runtime() const
{
return *runtime_;
}
RuntimeDiagnostics EditorRuntime::inspect_runtime() const
{
if (runtime_ == nullptr)
{
return RuntimeDiagnostics{};
}
return runtime_->diagnostics();
}
SceneFileData EditorRuntime::inspect_scenes() const
{
if (runtime_ == nullptr)
{
return SceneFileData{};
}
return runtime_->context().scenes().to_data();
}
RegistryStats EditorRuntime::inspect_registry() const
{
if (runtime_ == nullptr)
{
return RegistryStats{};
}
const auto *scene = runtime_->context().scenes().active();
if (scene == nullptr)
{
return RegistryStats{};
}
return scene->registry().stats();
}
} // namespace vix::game