mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-21 04:49:14 +12:00
[Qt] Add proper message queue for thread communication
This commit is contained in:
parent
5984c27960
commit
8d5485fbeb
2 changed files with 60 additions and 22 deletions
|
@ -9,9 +9,11 @@
|
|||
#include <filesystem>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "emulator.hpp"
|
||||
#include "panda_qt/screen.hpp"
|
||||
#include "services/hid.hpp"
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
@ -23,15 +25,34 @@ class MainWindow : public QMainWindow {
|
|||
Dark = 2,
|
||||
};
|
||||
|
||||
// Types of messages we might send from the GUI thread to the emulator thread
|
||||
enum class MessageType {
|
||||
LoadROM, Reset, Pause, Resume, TogglePause, DumpRomFS, PressKey, ReleaseKey
|
||||
};
|
||||
|
||||
// Tagged union representing our message queue messages
|
||||
struct EmulatorMessage {
|
||||
MessageType type;
|
||||
|
||||
union {
|
||||
struct {
|
||||
std::filesystem::path* p;
|
||||
} path;
|
||||
|
||||
struct {
|
||||
u32 key;
|
||||
} key;
|
||||
};
|
||||
};
|
||||
|
||||
// This would normally be an std::unique_ptr but it's shared between threads so definitely not
|
||||
Emulator* emu = nullptr;
|
||||
std::thread emuThread;
|
||||
|
||||
std::atomic<bool> appRunning = true; // Is the application itself running?
|
||||
std::mutex messageQueueMutex; // Used for synchronizing messages between the emulator and UI
|
||||
std::filesystem::path romToLoad = "";
|
||||
|
||||
bool needToLoadROM = false;
|
||||
// Used for synchronizing messages between the emulator and UI
|
||||
std::mutex messageQueueMutex;
|
||||
std::vector<EmulatorMessage> messageQueue;
|
||||
|
||||
ScreenWidget screen;
|
||||
QComboBox* themeSelect = nullptr;
|
||||
|
@ -43,6 +64,8 @@ class MainWindow : public QMainWindow {
|
|||
void emuThreadMainLoop();
|
||||
void selectROM();
|
||||
void dumpRomFS();
|
||||
void sendMessage(const EmulatorMessage& message);
|
||||
void dispatchMessage(const EmulatorMessage& message);
|
||||
|
||||
// Tracks whether we are using an OpenGL-backed renderer or a Vulkan-backed renderer
|
||||
bool usingGL = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue