diff --git a/src/game/Input.cpp b/src/game/Input.cpp index efc72b5..7ef7d3b 100644 --- a/src/game/Input.cpp +++ b/src/game/Input.cpp @@ -2,6 +2,7 @@ #include "Global.h" #include "Input.h" #include "imgui.h" +#include "imgui_internal.h" namespace Game { @@ -9,12 +10,14 @@ namespace Game bool IsKeyboardAllowed() { + if (GImGui == nullptr) return true; auto& IO = ImGui::GetIO(); return !IO.WantCaptureKeyboard || GetFlag(IO.ConfigFlags, ImGuiConfigFlags_NoKeyboard); } bool IsMouseAllowed() { + if (GImGui == nullptr) return true; auto& IO = ImGui::GetIO(); return !IO.WantCaptureMouse || GetFlag(IO.ConfigFlags, ImGuiConfigFlags_NoMouse); } @@ -60,6 +63,8 @@ namespace Game } Vec2 GetMousePos() { + // TODO: fix this!! + if (GImGui == nullptr) return {}; ImVec2 pos = ImGui::GetMousePos(); return {pos.x, pos.y}; } diff --git a/src/game/Level.cpp b/src/game/Level.cpp index 62c4e04..f0f5f38 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -93,9 +93,15 @@ namespace Game bool IsGaming = GetInstance().Player.InputM == InputMode::Game; bool captureMouse = IsGaming && GetInstance().Player.InteractionM == InteractionMode::Walk; SDL_SetWindowRelativeMouseMode(GetShared().Window.SDLWindow, captureMouse); - auto& IO = ImGui::GetIO(); - IO.ConfigFlags = FlagBool(IO.ConfigFlags, ImGuiConfigFlags_NoMouse | ImGuiConfigFlags_NoKeyboard, IsGaming); - GameRendering::Get().UIVisible = IsGaming ? UIVisibilityState::Game : UIVisibilityState::Debug; + + auto& rendering = GameRendering::Get(); + if (rendering.SetupData.UseImgui) + { + auto& IO = ImGui::GetIO(); + IO.ConfigFlags = + FlagBool(IO.ConfigFlags, ImGuiConfigFlags_NoMouse | ImGuiConfigFlags_NoKeyboard, IsGaming); + } + rendering.UIVisible = IsGaming ? UIVisibilityState::Game : UIVisibilityState::Debug; } } // namespace diff --git a/src/game/Setup.cpp b/src/game/Setup.cpp index 0338339..ebc9d91 100644 --- a/src/game/Setup.cpp +++ b/src/game/Setup.cpp @@ -58,7 +58,7 @@ namespace Game SetInstance(instance); ResetScratch(); Puzzle::LoadStaticPuzzleData(); - SetupInstance.Rendering.Setup(); + SetupInstance.Rendering.Setup({false}); instance.GameLevel.Setup(shared.Game); instance.IsInitialized = true; } diff --git a/src/game/Tools.cpp b/src/game/Tools.cpp index d283698..e641745 100644 --- a/src/game/Tools.cpp +++ b/src/game/Tools.cpp @@ -182,6 +182,8 @@ namespace Tools void RenderDebugUI(Game::GameRendering& rendering) { + if (!rendering.SetupData.UseImgui) return; + auto& time = Game::GetInstance().Time; auto& shared = Game::GetShared(); auto& debug = Game::GetInstance().DebugData; diff --git a/src/game/rendering/Rendering.cpp b/src/game/rendering/Rendering.cpp index 0dc722f..8ae02b9 100644 --- a/src/game/rendering/Rendering.cpp +++ b/src/game/rendering/Rendering.cpp @@ -312,11 +312,13 @@ namespace Game return *Instance; } - void GameRendering::Setup() + void GameRendering::Setup(const RenderingSetup& setup) { LOG("--- RENDERING STARTUP ---"); ZoneScopedN("Setup"); + SetupData = setup; + if (Instance != nullptr) LOG_WARN("old rendering wasn't destroyed!"); Instance = this; SharedData& shared = GetShared(); @@ -325,6 +327,8 @@ namespace Game init.type = bgfx::RendererType::Direct3D12; #ifdef _DEBUG // init.debug = true; +#else + // init.debug = false; #endif init.platformData.nwh = shared.Window.Handle; init.platformData.ndt = nullptr; @@ -354,23 +358,26 @@ namespace Game LoadModels(Models, ModelCount); ReloadShaders(); - imguiCreate(); - SetImguiStyle(); - if (!ImGui_ImplSDL3_InitForOther(shared.Window.SDLWindow)) + if (SetupData.UseImgui) { - LOG_ERROR("Failed to set up imgui implementation!"); - return; - } + imguiCreate(); + SetImguiStyle(); + if (!ImGui_ImplSDL3_InitForOther(shared.Window.SDLWindow)) + { + LOG_ERROR("Failed to set up imgui implementation!"); + return; + } - // ImGui::GetIO().BackendFlags |= ImGuiBackendFlags_RendererHasViewports; - ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable; - // ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; - // auto& platIO = ImGui::GetPlatformIO(); - // platIO.Renderer_CreateWindow = TODO; - // platIO.Platform_DestroyWindow = TODO; - // platIO.Platform_SetWindowSize = TODO; - // platIO.Platform_RenderWindow = TODO; + // ImGui::GetIO().BackendFlags |= ImGuiBackendFlags_RendererHasViewports; + ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable; + // ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; + // auto& platIO = ImGui::GetPlatformIO(); + // platIO.Renderer_CreateWindow = TODO; + // platIO.Platform_DestroyWindow = TODO; + // platIO.Platform_SetWindowSize = TODO; + // platIO.Platform_RenderWindow = TODO; + } GameInstance& inst = GetInstance(); if (!inst.IsInitialized) @@ -378,13 +385,16 @@ namespace Game inst.Time.StartTime = bx::getHPCounter(); } - if (inst.DebugData.ImguiIniSize > 0) + if (SetupData.UseImgui) { - ImGui::LoadIniSettingsFromMemory(inst.DebugData.ImguiIni, inst.DebugData.ImguiIniSize); - } - else - { - ImGui::LoadIniSettingsFromDisk("imgui.ini"); + if (inst.DebugData.ImguiIniSize > 0) + { + ImGui::LoadIniSettingsFromMemory(inst.DebugData.ImguiIni, inst.DebugData.ImguiIniSize); + } + else + { + ImGui::LoadIniSettingsFromDisk("imgui.ini"); + } } DitherGen(DitherTextures, DitherRecursion); } @@ -396,7 +406,10 @@ namespace Game for (uint16_t i = 0; i < shared.Window.SDLEventCount; ++i) { - ImGui_ImplSDL3_ProcessEvent(&shared.Window.SDLEvents[i]); + if (SetupData.UseImgui) + { + ImGui_ImplSDL3_ProcessEvent(&shared.Window.SDLEvents[i]); + } } shared.Window.SDLEventCount = 0; @@ -505,6 +518,7 @@ namespace Game HandleEvents(); // Start Rendering + if (SetupData.UseImgui) { ZoneScopedN("Imgui Start Frame"); imguiBeginFrame(20); @@ -518,12 +532,13 @@ namespace Game GetInstance().GameLevel.Render(MainViewID, Models, Materials, Textures); // Finish Frame + if (SetupData.UseImgui) { ZoneScopedN("Imgui End Frame"); imguiEndFrame(); } - if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + if (SetupData.UseImgui && ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { ZoneScopedN("Imgui Platform Update"); ImGui::UpdatePlatformWindows(); @@ -542,13 +557,18 @@ namespace Game { ZoneScopedN("Shutdown"); LOG("--- RENDERING_SHUTDOWN ---"); - ImGui::SaveIniSettingsToDisk("imgui.ini"); - auto& debug = GetInstance().DebugData; - const char* iniData = ImGui::SaveIniSettingsToMemory(reinterpret_cast(&debug.ImguiIniSize)); - assert(debug.ImguiIniSize <= BX_COUNTOF(InstanceDebugData::ImguiIni)); - bx::memCopy(debug.ImguiIni, iniData, bx::min(debug.ImguiIniSize, BX_COUNTOF(InstanceDebugData::ImguiIni))); - ImGui_ImplSDL3_Shutdown(); - imguiDestroy(); + + if (SetupData.UseImgui) + { + ImGui::SaveIniSettingsToDisk("imgui.ini"); + auto& debug = GetInstance().DebugData; + const char* iniData = ImGui::SaveIniSettingsToMemory(reinterpret_cast(&debug.ImguiIniSize)); + assert(debug.ImguiIniSize <= BX_COUNTOF(InstanceDebugData::ImguiIni)); + bx::memCopy(debug.ImguiIni, iniData, bx::min(debug.ImguiIniSize, BX_COUNTOF(InstanceDebugData::ImguiIni))); + ImGui_ImplSDL3_Shutdown(); + imguiDestroy(); + } + bgfx::shutdown(); Instance = nullptr; } diff --git a/src/game/rendering/Rendering.h b/src/game/rendering/Rendering.h index d778fcc..4519d72 100644 --- a/src/game/rendering/Rendering.h +++ b/src/game/rendering/Rendering.h @@ -64,6 +64,11 @@ namespace Game Debug, }; + struct RenderingSetup + { + bool UseImgui = true; + }; + class GameRendering { public: @@ -76,6 +81,7 @@ namespace Game DitherData DitherTextures; public: + RenderingSetup SetupData; bgfx::UniformHandle DefaultSampler; Texture Textures[MaxTextures]; Material Materials[8]; @@ -89,7 +95,7 @@ namespace Game int32_t DitherRecursion = 1; public: - void Setup(); + void Setup(const RenderingSetup& setup); void Update(); void HandleEvents(); void LoadTextures();