remove json lib

This commit is contained in:
irisz64
2025-06-26 23:33:03 +02:00
parent df55ee6d9b
commit 4e7afcd49e
1175 changed files with 125 additions and 183754 deletions

View File

@@ -101,7 +101,6 @@ if (${CMAKE_BUILD_TYPE} MATCHES Debug)
endif ()
add_subdirectory(../../external/discord_rpc discord_rpc)
add_subdirectory(../../external/json json)
add_subdirectory(../../external/fmt fmt)
add_subdirectory(../../external/mio mio)
add_subdirectory(../backend backend)
@@ -132,12 +131,10 @@ add_executable(kaizen
AudioSettings.hpp
AudioSettings.cpp
NativeWindow.hpp
InputSettings.hpp
InputSettings.cpp
Debugger.hpp
Debugger.cpp)
target_link_libraries(kaizen PUBLIC imgui nfd SDL3::SDL3 SDL3::SDL3-static cflags::cflags discord-rpc fmt mio nlohmann_json parallel-rdp capstone backend)
target_link_libraries(kaizen PUBLIC imgui nfd SDL3::SDL3 SDL3::SDL3-static cflags::cflags discord-rpc fmt mio parallel-rdp capstone backend)
target_compile_definitions(kaizen PUBLIC SDL_MAIN_HANDLED)
file(COPY ../../resources/ DESTINATION ${PROJECT_BINARY_DIR}/resources/)

View File

