From 92eff7f19821a3d5df55112bffe756b1fea40bb7 Mon Sep 17 00:00:00 2001 From: irisz64 Date: Thu, 3 Jul 2025 10:42:48 +0200 Subject: [PATCH] Make CPU respect chosen option (JIT, etc) --- src/backend/Core.cpp | 8 +++++- src/backend/Core.hpp | 7 ++++- src/frontend/AudioSettings.cpp | 4 --- src/frontend/CPUSettings.cpp | 10 ++----- src/frontend/CPUSettings.hpp | 1 + src/frontend/KaizenGui.cpp | 49 +++++++++++++++++++++------------ src/frontend/KaizenGui.hpp | 3 +- src/frontend/SettingsWindow.cpp | 12 ++++---- src/frontend/SettingsWindow.hpp | 3 +- 9 files changed, 57 insertions(+), 40 deletions(-) diff --git a/src/backend/Core.cpp b/src/backend/Core.cpp index 264d3f87..f8ae99dd 100644 --- a/src/backend/Core.cpp +++ b/src/backend/Core.cpp @@ -3,7 +3,13 @@ #include namespace n64 { -Core::Core() : cpu(std::make_unique(parallel)) {} +Core::Core(CPUType cpuType) { + switch (cpuType) { + case Interpreted: cpu = std::make_unique(parallel); break; + case DynamicRecompiler: cpu = std::make_unique(parallel); break; + default: Util::panic("Unimplemented CPU type\n"); + } +} void Core::Stop() { pause = true; diff --git a/src/backend/Core.hpp b/src/backend/Core.hpp index 7c50c1c7..f8906e68 100644 --- a/src/backend/Core.hpp +++ b/src/backend/Core.hpp @@ -6,7 +6,12 @@ namespace n64 { struct Core { - explicit Core(); + enum CPUType { + Interpreted, + DynamicRecompiler, + CachedInterpreter + }; + explicit Core(CPUType); void Stop(); void LoadROM(const std::string &); [[nodiscard]] bool LoadTAS(const fs::path &) const; diff --git a/src/frontend/AudioSettings.cpp b/src/frontend/AudioSettings.cpp index 752c08ad..b13c7abb 100644 --- a/src/frontend/AudioSettings.cpp +++ b/src/frontend/AudioSettings.cpp @@ -17,8 +17,6 @@ bool AudioSettings::render() { modified = true; } - - ImGui::SameLine(); if(ImGui::SliderFloat("Volume L", &volumeL, 0.f, 100.f, "%.2f")) { Options::GetInstance().SetValue("audio", "volumeL", volumeL / 100.f); @@ -30,8 +28,6 @@ bool AudioSettings::render() { modified = true; } - ImGui::SameLine(); - ImGui::BeginDisabled(lockChannels); if(ImGui::SliderFloat("Volume R", &volumeR, 0.f, 100.f, "%.2f")) { Options::GetInstance().SetValue("audio", "volumeR", volumeR / 100.f); diff --git a/src/frontend/CPUSettings.cpp b/src/frontend/CPUSettings.cpp index 41d81215..f32d8b94 100644 --- a/src/frontend/CPUSettings.cpp +++ b/src/frontend/CPUSettings.cpp @@ -19,10 +19,7 @@ bool CPUSettings::render() { const char* combo_preview_value = items[selectedCpuTypeIndex]; if (ImGui::BeginCombo("CPU Type", combo_preview_value)) { - for (int n = 0; n < IM_ARRAYSIZE(items); n++) { - if(n == 1) // make JIT non-selectable but visible for now. - ImGui::BeginDisabled(true); - + for (int n = 0; n < IM_ARRAYSIZE(items); n++) { const bool is_selected = (selectedCpuTypeIndex == n); if (ImGui::Selectable(items[n], is_selected)) { selectedCpuTypeIndex = n; @@ -32,9 +29,6 @@ bool CPUSettings::render() { // Set the initial focus when opening the combo (scrolling + keyboard navigation focus) if (is_selected) ImGui::SetItemDefaultFocus(); - - if(n == 1) // make JIT non-selectable but visible for now. - ImGui::EndDisabled(); } ImGui::EndCombo(); } @@ -43,7 +37,7 @@ bool CPUSettings::render() { if(selectedCpuTypeIndex == 0) { Options::GetInstance().SetValue("cpu", "type", "interpreter"); } else { - Util::panic("JIT should not be selectable??"); + Options::GetInstance().SetValue("cpu", "type", "jit"); } } diff --git a/src/frontend/CPUSettings.hpp b/src/frontend/CPUSettings.hpp index 63f4859c..9b132520 100644 --- a/src/frontend/CPUSettings.hpp +++ b/src/frontend/CPUSettings.hpp @@ -5,6 +5,7 @@ class CPUSettings final { int selectedCpuTypeIndex = 0; bool modified = false; public: + int GetCPUType() { return selectedCpuTypeIndex; } bool render(); explicit CPUSettings(); void setModified(bool v) { modified = v; } diff --git a/src/frontend/KaizenGui.cpp b/src/frontend/KaizenGui.cpp index 2e55e555..637390af 100644 --- a/src/frontend/KaizenGui.cpp +++ b/src/frontend/KaizenGui.cpp @@ -5,7 +5,7 @@ #include #include -KaizenGui::KaizenGui() noexcept : window("Kaizen", 800, 600), core(std::make_shared()), vulkanWidget(core, window.getHandle()), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) { +KaizenGui::KaizenGui() noexcept : window("Kaizen", 800, 600), core(std::make_shared(static_cast(settingsWindow.cpuSettings.GetCPUType()))), vulkanWidget(core, window.getHandle()), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) { gui::Initialize(core->parallel.wsi, window.getHandle()); SDL_InitSubSystem(SDL_INIT_GAMEPAD); @@ -179,34 +179,47 @@ void KaizenGui::RenderUI() { ImGui::EndDisabled(); - if(ImGui::MenuItem("Settings")) { - settingsWindow.render(); + if(ImGui::MenuItem("Options")) { + settingsWindow.isOpen = true; } ImGui::EndMenu(); } if(ImGui::BeginMenu("Help")) { if(ImGui::MenuItem("About")) { - ImGui::OpenPopup("About Kaizen"); - ImVec2 center = ImGui::GetMainViewport()->GetCenter(); - ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); - - if (ImGui::BeginPopupModal("About Kaizen", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::Text("Kaizen is a Nintendo 64 emulator that strives"); - ImGui::Text("to offer a friendly user experience and compatibility."); - ImGui::Text("Kaizen is licensed under the BSD 3-clause license."); - ImGui::Text("Nintendo 64 is a registered trademark of Nintendo Co., Ltd."); - if(ImGui::Button("OK")) { - ImGui::CloseCurrentPopup(); - } - - ImGui::EndPopup(); - } + aboutOpen = true; } ImGui::EndMenu(); } ImGui::EndMainMenuBar(); } + + if(settingsWindow.isOpen) { + ImGui::OpenPopup("Settings", ImGuiPopupFlags_None); + } + + if(aboutOpen) { + ImGui::OpenPopup("About Kaizen"); + } + + settingsWindow.render(); + + ImVec2 center = ImGui::GetMainViewport()->GetCenter(); + ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + + if (ImGui::BeginPopupModal("About Kaizen", &aboutOpen, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::Text("Kaizen is a Nintendo 64 emulator that strives"); + ImGui::Text("to offer a friendly user experience and compatibility."); + ImGui::Text("Kaizen is licensed under the BSD 3-clause license."); + ImGui::Text("Nintendo 64 is a registered trademark of Nintendo Co., Ltd."); + if(ImGui::Button("OK")) { + aboutOpen = false; + ImGui::CloseCurrentPopup(); + } + + ImGui::EndPopup(); + } + if(ImGui::BeginMainStatusBar()) { ImGui::Text("FPS: %.2f", ImGui::GetIO().Framerate); ImGui::EndMainStatusBar(); diff --git a/src/frontend/KaizenGui.hpp b/src/frontend/KaizenGui.hpp index d213dda2..44286ad4 100644 --- a/src/frontend/KaizenGui.hpp +++ b/src/frontend/KaizenGui.hpp @@ -14,9 +14,9 @@ public: double fpsCounter = -1.0; + SettingsWindow settingsWindow; std::shared_ptr core; RenderWidget vulkanWidget; - SettingsWindow settingsWindow; EmuThread emuThread; SDL_Gamepad* gamepad = nullptr; @@ -25,6 +25,7 @@ public: void LoadTAS(const std::string &path) const noexcept; void LoadROM(const std::string &path) noexcept; private: + bool aboutOpen = false; bool quit = false; std::function emuExitFunc; void FileDialog(); diff --git a/src/frontend/SettingsWindow.cpp b/src/frontend/SettingsWindow.cpp index b1da5ea0..c9a1dbc1 100644 --- a/src/frontend/SettingsWindow.cpp +++ b/src/frontend/SettingsWindow.cpp @@ -8,17 +8,12 @@ std::string savePath; bool SettingsWindow::render() { - ImGui::OpenPopup("Settings", ImGuiPopupFlags_None); ImVec2 center = ImGui::GetMainViewport()->GetCenter(); ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); - if(ImGui::BeginPopupModal("Settings")) { + if(ImGui::BeginPopupModal("Settings", &isOpen)) { if(ImGui::BeginTabBar("SettingsTabBar")) { if(ImGui::BeginTabItem("General")) { - ImGui::BeginDisabled(); - ImGui::InputText("Save Path", (char*)savesPath.c_str(), savesPath.length()); - ImGui::EndDisabled(); - ImGui::SameLine(); if(ImGui::Button("Pick...")) { NFD::Guard guard; NFD::UniquePath outPath; @@ -33,6 +28,10 @@ bool SettingsWindow::render() { applyEnabled = true; } } + ImGui::SameLine(); + ImGui::BeginDisabled(); + ImGui::InputText("Save Path", (char*)savesPath.c_str(), savesPath.length()); + ImGui::EndDisabled(); ImGui::EndTabItem(); } @@ -65,6 +64,7 @@ bool SettingsWindow::render() { ImGui::SameLine(); if(ImGui::Button("Cancel")) { + isOpen = false; ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); diff --git a/src/frontend/SettingsWindow.hpp b/src/frontend/SettingsWindow.hpp index 6561c423..24353dc7 100644 --- a/src/frontend/SettingsWindow.hpp +++ b/src/frontend/SettingsWindow.hpp @@ -5,11 +5,12 @@ #include class SettingsWindow final { - CPUSettings cpuSettings; AudioSettings audioSettings; std::string savesPath; bool applyEnabled = false; public: + CPUSettings cpuSettings; + bool isOpen = false; bool render(); SettingsWindow() = default; [[nodiscard]] float getVolumeL() const { return audioSettings.volumeL / 100.f; }