mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-06 22:25:41 +12:00
Properly join emulator thread
This commit is contained in:
parent
84044d078e
commit
061c80fd11
3 changed files with 18 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <QMenuBar>
|
||||
#include <QPalette>
|
||||
#include <QtWidgets>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#include "emulator.hpp"
|
||||
|
@ -24,9 +25,11 @@ class MainWindow : public QMainWindow {
|
|||
Emulator* emu = nullptr;
|
||||
std::thread emuThread;
|
||||
|
||||
std::atomic<bool> appRunning = true; // Is the application itself running?
|
||||
|
||||
ScreenWidget screen;
|
||||
QComboBox* themeSelect = nullptr;
|
||||
QMenuBar* menuBar = nullptr;
|
||||
ScreenWidget screen;
|
||||
|
||||
Theme currentTheme;
|
||||
void setTheme(Theme theme);
|
||||
|
|
|
@ -4,15 +4,21 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
setWindowTitle("Alber");
|
||||
// Enable drop events for loading ROMs
|
||||
setAcceptDrops(true);
|
||||
resize(400, 240 * 2);
|
||||
resize(800, 240 * 4);
|
||||
screen.show();
|
||||
|
||||
appRunning = true;
|
||||
|
||||
// Set our menu bar up
|
||||
menuBar = new QMenuBar(this);
|
||||
setMenuBar(menuBar);
|
||||
|
||||
auto pandaMenu = menuBar->addMenu(tr("PANDA"));
|
||||
auto pandaAction = pandaMenu->addAction(tr("panda..."));
|
||||
auto fileMenu = menuBar->addMenu(tr("File"));
|
||||
auto pandaAction = fileMenu->addAction(tr("panda..."));
|
||||
|
||||
auto emulationMenu = menuBar->addMenu(tr("Emulation"));
|
||||
auto helpMenu = menuBar->addMenu(tr("Help"));
|
||||
auto aboutMenu = menuBar->addMenu(tr("About"));
|
||||
|
||||
// Set up theme selection
|
||||
setTheme(Theme::Dark);
|
||||
|
@ -53,7 +59,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
Helpers::panic("Failed to load ROM");
|
||||
}
|
||||
|
||||
while (true) {
|
||||
while (appRunning) {
|
||||
emu->runFrame();
|
||||
swapEmuBuffer();
|
||||
}
|
||||
|
@ -70,6 +76,9 @@ void MainWindow::swapEmuBuffer() {
|
|||
|
||||
// Cleanup when the main window closes
|
||||
MainWindow::~MainWindow() {
|
||||
appRunning = false; // Set our running atomic to false in order to make the emulator thread stop, and join it
|
||||
emuThread.join();
|
||||
|
||||
delete emu;
|
||||
delete menuBar;
|
||||
delete themeSelect;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#ifdef PANDA3DS_ENABLE_OPENGL
|
||||
ScreenWidget::ScreenWidget(QWidget* parent) : QWidget(parent) {
|
||||
// Create a native window for use with our graphics API of choice
|
||||
resize(400, 240 * 2);
|
||||
resize(800, 240 * 4);
|
||||
|
||||
setAutoFillBackground(false);
|
||||
setAttribute(Qt::WA_NativeWindow, true);
|
||||
|
|
Loading…
Add table
Reference in a new issue