all repos — mgba @ dc5fb14fa18c31812bc2bbab72b718a7846113c2

mGBA Game Boy Advance Emulator

Qt: Clear cheats when the game ends
Jeffrey Pfau jeffrey@endrift.com
Sat, 14 Feb 2015 18:04:01 -0800
commit

dc5fb14fa18c31812bc2bbab72b718a7846113c2

parent

297551a5be1858061a84e2482bfd3b83a39f94b0

M src/platform/qt/CheatsModel.cppsrc/platform/qt/CheatsModel.cpp

@@ -108,4 +108,9 @@ void CheatsModel::addSet(GBACheatSet* set) {

beginInsertRows(QModelIndex(), GBACheatSetsSize(&m_device->cheats), GBACheatSetsSize(&m_device->cheats) + 1); *GBACheatSetsAppend(&m_device->cheats) = set; endInsertRows(); -}+} + +void CheatsModel::invalidated() { + beginResetModel(); + endResetModel(); +}
M src/platform/qt/CheatsModel.hsrc/platform/qt/CheatsModel.h

@@ -34,6 +34,9 @@

void loadFile(const QString& path); void addSet(GBACheatSet* set); +public slots: + void invalidated(); + private: GBACheatDevice* m_device; };
M src/platform/qt/CheatsView.cppsrc/platform/qt/CheatsView.cpp

@@ -5,6 +5,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this

* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "CheatsView.h" +#include "GameController.h" + #include <QFileDialog> extern "C" {

@@ -13,9 +15,9 @@ }

using namespace QGBA; -CheatsView::CheatsView(GBACheatDevice* device, QWidget* parent) +CheatsView::CheatsView(GameController* controller, QWidget* parent) : QWidget(parent) - , m_model(device) + , m_model(controller->cheatDevice()) { m_ui.setupUi(this);

@@ -23,6 +25,7 @@ m_ui.cheatList->setModel(&m_model);

connect(m_ui.load, SIGNAL(clicked()), this, SLOT(load())); 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]() { enterCheat(GBACheatAddLine);
M src/platform/qt/CheatsView.hsrc/platform/qt/CheatsView.h

@@ -18,11 +18,13 @@ struct GBACheatDevice;

namespace QGBA { +class GameController; + class CheatsView : public QWidget { Q_OBJECT public: - CheatsView(GBACheatDevice* device, QWidget* parent = nullptr); + CheatsView(GameController* controller, QWidget* parent = nullptr); private slots: void load();
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -141,6 +141,7 @@ m_audioThread->quit();

m_audioThread->wait(); disconnect(); closeGame(); + GBACheatDeviceDestroy(&m_cheatDevice); delete m_renderer; delete[] m_drawContext; }

@@ -275,6 +276,13 @@ m_threadContext.fname = nullptr;

} 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; emit gameStopped(&m_threadContext);
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -241,7 +241,7 @@ sensorWindow->show();

} void Window::openCheatsWindow() { - CheatsView* cheatsWindow = new CheatsView(m_controller->cheatDevice()); + CheatsView* cheatsWindow = new CheatsView(m_controller); connect(this, SIGNAL(shutdown()), cheatsWindow, SLOT(close())); cheatsWindow->setAttribute(Qt::WA_DeleteOnClose); cheatsWindow->show();
M src/util/vector.hsrc/util/vector.h

@@ -18,6 +18,7 @@ void NAME ## Init(struct NAME* vector, size_t capacity); \

void NAME ## Deinit(struct NAME* vector); \ TYPE* NAME ## GetPointer(struct NAME* vector, size_t location); \ TYPE* NAME ## Append(struct NAME* vector); \ + void NAME ## Clear(struct NAME* vector); \ void NAME ## Resize(struct NAME* vector, ssize_t change); \ void NAME ## Shift(struct NAME* vector, size_t location, size_t difference); \ void NAME ## Unshift(struct NAME* vector, size_t location, size_t difference); \

@@ -50,6 +51,9 @@ if (change > 0) { \

NAME ## EnsureCapacity(vector, vector->size + change); \ } \ vector->size += change; \ + } \ + void NAME ## Clear(struct NAME* vector) { \ + vector->size = 0; \ } \ void NAME ## EnsureCapacity(struct NAME* vector, size_t capacity) { \ if (capacity <= vector->capacity) { \