1- #include " Includes/ Engine.h"
1+ #include " Engine.h"
22
33Engine::Engine (uint32_t width, uint32_t height) : m_last_time(std::chrono::high_resolution_clock::now())
44{
55 mp_main_camera = std::make_shared<Camera>();
66 mp_controller = std::make_shared<Controller>(mp_main_camera);
7+
8+ // setup default UI
9+ ConsoleUI* console = &ConsoleUI::Get ();
10+ std::function<void ()> console_hide = [console]() { console->SetActive (!console->IsActive ()); };
11+ BindKeyToFunc (GLFW_KEY_GRAVE_ACCENT, console_hide, ActionType::R3D_PRESS);
12+
13+ m_UIs.push_back (console);
14+
15+ Watcher* watcher = &Watcher::Get ();
16+ std::function<void ()> watcher_hide = [watcher]() { watcher->SetActive (!watcher->IsActive ()); };
17+ BindKeyToFunc (GLFW_KEY_F1, watcher_hide, ActionType::R3D_PRESS);
18+
19+ m_UIs.push_back (watcher);
20+
21+ // load config
722 mp_config = std::make_shared<Config>();
823 mp_config->width = width;
924 mp_config->height = height;
1025
26+ // start the interface
1127 mp_window = std::make_unique<Window>(mp_config, *mp_controller.get ());
12-
1328 mp_renderer = std::make_shared<Renderer>(mp_window->getHandle (), mp_config->width , mp_config->height );
1429}
1530
@@ -155,6 +170,23 @@ void Engine::SetColorMode(const ColorMode color_map)
155170 mp_renderer->SetColorMode (color_map);
156171}
157172
173+ void Engine::RenderUI (UI& ui)
174+ {
175+ m_UIs.push_back (&ui);
176+ }
177+
178+ void Engine::RemoveUI (UI& ui)
179+ {
180+ for (auto it = m_UIs.begin (); it != m_UIs.end (); it++)
181+ {
182+ if (*it == &ui)
183+ {
184+ m_UIs.erase (it);
185+ break ;
186+ }
187+ }
188+ }
189+
158190const bool & Engine::shouldClose ()
159191{
160192 return glfwWindowShouldClose (&mp_window->getHandle ());
@@ -175,7 +207,7 @@ void Engine::update()
175207 if (frame == -1 )
176208 return ;
177209
178- if (mp_scene->isUpdate (frame) || mp_renderer->NeedUpdate (frame))
210+ if (mp_scene->IsUpdate (frame) || mp_renderer->NeedUpdate (frame))
179211 {
180212 mp_renderer->WaitForSwapchainImageFence ();
181213
@@ -193,10 +225,21 @@ void Engine::update()
193225 mp_scene->UpdateUBO (mp_main_camera, mp_renderer, frame);
194226 mp_scene->UpdateSceneUBO (mp_renderer);
195227
228+ // Update UI
229+ ImGui_ImplVulkan_NewFrame ();
230+ ImGui_ImplGlfw_NewFrame ();
231+ ImGui::NewFrame ();
232+
233+ for (size_t i = 0 ; i < m_UIs.size (); i++)
234+ m_UIs[i]->Update (mp_config->width , mp_config->height );
235+
236+ ImGui::Render ();
237+
196238 // std::this_thread::sleep_for(std::chrono::nanoseconds(500));//delete when not streaming
197239}
198240
199241void Engine::draw ()
200242{
243+ mp_renderer->UpdateUI ();
201244 mp_renderer->draw ();
202245}
0 commit comments