Decouple emulator and frontend code

This commit is contained in:
offtkp 2023-10-18 01:12:59 +03:00
parent ab83fc1e71
commit fb0a2a6801
8 changed files with 411 additions and 364 deletions

View file

@ -1,7 +1,5 @@
#pragma once
#include <SDL.h>
#include <filesystem>
#include <fstream>
#include <optional>
@ -25,6 +23,8 @@
#include "gl/context.h"
#endif
class SDL_Window;
enum class ROMType {
None,
ELF,
@ -42,17 +42,6 @@ class Emulator {
Crypto::AESEngine aesEngine;
Cheats cheats;
#ifdef PANDA3DS_FRONTEND_SDL
SDL_Window* window;
#ifdef PANDA3DS_ENABLE_OPENGL
SDL_GLContext glContext;
#endif
#endif
SDL_GameController* gameController = nullptr;
int gameControllerID;
// 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
@ -100,7 +89,7 @@ class Emulator {
void step();
void render();
void reset(ReloadOption reload);
void run();
void run(void* frontend = nullptr);
void runFrame();
void resume(); // Resume the emulator
@ -118,7 +107,7 @@ class Emulator {
// For passing the GL context from Qt to the renderer
void initGraphicsContext(GL::Context* glContext) { gpu.initGraphicsContext(nullptr); }
#else
void initGraphicsContext() { gpu.initGraphicsContext(window); }
void initGraphicsContext(SDL_Window* window) { gpu.initGraphicsContext(window); }
#endif
RomFS::DumpingResult dumpRomFS(const std::filesystem::path& path);

View file

@ -1,5 +1,7 @@
#pragma once
#include <SDL.h>
#include <QApplication>
#include <QComboBox>
#include <QMenuBar>
@ -37,6 +39,9 @@ class MainWindow : public QMainWindow {
QComboBox* themeSelect = nullptr;
QMenuBar* menuBar = nullptr;
SDL_GameController* gameController = nullptr;
int gameControllerID;
Theme currentTheme;
void setTheme(Theme theme);
void swapEmuBuffer();

View file

@ -0,0 +1,19 @@
#pragma once
#include <SDL.h>
#include "emulator.hpp"
struct FrontendSDL {
FrontendSDL();
bool loadROM(const std::filesystem::path& path);
void run();
Emulator emu;
SDL_Window* window = nullptr;
#ifdef PANDA3DS_ENABLE_OPENGL
SDL_GLContext glContext;
#endif
SDL_GameController* gameController = nullptr;
int gameControllerID;
};