Merge pull request #1 from wheremyfoodat/wrage-4

Title
This commit is contained in:
Paris 2023-10-20 01:36:10 +03:00 committed by GitHub
commit b79c12901b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 33 deletions

View file

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

View file

@ -4,16 +4,18 @@
#include "emulator.hpp" #include "emulator.hpp"
struct FrontendSDL { class FrontendSDL {
Emulator emu;
#ifdef PANDA3DS_ENABLE_OPENGL
SDL_GLContext glContext;
#endif
public:
FrontendSDL(); FrontendSDL();
bool loadROM(const std::filesystem::path& path); bool loadROM(const std::filesystem::path& path);
void run(); void run();
Emulator emu;
SDL_Window* window = nullptr; SDL_Window* window = nullptr;
#ifdef PANDA3DS_ENABLE_OPENGL
SDL_GLContext glContext;
#endif
SDL_GameController* gameController = nullptr; SDL_GameController* gameController = nullptr;
int gameControllerID; int gameControllerID;
}; };

View file

@ -51,24 +51,6 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
usingGL = (rendererType == RendererType::OpenGL || rendererType == RendererType::Software || rendererType == RendererType::Null); usingGL = (rendererType == RendererType::OpenGL || rendererType == RendererType::Software || rendererType == RendererType::Null);
usingVk = (rendererType == RendererType::Vulkan); usingVk = (rendererType == RendererType::Vulkan);
if (SDL_Init(SDL_INIT_EVENTS) < 0) {
Helpers::panic("Failed to initialize SDL2");
}
// Make SDL use consistent positional button mapping
SDL_SetHint(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0");
if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0) {
Helpers::warn("Failed to initialize SDL2 GameController: %s", SDL_GetError());
}
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER)) {
gameController = SDL_GameControllerOpen(0);
if (gameController != nullptr) {
SDL_Joystick* stick = SDL_GameControllerGetJoystick(gameController);
gameControllerID = SDL_JoystickInstanceID(stick);
}
}
if (usingGL) { if (usingGL) {
// Make GL context current for this thread, enable VSync // Make GL context current for this thread, enable VSync
GL::Context* glContext = screen.getGLContext(); GL::Context* glContext = screen.getGLContext();

View file

@ -75,7 +75,6 @@ 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 FrontendSDL::run() { emu.run(this); }
void Emulator::run(void* frontend) { void Emulator::run(void* frontend) {
@ -352,7 +351,6 @@ void Emulator::run(void* frontend) {
// TODO: Should this be uncommented? // TODO: Should this be uncommented?
// kernel.evalReschedule(); // kernel.evalReschedule();
// Update inputs in the HID module
SDL_GL_SwapWindow(frontendSDL->window); SDL_GL_SwapWindow(frontendSDL->window);
} }
} }

View file

@ -1,11 +1,11 @@
#include "panda_sdl/frontend_sdl.hpp" #include "panda_sdl/frontend_sdl.hpp"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
FrontendSDL frontend; FrontendSDL app;
if (argc > 1) { if (argc > 1) {
auto romPath = std::filesystem::current_path() / argv[1]; auto romPath = std::filesystem::current_path() / argv[1];
if (!frontend.loadROM(romPath)) { if (!app.loadROM(romPath)) {
// For some reason just .c_str() doesn't show the proper path // For some reason just .c_str() doesn't show the proper path
Helpers::panic("Failed to load ROM file: %s", romPath.string().c_str()); Helpers::panic("Failed to load ROM file: %s", romPath.string().c_str());
} }
@ -13,5 +13,5 @@ int main(int argc, char *argv[]) {
printf("No ROM inserted! Load a ROM by dragging and dropping it into the emulator window!\n"); printf("No ROM inserted! Load a ROM by dragging and dropping it into the emulator window!\n");
} }
frontend.run(); app.run();
} }