mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-17 19:21:30 +12:00
[Qt] Add file picker
This commit is contained in:
parent
061c80fd11
commit
c648b6c62d
2 changed files with 51 additions and 9 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include "emulator.hpp"
|
#include "emulator.hpp"
|
||||||
#include "panda_qt/screen.hpp"
|
#include "panda_qt/screen.hpp"
|
||||||
|
@ -26,6 +27,8 @@ class MainWindow : public QMainWindow {
|
||||||
std::thread emuThread;
|
std::thread emuThread;
|
||||||
|
|
||||||
std::atomic<bool> appRunning = true; // Is the application itself running?
|
std::atomic<bool> appRunning = true; // Is the application itself running?
|
||||||
|
std::atomic<bool> needToLoadROM = false;
|
||||||
|
std::filesystem::path romToLoad = "";
|
||||||
|
|
||||||
ScreenWidget screen;
|
ScreenWidget screen;
|
||||||
QComboBox* themeSelect = nullptr;
|
QComboBox* themeSelect = nullptr;
|
||||||
|
@ -34,6 +37,8 @@ class MainWindow : public QMainWindow {
|
||||||
Theme currentTheme;
|
Theme currentTheme;
|
||||||
void setTheme(Theme theme);
|
void setTheme(Theme theme);
|
||||||
void swapEmuBuffer();
|
void swapEmuBuffer();
|
||||||
|
void emuThreadMainLoop();
|
||||||
|
void selectROM();
|
||||||
|
|
||||||
// Tracks whether we are using an OpenGL-backed renderer or a Vulkan-backed renderer
|
// Tracks whether we are using an OpenGL-backed renderer or a Vulkan-backed renderer
|
||||||
bool usingGL = false;
|
bool usingGL = false;
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#include "panda_qt/main_window.hpp"
|
#include "panda_qt/main_window.hpp"
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent), screen(this) {
|
MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent), screen(this) {
|
||||||
setWindowTitle("Alber");
|
setWindowTitle("Alber");
|
||||||
// Enable drop events for loading ROMs
|
// Enable drop events for loading ROMs
|
||||||
|
@ -15,6 +18,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
||||||
|
|
||||||
auto fileMenu = menuBar->addMenu(tr("File"));
|
auto fileMenu = menuBar->addMenu(tr("File"));
|
||||||
auto pandaAction = fileMenu->addAction(tr("panda..."));
|
auto pandaAction = fileMenu->addAction(tr("panda..."));
|
||||||
|
connect(pandaAction, &QAction::triggered, this, &MainWindow::selectROM);
|
||||||
|
|
||||||
auto emulationMenu = menuBar->addMenu(tr("Emulation"));
|
auto emulationMenu = menuBar->addMenu(tr("Emulation"));
|
||||||
auto helpMenu = menuBar->addMenu(tr("Help"));
|
auto helpMenu = menuBar->addMenu(tr("Help"));
|
||||||
|
@ -54,16 +58,28 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
||||||
Helpers::panic("Unsupported graphics backend for Qt frontend!");
|
Helpers::panic("Unsupported graphics backend for Qt frontend!");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = emu->loadROM("OoT.3ds");
|
// Enter our emulator main loop
|
||||||
if (!success) {
|
emuThreadMainLoop();
|
||||||
Helpers::panic("Failed to load ROM");
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is the main loop that the emulator thread runs after being initialized
|
||||||
|
void MainWindow::emuThreadMainLoop() {
|
||||||
while (appRunning) {
|
while (appRunning) {
|
||||||
|
if (needToLoadROM.load()) {
|
||||||
|
bool success = emu->loadROM(romToLoad);
|
||||||
|
if (!success) {
|
||||||
|
printf("Failed to load ROM");
|
||||||
|
}
|
||||||
|
|
||||||
|
needToLoadROM.store(false, std::memory_order::seq_cst);
|
||||||
|
}
|
||||||
|
|
||||||
emu->runFrame();
|
emu->runFrame();
|
||||||
swapEmuBuffer();
|
swapEmuBuffer();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
printf("Emulator thread returned");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::swapEmuBuffer() {
|
void MainWindow::swapEmuBuffer() {
|
||||||
|
@ -74,10 +90,31 @@ void MainWindow::swapEmuBuffer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::selectROM() {
|
||||||
|
// Are we already waiting for a ROM to be loaded? Then complain about it!
|
||||||
|
if (needToLoadROM.load()) {
|
||||||
|
QMessageBox::warning(this, tr("Already loading ROM"), tr("Panda3DS is already busy loading a ROM, please wait"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto path =
|
||||||
|
QFileDialog::getOpenFileName(this, tr("Select 3DS ROM to load"), "", tr("Nintendo 3DS ROMs (*.3ds *.cci *.cxi *.app *.3dsx *.elf *.axf)"));
|
||||||
|
|
||||||
|
if (!path.isEmpty()) {
|
||||||
|
romToLoad = path.toStdU16String();
|
||||||
|
needToLoadROM.store(true, std::memory_order_seq_cst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup when the main window closes
|
// Cleanup when the main window closes
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
|
printf("Destroying window class\n");
|
||||||
appRunning = false; // Set our running atomic to false in order to make the emulator thread stop, and join it
|
appRunning = false; // Set our running atomic to false in order to make the emulator thread stop, and join it
|
||||||
|
|
||||||
|
if (emuThread.joinable()) {
|
||||||
emuThread.join();
|
emuThread.join();
|
||||||
|
}
|
||||||
|
printf("Emu thread joined!\n");
|
||||||
|
|
||||||
delete emu;
|
delete emu;
|
||||||
delete menuBar;
|
delete menuBar;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue