Qt: Clear cheats when the game ends

This commit is contained in:
Jeffrey Pfau 2015-02-14 18:04:01 -08:00
parent 297551a5be
commit dc5fb14fa1
7 changed files with 30 additions and 5 deletions

View File

@ -109,3 +109,8 @@ void CheatsModel::addSet(GBACheatSet* set) {
*GBACheatSetsAppend(&m_device->cheats) = set; *GBACheatSetsAppend(&m_device->cheats) = set;
endInsertRows(); endInsertRows();
} }
void CheatsModel::invalidated() {
beginResetModel();
endResetModel();
}

View File

@ -34,6 +34,9 @@ public:
void loadFile(const QString& path); void loadFile(const QString& path);
void addSet(GBACheatSet* set); void addSet(GBACheatSet* set);
public slots:
void invalidated();
private: private:
GBACheatDevice* m_device; GBACheatDevice* m_device;
}; };

View File

@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CheatsView.h" #include "CheatsView.h"
#include "GameController.h"
#include <QFileDialog> #include <QFileDialog>
extern "C" { extern "C" {
@ -13,9 +15,9 @@ extern "C" {
using namespace QGBA; using namespace QGBA;
CheatsView::CheatsView(GBACheatDevice* device, QWidget* parent) CheatsView::CheatsView(GameController* controller, QWidget* parent)
: QWidget(parent) : QWidget(parent)
, m_model(device) , m_model(controller->cheatDevice())
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
@ -23,6 +25,7 @@ CheatsView::CheatsView(GBACheatDevice* device, QWidget* parent)
connect(m_ui.load, SIGNAL(clicked()), this, SLOT(load())); connect(m_ui.load, SIGNAL(clicked()), this, SLOT(load()));
connect(m_ui.addSet, SIGNAL(clicked()), this, SLOT(addSet())); connect(m_ui.addSet, SIGNAL(clicked()), this, SLOT(addSet()));
connect(controller, SIGNAL(gameStopped(GBAThread*)), &m_model, SLOT(invalidated()));
connect(m_ui.add, &QPushButton::clicked, [this]() { connect(m_ui.add, &QPushButton::clicked, [this]() {
enterCheat(GBACheatAddLine); enterCheat(GBACheatAddLine);

View File

@ -18,11 +18,13 @@ struct GBACheatDevice;
namespace QGBA { namespace QGBA {
class GameController;
class CheatsView : public QWidget { class CheatsView : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
CheatsView(GBACheatDevice* device, QWidget* parent = nullptr); CheatsView(GameController* controller, QWidget* parent = nullptr);
private slots: private slots:
void load(); void load();

View File

@ -141,6 +141,7 @@ GameController::~GameController() {
m_audioThread->wait(); m_audioThread->wait();
disconnect(); disconnect();
closeGame(); closeGame();
GBACheatDeviceDestroy(&m_cheatDevice);
delete m_renderer; delete m_renderer;
delete[] m_drawContext; delete[] m_drawContext;
} }
@ -276,6 +277,13 @@ void GameController::closeGame() {
m_patch = QString(); m_patch = QString();
for (size_t i = 0; i < GBACheatSetsSize(&m_cheatDevice.cheats); ++i) {
GBACheatSet* set = *GBACheatSetsGetPointer(&m_cheatDevice.cheats, i);
GBACheatSetDeinit(set);
delete set;
}
GBACheatSetsClear(&m_cheatDevice.cheats);
m_gameOpen = false; m_gameOpen = false;
emit gameStopped(&m_threadContext); emit gameStopped(&m_threadContext);
} }

View File

@ -241,7 +241,7 @@ void Window::openSensorWindow() {
} }
void Window::openCheatsWindow() { void Window::openCheatsWindow() {
CheatsView* cheatsWindow = new CheatsView(m_controller->cheatDevice()); CheatsView* cheatsWindow = new CheatsView(m_controller);
connect(this, SIGNAL(shutdown()), cheatsWindow, SLOT(close())); connect(this, SIGNAL(shutdown()), cheatsWindow, SLOT(close()));
cheatsWindow->setAttribute(Qt::WA_DeleteOnClose); cheatsWindow->setAttribute(Qt::WA_DeleteOnClose);
cheatsWindow->show(); cheatsWindow->show();

View File

@ -18,6 +18,7 @@
void NAME ## Deinit(struct NAME* vector); \ void NAME ## Deinit(struct NAME* vector); \
TYPE* NAME ## GetPointer(struct NAME* vector, size_t location); \ TYPE* NAME ## GetPointer(struct NAME* vector, size_t location); \
TYPE* NAME ## Append(struct NAME* vector); \ TYPE* NAME ## Append(struct NAME* vector); \
void NAME ## Clear(struct NAME* vector); \
void NAME ## Resize(struct NAME* vector, ssize_t change); \ void NAME ## Resize(struct NAME* vector, ssize_t change); \
void NAME ## Shift(struct NAME* vector, size_t location, size_t difference); \ void NAME ## Shift(struct NAME* vector, size_t location, size_t difference); \
void NAME ## Unshift(struct NAME* vector, size_t location, size_t difference); \ void NAME ## Unshift(struct NAME* vector, size_t location, size_t difference); \
@ -51,6 +52,9 @@
} \ } \
vector->size += change; \ vector->size += change; \
} \ } \
void NAME ## Clear(struct NAME* vector) { \
vector->size = 0; \
} \
void NAME ## EnsureCapacity(struct NAME* vector, size_t capacity) { \ void NAME ## EnsureCapacity(struct NAME* vector, size_t capacity) { \
if (capacity <= vector->capacity) { \ if (capacity <= vector->capacity) { \
return; \ return; \