Skip to content

Commit 46135fb

Browse files
committed
Apply CoreConsumer to classes using setController()
1 parent a33866b commit 46135fb

32 files changed

+146
-180
lines changed

src/platform/qt/AssetTile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int AssetTile::customLocation(const QString&) {
4545
return layout()->indexOf(m_ui.line);
4646
}
4747

48-
void AssetTile::setController(std::shared_ptr<CoreController> controller) {
48+
void AssetTile::onCoreAttached(std::shared_ptr<CoreController> controller) {
4949
m_cacheSet = controller->graphicCaches();
5050
switch (controller->platform()) {
5151
#ifdef M_CORE_GBA

src/platform/qt/AssetTile.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66
#pragma once
77

8+
#include "CorePointer.h"
89
#include "ui_AssetTile.h"
910

1011
#include <memory>
@@ -15,12 +16,11 @@ namespace QGBA {
1516

1617
class CoreController;
1718

18-
class AssetTile : public AssetInfo {
19+
class AssetTile : public AssetInfo, public CoreConsumer {
1920
Q_OBJECT
2021

2122
public:
2223
AssetTile(QWidget* parent = nullptr);
23-
void setController(std::shared_ptr<CoreController>);
2424
QImage activeTile() const { return m_activeTile; }
2525

2626
public slots:
@@ -35,6 +35,8 @@ public slots:
3535
int customLocation(const QString& id = {}) override;
3636

3737
private:
38+
void onCoreAttached(std::shared_ptr<CoreController>);
39+
3840
Ui::AssetTile m_ui;
3941

4042
mCacheSet* m_cacheSet;

src/platform/qt/AssetView.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "AssetView.h"
77

88
#include "CoreController.h"
9+
#include "CorePointerSource.h"
910

1011
#include <QTimer>
1112

@@ -21,18 +22,18 @@
2122

2223
using namespace QGBA;
2324

24-
AssetView::AssetView(std::shared_ptr<CoreController> controller, QWidget* parent)
25+
AssetView::AssetView(CorePointerSource* controller, QWidget* parent)
2526
: QWidget(parent)
26-
, m_cacheSet(controller->graphicCaches())
27-
, m_controller(controller)
27+
, CoreConsumer(controller)
28+
, m_cacheSet(m_controller->graphicCaches())
2829
{
2930
m_updateTimer.setSingleShot(true);
3031
m_updateTimer.setInterval(1);
3132
connect(&m_updateTimer, &QTimer::timeout, this, static_cast<void(AssetView::*)()>(&AssetView::updateTiles));
3233

33-
connect(controller.get(), &CoreController::frameAvailable, &m_updateTimer,
34+
connect(m_controller.get(), &CoreController::frameAvailable, &m_updateTimer,
3435
static_cast<void(QTimer::*)()>(&QTimer::start));
35-
connect(controller.get(), &CoreController::stopping, &m_updateTimer, &QTimer::stop);
36+
connect(m_controller.get(), &CoreController::stopping, &m_updateTimer, &QTimer::stop);
3637
}
3738

3839
void AssetView::updateTiles() {

src/platform/qt/AssetView.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,26 @@
1313

1414
#include <memory>
1515

16+
#include "CorePointer.h"
17+
1618
struct mMapCacheEntry;
1719

1820
namespace QGBA {
1921

2022
class CoreController;
2123

22-
class AssetView : public QWidget {
24+
class AssetView : public QWidget, public CoreConsumer {
2325
Q_OBJECT
2426

2527
public:
26-
AssetView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
28+
AssetView(CorePointerSource* controller, QWidget* parent = nullptr);
2729

2830
protected slots:
2931
void updateTiles();
3032
void updateTiles(bool force);
3133

3234
protected:
3335
mCacheSet* const m_cacheSet;
34-
std::shared_ptr<CoreController> m_controller;
3536

3637
struct ObjInfo {
3738
unsigned tile;

src/platform/qt/DebuggerConsoleController.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ DebuggerConsoleController::DebuggerConsoleController(QObject* parent)
3535
}
3636

3737
void DebuggerConsoleController::enterLine(const QString& line) {
38-
CoreController::Interrupter interrupter(m_gameController);
38+
CoreController::Interrupter interrupter(m_controller);
3939
QMutexLocker lock(&m_mutex);
4040
m_lines.append(line);
4141
if (m_cliDebugger.d.p && m_cliDebugger.d.p->state == DEBUGGER_RUNNING) {
@@ -46,7 +46,7 @@ void DebuggerConsoleController::enterLine(const QString& line) {
4646

4747
void DebuggerConsoleController::detach() {
4848
{
49-
CoreController::Interrupter interrupter(m_gameController);
49+
CoreController::Interrupter interrupter(m_controller);
5050
QMutexLocker lock(&m_mutex);
5151
if (m_cliDebugger.d.p && m_cliDebugger.d.p->state != DEBUGGER_SHUTDOWN) {
5252
m_lines.append(QString());
@@ -58,9 +58,9 @@ void DebuggerConsoleController::detach() {
5858
}
5959

6060
void DebuggerConsoleController::attachInternal() {
61-
CoreController::Interrupter interrupter(m_gameController);
61+
CoreController::Interrupter interrupter(m_controller);
6262
QMutexLocker lock(&m_mutex);
63-
mCore* core = m_gameController->thread()->core;
63+
mCore* core = m_controller->thread()->core;
6464
CLIDebuggerAttachBackend(&m_cliDebugger, &m_backend);
6565
CLIDebuggerAttachSystem(&m_cliDebugger, core->cliDebuggerSystem(core));
6666
}
@@ -123,7 +123,7 @@ void DebuggerConsoleController::lineAppend(struct CLIDebuggerBackend* be, const
123123
const char* DebuggerConsoleController::historyLast(struct CLIDebuggerBackend* be, size_t* len) {
124124
Backend* consoleBe = reinterpret_cast<Backend*>(be);
125125
DebuggerConsoleController* self = consoleBe->self;
126-
CoreController::Interrupter interrupter(self->m_gameController);
126+
CoreController::Interrupter interrupter(self->m_controller);
127127
QMutexLocker lock(&self->m_mutex);
128128
if (self->m_history.isEmpty()) {
129129
return "i";
@@ -136,7 +136,7 @@ const char* DebuggerConsoleController::historyLast(struct CLIDebuggerBackend* be
136136
void DebuggerConsoleController::historyAppend(struct CLIDebuggerBackend* be, const char* line) {
137137
Backend* consoleBe = reinterpret_cast<Backend*>(be);
138138
DebuggerConsoleController* self = consoleBe->self;
139-
CoreController::Interrupter interrupter(self->m_gameController);
139+
CoreController::Interrupter interrupter(self->m_controller);
140140
QMutexLocker lock(&self->m_mutex);
141141
self->m_history.append(QString::fromUtf8(line));
142142
}

src/platform/qt/DebuggerController.cpp

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,30 @@ DebuggerController::DebuggerController(mDebuggerModule* debugger, QObject* paren
1616
}
1717

1818
bool DebuggerController::isAttached() {
19-
if (!m_gameController) {
19+
if (!m_controller) {
2020
return false;
2121
}
22-
return m_gameController->debugger() == m_debugger->p;
22+
return m_controller->debugger() == m_debugger->p;
2323
}
2424

25-
void DebuggerController::setController(std::shared_ptr<CoreController> controller) {
26-
if (m_gameController && controller != m_gameController) {
27-
m_gameController->disconnect(this);
28-
detach();
29-
}
30-
m_gameController = controller;
31-
if (controller) {
32-
connect(m_gameController.get(), &CoreController::stopping, [this]() {
33-
setController(nullptr);
34-
});
35-
if (m_autoattach) {
36-
m_autoattach = false;
37-
attach();
38-
}
25+
void DebuggerController::onCoreDetached(std::shared_ptr<CoreController>) {
26+
detach();
27+
}
28+
29+
void DebuggerController::onCoreAttached(std::shared_ptr<CoreController>) {
30+
if (m_autoattach) {
31+
m_autoattach = false;
32+
attach();
3933
}
4034
}
4135

4236
void DebuggerController::attach() {
4337
if (isAttached()) {
4438
return;
4539
}
46-
if (m_gameController) {
40+
if (m_controller) {
4741
attachInternal();
48-
m_gameController->attachDebuggerModule(m_debugger);
42+
m_controller->attachDebuggerModule(m_debugger);
4943
} else {
5044
m_autoattach = true;
5145
}
@@ -55,10 +49,10 @@ void DebuggerController::detach() {
5549
if (!isAttached()) {
5650
return;
5751
}
58-
if (m_gameController) {
59-
CoreController::Interrupter interrupter(m_gameController);
52+
if (m_controller) {
53+
CoreController::Interrupter interrupter(m_controller);
6054
shutdownInternal();
61-
m_gameController->detachDebuggerModule(m_debugger);
55+
m_controller->detachDebuggerModule(m_debugger);
6256
} else {
6357
m_autoattach = false;
6458
}
@@ -68,7 +62,7 @@ void DebuggerController::breakInto() {
6862
if (!isAttached()) {
6963
return;
7064
}
71-
CoreController::Interrupter interrupter(m_gameController);
65+
CoreController::Interrupter interrupter(m_controller);
7266
mDebuggerEnter(m_debugger->p, DEBUGGER_ENTER_MANUAL, 0);
7367
}
7468

@@ -77,7 +71,7 @@ void DebuggerController::shutdown() {
7771
if (!isAttached()) {
7872
return;
7973
}
80-
CoreController::Interrupter interrupter(m_gameController);
74+
CoreController::Interrupter interrupter(m_controller);
8175
shutdownInternal();
8276
}
8377

src/platform/qt/DebuggerController.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99

1010
#include <memory>
1111

12+
#include "CorePointer.h"
13+
1214
struct mDebuggerModule;
1315

1416
namespace QGBA {
1517

16-
class CoreController;
17-
18-
class DebuggerController : public QObject {
18+
class DebuggerController : public QObject, public CoreConsumer {
1919
Q_OBJECT
2020

2121
public:
2222
DebuggerController(mDebuggerModule* debugger, QObject* parent = nullptr);
2323

2424
public:
2525
bool isAttached();
26-
void setController(std::shared_ptr<CoreController>);
2726

2827
public slots:
2928
virtual void attach();
@@ -36,9 +35,10 @@ public slots:
3635
virtual void shutdownInternal();
3736

3837
mDebuggerModule* const m_debugger;
39-
std::shared_ptr<CoreController> m_gameController;
4038

4139
private:
40+
void onCoreDetached(std::shared_ptr<CoreController>);
41+
void onCoreAttached(std::shared_ptr<CoreController>);
4242
bool m_autoattach = false;
4343
};
4444

src/platform/qt/FrameView.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
using namespace QGBA;
3232

33-
FrameView::FrameView(std::shared_ptr<CoreController> controller, QWidget* parent)
34-
: AssetView(std::move(controller), parent)
33+
FrameView::FrameView(CorePointerSource* controller, QWidget* parent)
34+
: AssetView(controller, parent)
3535
{
3636
m_ui.setupUi(this);
3737

src/platform/qt/FrameView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FrameView : public AssetView {
3232
Q_OBJECT
3333

3434
public:
35-
FrameView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
35+
FrameView(CorePointerSource* controller, QWidget* parent = nullptr);
3636
~FrameView();
3737

3838
public slots:

src/platform/qt/GIFView.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
using namespace QGBA;
1717

18-
GIFView::GIFView(std::shared_ptr<CoreController> controller, QWidget* parent)
18+
GIFView::GIFView(CorePointerSource* controller, QWidget* parent)
1919
: QWidget(parent)
20+
, CoreConsumer(controller)
2021
{
2122
m_ui.setupUi(this);
2223

@@ -31,15 +32,13 @@ GIFView::GIFView(std::shared_ptr<CoreController> controller, QWidget* parent)
3132

3233
FFmpegEncoderInit(&m_encoder);
3334
FFmpegEncoderSetAudio(&m_encoder, nullptr, 0);
34-
35-
setController(controller);
3635
}
3736

3837
GIFView::~GIFView() {
3938
stopRecording();
4039
}
4140

42-
void GIFView::setController(std::shared_ptr<CoreController> controller) {
41+
void GIFView::onCoreAttached(std::shared_ptr<CoreController> controller) {
4342
connect(controller.get(), &CoreController::stopping, this, &GIFView::stopRecording);
4443
connect(this, &GIFView::recordingStarted, controller.get(), &CoreController::setAVStream);
4544
connect(this, &GIFView::recordingStopped, controller.get(), &CoreController::clearAVStream, Qt::DirectConnection);

0 commit comments

Comments
 (0)