Skip to content

Commit

Permalink
Merge pull request #1 from wheremyfoodat/wrage-4
Browse files Browse the repository at this point in the history
Title
  • Loading branch information
OFFTKP authored Oct 19, 2023
2 parents fb0a2a6 + c0c3153 commit b79c129
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 33 deletions.
5 changes: 0 additions & 5 deletions include/panda_qt/main_window.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <SDL.h>

#include <QApplication>
#include <QComboBox>
#include <QMenuBar>
Expand Down Expand Up @@ -39,9 +37,6 @@ class MainWindow : public QMainWindow {
QComboBox* themeSelect = nullptr;
QMenuBar* menuBar = nullptr;

SDL_GameController* gameController = nullptr;
int gameControllerID;

Theme currentTheme;
void setTheme(Theme theme);
void swapEmuBuffer();
Expand Down
12 changes: 7 additions & 5 deletions include/panda_sdl/frontend_sdl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

#include "emulator.hpp"

struct FrontendSDL {
class FrontendSDL {
Emulator emu;
#ifdef PANDA3DS_ENABLE_OPENGL
SDL_GLContext glContext;
#endif

public:
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;
};
18 changes: 0 additions & 18 deletions src/panda_qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,6 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
usingGL = (rendererType == RendererType::OpenGL || rendererType == RendererType::Software || rendererType == RendererType::Null);
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) {
// Make GL context current for this thread, enable VSync
GL::Context* glContext = screen.getGLContext();
Expand Down
2 changes: 0 additions & 2 deletions src/panda_sdl/frontend_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ 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) {
Expand Down Expand Up @@ -352,7 +351,6 @@ void Emulator::run(void* frontend) {
// TODO: Should this be uncommented?
// kernel.evalReschedule();

// Update inputs in the HID module
SDL_GL_SwapWindow(frontendSDL->window);
}
}
6 changes: 3 additions & 3 deletions src/panda_sdl/main.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "panda_sdl/frontend_sdl.hpp"

int main(int argc, char *argv[]) {
FrontendSDL frontend;
FrontendSDL app;

if (argc > 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
Helpers::panic("Failed to load ROM file: %s", romPath.string().c_str());
}
} else {
printf("No ROM inserted! Load a ROM by dragging and dropping it into the emulator window!\n");
}

frontend.run();
app.run();
}

0 comments on commit b79c129

Please sign in to comment.