122 lines
3.0 KiB
C++
122 lines
3.0 KiB
C++
#include <KaizenGui.hpp>
|
|
#include <nfd.hpp>
|
|
#include <backend/Core.hpp>
|
|
#include <ImGuiImpl/StatusBar.hpp>
|
|
#include <imgui.h>
|
|
#include <imgui_impl_sdl3.h>
|
|
#include <imgui_impl_vulkan.h>
|
|
|
|
static void check_vk_result(VkResult err)
|
|
{
|
|
if (err == 0)
|
|
return;
|
|
fprintf(stderr, "[vulkan] Error: VkResult = %d\n", err);
|
|
if (err < 0)
|
|
abort();
|
|
}
|
|
|
|
KaizenGui::KaizenGui() noexcept : window("Kaizen", 1280, 720), core(std::make_shared<n64::Core>()), vulkanWidget(core, window.getHandle()), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) {
|
|
emuExitFunc = [&]() {
|
|
quit = true;
|
|
if (emuThread.isRunning) {
|
|
emuThread.requestInterruption();
|
|
while (emuThread.isRunning) {}
|
|
}
|
|
};
|
|
|
|
about.setFunc([&]() {
|
|
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 trademarks of Nintendo Co., Ltd.");
|
|
if(ImGui::Button("OK")) {
|
|
about.setOpened(false);
|
|
}
|
|
});
|
|
|
|
statusBar.setFunc([&]() {
|
|
ImGui::Text("GUI FPS: %.2f, Emulation FPS: %.2f", ImGui::GetIO().Framerate, fpsCounter);
|
|
});
|
|
|
|
menuBar.addMenu({"File",
|
|
{
|
|
{"Open", [&]() {
|
|
NFD::Guard guard;
|
|
NFD::UniquePath path;
|
|
nfdfilteritem_t filterItem = {"Nintendo 64 roms", "n64,z64,v64,N64,Z64,V64"};
|
|
|
|
auto result = NFD::OpenDialog(path, &filterItem, 1);
|
|
if(result == NFD_CANCEL) return;
|
|
if(result == NFD_ERROR)
|
|
Util::panic("Error: {}", NFD::GetError());
|
|
LoadROM(path.get());
|
|
}},
|
|
{"Exit", std::move(emuExitFunc)}
|
|
}
|
|
});
|
|
|
|
menuBar.addMenu({"Emulation",
|
|
{
|
|
actionPause,
|
|
actionStop,
|
|
actionReset,
|
|
{"Settings", [&]() {
|
|
settingsWindow.render();
|
|
}},
|
|
}
|
|
});
|
|
|
|
menuBar.addMenu({"Help",
|
|
{
|
|
{"About", [&]() {
|
|
about.setOpened(true);
|
|
}},
|
|
}
|
|
});
|
|
}
|
|
|
|
void KaizenGui::LoadROM(const std::string &path) noexcept {
|
|
actionPause.setEnabled(true);
|
|
actionReset.setEnabled(true);
|
|
actionStop.setEnabled(true);
|
|
emuThread.start();
|
|
emuThread.core->LoadROM(path);
|
|
const auto gameNameDB = emuThread.core->cpu->GetMem().rom.gameNameDB;
|
|
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) {
|
|
handleEvents();
|
|
|
|
menuBar.render();
|
|
|
|
about.render();
|
|
|
|
statusBar.render();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void KaizenGui::LoadTAS(const std::string &path) const noexcept {
|
|
if (emuThread.core->LoadTAS(fs::path(path))) {
|
|
const auto gameNameDB = emuThread.core->cpu->GetMem().rom.gameNameDB;
|
|
const auto movieName = fs::path(path).stem().string();
|
|
Util::RPC::GetInstance().Update(Util::RPC::MovieReplay, gameNameDB, movieName);
|
|
return;
|
|
}
|
|
|
|
Util::panic("Could not load TAS movie {}!", path);
|
|
} |