From 9fd6c585d64a74b6c775912ea483f42e2d7fb15f Mon Sep 17 00:00:00 2001 From: irisz64 Date: Fri, 23 May 2025 10:15:25 +0200 Subject: [PATCH] Settings widget mostly works --- external/parallel-rdp/ParallelRDPWrapper.cpp | 4 +++ src/frontend/CPUSettings.cpp | 2 ++ src/frontend/EmuThread.cpp | 2 +- src/frontend/ImGuiImpl/Combobox.hpp | 4 +-- src/frontend/ImGuiImpl/TabBar.hpp | 4 +-- src/frontend/InputSettings.cpp | 8 +++--- src/frontend/KaizenGui.cpp | 27 +++++++------------- src/frontend/SettingsWindow.cpp | 6 +++++ src/frontend/SettingsWindow.hpp | 2 +- 9 files changed, 32 insertions(+), 27 deletions(-) diff --git a/external/parallel-rdp/ParallelRDPWrapper.cpp b/external/parallel-rdp/ParallelRDPWrapper.cpp index cb8d152c..d701efaa 100644 --- a/external/parallel-rdp/ParallelRDPWrapper.cpp +++ b/external/parallel-rdp/ParallelRDPWrapper.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace Vulkan; using namespace RDP; @@ -158,7 +159,10 @@ void ParallelRDP::DrawFullscreenTexturedQuad(Util::IntrusivePtr image, cmd->draw(3, 1); } +std::mutex coreM; + void ParallelRDP::UpdateScreen(Util::IntrusivePtr image) const { + std::lock_guard coreLock(coreM); wsi->begin_frame(); if (!image) { diff --git a/src/frontend/CPUSettings.cpp b/src/frontend/CPUSettings.cpp index 7f363a0f..c2f6e4fc 100644 --- a/src/frontend/CPUSettings.cpp +++ b/src/frontend/CPUSettings.cpp @@ -20,4 +20,6 @@ bool CPUSettings::render() { modified = true; } + + return modified; } diff --git a/src/frontend/EmuThread.cpp b/src/frontend/EmuThread.cpp index e0b4b2dd..1175a4c3 100644 --- a/src/frontend/EmuThread.cpp +++ b/src/frontend/EmuThread.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include EmuThread::EmuThread(const std::shared_ptr &core, double &fps, RenderWidget &renderWidget, diff --git a/src/frontend/ImGuiImpl/Combobox.hpp b/src/frontend/ImGuiImpl/Combobox.hpp index 50f0fce5..9a1d7893 100644 --- a/src/frontend/ImGuiImpl/Combobox.hpp +++ b/src/frontend/ImGuiImpl/Combobox.hpp @@ -5,7 +5,7 @@ namespace gui { struct ComboItem { - ComboItem(std::string label, bool enabled = true) : enabled(enabled) {} + ComboItem(const std::string& label, bool enabled = true) : enabled(enabled), label(label) {} bool render(bool is_selected) { ImGui::BeginDisabled(!enabled); @@ -22,7 +22,7 @@ private: }; struct Combobox { - Combobox(std::string label, std::vector items, std::string preview = "", bool enabled = true) : label(label), items(items), preview(preview), enabled(enabled) {} + Combobox(const std::string& label, const std::vector& items, const std::string& preview = "", bool enabled = true) : label(label), items(items), preview(preview), enabled(enabled) {} void addItem(const ComboItem& item) { if(std::find_if(items.begin(), items.end(), diff --git a/src/frontend/ImGuiImpl/TabBar.hpp b/src/frontend/ImGuiImpl/TabBar.hpp index 6f79c0cd..4f0abb1f 100644 --- a/src/frontend/ImGuiImpl/TabBar.hpp +++ b/src/frontend/ImGuiImpl/TabBar.hpp @@ -7,7 +7,7 @@ namespace gui { struct TabItem { - TabItem(std::string label, std::function&& func, bool enabled = true) : exec(std::move(func)), enabled(enabled) {} + TabItem(const std::string& label, std::function&& func, bool enabled = true) : exec(std::move(func)), enabled(enabled), label(label) {} bool render() { bool ret = false; @@ -28,7 +28,7 @@ private: }; struct TabBar { - TabBar(std::string label, const std::vector& items = {}) : label(label), tabs(items) {} + TabBar(const std::string& label, const std::vector& items = {}) : label(label), tabs(items) {} void addTab(TabItem tabItem) { tabs.push_back(tabItem); } bool render() { diff --git a/src/frontend/InputSettings.cpp b/src/frontend/InputSettings.cpp index 5eff9b91..4370325a 100644 --- a/src/frontend/InputSettings.cpp +++ b/src/frontend/InputSettings.cpp @@ -3,8 +3,10 @@ #include InputSettings::InputSettings(nlohmann::json &settings) : settings(settings) { + int i = 0; for(auto& kb : kbButtons) { - kb.setLabel(JSONGetField(settings, "input", kb.getName())); + auto field = JSONGetField(settings, "input", kb.getName()); + kb.setLabel(field != "" ? field : "##unsetButton" + std::to_string(i++)); } devices.addItem({"Keyboard/Mouse"}); @@ -33,13 +35,13 @@ bool InputSettings::render() { QueryDevices(); PollGamepad(); - if(i % 2 != 0) // only go down every 2 buttons... just... i like it this way + if((i % 2 == 0) || i == 0) // only go down every 2 buttons... just... i like it this way ImGui::SameLine(); i++; } - return true; + return modified; } std::array InputSettings::GetMappedKeys() { diff --git a/src/frontend/KaizenGui.cpp b/src/frontend/KaizenGui.cpp index c4e33257..fc787352 100644 --- a/src/frontend/KaizenGui.cpp +++ b/src/frontend/KaizenGui.cpp @@ -4,10 +4,15 @@ #include #include -KaizenGui::KaizenGui() noexcept : window("Kaizen", 1280, 720), core(std::make_shared()), vulkanWidget(core, window.getHandle()), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) { +KaizenGui::KaizenGui() noexcept : window("Kaizen", 800, 600), core(std::make_shared()), vulkanWidget(core, window.getHandle()), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) { gui::Initialize(core->parallel.wsi, window.getHandle()); emuExitFunc = [&]() { + quit = true; + if (emuThread.isRunning) { + emuThread.requestInterruption(); + while (emuThread.isRunning) {} + } }; about.setFunc([&]() { @@ -17,6 +22,7 @@ KaizenGui::KaizenGui() noexcept : window("Kaizen", 1280, 720), core(std::make_sh ImGui::Text("Nintendo 64 is a registered trademark of Nintendo Co., Ltd."); if(ImGui::Button("OK")) { about.setOpened(false); + ImGui::CloseCurrentPopup(); } }); @@ -49,7 +55,6 @@ KaizenGui::KaizenGui() noexcept : window("Kaizen", 1280, 720), core(std::make_sh actionReset, {"Settings", [&]() { settingsWindow.popup.setOpened(true); - settingsWindow.render(); }}, }}); @@ -66,6 +71,7 @@ void KaizenGui::RenderUI() { menuBar.render(); about.render(); statusBar.render(); + settingsWindow.render(); gui::EndFrame(); if (core->render) { @@ -85,25 +91,10 @@ void KaizenGui::LoadROM(const std::string &path) noexcept { Util::RPC::GetInstance().Update(Util::RPC::Playing, gameNameDB); } -void KaizenGui::handleEvents() { - SDL_Event e; - while(SDL_PollEvent(&e)) { - switch(e.type) { - case SDL_EVENT_QUIT: - emuExitFunc(); - break; - } - } -} - int KaizenGui::run() { while(!quit) { if(vulkanWidget.wsiPlatform->quitRequested) { - quit = true; - if (emuThread.isRunning) { - emuThread.requestInterruption(); - while (emuThread.isRunning) {} - } + emuExitFunc(); } RenderUI(); diff --git a/src/frontend/SettingsWindow.cpp b/src/frontend/SettingsWindow.cpp index 3cb99949..f7bd3e6f 100644 --- a/src/frontend/SettingsWindow.cpp +++ b/src/frontend/SettingsWindow.cpp @@ -65,6 +65,12 @@ SettingsWindow::SettingsWindow() : settings{JSONOpenOrCreate("resources/settings file << settings; file.close(); } + + ImGui::SameLine(); + + if(cancel.render()) { + ImGui::CloseCurrentPopup(); + } }); } diff --git a/src/frontend/SettingsWindow.hpp b/src/frontend/SettingsWindow.hpp index f4736fe1..22dbe12f 100644 --- a/src/frontend/SettingsWindow.hpp +++ b/src/frontend/SettingsWindow.hpp @@ -14,7 +14,7 @@ class SettingsWindow final { AudioSettings audioSettings{settings}; InputSettings inputSettings{settings}; public: - gui::PopupWindow popup{"Settings"}; + gui::PopupWindow popup{"Emulator Settings"}; bool render(); SettingsWindow(); [[nodiscard]] float getVolumeL() const { return audioSettings.volumeL.getValue() / 100.f; }