mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 07:05:40 +12:00
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>
This commit is contained in:
parent
a00a5e0f8f
commit
27ad7b01f3
4 changed files with 41 additions and 41 deletions
|
@ -51,22 +51,11 @@ class Emulator {
|
||||||
MiniAudioDevice audioDevice;
|
MiniAudioDevice audioDevice;
|
||||||
Cheats cheats;
|
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:
|
public:
|
||||||
static constexpr u32 width = 400;
|
static constexpr u32 width = 400;
|
||||||
static constexpr u32 height = 240 * 2; // * 2 because 2 screens
|
static constexpr u32 height = 240 * 2; // * 2 because 2 screens
|
||||||
ROMType romType = ROMType::None;
|
ROMType romType = ROMType::None;
|
||||||
bool running = false; // Is the emulator running a game?
|
bool running = false; // Is the emulator running a game?
|
||||||
bool programRunning = false; // Is the emulator program itself running?
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
||||||
|
@ -103,7 +92,6 @@ class Emulator {
|
||||||
void step();
|
void step();
|
||||||
void render();
|
void render();
|
||||||
void reset(ReloadOption reload);
|
void reset(ReloadOption reload);
|
||||||
void run(void* frontend = nullptr);
|
|
||||||
void runFrame();
|
void runFrame();
|
||||||
// Poll the scheduler for events
|
// Poll the scheduler for events
|
||||||
void pollScheduler();
|
void pollScheduler();
|
||||||
|
|
|
@ -20,4 +20,15 @@ class FrontendSDL {
|
||||||
SDL_Window* window = nullptr;
|
SDL_Window* window = nullptr;
|
||||||
SDL_GameController* gameController = nullptr;
|
SDL_GameController* gameController = nullptr;
|
||||||
int gameControllerID;
|
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;
|
||||||
};
|
};
|
|
@ -18,7 +18,7 @@ __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1;
|
||||||
|
|
||||||
Emulator::Emulator()
|
Emulator::Emulator()
|
||||||
: config(getConfigPath()), kernel(cpu, memory, gpu, config), cpu(memory, kernel, *this), gpu(memory, config), memory(cpu.getTicksRef(), config),
|
: 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
|
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
||||||
,
|
,
|
||||||
httpServer(this)
|
httpServer(this)
|
||||||
|
|
|
@ -67,19 +67,20 @@ FrontendSDL::FrontendSDL() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FrontendSDL::loadROM(const std::filesystem::path& path) { return emu.loadROM(path); }
|
bool FrontendSDL::loadROM(const std::filesystem::path& path) { return emu.loadROM(path); }
|
||||||
void FrontendSDL::run() { emu.run(this); }
|
|
||||||
|
|
||||||
void Emulator::run(void* frontend) {
|
void FrontendSDL::run() {
|
||||||
FrontendSDL* frontendSDL = reinterpret_cast<FrontendSDL*>(frontend);
|
|
||||||
programRunning = true;
|
programRunning = true;
|
||||||
|
keyboardAnalogX = false;
|
||||||
|
keyboardAnalogY = false;
|
||||||
|
holdingRightClick = false;
|
||||||
|
|
||||||
while (programRunning) {
|
while (programRunning) {
|
||||||
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
||||||
httpServer.processActions();
|
httpServer.processActions();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
runFrame();
|
emu.runFrame();
|
||||||
HIDService& hid = kernel.getServiceManager().getHID();
|
HIDService& hid = emu.getServiceManager().getHID();
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
|
@ -92,7 +93,7 @@ void Emulator::run(void* frontend) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
if (romType == ROMType::None) break;
|
if (emu.romType == ROMType::None) break;
|
||||||
|
|
||||||
switch (event.key.keysym.sym) {
|
switch (event.key.keysym.sym) {
|
||||||
case SDLK_l: hid.pressKey(Keys::A); break;
|
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
|
// 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
|
// We can't use the audio play/pause buttons because it's annoying
|
||||||
case SDLK_F4: {
|
case SDLK_F4: {
|
||||||
togglePause();
|
emu.togglePause();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use F5 as a reset button
|
// Use F5 as a reset button
|
||||||
case SDLK_F5: {
|
case SDLK_F5: {
|
||||||
reset(ReloadOption::Reload);
|
emu.reset(Emulator::ReloadOption::Reload);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
if (romType == ROMType::None) break;
|
if (emu.romType == ROMType::None) break;
|
||||||
|
|
||||||
switch (event.key.keysym.sym) {
|
switch (event.key.keysym.sym) {
|
||||||
case SDLK_l: hid.releaseKey(Keys::A); break;
|
case SDLK_l: hid.releaseKey(Keys::A); break;
|
||||||
|
@ -182,7 +183,7 @@ void Emulator::run(void* frontend) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
if (romType == ROMType::None) break;
|
if (emu.romType == ROMType::None) break;
|
||||||
|
|
||||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||||
const s32 x = event.button.x;
|
const s32 x = event.button.x;
|
||||||
|
@ -205,7 +206,7 @@ void Emulator::run(void* frontend) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
if (romType == ROMType::None) break;
|
if (emu.romType == ROMType::None) break;
|
||||||
|
|
||||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||||
hid.releaseTouchScreen();
|
hid.releaseTouchScreen();
|
||||||
|
@ -215,23 +216,23 @@ void Emulator::run(void* frontend) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_CONTROLLERDEVICEADDED:
|
case SDL_CONTROLLERDEVICEADDED:
|
||||||
if (frontendSDL->gameController == nullptr) {
|
if (gameController == nullptr) {
|
||||||
frontendSDL->gameController = SDL_GameControllerOpen(event.cdevice.which);
|
gameController = SDL_GameControllerOpen(event.cdevice.which);
|
||||||
frontendSDL->gameControllerID = event.cdevice.which;
|
gameControllerID = event.cdevice.which;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_CONTROLLERDEVICEREMOVED:
|
case SDL_CONTROLLERDEVICEREMOVED:
|
||||||
if (event.cdevice.which == frontendSDL->gameControllerID) {
|
if (event.cdevice.which == gameControllerID) {
|
||||||
SDL_GameControllerClose(frontendSDL->gameController);
|
SDL_GameControllerClose(gameController);
|
||||||
frontendSDL->gameController = nullptr;
|
gameController = nullptr;
|
||||||
frontendSDL->gameControllerID = 0;
|
gameControllerID = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_CONTROLLERBUTTONUP:
|
case SDL_CONTROLLERBUTTONUP:
|
||||||
case SDL_CONTROLLERBUTTONDOWN: {
|
case SDL_CONTROLLERBUTTONDOWN: {
|
||||||
if (romType == ROMType::None) break;
|
if (emu.romType == ROMType::None) break;
|
||||||
u32 key = 0;
|
u32 key = 0;
|
||||||
|
|
||||||
switch (event.cbutton.button) {
|
switch (event.cbutton.button) {
|
||||||
|
@ -261,7 +262,7 @@ void Emulator::run(void* frontend) {
|
||||||
|
|
||||||
// Detect mouse motion events for gyroscope emulation
|
// Detect mouse motion events for gyroscope emulation
|
||||||
case SDL_MOUSEMOTION: {
|
case SDL_MOUSEMOTION: {
|
||||||
if (romType == ROMType::None) break;
|
if (emu.romType == ROMType::None) break;
|
||||||
|
|
||||||
// Handle "dragging" across the touchscreen
|
// Handle "dragging" across the touchscreen
|
||||||
if (hid.isTouchScreenPressed()) {
|
if (hid.isTouchScreenPressed()) {
|
||||||
|
@ -301,9 +302,9 @@ void Emulator::run(void* frontend) {
|
||||||
const std::filesystem::path path(droppedDir);
|
const std::filesystem::path path(droppedDir);
|
||||||
|
|
||||||
if (path.extension() == ".amiibo") {
|
if (path.extension() == ".amiibo") {
|
||||||
loadAmiibo(path);
|
emu.loadAmiibo(path);
|
||||||
} else if (path.extension() == ".lua") {
|
} else if (path.extension() == ".lua") {
|
||||||
lua.loadFile(droppedDir);
|
emu.getLua().loadFile(droppedDir);
|
||||||
} else {
|
} else {
|
||||||
loadROM(path);
|
loadROM(path);
|
||||||
}
|
}
|
||||||
|
@ -316,10 +317,10 @@ void Emulator::run(void* frontend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update controller analog sticks and HID service
|
// Update controller analog sticks and HID service
|
||||||
if (romType != ROMType::None) {
|
if (emu.romType != ROMType::None) {
|
||||||
if (frontendSDL->gameController != nullptr) {
|
if (gameController != nullptr) {
|
||||||
const s16 stickX = SDL_GameControllerGetAxis(frontendSDL->gameController, SDL_CONTROLLER_AXIS_LEFTX);
|
const s16 stickX = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTX);
|
||||||
const s16 stickY = SDL_GameControllerGetAxis(frontendSDL->gameController, SDL_CONTROLLER_AXIS_LEFTY);
|
const s16 stickY = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTY);
|
||||||
constexpr s16 deadzone = 3276;
|
constexpr s16 deadzone = 3276;
|
||||||
constexpr s16 maxValue = 0x9C;
|
constexpr s16 maxValue = 0x9C;
|
||||||
constexpr s16 div = 0x8000 / maxValue;
|
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?
|
// TODO: Should this be uncommented?
|
||||||
// kernel.evalReschedule();
|
// kernel.evalReschedule();
|
||||||
|
|
||||||
SDL_GL_SwapWindow(frontendSDL->window);
|
SDL_GL_SwapWindow(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue