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>
8#include <version/version.h>
9
14#include "events.h"
15#include "hub/hub.h"
17#include "system/mcp_manager.h"
20#include <filedialog/filedialog.h>
21
22
23namespace unravel
24{
25
27{
28 entt::meta_factory<editor>{}
29 .type("editor"_hs)
30 .func<&editor::create>("create"_hs)
31 .func<&editor::init>("init"_hs)
32 .func<&editor::deinit>("deinit"_hs)
33 .func<&editor::destroy>("destroy"_hs)
34 .func<&editor::process>("process"_hs)
35 .func<&editor::interrupt>("interrupt"_hs);
36
37
38}
39
41{
42 if(!engine::create(ctx, parser))
43 {
44 return false;
45 }
46
47 fs::path binary_path = fs::resolve_protocol("binary:/");
48 fs::path editor_data = binary_path / "data" / "editor";
49 fs::add_path_protocol("editor", editor_data);
50
51 ctx.add<ui_events>();
52 ctx.add<project_manager>(ctx, parser);
53 ctx.add<imgui_interface>(ctx);
54 ctx.add<hub>(ctx);
55 ctx.add<editing_manager>();
56 ctx.add<picking_manager>();
57 ctx.add<thumbnail_manager>();
58 ctx.add<asset_watcher>();
59 ctx.add<version_manager>();
60 ctx.add<mcp_manager>();
61
62 return true;
63}
64
65auto editor::init(const cmd_line::parser& parser) -> bool
66{
67 auto& ctx = engine::context();
68 auto& ls = ctx.get_cached<loading_screen>();
69
70 ls.set_on_fail([](const std::string& module, const std::string& message) -> void
71 {
72 native::message_box(message, native::dialog_type::ok, native::icon_type::error, module);
73 });
74 // --- Phase 1: core systems (no ImGui yet, console-only progress) ---
75
76 if(!engine::init_core(parser))
77 {
78 return false;
79 }
80
81 ls.begin_module("Window");
82 if(!ls.check(init_window(ctx)))
83 {
84 return false;
85 }
86
87 // {
88 // auto& rend = ctx.get_cached<renderer>();
89 // rend.set_vsync(false);
90
91 // auto& sim = ctx.get_cached<simulation>();
92 // auto primary_display = os::display::get_primary_display_index();
93 // auto desktop_mode = os::display::get_desktop_mode(primary_display);
94 // sim.set_max_fps(desktop_mode.refresh_rate > 0 ? desktop_mode.refresh_rate : 144); // uncapped while focused (active)
95 // sim.set_max_inactive_fps(30); // throttled while unfocused
96 // }
97
98 ls.begin_module("Editor UI");
99 if(!ls.check(ctx.get_cached<imgui_interface>().init_basic(ctx)))
100 {
101 return false;
102 }
103
104 // --- ImGui is now available: register the visual loading screen ---
105
106 auto& imgui = ctx.get_cached<imgui_interface>();
107 ls.set_visualizer([&imgui, &ctx](const loading_screen& screen) -> void
108 {
109 imgui.render_loading_frame(ctx,
110 screen.current_module(),
111 screen.completed(),
112 screen.total(),
113 screen.current_job());
114 });
115
116
117 // --- Phase 2: engine assets (visual progress bar) ---
118
119 ls.begin_module("Asset Watcher");
120 auto& aw = ctx.get_cached<asset_watcher>();
121 if(!ls.check(aw.init(ctx)))
122 {
123 return false;
124 }
125 ls.begin_module("Engine Assets");
126 aw.watch_assets(ctx, "engine:/", true, [&ls](size_t completed, size_t total, const std::string& job) -> void
127 {
128 ls.progress(completed, total, job);
129 });
130
131
132 // --- Phase 3: engine subsystems (visual module names) ---
133
134 if(!engine::init_systems(parser))
135 {
136 return false;
137 }
138
139 // --- Phase 4: editor assets (visual progress bar) ---
140
141 ls.begin_module("Editor Assets");
142 aw.watch_assets(ctx, "editor:/", true, [&ls](size_t completed, size_t total, const std::string& job) -> void
143 {
144 ls.progress(completed, total, job);
145 });
146
147 // --- Phase 5: editor subsystems ---
148
149 ls.begin_module("Editor UI Finalize");
150 if(!ls.check(ctx.get_cached<imgui_interface>().init_finalize(ctx)))
151 {
152 return false;
153 }
154
155 ls.begin_module("Hub");
156 if(!ls.check(ctx.get_cached<hub>().init(ctx)))
157 {
158 return false;
159 }
160
161 ls.begin_module("Editing");
162 if(!ls.check(ctx.get_cached<editing_manager>().init(ctx)))
163 {
164 return false;
165 }
166
167 ls.begin_module("Picking");
168 if(!ls.check(ctx.get_cached<picking_manager>().init(ctx)))
169 {
170 return false;
171 }
172
173 ls.begin_module("Thumbnails");
174 if(!ls.check(ctx.get_cached<thumbnail_manager>().init(ctx)))
175 {
176 return false;
177 }
178
179 ls.begin_module("Project Manager");
180 if(!ls.check(ctx.get_cached<project_manager>().init(ctx, parser)))
181 {
182 return false;
183 }
184
185 ls.begin_module("Version Manager");
186 if(!ls.check(ctx.get_cached<version_manager>().init(ctx)))
187 {
188 return false;
189 }
190
191 ls.begin_module("MCP Server");
192 if(!ls.check(ctx.get_cached<mcp_manager>().init(ctx)))
193 {
194 return false;
195 }
196
197 return true;
198}
199
201{
202 auto title = fmt::format("Unravel Editor <{}> {}", gfx::get_renderer_name(gfx::get_renderer_type()), version::get_full());
203 uint32_t flags = os::window::resizable | os::window::maximized;
204 auto primary_display = os::display::get_primary_display_index();
205
206 auto& rend = ctx.get_cached<renderer>();
207 rend.create_window_for_display(primary_display, title, flags);
208 return true;
209}
210
211auto editor::deinit() -> bool
212{
213 auto& ctx = engine::context();
214
215
216 if(!ctx.get_cached<mcp_manager>().deinit(ctx))
217 {
218 return false;
219 }
220
221 if(!ctx.get_cached<thumbnail_manager>().deinit(ctx))
222 {
223 return false;
224 }
225
226 if(!ctx.get_cached<picking_manager>().deinit(ctx))
227 {
228 return false;
229 }
230
231 if(!ctx.get_cached<editing_manager>().deinit(ctx))
232 {
233 return false;
234 }
235
236 if(!ctx.get_cached<hub>().deinit(ctx))
237 {
238 return false;
239 }
240
241 if(!ctx.get_cached<imgui_interface>().deinit(ctx))
242 {
243 return false;
244 }
245
246
247 if(!ctx.get_cached<asset_watcher>().deinit(ctx))
248 {
249 return false;
250 }
251
252 if(!ctx.get_cached<project_manager>().deinit(ctx))
253 {
254 return false;
255 }
256
257 if(!ctx.get_cached<version_manager>().deinit(ctx))
258 {
259 return false;
260 }
261
262 {
263 auto& aw = ctx.get_cached<asset_watcher>();
264 aw.unwatch_assets(ctx, "editor:/");
265 aw.unwatch_assets(ctx, "engine:/");
266 }
267
268 return engine::deinit();
269}
270
271auto editor::destroy() -> bool
272{
273 auto& ctx = engine::context();
274
275 ctx.remove<asset_watcher>();
276 ctx.remove<thumbnail_manager>();
277 ctx.remove<picking_manager>();
278 ctx.remove<editing_manager>();
279
280 ctx.remove<hub>();
281 ctx.remove<imgui_interface>();
282
283 ctx.remove<project_manager>();
284 ctx.remove<version_manager>();
285 ctx.remove<mcp_manager>();
286
287 ctx.remove<ui_events>();
288
289 return engine::destroy();
290}
291
292auto editor::process() -> int
293{
294 return engine::process();
295}
296auto editor::interrupt() -> bool
297{
298 return engine::interrupt();
299}
300
301} // namespace unravel
auto deinit(rtti::context &ctx) -> bool
void watch_assets(rtti::context &ctx, const std::string &protocol, bool wait=false, const on_wait_progress_t &on_progress=nullptr)
void unwatch_assets(rtti::context &ctx, const std::string &protocol)
auto deinit(rtti::context &ctx) -> bool
Definition hub.cpp:399
auto init(rtti::context &ctx) -> bool
Definition hub.cpp:390
auto deinit(rtti::context &ctx) -> bool
auto init_finalize(rtti::context &ctx) -> bool
Phase 2: creates the cubemap shader program from compiled editor:/ assets.
auto init_basic(rtti::context &ctx) -> bool
Phase 1: creates ImGui context, embedded shaders, fonts. No asset dependencies.
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
const char * title
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:440
const char * get_renderer_name(renderer_type _type)
Definition graphics.cpp:412
REFLECTION_REGISTRATION
Definition editor.cpp:27
auto get_full() -> std::string
Definition version.cpp:226
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:40
static auto interrupt() -> bool
Definition editor.cpp:296
static auto destroy() -> bool
Definition editor.cpp:271
static auto process() -> int
Definition editor.cpp:292
static auto init(const cmd_line::parser &parser) -> bool
Definition editor.cpp:65
static auto deinit() -> bool
Definition editor.cpp:211
static auto init_window(rtti::context &ctx) -> bool
Definition editor.cpp:200
static auto process() -> int
Definition engine.cpp:446
static auto init_systems(const cmd_line::parser &parser) -> bool
Definition engine.cpp:204
static auto destroy() -> bool
Definition engine.cpp:406
static auto context() -> rtti::context &
Definition engine.cpp:111
static auto deinit() -> bool
Definition engine.cpp:302
static auto interrupt() -> bool
Definition engine.cpp:563
static auto create(rtti::context &ctx, cmd_line::parser &parser) -> bool
Definition engine.cpp:116
static auto init_core(const cmd_line::parser &parser) -> bool
Definition engine.cpp:172
auto current_module() const -> const std::string &
auto completed() const -> size_t
auto current_job() const -> const std::string &
void set_on_fail(on_fail_fn fn)
auto total() const -> size_t
auto create_window_for_display(int index, const std::string &title, uint32_t flags) -> const std::unique_ptr< render_window > &
Definition renderer.cpp:138
auto init(rtti::context &ctx) -> bool
auto deinit(rtti::context &ctx) -> bool
auto init(rtti::context &ctx) -> bool
auto deinit(rtti::context &ctx) -> bool