Unravel Engine C++ Reference
Loading...
Searching...
No Matches
editor.cpp
Go to the documentation of this file.
1#include "editor.h"
2
3#include <engine/engine.h>
4#include <engine/events.h>
6#include <version/version.h>
7
12#include "events.h"
13#include "hub/hub.h"
16#include <filedialog/filedialog.h>
17
18
19namespace unravel
20{
21namespace
22{
23void print_init_error(const rtti::context& ctx)
24{
25 if(ctx.has<init_error>())
26 {
27 const auto& error = ctx.get<init_error>();
28 native::message_box(error.msg,
29 native::dialog_type::ok,
30 native::icon_type::error,
31 error.category);
32 }
33}
34
35}
36
38{
39 entt::meta_factory<editor>{}
40 .type("editor"_hs)
41 .func<&editor::create>("create"_hs)
42 .func<&editor::init>("init"_hs)
43 .func<&editor::deinit>("deinit"_hs)
44 .func<&editor::destroy>("destroy"_hs)
45 .func<&editor::process>("process"_hs)
46 .func<&editor::interrupt>("interrupt"_hs);
47
48
49}
50
52{
53 if(!engine::create(ctx, parser))
54 {
55 return false;
56 }
57
58 fs::path binary_path = fs::resolve_protocol("binary:/");
59 fs::path editor_data = binary_path / "data" / "editor";
60 fs::add_path_protocol("editor", editor_data);
61
62 ctx.add<ui_events>();
63 ctx.add<project_manager>(ctx, parser);
64 ctx.add<imgui_interface>(ctx);
65 ctx.add<hub>(ctx);
66 ctx.add<editing_manager>();
67 ctx.add<picking_manager>();
68 ctx.add<thumbnail_manager>();
69 ctx.add<asset_watcher>();
70
71 return true;
72}
73
74auto editor::init(const cmd_line::parser& parser) -> bool
75{
76 auto& ctx = engine::context();
77
78 if(!engine::init_core(parser))
79 {
80 print_init_error(ctx);
81 return false;
82 }
83
84 if(!init_window(ctx))
85 {
86 print_init_error(ctx);
87 return false;
88 }
89
90 if(!ctx.get_cached<asset_watcher>().init(ctx))
91 {
92 print_init_error(ctx);
93 return false;
94 }
95
96 if(!engine::init_systems(parser))
97 {
98 print_init_error(ctx);
99 return false;
100 }
101
102 {
103 auto& aw = ctx.get_cached<asset_watcher>();
104 aw.watch_assets(ctx, "editor:/", true);
105 }
106
107
108 if(!ctx.get_cached<imgui_interface>().init(ctx))
109 {
110 print_init_error(ctx);
111 return false;
112 }
113
114 if(!ctx.get_cached<hub>().init(ctx))
115 {
116 print_init_error(ctx);
117 return false;
118 }
119
120 if(!ctx.get_cached<editing_manager>().init(ctx))
121 {
122 print_init_error(ctx);
123 return false;
124 }
125
126 if(!ctx.get_cached<picking_manager>().init(ctx))
127 {
128 print_init_error(ctx);
129 return false;
130 }
131
132 if(!ctx.get_cached<thumbnail_manager>().init(ctx))
133 {
134 print_init_error(ctx);
135 return false;
136 }
137
138 if(!ctx.get_cached<project_manager>().init(ctx, parser))
139 {
140 print_init_error(ctx);
141 return false;
142 }
143
144 return true;
145}
146
148{
149 auto title = fmt::format("Unravel Editor <{}> {}", gfx::get_renderer_name(gfx::get_renderer_type()), version::get_full());
150 uint32_t flags = os::window::resizable | os::window::maximized;
151 auto primary_display = os::display::get_primary_display_index();
152
153 auto& rend = ctx.get_cached<renderer>();
154 rend.create_window_for_display(primary_display, title, flags);
155 return true;
156}
157
158auto editor::deinit() -> bool
159{
160 auto& ctx = engine::context();
161
162 if(!ctx.get_cached<asset_watcher>().deinit(ctx))
163 {
164 return false;
165 }
166
167 if(!ctx.get_cached<thumbnail_manager>().deinit(ctx))
168 {
169 return false;
170 }
171
172 if(!ctx.get_cached<picking_manager>().deinit(ctx))
173 {
174 return false;
175 }
176
177 if(!ctx.get_cached<editing_manager>().deinit(ctx))
178 {
179 return false;
180 }
181
182 if(!ctx.get_cached<hub>().deinit(ctx))
183 {
184 return false;
185 }
186
187 if(!ctx.get_cached<imgui_interface>().deinit(ctx))
188 {
189 return false;
190 }
191
192 if(!ctx.get_cached<project_manager>().deinit(ctx))
193 {
194 return false;
195 }
196
197 {
198 auto& aw = ctx.get_cached<asset_watcher>();
199 aw.unwatch_assets(ctx, "editor:/");
200 }
201
202 return engine::deinit();
203}
204
205auto editor::destroy() -> bool
206{
207 auto& ctx = engine::context();
208
209 ctx.remove<asset_watcher>();
210 ctx.remove<thumbnail_manager>();
211 ctx.remove<picking_manager>();
212 ctx.remove<editing_manager>();
213
214 ctx.remove<hub>();
215 ctx.remove<imgui_interface>();
216
217 ctx.remove<project_manager>();
218
219 ctx.remove<ui_events>();
220
221 return engine::destroy();
222}
223
224auto editor::process() -> int
225{
226 return engine::process();
227}
228auto editor::interrupt() -> bool
229{
230 return engine::interrupt();
231}
232
233} // namespace unravel
auto deinit(rtti::context &ctx) -> bool
void watch_assets(rtti::context &ctx, const std::string &protocol, bool wait=false)
auto init(rtti::context &ctx) -> bool
void unwatch_assets(rtti::context &ctx, const std::string &protocol)
auto deinit(rtti::context &ctx) -> bool
Definition hub.cpp:287
auto init(rtti::context &ctx) -> bool
Definition hub.cpp:278
auto deinit(rtti::context &ctx) -> bool
auto init(rtti::context &ctx) -> bool
auto init(rtti::context &ctx) -> bool
auto deinit(rtti::context &ctx) -> bool
auto init(rtti::context &ctx, const cmd_line::parser &parser) -> bool
auto deinit(rtti::context &ctx) -> bool
bool add_path_protocol(const std::string &protocol, const path &dir)
Allows us to map a protocol to a specific directory. A path protocol gives the caller the ability to ...
path resolve_protocol(const path &_path)
Given the specified path/filename, resolve the final full filename. This will be based on either the ...
renderer_type get_renderer_type()
Definition graphics.cpp:281
const char * get_renderer_name(renderer_type _type)
Definition graphics.cpp:255
REFLECTION_REGISTRATION
Definition editor.cpp:38
std::string get_full()
Definition version.cpp:20
auto has() const -> bool
Definition context.hpp:28
auto get() -> T &
Definition context.hpp:35
auto init(rtti::context &ctx) -> bool
auto deinit(rtti::context &ctx) -> bool
static auto create(rtti::context &ctx, cmd_line::parser &parser) -> bool
Definition editor.cpp:51
static auto interrupt() -> bool
Definition editor.cpp:228
static auto destroy() -> bool
Definition editor.cpp:205
static auto process() -> int
Definition editor.cpp:224
static auto init(const cmd_line::parser &parser) -> bool
Definition editor.cpp:74
static auto deinit() -> bool
Definition editor.cpp:158
static auto init_window(rtti::context &ctx) -> bool
Definition editor.cpp:147
static auto process() -> int
Definition engine.cpp:403
static auto init_systems(const cmd_line::parser &parser) -> bool
Definition engine.cpp:200
static auto destroy() -> bool
Definition engine.cpp:366
static auto context() -> rtti::context &
Definition engine.cpp:115
static auto deinit() -> bool
Definition engine.cpp:279
static auto interrupt() -> bool
Definition engine.cpp:477
static auto create(rtti::context &ctx, cmd_line::parser &parser) -> bool
Definition engine.cpp:120
static auto init_core(const cmd_line::parser &parser) -> bool
Definition engine.cpp:169
auto create_window_for_display(int index, const std::string &title, uint32_t flags) -> const std::unique_ptr< render_window > &
Definition renderer.cpp:64
auto init(rtti::context &ctx) -> bool
auto deinit(rtti::context &ctx) -> bool