From d1bcc1d8b539cc60b59bddb98d1fcb161f974c28 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 9 Aug 2022 18:27:33 -0400 Subject: [PATCH 1/3] CGraphicsPalette: Use GXDestroyTlutObj --- Runtime/Graphics/CGraphicsPalette.cpp | 6 ++++++ Runtime/Graphics/CGraphicsPalette.hpp | 1 + extern/aurora | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Runtime/Graphics/CGraphicsPalette.cpp b/Runtime/Graphics/CGraphicsPalette.cpp index be0216037..eb59bd9cc 100644 --- a/Runtime/Graphics/CGraphicsPalette.cpp +++ b/Runtime/Graphics/CGraphicsPalette.cpp @@ -19,6 +19,12 @@ CGraphicsPalette::CGraphicsPalette(CInputStream& in) : x0_fmt(EPaletteFormat(in. // DCFlushRange(xc_entries.get(), x8_entryCount * 2); } +CGraphicsPalette::~CGraphicsPalette() { +#ifdef AURORA + GXDestroyTlutObj(&x10_tlutObj); +#endif +} + void CGraphicsPalette::Load() { GXLoadTlut(&x10_tlutObj, GX_TLUT0); x4_frameLoaded = sCurrentFrameCount; diff --git a/Runtime/Graphics/CGraphicsPalette.hpp b/Runtime/Graphics/CGraphicsPalette.hpp index 813946fd9..5ffe01bc4 100644 --- a/Runtime/Graphics/CGraphicsPalette.hpp +++ b/Runtime/Graphics/CGraphicsPalette.hpp @@ -27,6 +27,7 @@ class CGraphicsPalette { public: explicit CGraphicsPalette(EPaletteFormat fmt, int count); explicit CGraphicsPalette(CInputStream& in); + ~CGraphicsPalette(); u16* Lock() { x1c_locked = true; diff --git a/extern/aurora b/extern/aurora index 5f06d873b..8cbebc12b 160000 --- a/extern/aurora +++ b/extern/aurora @@ -1 +1 @@ -Subproject commit 5f06d873bc25d139e5c1fe457a3e4706188c64ee +Subproject commit 8cbebc12b2b2d0598a130aa704855ceb89507068 From 5b6744e1881d804cbda7b83e2f56c1212a56b167 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 9 Aug 2022 18:28:42 -0400 Subject: [PATCH 2/3] Restore graphics backend switching --- Runtime/CMain.cpp | 35 ++---------- Runtime/ImGuiConsole.cpp | 117 +++++++++++++++++++++++++++++++-------- Runtime/ImGuiConsole.hpp | 4 ++ 3 files changed, 103 insertions(+), 53 deletions(-) diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index a08117437..04469bdd5 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -186,33 +186,8 @@ public: void onAppLaunched(const AuroraInfo& info) noexcept { initialize(); - std::string_view backend; - switch (info.backend) { - case BACKEND_D3D12: - backend = "D3D12"sv; - break; - case BACKEND_METAL: - backend = "Metal"sv; - break; - case BACKEND_VULKAN: - backend = "Vulkan"sv; - break; - case BACKEND_OPENGL: - backend = "OpenGL"sv; - break; - case BACKEND_OPENGLES: - backend = "OpenGL ES"sv; - break; - case BACKEND_WEBGPU: - backend = "WebGPU"sv; - break; - case BACKEND_NULL: - backend = "Null"sv; - break; - default: - break; - } - VISetWindowTitle(fmt::format(FMT_STRING("Metaforce {} [{}]"), METAFORCE_WC_DESCRIBE, backend).c_str()); + VISetWindowTitle( + fmt::format(FMT_STRING("Metaforce {} [{}]"), METAFORCE_WC_DESCRIBE, backend_name(info.backend)).c_str()); m_voiceEngine = boo::NewAudioVoiceEngine("metaforce", "Metaforce"); m_voiceEngine->setVolume(0.7f); @@ -449,8 +424,6 @@ static bool IsClientLoggingEnabled(int argc, char** argv) { #endif } -static void SetupLogging() {} - static std::unique_ptr g_app; static SDL_Window* g_window; static bool g_paused; @@ -539,7 +512,7 @@ int main(int argc, char** argv) { const AuroraConfig config{ .appName = "Metaforce", .configPath = configPath.c_str(), - // .desiredBackend = TODO + .desiredBackend = metaforce::backend_from_string(cvarCmns.getGraphicsApi()), .msaa = cvarCmns.getSamples(), .maxTextureAnisotropy = static_cast(cvarCmns.getAnisotropy()), .startFullscreen = cvarCmns.getFullscreen(), @@ -554,7 +527,7 @@ int main(int argc, char** argv) { g_app->onImGuiAddTextures(); g_app->onAppLaunched(info); g_app->onAppWindowResized(info.windowSize); - while (true) { + while (!cvarMgr.restartRequired()) { const auto* event = aurora_update(); bool exiting = false; while (event != nullptr && event->type != AURORA_NONE) { diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index 6c9cc5712..f24845a1b 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -1892,28 +1892,27 @@ void ImGuiConsole::ShowPreLaunchSettingsWindow() { if (ImGui::Begin("Settings", &m_showPreLaunchSettingsWindow, ImGuiWindowFlags_AlwaysAutoResize)) { if (ImGui::BeginTabBar("Settings")) { if (ImGui::BeginTabItem("Graphics")) { - // TODO - // static auto AvailableBackends = aurora::get_available_backends(); - // ImGuiStringViewText(fmt::format(FMT_STRING("Current backend: {}"), aurora::get_backend_string())); - // auto desiredBackend = static_cast(aurora::Backend::Invalid); - // if (auto* cvar = m_cvarMgr.findCVar("graphicsApi")) { - // bool valid = false; - // const auto name = cvar->toLiteral(&valid); - // if (valid) { - // desiredBackend = static_cast(aurora::backend_from_string(name)); - // } - // } - // bool modified = false; - // modified = ImGui::RadioButton("Auto", &desiredBackend, static_cast(aurora::Backend::Invalid)); - // for (const auto& item : AvailableBackends) { - // modified = ImGui::RadioButton(magic_enum::enum_name(item).data(), &desiredBackend, - // static_cast(item)) || - // modified; - // } - // if (modified) { - // m_cvarCommons.m_graphicsApi->fromLiteral( - // aurora::backend_to_string(static_cast(desiredBackend))); - // } + size_t backendCount = 0; + const auto* backends = aurora_get_available_backends(&backendCount); + ImGuiStringViewText(fmt::format(FMT_STRING("Current backend: {}"), backend_name(aurora_get_backend()))); + auto desiredBackend = static_cast(BACKEND_AUTO); + if (auto* cvar = m_cvarMgr.findCVar("graphicsApi")) { + bool valid = false; + const auto name = cvar->toLiteral(&valid); + if (valid) { + desiredBackend = static_cast(backend_from_string(name)); + } + } + bool modified = false; + modified = ImGui::RadioButton("Auto", &desiredBackend, static_cast(BACKEND_AUTO)); + for (size_t i = 0; i < backendCount; ++i, ++backends) { + const auto backend = *backends; + modified = + ImGui::RadioButton(backend_name(backend).data(), &desiredBackend, static_cast(backend)) || modified; + } + if (modified) { + m_cvarCommons.m_graphicsApi->fromLiteral(backend_to_string(static_cast(desiredBackend))); + } ImGuiCVarCheckbox(m_cvarMgr, "fullscreen", "Fullscreen"); ImGui::EndTabItem(); } @@ -1934,4 +1933,78 @@ void ImGuiConsole::ShowPreLaunchSettingsWindow() { } ImGui::End(); } + +static bool eq(std::string_view a, std::string_view b) { + if (a.size() != b.size()) { + return false; + } + return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](char a, char b) { return tolower(a) == b; }); +} + +AuroraBackend backend_from_string(const std::string& str) { + if (eq(str, "d3d12"sv) || eq(str, "d3d"sv)) { + return BACKEND_D3D12; + } + if (eq(str, "metal"sv)) { + return BACKEND_METAL; + } + if (eq(str, "vulkan"sv) || eq(str, "vk"sv)) { + return BACKEND_VULKAN; + } + if (eq(str, "opengl"sv) || eq(str, "gl"sv)) { + return BACKEND_OPENGL; + } + if (eq(str, "opengles"sv) || eq(str, "gles"sv)) { + return BACKEND_OPENGLES; + } + if (eq(str, "webgpu"sv) || eq(str, "wgpu"sv)) { + return BACKEND_WEBGPU; + } + if (eq(str, "null"sv) || eq(str, "none"sv)) { + return BACKEND_NULL; + } + return BACKEND_AUTO; +} + +std::string_view backend_to_string(AuroraBackend backend) { + switch (backend) { + default: + return "auto"sv; + case BACKEND_D3D12: + return "d3d12"sv; + case BACKEND_METAL: + return "metal"sv; + case BACKEND_VULKAN: + return "vulkan"sv; + case BACKEND_OPENGL: + return "opengl"sv; + case BACKEND_OPENGLES: + return "opengles"sv; + case BACKEND_WEBGPU: + return "webgpu"sv; + case BACKEND_NULL: + return "null"sv; + } +} + +std::string_view backend_name(AuroraBackend backend) { + switch (backend) { + default: + return "Auto"sv; + case BACKEND_D3D12: + return "D3D12"sv; + case BACKEND_METAL: + return "Metal"sv; + case BACKEND_VULKAN: + return "Vulkan"sv; + case BACKEND_OPENGL: + return "OpenGL"sv; + case BACKEND_OPENGLES: + return "OpenGL ES"sv; + case BACKEND_WEBGPU: + return "WebGPU"sv; + case BACKEND_NULL: + return "Null"sv; + } +} } // namespace metaforce diff --git a/Runtime/ImGuiConsole.hpp b/Runtime/ImGuiConsole.hpp index ad6ecd617..1f5cfc242 100644 --- a/Runtime/ImGuiConsole.hpp +++ b/Runtime/ImGuiConsole.hpp @@ -159,4 +159,8 @@ private: void ShowPipelineProgress(); void ShowPreLaunchSettingsWindow(); }; + +AuroraBackend backend_from_string(const std::string& str); +std::string_view backend_to_string(AuroraBackend backend); +std::string_view backend_name(AuroraBackend backend); } // namespace metaforce From 1193bab7e4b4a9b3ed2e5af6c7d104047b662c78 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 9 Aug 2022 18:29:12 -0400 Subject: [PATCH 3/3] Use Left Alt for ImGui toggle --- Runtime/CMain.cpp | 8 ++++++++ Runtime/ImGuiConsole.cpp | 11 +++++++---- Runtime/ImGuiConsole.hpp | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index 04469bdd5..4fc5171b6 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -168,6 +168,7 @@ private: bool m_firstFrame = true; bool m_fullscreenToggleRequested = false; bool m_quitRequested = false; + bool m_lAltHeld = false; using delta_clock = std::chrono::high_resolution_clock; delta_clock::time_point m_prevFrameTime; @@ -220,10 +221,17 @@ public: void onSdlEvent(const SDL_Event& event) noexcept { switch (event.type) { case SDL_KEYDOWN: + m_lAltHeld = event.key.keysym.sym == SDLK_LALT; // Toggle fullscreen on ALT+ENTER if (event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & KMOD_ALT) != 0u && event.key.repeat == 0u) { m_cvarCommons.m_fullscreen->fromBoolean(!m_cvarCommons.m_fullscreen->toBoolean()); } + break; + case SDL_KEYUP: + if (m_lAltHeld && event.key.keysym.sym == SDLK_LALT) { + m_imGuiConsole.ToggleVisible(); + m_lAltHeld = false; + } } } diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index f24845a1b..d560ef622 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -1301,6 +1301,12 @@ void ImGuiConsole::ShowAppMainMenuBar(bool canInspect, bool preLaunch) { } } +void ImGuiConsole::ToggleVisible() { + if (g_Main != nullptr) { + m_isVisible ^= 1; + } +} + void ImGuiConsole::PreUpdate() { OPTICK_EVENT(); bool preLaunch = g_Main == nullptr; @@ -1332,7 +1338,7 @@ void ImGuiConsole::PreUpdate() { } if (!preLaunch && !m_isLaunchInitialized) { if (m_developer) { - m_toasts.emplace_back("Press ` to toggle menu"s, 5.f); + m_toasts.emplace_back("Press Left Alt to toggle menu"s, 5.f); } m_isLaunchInitialized = true; } @@ -1342,9 +1348,6 @@ void ImGuiConsole::PreUpdate() { } if (!preLaunch) { - if (ImGui::IsKeyReleased(ImGuiKey_GraveAccent)) { - m_isVisible ^= 1; - } if (m_stepFrame) { g_Main->SetPaused(true); m_stepFrame = false; diff --git a/Runtime/ImGuiConsole.hpp b/Runtime/ImGuiConsole.hpp index 1f5cfc242..1954ed353 100644 --- a/Runtime/ImGuiConsole.hpp +++ b/Runtime/ImGuiConsole.hpp @@ -61,6 +61,7 @@ public: void ControllerAdded(uint32_t idx); void ControllerRemoved(uint32_t idx); + void ToggleVisible(); std::optional m_errorString; std::optional m_gameDiscSelected;