@@ -3,7 +3,7 @@
#include <log.hpp>
CPUSettings::CPUSettings(nlohmann::json &settings) : settings(settings) {
if (JSONGetField<std::string>(settings, "cpu", "type") == "jit") {
if (JSONGetField<std::string>(settings, "cpu_type") == "jit") {
cpuTypes.setCurrentIndex(1);
} else {
cpuTypes.setCurrentIndex(0);
@@ -13,7 +13,7 @@ CPUSettings::CPUSettings(nlohmann::json &settings) : settings(settings) {
bool CPUSettings::render() {
if(cpuTypes.render()) {
if(cpuTypes.getCurrentIndex() == 0) {
JSONSetField(settings, "cpu", "type", "interpreter");
JSONSetField(settings, "cpu_type", "interpreter");
} else {
Util::panic("JIT should not be selectable??");
}

View File

@@ -1,164 +0,0 @@
#include <InputSettings.hpp>
#include <log.hpp>
#include <SDL3/SDL.h>
bool QueryDevices(void *userdata, SDL_Event *event);
bool PollGamepad(void *userdata, SDL_Event *event);
InputSettings::InputSettings(nlohmann::json &settings) : settings(settings) {
int i = 0;
for(auto& kb : kbButtons) {
auto field = JSONGetField<std::string>(settings, "input", kb.getName());
kb.setLabel(field != "" ? field : "##unsetButton" + std::to_string(i++));
}
devices.addItem({"Keyboard/Mouse"});
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
}
void InputSettings::RegisterEventWatchers() {
SDL_AddEventWatch(QueryDevices, this);
SDL_AddEventWatch(PollGamepad, this);
}
void InputSettings::UnregisterEventWatchers() {
SDL_RemoveEventWatch(QueryDevices, this);
SDL_RemoveEventWatch(PollGamepad, this);
}
bool InputSettings::render() {
if(devices.render()) {
auto currentlySelectedDevice = devices.getCurrentlySelected();
currentlySelectedDeviceIndex = devices.getCurrentlySelectedIndex();
JSONSetField<std::string>(settings, "input", "Device", currentlySelectedDevice);
selectedDeviceIsNotKeyboard = currentlySelectedDevice != "Keyboard/Mouse";
modified = true;
}
int i = 0;
for(auto& kb : kbButtons) {
if(kb.render()) {
devices.setEnabled(false);
for (auto &otherKb : kbButtons) {
otherKb.setEnabled(false);
}
whichGrabbing = i;
}
if((i % 2 == 0) || i == 0) // only go down every 2 buttons... just... i like it this way
ImGui::SameLine();
i++;
}
return modified;
}
std::array<SDL_Keycode, 18> InputSettings::GetMappedKeys() {
std::array<SDL_Keycode, 18> ret{};
int i = 0;
for (auto& kb : kbButtons) {
ret[i++] = SDL_GetKeyFromName(kb.getLabel().c_str());
}
return ret;
}
bool QueryDevices(void *userdata, SDL_Event *event) {
auto _this = (InputSettings*)userdata;
if (!_this->devices.isEnabled())
return false;
switch (event->type) {
case SDL_EVENT_GAMEPAD_ADDED:
{
const auto index = event->gdevice.which;
auto gamepad = SDL_OpenGamepad(index);
Util::info("Found controller!");
const auto serial = SDL_GetGamepadSerial(gamepad);
const auto name = SDL_GetGamepadName(gamepad);
const auto path = SDL_GetGamepadPath(gamepad);
_this->gamepads[index] = gamepad;
if (name) {
if (!_this->gamepadIndexes.contains(index)) {
_this->gamepadIndexes[index] = name;
}
_this->devices.addItem({name});
} else if (serial) {
if (!_this->gamepadIndexes.contains(index)) {
_this->gamepadIndexes[index] = serial;
}
_this->devices.addItem({serial});
} else if (path) {
if (!_this->gamepadIndexes.contains(index)) {
_this->gamepadIndexes[index] = path;
}
_this->devices.addItem({path});
}
}
return true;
case SDL_EVENT_GAMEPAD_REMOVED:
{
const auto index = event->gdevice.which;
if (_this->gamepadIndexes.contains(index)) {
_this->devices.removeItem(_this->gamepadIndexes[index]);
SDL_CloseGamepad(_this->gamepads[index]);
}
}
return true;
default:
return false;
}
}
bool PollGamepad(void *userdata, SDL_Event *event) {
auto _this = (InputSettings*)userdata;
switch (event->type) {
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
{
if (!_this->selectedDeviceIsNotKeyboard)
return false;
const auto k = SDL_GetGamepadStringForButton(static_cast<SDL_GamepadButton>(event->gbutton.button));
JSONSetField<std::string>(_this->settings, "input", _this->kbButtons[_this->whichGrabbing].getName(), k);
_this->kbButtons[_this->whichGrabbing].setLabel(k);
_this->devices.setEnabled(true);
for (auto &kbButton : _this->kbButtons) {
kbButton.setEnabled(true);
}
_this->grabbing = false;
_this->whichGrabbing = -1;
_this->modified = true;
}
return true;
case SDL_EVENT_KEY_DOWN:
{
if (_this->selectedDeviceIsNotKeyboard)
return false;
const auto k = SDL_GetKeyName(event->key.key);
JSONSetField<std::string>(_this->settings, "input", _this->kbButtons[_this->whichGrabbing].getName(), k);
_this->kbButtons[_this->whichGrabbing].setLabel(k);
_this->devices.setEnabled(true);
for (auto &kbButton : _this->kbButtons) {
kbButton.setEnabled(true);
}
_this->grabbing = false;
_this->whichGrabbing = -1;
_this->modified = true;
}
return true;
default:
return false;
}
}

View File

@@ -1,66 +0,0 @@
#pragma once
#include <JSONUtils.hpp>
#include <unordered_map>
#include <ImGuiImpl/PushButton.hpp>
#include <ImGuiImpl/Combobox.hpp>
#include <SDL3/SDL.h>
class InputSettings final {
public:
std::unordered_map<u32, SDL_Gamepad*> gamepads{};
bool grabbing = false;
int whichGrabbing = -1;
int currentlySelectedDeviceIndex = -1;
std::unordered_map<u32, std::string> gamepadIndexes{};
std::array<gui::PushButton, 18> kbButtons = {
gui::PushButton{"", "A"},
gui::PushButton{"", "B"},
gui::PushButton{"", "Z"},
gui::PushButton{"", "Start"},
gui::PushButton{"", "L"},
gui::PushButton{"", "R"},
gui::PushButton{"", "Dpad Up"},
gui::PushButton{"", "Dpad Down"},
gui::PushButton{"", "Dpad Left"},
gui::PushButton{"", "Dpad Right"},
gui::PushButton{"", "C Up"},
gui::PushButton{"", "C Down"},
gui::PushButton{"", "C Left"},
gui::PushButton{"", "C Right"},
gui::PushButton{"", "Analog Up"},
gui::PushButton{"", "Analog Down"},
gui::PushButton{"", "Analog Left"},
gui::PushButton{"", "Analog Right"},
};
gui::Combobox devices{"Device:", {}};
bool modified = false;
//std::unique_ptr<QHBoxLayout> AB = std::make_unique<QHBoxLayout>();
//std::unique_ptr<QHBoxLayout> ZStart = std::make_unique<QHBoxLayout>();
//std::unique_ptr<QHBoxLayout> LR = std::make_unique<QHBoxLayout>();
//std::unique_ptr<QHBoxLayout> DupDdown = std::make_unique<QHBoxLayout>();
//std::unique_ptr<QHBoxLayout> DleftDright = std::make_unique<QHBoxLayout>();
//std::unique_ptr<QHBoxLayout> CupCdown = std::make_unique<QHBoxLayout>();
//std::unique_ptr<QHBoxLayout> CleftCright = std::make_unique<QHBoxLayout>();
//std::unique_ptr<QHBoxLayout> AupAdown = std::make_unique<QHBoxLayout>();
//std::unique_ptr<QHBoxLayout> AleftAright = std::make_unique<QHBoxLayout>();
//std::unique_ptr<QVBoxLayout> mainLayout = std::make_unique<QVBoxLayout>();
//std::array<std::unique_ptr<QPushButton>, 18> kbButtons;
//std::array<std::unique_ptr<QLabel>, 18> buttonLabels;
//std::unique_ptr<QHBoxLayout> deviceComboBoxLayout = std::make_unique<QHBoxLayout>();
//QTimer refresh, pollGamepad;
//std::unique_ptr<QLabel> devicesLabel = std::make_unique<QLabel>("Device:");
//std::unique_ptr<QComboBox> devices = std::make_unique<QComboBox>();
//Q_OBJECT
bool render();
bool selectedDeviceIsNotKeyboard = false;
explicit InputSettings(nlohmann::json &);
void setModified(bool v) { modified = v; }
bool getModified() { return modified; }
nlohmann::json &settings;
std::array<SDL_Keycode, 18> GetMappedKeys();
void RegisterEventWatchers();
void UnregisterEventWatchers();
};

View File

@@ -9,41 +9,22 @@ namespace fs = std::filesystem;
static FORCE_INLINE nlohmann::json JSONOpenOrCreate(const std::string &path) {
auto fileExists = fs::exists(path);
std::fstream file;
nlohmann::json json;
if (fileExists) {
auto file = std::fstream(path, std::fstream::in | std::fstream::out);
auto json = nlohmann::json::parse(file);
file = std::fstream(path, std::fstream::in | std::fstream::out);
json = nlohmann::json::parse(file);
file.close();
return json;
}
auto file = std::fstream(path, std::fstream::in | std::fstream::out | std::fstream::trunc);
nlohmann::json json;
file = std::fstream(path, std::fstream::in | std::fstream::out | std::fstream::trunc);
json["general"]["savePath"] = "";
json["audio"]["volumeL"] = 0.5;
json["audio"]["volumeR"] = 0.5;
json["audio"]["lock"] = true;
json["cpu"]["type"] = "interpreter";
json["input"] = {
{"Device", "Keyboard/Mouse"},
{"A", "X"},
{"B", "C"},
{"Z", "Z"},
{"Start", "Return"},
{"L", "A"},
{"R", "S"},
{"Dpad Up", ""},
{"Dpad Down", ""},
{"Dpad Left", ""},
{"Dpad Right", ""},
{"C Up", "I"},
{"C Down", "K"},
{"C Left", "J"},
{"C Right", "L"},
{"Analog Up", "Up"},
{"Analog Down", "Down"},
{"Analog Left", "Left"},
{"Analog Right", "Right"},
};
json["cpu_type"] = "interpreter";
file << json;
file.close();
@@ -52,12 +33,22 @@ static FORCE_INLINE nlohmann::json JSONOpenOrCreate(const std::string &path) {
}
template <typename T>
static FORCE_INLINE void JSONSetField(nlohmann::json &json, const std::string &field1, const std::string &field2,
static FORCE_INLINE void JSONSetField(nlohmann::json &json, const std::string &key, const std::string &field,
const T &value) {
json[field1][field2] = value;
json[key][field] = value;
}
template <typename T>
static FORCE_INLINE T JSONGetField(nlohmann::json &json, const std::string &field1, const std::string &field2) {
return json[field1][field2].get<T>();
static FORCE_INLINE T JSONGetField(nlohmann::json &json, const std::string &key, const std::string &field) {
return json[key][field].get<T>();
}
template <typename T>
static FORCE_INLINE void JSONSetField(nlohmann::json &json, const std::string &key, const T &value) {
json[key] = value;
}
template <typename T>
static FORCE_INLINE T JSONGetField(nlohmann::json &json, const std::string &key) {
return json[key].get<T>();
}

View File

@@ -5,11 +5,13 @@
#include <ImGuiImpl/GUI.hpp>
bool HandleInput(void *userdata, SDL_Event *event);
bool QueryDevices(void *userdata, SDL_Event *event);
KaizenGui::KaizenGui() noexcept : window("Kaizen", 800, 600), core(std::make_shared<n64::Core>()), vulkanWidget(core, window.getHandle()), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) {
gui::Initialize(core->parallel.wsi, window.getHandle());
SDL_AddEventWatch(HandleInput, this);
SDL_AddEventWatch(QueryDevices, this);
actionPause.setFunc([&]() {
if(ImGui::IsItemClicked()) {
@@ -87,26 +89,50 @@ KaizenGui::KaizenGui() noexcept : window("Kaizen", 800, 600), core(std::make_sha
KaizenGui::~KaizenGui() {
gui::Cleanup();
SDL_RemoveEventWatch(HandleInput, this);
SDL_RemoveEventWatch(QueryDevices, this);
SDL_Quit();
}
bool QueryDevices(void *userdata, SDL_Event *event) {
auto _this = (KaizenGui*)userdata;
switch (event->type) {
case SDL_EVENT_GAMEPAD_ADDED:
{
const auto index = event->gdevice.which;
auto gamepad = SDL_OpenGamepad(index);
Util::info("Found controller!");
const auto serial = SDL_GetGamepadSerial(gamepad);
const auto name = SDL_GetGamepadName(gamepad);
const auto path = SDL_GetGamepadPath(gamepad);
_this->gamepad = gamepad;
}
return true;
case SDL_EVENT_GAMEPAD_REMOVED:
SDL_CloseGamepad(_this->gamepad);
return true;
default:
return false;
}
}
bool HandleInput(void *userdata, SDL_Event *event) {
auto _this = (KaizenGui*)userdata;
InputSettings& inputSettings = _this->settingsWindow.inputSettings;
n64::PIF &pif = _this->core->cpu->GetMem().mmio.si.pif;
switch(event->type) {
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
if(!inputSettings.selectedDeviceIsNotKeyboard)
if(!_this->gamepad)
return false;
{
_this->core->pause = true;
pif.UpdateButton(0, n64::Controller::Key::Z, SDL_GetGamepadAxis(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_AXIS_LEFT_TRIGGER) == SDL_JOYSTICK_AXIS_MAX);
pif.UpdateButton(0, n64::Controller::Key::CUp, SDL_GetGamepadAxis(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_AXIS_RIGHTY) <= -127);
pif.UpdateButton(0, n64::Controller::Key::CDown, SDL_GetGamepadAxis(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_AXIS_RIGHTY) >= 127);
pif.UpdateButton(0, n64::Controller::Key::CLeft, SDL_GetGamepadAxis(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_AXIS_RIGHTX) <= -127);
pif.UpdateButton(0, n64::Controller::Key::CRight, SDL_GetGamepadAxis(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_AXIS_RIGHTX) >= 127);
pif.UpdateButton(0, n64::Controller::Key::Z, SDL_GetGamepadAxis(_this->gamepad, SDL_GAMEPAD_AXIS_LEFT_TRIGGER) == SDL_JOYSTICK_AXIS_MAX);
pif.UpdateButton(0, n64::Controller::Key::CUp, SDL_GetGamepadAxis(_this->gamepad, SDL_GAMEPAD_AXIS_RIGHTY) <= -127);
pif.UpdateButton(0, n64::Controller::Key::CDown, SDL_GetGamepadAxis(_this->gamepad, SDL_GAMEPAD_AXIS_RIGHTY) >= 127);
pif.UpdateButton(0, n64::Controller::Key::CLeft, SDL_GetGamepadAxis(_this->gamepad, SDL_GAMEPAD_AXIS_RIGHTX) <= -127);
pif.UpdateButton(0, n64::Controller::Key::CRight, SDL_GetGamepadAxis(_this->gamepad, SDL_GAMEPAD_AXIS_RIGHTX) >= 127);
float xclamped = SDL_GetGamepadAxis(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_AXIS_LEFTX);
float xclamped = SDL_GetGamepadAxis(_this->gamepad, SDL_GAMEPAD_AXIS_LEFTX);
if (xclamped < 0) {
xclamped /= float(std::abs(SDL_JOYSTICK_AXIS_MAX));
} else {
@@ -115,7 +141,7 @@ bool HandleInput(void *userdata, SDL_Event *event) {
xclamped *= 86;
float yclamped = SDL_GetGamepadAxis(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_AXIS_LEFTY);
float yclamped = SDL_GetGamepadAxis(_this->gamepad, SDL_GAMEPAD_AXIS_LEFTY);
if (yclamped < 0) {
yclamped /= float(std::abs(SDL_JOYSTICK_AXIS_MIN));
} else {
@@ -130,25 +156,25 @@ bool HandleInput(void *userdata, SDL_Event *event) {
}
return true;
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
if(!inputSettings.selectedDeviceIsNotKeyboard)
if(!_this->gamepad)
return false;
{
_this->core->pause = true;
pif.UpdateButton(0, n64::Controller::Key::A, SDL_GetGamepadButton(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_BUTTON_SOUTH));
pif.UpdateButton(0, n64::Controller::Key::B, SDL_GetGamepadButton(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_BUTTON_WEST));
pif.UpdateButton(0, n64::Controller::Key::Start, SDL_GetGamepadButton(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_BUTTON_START));
pif.UpdateButton(0, n64::Controller::Key::DUp, SDL_GetGamepadButton(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_BUTTON_DPAD_UP));
pif.UpdateButton(0, n64::Controller::Key::DDown, SDL_GetGamepadButton(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_BUTTON_DPAD_DOWN));
pif.UpdateButton(0, n64::Controller::Key::DLeft, SDL_GetGamepadButton(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_BUTTON_DPAD_LEFT));
pif.UpdateButton(0, n64::Controller::Key::DRight, SDL_GetGamepadButton(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_BUTTON_DPAD_RIGHT));
pif.UpdateButton(0, n64::Controller::Key::LT, SDL_GetGamepadButton(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_BUTTON_LEFT_SHOULDER));
pif.UpdateButton(0, n64::Controller::Key::RT, SDL_GetGamepadButton(inputSettings.gamepads[inputSettings.currentlySelectedDeviceIndex], SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER));
pif.UpdateButton(0, n64::Controller::Key::A, SDL_GetGamepadButton(_this->gamepad, SDL_GAMEPAD_BUTTON_SOUTH));
pif.UpdateButton(0, n64::Controller::Key::B, SDL_GetGamepadButton(_this->gamepad, SDL_GAMEPAD_BUTTON_WEST));
pif.UpdateButton(0, n64::Controller::Key::Start, SDL_GetGamepadButton(_this->gamepad, SDL_GAMEPAD_BUTTON_START));
pif.UpdateButton(0, n64::Controller::Key::DUp, SDL_GetGamepadButton(_this->gamepad, SDL_GAMEPAD_BUTTON_DPAD_UP));
pif.UpdateButton(0, n64::Controller::Key::DDown, SDL_GetGamepadButton(_this->gamepad, SDL_GAMEPAD_BUTTON_DPAD_DOWN));
pif.UpdateButton(0, n64::Controller::Key::DLeft, SDL_GetGamepadButton(_this->gamepad, SDL_GAMEPAD_BUTTON_DPAD_LEFT));
pif.UpdateButton(0, n64::Controller::Key::DRight, SDL_GetGamepadButton(_this->gamepad, SDL_GAMEPAD_BUTTON_DPAD_RIGHT));
pif.UpdateButton(0, n64::Controller::Key::LT, SDL_GetGamepadButton(_this->gamepad, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER));
pif.UpdateButton(0, n64::Controller::Key::RT, SDL_GetGamepadButton(_this->gamepad, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER));
_this->core->pause = false;
}
return true;
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
if(inputSettings.selectedDeviceIsNotKeyboard)
if(_this->gamepad)
return false;
{
_this->core->pause = true;

View File

@@ -6,6 +6,7 @@
#include <ImGuiImpl/StatusBar.hpp>
#include <EmuThread.hpp>
#include <Discord.hpp>
#include <SDL3/SDL_gamepad.h>
class KaizenGui final {
gui::NativeWindow window;
@@ -21,6 +22,7 @@ public:
EmuThread emuThread;
gui::PopupWindow about{"About Kaizen"};
gui::StatusBar statusBar{};
SDL_Gamepad* gamepad = nullptr;
void run();
void LoadTAS(const std::string &path) const noexcept;

View File

@@ -2,7 +2,6 @@
#include <KaizenGui.hpp>
#include <RenderWidget.hpp>
#include <SDL3/SDL.h>
#include <InputSettings.hpp>
#include <imgui_impl_sdl3.h>
RenderWidget::RenderWidget(const std::shared_ptr<n64::Core> &core, SDL_Window* window) {

View File

@@ -6,9 +6,7 @@
std::string savePath;
SettingsWindow::SettingsWindow() : settings{JSONOpenOrCreate("resources/settings.json")} {
keyMap = inputSettings.GetMappedKeys();
SettingsWindow::SettingsWindow() : settings{JSONOpenOrCreate("resources/settings.json")}, cpuSettings{settings}, audioSettings{settings} {
savesFolder.setName(fmt::format("Save path: {}",
JSONGetField<std::string>(settings, "general", "savePath")));
@@ -43,31 +41,12 @@ SettingsWindow::SettingsWindow() : settings{JSONOpenOrCreate("resources/settings
}
}});
tabs.addTab({"Input", [&]() {
if(inputSettings.render()) {
if(inputSettings.getModified())
apply.setEnabled(true);
}
}});
apply.setEnabled(false);
popup.setOnOpen([&]() {
inputSettings.RegisterEventWatchers();
});
popup.setOnClose([&]() {
inputSettings.UnregisterEventWatchers();
});
popup.setFunc([&]() {
tabs.render();
if(apply.render()) {
auto newMap = inputSettings.GetMappedKeys();
if (keyMap != newMap)
keyMap = newMap;
apply.setEnabled(false);
std::ofstream file("resources/settings.json");
file << settings;

View File

@@ -1,25 +1,23 @@
#pragma once
#include <AudioSettings.hpp>
#include <CPUSettings.hpp>
#include <InputSettings.hpp>
#include <ImGuiImpl/TabBar.hpp>
#include <ImGuiImpl/PopupWindow.hpp>
#include <ImGuiImpl/PushButton.hpp>
#include <SDL3/SDL.h>
#include <memory>
class SettingsWindow final {
gui::PushButton apply{"Apply", "", false}, savesFolder{"Open", "Save path: {}"};
nlohmann::json settings;
CPUSettings cpuSettings{settings};
AudioSettings audioSettings{settings};
CPUSettings cpuSettings;
AudioSettings audioSettings;
public:
InputSettings inputSettings{settings};
gui::PopupWindow popup{"Emulator Settings"};
bool render();
SettingsWindow();
[[nodiscard]] float getVolumeL() const { return audioSettings.volumeL.getValue() / 100.f; }
[[nodiscard]] float getVolumeR() const { return audioSettings.volumeR.getValue() / 100.f; }
std::array<SDL_Keycode, 18> keyMap{};
gui::TabBar tabs{"SettingsTabs"};
};