From 27ad7b01f3971c059d35e63c416191ea7aef4f52 Mon Sep 17 00:00:00 2001 From: Paris Oplopoios Date: Sat, 16 Mar 2024 23:20:37 +0200 Subject: [PATCH] Rename Emulator::run to FrontendSDL::run (#466) * Rename Emulator::run to FrontendSDL::run * Update frontend_sdl.cpp --------- Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> --- include/emulator.hpp | 12 ------- include/panda_sdl/frontend_sdl.hpp | 11 ++++++ src/emulator.cpp | 2 +- src/panda_sdl/frontend_sdl.cpp | 57 +++++++++++++++--------------- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/include/emulator.hpp b/include/emulator.hpp index 47fbc839..de04648e 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -51,22 +51,11 @@ class Emulator { MiniAudioDevice audioDevice; Cheats cheats; - // Variables to keep track of whether the user is controlling the 3DS analog stick with their keyboard - // This is done so when a gamepad is connected, we won't automatically override the 3DS analog stick settings with the gamepad's state - // And so the user can still use the keyboard to control the analog - bool keyboardAnalogX = false; - bool keyboardAnalogY = false; - - // For tracking whether to update gyroscope - // We bind gyro to right click + mouse movement - bool holdingRightClick = false; - public: static constexpr u32 width = 400; static constexpr u32 height = 240 * 2; // * 2 because 2 screens ROMType romType = ROMType::None; bool running = false; // Is the emulator running a game? - bool programRunning = false; // Is the emulator program itself running? private: #ifdef PANDA3DS_ENABLE_HTTP_SERVER @@ -103,7 +92,6 @@ class Emulator { void step(); void render(); void reset(ReloadOption reload); - void run(void* frontend = nullptr); void runFrame(); // Poll the scheduler for events void pollScheduler(); diff --git a/include/panda_sdl/frontend_sdl.hpp b/include/panda_sdl/frontend_sdl.hpp index 8e58c768..2d206175 100644 --- a/include/panda_sdl/frontend_sdl.hpp +++ b/include/panda_sdl/frontend_sdl.hpp @@ -20,4 +20,15 @@ class FrontendSDL { SDL_Window* window = nullptr; SDL_GameController* gameController = nullptr; int gameControllerID; + bool programRunning = true; + + // For tracking whether to update gyroscope + // We bind gyro to right click + mouse movement + bool holdingRightClick = false; + + // Variables to keep track of whether the user is controlling the 3DS analog stick with their keyboard + // This is done so when a gamepad is connected, we won't automatically override the 3DS analog stick settings with the gamepad's state + // And so the user can still use the keyboard to control the analog + bool keyboardAnalogX = false; + bool keyboardAnalogY = false; }; \ No newline at end of file diff --git a/src/emulator.cpp b/src/emulator.cpp index a02ead48..16c3bffd 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -18,7 +18,7 @@ __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1; Emulator::Emulator() : config(getConfigPath()), kernel(cpu, memory, gpu, config), cpu(memory, kernel, *this), gpu(memory, config), memory(cpu.getTicksRef(), config), - cheats(memory, kernel.getServiceManager().getHID()), lua(*this), running(false), programRunning(false) + cheats(memory, kernel.getServiceManager().getHID()), lua(*this), running(false) #ifdef PANDA3DS_ENABLE_HTTP_SERVER , httpServer(this) diff --git a/src/panda_sdl/frontend_sdl.cpp b/src/panda_sdl/frontend_sdl.cpp index 04b582e1..b6486b45 100644 --- a/src/panda_sdl/frontend_sdl.cpp +++ b/src/panda_sdl/frontend_sdl.cpp @@ -67,19 +67,20 @@ FrontendSDL::FrontendSDL() { } bool FrontendSDL::loadROM(const std::filesystem::path& path) { return emu.loadROM(path); } -void FrontendSDL::run() { emu.run(this); } -void Emulator::run(void* frontend) { - FrontendSDL* frontendSDL = reinterpret_cast(frontend); +void FrontendSDL::run() { programRunning = true; + keyboardAnalogX = false; + keyboardAnalogY = false; + holdingRightClick = false; while (programRunning) { #ifdef PANDA3DS_ENABLE_HTTP_SERVER httpServer.processActions(); #endif - runFrame(); - HIDService& hid = kernel.getServiceManager().getHID(); + emu.runFrame(); + HIDService& hid = emu.getServiceManager().getHID(); SDL_Event event; while (SDL_PollEvent(&event)) { @@ -92,7 +93,7 @@ void Emulator::run(void* frontend) { return; case SDL_KEYDOWN: - if (romType == ROMType::None) break; + if (emu.romType == ROMType::None) break; switch (event.key.keysym.sym) { case SDLK_l: hid.pressKey(Keys::A); break; @@ -134,20 +135,20 @@ void Emulator::run(void* frontend) { // Use the F4 button as a hot-key to pause or resume the emulator // We can't use the audio play/pause buttons because it's annoying case SDLK_F4: { - togglePause(); + emu.togglePause(); break; } // Use F5 as a reset button case SDLK_F5: { - reset(ReloadOption::Reload); + emu.reset(Emulator::ReloadOption::Reload); break; } } break; case SDL_KEYUP: - if (romType == ROMType::None) break; + if (emu.romType == ROMType::None) break; switch (event.key.keysym.sym) { case SDLK_l: hid.releaseKey(Keys::A); break; @@ -182,7 +183,7 @@ void Emulator::run(void* frontend) { break; case SDL_MOUSEBUTTONDOWN: - if (romType == ROMType::None) break; + if (emu.romType == ROMType::None) break; if (event.button.button == SDL_BUTTON_LEFT) { const s32 x = event.button.x; @@ -205,7 +206,7 @@ void Emulator::run(void* frontend) { break; case SDL_MOUSEBUTTONUP: - if (romType == ROMType::None) break; + if (emu.romType == ROMType::None) break; if (event.button.button == SDL_BUTTON_LEFT) { hid.releaseTouchScreen(); @@ -215,23 +216,23 @@ void Emulator::run(void* frontend) { break; case SDL_CONTROLLERDEVICEADDED: - if (frontendSDL->gameController == nullptr) { - frontendSDL->gameController = SDL_GameControllerOpen(event.cdevice.which); - frontendSDL->gameControllerID = event.cdevice.which; + if (gameController == nullptr) { + gameController = SDL_GameControllerOpen(event.cdevice.which); + gameControllerID = event.cdevice.which; } break; case SDL_CONTROLLERDEVICEREMOVED: - if (event.cdevice.which == frontendSDL->gameControllerID) { - SDL_GameControllerClose(frontendSDL->gameController); - frontendSDL->gameController = nullptr; - frontendSDL->gameControllerID = 0; + if (event.cdevice.which == gameControllerID) { + SDL_GameControllerClose(gameController); + gameController = nullptr; + gameControllerID = 0; } break; case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERBUTTONDOWN: { - if (romType == ROMType::None) break; + if (emu.romType == ROMType::None) break; u32 key = 0; switch (event.cbutton.button) { @@ -261,7 +262,7 @@ void Emulator::run(void* frontend) { // Detect mouse motion events for gyroscope emulation case SDL_MOUSEMOTION: { - if (romType == ROMType::None) break; + if (emu.romType == ROMType::None) break; // Handle "dragging" across the touchscreen if (hid.isTouchScreenPressed()) { @@ -301,9 +302,9 @@ void Emulator::run(void* frontend) { const std::filesystem::path path(droppedDir); if (path.extension() == ".amiibo") { - loadAmiibo(path); + emu.loadAmiibo(path); } else if (path.extension() == ".lua") { - lua.loadFile(droppedDir); + emu.getLua().loadFile(droppedDir); } else { loadROM(path); } @@ -316,10 +317,10 @@ void Emulator::run(void* frontend) { } // Update controller analog sticks and HID service - if (romType != ROMType::None) { - if (frontendSDL->gameController != nullptr) { - const s16 stickX = SDL_GameControllerGetAxis(frontendSDL->gameController, SDL_CONTROLLER_AXIS_LEFTX); - const s16 stickY = SDL_GameControllerGetAxis(frontendSDL->gameController, SDL_CONTROLLER_AXIS_LEFTY); + if (emu.romType != ROMType::None) { + if (gameController != nullptr) { + const s16 stickX = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTX); + const s16 stickY = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTY); constexpr s16 deadzone = 3276; constexpr s16 maxValue = 0x9C; constexpr s16 div = 0x8000 / maxValue; @@ -338,11 +339,11 @@ void Emulator::run(void* frontend) { } } - hid.updateInputs(cpu.getTicks()); + hid.updateInputs(emu.getTicks()); } // TODO: Should this be uncommented? // kernel.evalReschedule(); - SDL_GL_SwapWindow(frontendSDL->window); + SDL_GL_SwapWindow(window); } }