This commit is contained in:
iris
2026-04-13 23:58:36 +02:00
parent ad6007b254
commit 004dcee429
2 changed files with 264 additions and 237 deletions
+56 -30
View File
@@ -8,7 +8,9 @@
using namespace std::chrono_literals; using namespace std::chrono_literals;
KaizenGui::KaizenGui() noexcept : window("Kaizen " KAIZEN_VERSION_STR, 1280, 720), settingsWindow(window), emuThread(fpsCounter, settingsWindow), vulkanWidget(window.getHandle(), emuThread.rdramCopy.data()) { KaizenGui::KaizenGui() noexcept :
window("Kaizen " KAIZEN_VERSION_STR, 1280, 720), settingsWindow(window), emuThread(fpsCounter, settingsWindow),
vulkanWidget(window.getHandle(), emuThread.rdramCopy.data()) {
gui::Initialize(n64::Core::GetInstance().parallel.wsi, window.getHandle()); gui::Initialize(n64::Core::GetInstance().parallel.wsi, window.getHandle());
SDL_InitSubSystem(SDL_INIT_GAMEPAD); SDL_InitSubSystem(SDL_INIT_GAMEPAD);
@@ -36,7 +38,8 @@ void KaizenGui::QueryDevices(const SDL_Event &event) {
if (gamepad) if (gamepad)
SDL_CloseGamepad(gamepad); SDL_CloseGamepad(gamepad);
break; break;
default: break; default:
break;
} }
} }
@@ -48,7 +51,8 @@ void KaizenGui::HandleInput(const SDL_Event &event) {
if (!gamepad) if (!gamepad)
break; break;
{ {
pif.UpdateButton(0, n64::Controller::Key::Z, SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_LEFT_TRIGGER) == SDL_JOYSTICK_AXIS_MAX); pif.UpdateButton(0, n64::Controller::Key::Z,
SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_LEFT_TRIGGER) == SDL_JOYSTICK_AXIS_MAX);
pif.UpdateButton(0, n64::Controller::Key::CUp, SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_RIGHTY) <= -127); pif.UpdateButton(0, n64::Controller::Key::CUp, SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_RIGHTY) <= -127);
pif.UpdateButton(0, n64::Controller::Key::CDown, SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_RIGHTY) >= 127); pif.UpdateButton(0, n64::Controller::Key::CDown, SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_RIGHTY) >= 127);
pif.UpdateButton(0, n64::Controller::Key::CLeft, SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_RIGHTX) <= -127); pif.UpdateButton(0, n64::Controller::Key::CLeft, SDL_GetGamepadAxis(gamepad, SDL_GAMEPAD_AXIS_RIGHTX) <= -127);
@@ -137,16 +141,21 @@ void KaizenGui::HandleInput(const SDL_Event &event) {
float x = 0, y = 0; float x = 0, y = 0;
if (keys[SDL_SCANCODE_UP]) y = 86; if (keys[SDL_SCANCODE_UP])
if (keys[SDL_SCANCODE_DOWN]) y = -86; y = 86;
if (keys[SDL_SCANCODE_LEFT]) x = -86; if (keys[SDL_SCANCODE_DOWN])
if (keys[SDL_SCANCODE_RIGHT]) x = 86; y = -86;
if (keys[SDL_SCANCODE_LEFT])
x = -86;
if (keys[SDL_SCANCODE_RIGHT])
x = 86;
pif.UpdateAxis(0, n64::Controller::Axis::X, x); pif.UpdateAxis(0, n64::Controller::Axis::X, x);
pif.UpdateAxis(0, n64::Controller::Axis::Y, y); pif.UpdateAxis(0, n64::Controller::Axis::Y, y);
} }
break; break;
default: break; default:
break;
} }
} }
@@ -159,9 +168,9 @@ std::pair<std::optional<s64>, std::optional<Util::Error::MemoryAccess>> RenderEr
auto memoryAccess = Util::Error::GetMemoryAccess(); auto memoryAccess = Util::Error::GetMemoryAccess();
if (memoryAccess.has_value()) { if (memoryAccess.has_value()) {
const auto [is_write, size, address, written_val] = memoryAccess.value(); const auto [is_write, size, address, written_val] = memoryAccess.value();
ImGui::Text("%s", std::format("{} {}-bit value @ {:08X}{}", is_write ? "Writing" : "Reading", ImGui::Text("%s",
static_cast<u8>(size), address, std::format("{} {}-bit value @ {:08X}{}", is_write ? "Writing" : "Reading", static_cast<u8>(size),
is_write ? std::format(" (value = 0x{:X})", written_val) : "") address, is_write ? std::format(" (value = 0x{:X})", written_val) : "")
.c_str()); .c_str());
} }
@@ -263,7 +272,8 @@ void KaizenGui::RenderUI() {
if (ImGui::BeginPopupModal(Util::Error::GetSeverity().as_c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { if (ImGui::BeginPopupModal(Util::Error::GetSeverity().as_c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
emuThread.TogglePause(); emuThread.TogglePause();
switch (Util::Error::GetSeverity().as_enum) { switch (Util::Error::GetSeverity().as_enum) {
case Util::Error::Severity::WARN: { case Util::Error::Severity::WARN:
{
ImGui::PushStyleColor(ImGuiCol_TitleBg, 0x8054eae5); ImGui::PushStyleColor(ImGuiCol_TitleBg, 0x8054eae5);
ImGui::PushStyleColor(ImGuiCol_Text, 0xff7be4e1); ImGui::PushStyleColor(ImGuiCol_Text, 0xff7be4e1);
ImGui::Text("Warning of type: %s", Util::Error::GetType().as_c_str()); ImGui::Text("Warning of type: %s", Util::Error::GetType().as_c_str());
@@ -273,8 +283,10 @@ void KaizenGui::RenderUI() {
RenderErrorMessageDetails(); RenderErrorMessageDetails();
if (n64::Core::GetInstance().romLoaded && !n64::Core::GetInstance().pause) { if (n64::Core::GetInstance().romLoaded && !n64::Core::GetInstance().pause) {
const bool ignore = ImGui::Button("Try continuing"); ImGui::SameLine(); const bool ignore = ImGui::Button("Try continuing");
const bool stop = ImGui::Button("Stop emulation"); ImGui::SameLine(); ImGui::SameLine();
const bool stop = ImGui::Button("Stop emulation");
ImGui::SameLine();
const bool chooseAnother = ImGui::Button("Choose another ROM"); const bool chooseAnother = ImGui::Button("Choose another ROM");
if (ignore || stop || chooseAnother) { if (ignore || stop || chooseAnother) {
Util::Error::SetHandled(); Util::Error::SetHandled();
@@ -297,8 +309,10 @@ void KaizenGui::RenderUI() {
if (ImGui::Button("OK")) if (ImGui::Button("OK"))
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} break; }
case Util::Error::Severity::UNRECOVERABLE: { break;
case Util::Error::Severity::UNRECOVERABLE:
{
emuThread.Stop(); emuThread.Stop();
ImGui::PushStyleColor(ImGuiCol_TitleBg, 0x800000ff); ImGui::PushStyleColor(ImGuiCol_TitleBg, 0x800000ff);
ImGui::PushStyleColor(ImGuiCol_Text, 0xff3b3bbf); ImGui::PushStyleColor(ImGuiCol_Text, 0xff3b3bbf);
@@ -310,8 +324,10 @@ void KaizenGui::RenderUI() {
RenderErrorMessageDetails(); RenderErrorMessageDetails();
if (ImGui::Button("OK")) if (ImGui::Button("OK"))
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} break; }
case Util::Error::Severity::NON_FATAL: { break;
case Util::Error::Severity::NON_FATAL:
{
ImGui::PushStyleColor(ImGuiCol_TitleBg, 0x800000ff); ImGui::PushStyleColor(ImGuiCol_TitleBg, 0x800000ff);
ImGui::PushStyleColor(ImGuiCol_Text, 0xff3b3bbf); ImGui::PushStyleColor(ImGuiCol_Text, 0xff3b3bbf);
ImGui::Text("An error has occurred!"); ImGui::Text("An error has occurred!");
@@ -321,10 +337,13 @@ void KaizenGui::RenderUI() {
ImGui::Text(R"(Error message: "%s")", Util::Error::GetError().c_str()); ImGui::Text(R"(Error message: "%s")", Util::Error::GetError().c_str());
auto [lastPC, memoryAccess] = RenderErrorMessageDetails(); auto [lastPC, memoryAccess] = RenderErrorMessageDetails();
const bool ignore = ImGui::Button("Try continuing"); ImGui::SameLine(); const bool ignore = ImGui::Button("Try continuing");
const bool stop = ImGui::Button("Stop emulation"); ImGui::SameLine(); ImGui::SameLine();
const bool stop = ImGui::Button("Stop emulation");
ImGui::SameLine();
const bool chooseAnother = ImGui::Button("Choose another ROM"); const bool chooseAnother = ImGui::Button("Choose another ROM");
const bool openInDebugger = lastPC.has_value() ? ImGui::Button("Add breakpoint at this PC and open the debugger") : false; const bool openInDebugger =
lastPC.has_value() ? ImGui::Button("Add breakpoint at this PC and open the debugger") : false;
if (ignore || stop || chooseAnother || openInDebugger) { if (ignore || stop || chooseAnother || openInDebugger) {
Util::Error::SetHandled(); Util::Error::SetHandled();
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
@@ -349,8 +368,10 @@ void KaizenGui::RenderUI() {
debugger.Open(); debugger.Open();
emuThread.Reset(); emuThread.Reset();
} }
} break; }
default: break; break;
default:
break;
} }
ImGui::EndPopup(); ImGui::EndPopup();
@@ -362,7 +383,8 @@ void KaizenGui::RenderUI() {
} }
if (shouldDisplaySpinner) { if (shouldDisplaySpinner) {
ImGui::SetNextWindowPos({static_cast<float>(width) * 0.5f, static_cast<float>(height) * 0.5f}, 0, ImVec2(0.5f, 0.5f)); ImGui::SetNextWindowPos({static_cast<float>(width) * 0.5f, static_cast<float>(height) * 0.5f}, 0,
ImVec2(0.5f, 0.5f));
ImGui::PushStyleColor(ImGuiCol_WindowBg, IM_COL32_BLACK_TRANS); ImGui::PushStyleColor(ImGuiCol_WindowBg, IM_COL32_BLACK_TRANS);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
@@ -389,8 +411,11 @@ void KaizenGui::RenderUI() {
if (fileDialogOpen) { if (fileDialogOpen) {
fileDialogOpen = false; fileDialogOpen = false;
constexpr SDL_DialogFileFilter filters[] = {{"All files", "*"}, {"Nintendo 64 executable", "n64;z64;v64"}, {"Nintendo 64 executable archive", "rar;tar;zip;7z"}}; constexpr SDL_DialogFileFilter filters[] = {{"All files", "*"},
SDL_ShowOpenFileDialog([](void *userdata, const char * const *filelist, int) { {"Nintendo 64 executable", "n64;z64;v64"},
{"Nintendo 64 executable archive", "rar;tar;zip;7z"}};
SDL_ShowOpenFileDialog(
[](void *userdata, const char *const *filelist, int) {
auto kaizen = static_cast<KaizenGui *>(userdata); auto kaizen = static_cast<KaizenGui *>(userdata);
if (!filelist) { if (!filelist) {
@@ -408,7 +433,8 @@ void KaizenGui::RenderUI() {
std::thread fileWorker(&KaizenGui::FileWorker, kaizen); std::thread fileWorker(&KaizenGui::FileWorker, kaizen);
fileWorker.detach(); fileWorker.detach();
}, this, window.getHandle(), filters, 3, nullptr, false); },
this, window.getHandle(), filters, 3, nullptr, false);
} }
if (minimized) if (minimized)
@@ -451,6 +477,7 @@ void KaizenGui::run() {
minimized = false; minimized = false;
break; break;
default: default:
break;
} }
QueryDevices(e); QueryDevices(e);
HandleInput(e); HandleInput(e);
@@ -461,6 +488,5 @@ void KaizenGui::run() {
} }
} }
void KaizenGui::LoadTAS(const std::string &path) noexcept { void KaizenGui::LoadTAS(const std::string &path) noexcept { n64::Core::GetInstance().LoadTAS(fs::path(path)); }
n64::Core::GetInstance().LoadTAS(fs::path(path));
}
+2 -1
View File
@@ -1,6 +1,5 @@
#pragma once #pragma once
#include <filesystem> #include <filesystem>
#include <fstream>
#include <common.hpp> #include <common.hpp>
#include <mini/ini.h> #include <mini/ini.h>
#include <log.hpp> #include <log.hpp>
@@ -40,7 +39,9 @@ struct Options {
if (!file.write(structure)) if (!file.write(structure))
panic("Could not modify options on disk!"); panic("Could not modify options on disk!");
} }
private: private:
mINI::INIFile file; mINI::INIFile file;
mINI::INIStructure structure; mINI::INIStructure structure;
}; };