Add imgui
This commit is contained in:
+35
-9
@@ -6,12 +6,14 @@
|
||||
#include <destrum/FS/AssetFS.h>
|
||||
#include <destrum/Util/DeltaTime.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "glm/gtx/transform.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
App::App() {}
|
||||
App::App() {
|
||||
}
|
||||
|
||||
void App::init(const AppParams& params) {
|
||||
void App::init(const AppParams ¶ms) {
|
||||
m_params = params;
|
||||
|
||||
AssetFS::GetInstance().Init(params.exeDir);
|
||||
@@ -35,6 +37,8 @@ void App::init(const AppParams& params) {
|
||||
}
|
||||
|
||||
gfxDevice.init(window, params.appName, false);
|
||||
imguiPass.init(window, gfxDevice);
|
||||
|
||||
|
||||
InputManager::GetInstance().Init();
|
||||
Time::GetInstance().Update();
|
||||
@@ -46,7 +50,7 @@ void App::run() {
|
||||
Time::GetInstance().Update(); // initialize delta timing
|
||||
|
||||
const float fixedDt = static_cast<float>(Time::GetInstance().FixedDeltaTime());
|
||||
const int maxSteps = 5; // prevent spiral of death
|
||||
const int maxSteps = 5; // prevent spiral of death
|
||||
float accumulator = 0.0f;
|
||||
|
||||
isRunning = true;
|
||||
@@ -68,9 +72,9 @@ void App::run() {
|
||||
camera.Update(dt);
|
||||
|
||||
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
imguiPass.handleEvent(event);
|
||||
if (event.type == SDL_QUIT) {
|
||||
isRunning = false;
|
||||
break;
|
||||
@@ -78,22 +82,44 @@ void App::run() {
|
||||
if (event.type == SDL_WINDOWEVENT) {
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
{
|
||||
case SDL_WINDOWEVENT_RESIZED: {
|
||||
resizePending = true;
|
||||
lastResizeTime = std::chrono::steady_clock::now();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (InputManager::GetInstance().ProcessEvent(event)) {
|
||||
isRunning = false;
|
||||
const bool mouseEvent =
|
||||
event.type == SDL_MOUSEBUTTONDOWN ||
|
||||
event.type == SDL_MOUSEBUTTONUP ||
|
||||
event.type == SDL_MOUSEMOTION ||
|
||||
event.type == SDL_MOUSEWHEEL;
|
||||
|
||||
const bool keyboardEvent =
|
||||
event.type == SDL_KEYDOWN ||
|
||||
event.type == SDL_KEYUP ||
|
||||
event.type == SDL_TEXTINPUT;
|
||||
|
||||
const bool capturedByImgui =
|
||||
(mouseEvent && imguiPass.wantsMouse()) ||
|
||||
(keyboardEvent && imguiPass.wantsKeyboard());
|
||||
|
||||
if (!capturedByImgui) {
|
||||
if (InputManager::GetInstance().ProcessEvent(event)) {
|
||||
isRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isRunning) break;
|
||||
imguiPass.beginFrame();
|
||||
|
||||
customUpdate(dt);
|
||||
|
||||
ImGui::Begin("Debug");
|
||||
ImGui::Text("FPS: %.2f", avgFPS);
|
||||
ImGui::End();
|
||||
|
||||
imguiPass.endFrame();
|
||||
int steps = 0;
|
||||
while (accumulator >= fixedDt && steps < maxSteps) {
|
||||
// physics.Update(fixedDt);
|
||||
@@ -116,7 +142,7 @@ void App::run() {
|
||||
if (resizePending &&
|
||||
now - lastResizeTime < std::chrono::milliseconds(100)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
|
||||
Reference in New Issue
Block a user