From 31e221bc925223a78cc44c440aea48049b14a092 Mon Sep 17 00:00:00 2001 From: Emil Lenngren Date: Thu, 14 Apr 2022 22:35:41 +0200 Subject: [PATCH] Restructure sohimgui code a bit and add graphics menu --- libultraship/libultraship/GameSettings.h | 5 ++ .../libultraship/Lib/Fast3D/gfx_pc.cpp | 6 +- libultraship/libultraship/Lib/ImGui/imgui.h | 1 - .../libultraship/Lib/ImGui/imgui_widgets.cpp | 27 -------- libultraship/libultraship/SohImGuiImpl.cpp | 69 +++++++++++-------- libultraship/libultraship/SohImGuiImpl.h | 4 +- 6 files changed, 52 insertions(+), 60 deletions(-) diff --git a/libultraship/libultraship/GameSettings.h b/libultraship/libultraship/GameSettings.h index 8e1293c65..bc8b7f7c8 100644 --- a/libultraship/libultraship/GameSettings.h +++ b/libultraship/libultraship/GameSettings.h @@ -50,6 +50,11 @@ struct SoHConfigType { bool moon_jump_on_l = false; bool super_tunic = false; } cheats; + + // Graphics + struct { + bool show = false; + } graphics; }; enum SeqPlayers { diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp index 9bc214e98..5918ccaf7 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp @@ -2690,7 +2690,7 @@ struct GfxRenderingAPI *gfx_get_current_rendering_api(void) { void gfx_start_frame(void) { gfx_wapi->handle_events(); gfx_wapi->get_dimensions(&gfx_current_window_dimensions.width, &gfx_current_window_dimensions.height); - SohImGui::Draw1(); + SohImGui::DrawMainMenuAndCalculateGameSize(); if (gfx_current_dimensions.height == 0) { // Avoid division by zero gfx_current_dimensions.height = 1; @@ -2738,7 +2738,7 @@ void gfx_run(Gfx *commands) { if (!gfx_wapi->start_frame()) { dropped_frame = true; - SohImGui::Draw2(); + SohImGui::DrawFramebufferAndGameInput(); SohImGui::CancelFrame(); return; } @@ -2769,7 +2769,7 @@ void gfx_run(Gfx *commands) { SohUtils::saveEnvironmentVar("framebuffer", std::to_string((uintptr_t)gfx_rapi->get_framebuffer_texture_id(game_framebuffer))); } } - SohImGui::Draw2(); + SohImGui::DrawFramebufferAndGameInput(); SohImGui::Render(); double t1 = gfx_wapi->get_time(); //printf("Process %f %f\n", t1, t1 - t0); diff --git a/libultraship/libultraship/Lib/ImGui/imgui.h b/libultraship/libultraship/Lib/ImGui/imgui.h index 907ef3c87..323832071 100644 --- a/libultraship/libultraship/Lib/ImGui/imgui.h +++ b/libultraship/libultraship/Lib/ImGui/imgui.h @@ -502,7 +502,6 @@ namespace ImGui IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size, ImGuiButtonFlags flags = 0); // flexible button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.) IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir); // square button with an arrow shape - IMGUI_API void ImageSimple(ImTextureID tex_id, ImVec2 center, ImVec2 size); IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0)); IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding IMGUI_API bool Checkbox(const char* label, bool* v); diff --git a/libultraship/libultraship/Lib/ImGui/imgui_widgets.cpp b/libultraship/libultraship/Lib/ImGui/imgui_widgets.cpp index ac89a54d6..8e4210002 100644 --- a/libultraship/libultraship/Lib/ImGui/imgui_widgets.cpp +++ b/libultraship/libultraship/Lib/ImGui/imgui_widgets.cpp @@ -1007,33 +1007,6 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6 return held; } -void ImGui::ImageSimple(ImTextureID tex_id, ImVec2 center, ImVec2 size) { - - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; - - ImDrawList* draw_list = ImGui::GetWindowDrawList(); - ImRect bb(window->DC.CursorPos + ImVec2(size.x / 2, size.y / 2), window->DC.CursorPos + size); - - ImVec2 pos[4] = - { - center + bb.Min + ImVec2(-size.x * 0.5f, -size.y * 0.5f), - center + bb.Min + ImVec2(+size.x * 0.5f, -size.y * 0.5f), - center + bb.Min + ImVec2(+size.x * 0.5f, +size.y * 0.5f), - center + bb.Min + ImVec2(-size.x * 0.5f, +size.y * 0.5f) - }; - ImVec2 uvs[4] = - { - ImVec2(0.0f, 0.0f), - ImVec2(1.0f, 0.0f), - ImVec2(1.0f, 1.0f), - ImVec2(0.0f, 1.0f) - }; - - draw_list->AddImageQuad(tex_id, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], IM_COL32_WHITE); -} - void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col) { ImGuiWindow* window = GetCurrentWindow(); diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 72d0041c4..45c468e90 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -248,7 +248,7 @@ namespace SohImGui { } } - void Draw1() { + void DrawMainMenuAndCalculateGameSize() { console->Update(); ImGuiBackendNewFrame(); ImGuiWMNewFrame(); @@ -408,6 +408,11 @@ namespace SohImGui { ImGui::EndMenu(); } + if (ImGui::BeginMenu("Graphics")) { + HOOK(ImGui::MenuItem("Anti-aliasing", nullptr, &Game::Settings.graphics.show)); + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Cheats")) { if (ImGui::Checkbox("Infinite Money", &Game::Settings.cheats.infinite_money)) { CVar_SetS32("gInfiniteMoney", Game::Settings.cheats.infinite_money); @@ -465,6 +470,38 @@ namespace SohImGui { } ImGui::End(); + + if (Game::Settings.debug.soh) { + const float framerate = ImGui::GetIO().Framerate; + ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0)); + ImGui::Begin("Debug Stats", nullptr, ImGuiWindowFlags_None); + + ImGui::Text("Platform: Windows"); + ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", 1000.0f / framerate, framerate); + ImGui::End(); + ImGui::PopStyleColor(); + } + + if (Game::Settings.graphics.show) { + ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0)); + ImGui::Begin("Anti-aliasing settings", nullptr, ImGuiWindowFlags_None); + ImGui::Text("Internal Resolution:"); + ImGui::SliderInt("Mul", reinterpret_cast(&gfx_current_dimensions.internal_mul), 1, 8); + ImGui::Text("MSAA:"); + ImGui::SliderInt("MSAA", reinterpret_cast(&gfx_msaa_level), 1, 8); + ImGui::End(); + ImGui::PopStyleColor(); + } + + console->Draw(); + + for (auto& windowIter : customWindows) { + CustomWindow& window = windowIter.second; + if (window.drawFunc != nullptr) { + window.drawFunc(window.enabled); + } + } + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f); @@ -496,7 +533,7 @@ namespace SohImGui { } } - void Draw2() { + void DrawFramebufferAndGameInput() { ImVec2 main_pos = ImGui::GetWindowPos(); ImVec2 size = ImGui::GetContentRegionAvail(); ImVec2 pos = ImVec2(0, 0); @@ -508,26 +545,13 @@ namespace SohImGui { std::string fb_str = SohUtils::getEnvironmentVar("framebuffer"); if (!fb_str.empty()) { uintptr_t fbuf = (uintptr_t)std::stoull(fb_str); - ImGui::ImageSimple(reinterpret_cast(fbuf), pos, size); + //ImGui::ImageSimple(reinterpret_cast(fbuf), pos, size); + ImGui::SetCursorPos(pos); + ImGui::Image(reinterpret_cast(fbuf), size); } ImGui::End(); - if (Game::Settings.debug.soh) { - const float framerate = ImGui::GetIO().Framerate; - ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0)); - ImGui::Begin("Debug Stats", nullptr, ImGuiWindowFlags_None); - - ImGui::Text("Platform: Windows"); - ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", 1000.0f / framerate, framerate); - ImGui::Text("Internal Resolution:"); - ImGui::SliderInt("Mul", reinterpret_cast(&gfx_current_dimensions.internal_mul), 1, 8); - ImGui::Text("MSAA:"); - ImGui::SliderInt("MSAA", reinterpret_cast(&gfx_msaa_level), 1, 8); - ImGui::End(); - ImGui::PopStyleColor(); - } - const float scale = Game::Settings.controller.input_scale; ImVec2 BtnPos = ImVec2(160 * scale, 85 * scale); @@ -577,15 +601,6 @@ namespace SohImGui { ImGui::End(); } } - - console->Draw(); - - for (auto& windowIter : customWindows) { - CustomWindow& window = windowIter.second; - if (window.drawFunc != nullptr) { - window.drawFunc(window.enabled); - } - } } void Render() { diff --git a/libultraship/libultraship/SohImGuiImpl.h b/libultraship/libultraship/SohImGuiImpl.h index 60d10d5ce..a73a4cbb8 100644 --- a/libultraship/libultraship/SohImGuiImpl.h +++ b/libultraship/libultraship/SohImGuiImpl.h @@ -59,8 +59,8 @@ namespace SohImGui { extern Console* console; void Init(WindowImpl window_impl); void Update(EventImpl event); - void Draw1(void); - void Draw2(void); + void DrawMainMenuAndCalculateGameSize(void); + void DrawFramebufferAndGameInput(void); void Render(void); void CancelFrame(void); void ShowCursor(bool hide, Dialogues w);