mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
Threading shenanigans
This commit is contained in:
parent
a2276c922f
commit
3d52692536
2 changed files with 27 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <functional>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include "cheats.hpp"
|
#include "cheats.hpp"
|
||||||
#include "emulator.hpp"
|
#include "emulator.hpp"
|
||||||
|
@ -23,6 +25,19 @@ struct CheatMetadata {
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void dispatchToMainThread(std::function<void()> callback)
|
||||||
|
{
|
||||||
|
QTimer* timer = new QTimer();
|
||||||
|
timer->moveToThread(qApp->thread());
|
||||||
|
timer->setSingleShot(true);
|
||||||
|
QObject::connect(timer, &QTimer::timeout, [=]()
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
timer->deleteLater();
|
||||||
|
});
|
||||||
|
QMetaObject::invokeMethod(timer, "start", Qt::QueuedConnection, Q_ARG(int, 0));
|
||||||
|
}
|
||||||
|
|
||||||
class CheatEntryWidget : public QWidget {
|
class CheatEntryWidget : public QWidget {
|
||||||
public:
|
public:
|
||||||
CheatEntryWidget(Emulator* emu, CheatMetadata metadata, QListWidget* parent);
|
CheatEntryWidget(Emulator* emu, CheatMetadata metadata, QListWidget* parent);
|
||||||
|
@ -181,16 +196,22 @@ void CheatEditDialog::accepted() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow->editCheat(cheatEntry.GetMetadata().handle, bytes, [this](u32 handle) {
|
mainWindow->editCheat(cheatEntry.GetMetadata().handle, bytes, [this](u32 handle) {
|
||||||
CheatMetadata metadata = cheatEntry.GetMetadata();
|
dispatchToMainThread([this, handle]() {
|
||||||
metadata.handle = handle;
|
if (handle == badCheatHandle) {
|
||||||
cheatEntry.SetMetadata(metadata);
|
cheatEntry.Remove();
|
||||||
cheatEntry.Update();
|
return;
|
||||||
|
} else {
|
||||||
|
CheatMetadata metadata = cheatEntry.GetMetadata();
|
||||||
|
metadata.handle = handle;
|
||||||
|
cheatEntry.SetMetadata(metadata);
|
||||||
|
cheatEntry.Update();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatEditDialog::rejected() {
|
void CheatEditDialog::rejected() {
|
||||||
bool isEditing = cheatEntry.GetMetadata().handle != badCheatHandle;
|
bool isEditing = cheatEntry.GetMetadata().handle != badCheatHandle;
|
||||||
|
|
||||||
if (!isEditing) {
|
if (!isEditing) {
|
||||||
// Was adding a cheat but pressed cancel
|
// Was adding a cheat but pressed cancel
|
||||||
cheatEntry.Remove();
|
cheatEntry.Remove();
|
||||||
|
|
Loading…
Add table
Reference in a new issue