Qt: Migrate multiplayer window handling into GBAApp
Jeffrey Pfau jeffrey@endrift.com
Fri, 29 May 2015 22:57:30 -0700
7 files changed,
56 insertions(+),
31 deletions(-)
M
CHANGES
→
CHANGES
@@ -45,6 +45,7 @@ - GBA SIO: Add a dummy driver for Normal mode
- GBA: GBARewind now returns how many states it has rewound - All: Enable static linking for Windows - All: Enable static linking for OS X + - Qt: Migrate multiplayer window handling into GBAApp 0.2.1: (2015-05-13) Bugfixes:
M
src/platform/qt/GBAApp.cpp
→
src/platform/qt/GBAApp.cpp
@@ -7,6 +7,7 @@ #include "GBAApp.h"
#include "AudioProcessor.h" #include "GameController.h" +#include "Window.h" #include <QFileOpenEvent>@@ -17,10 +18,13 @@ }
using namespace QGBA; +GBAApp* g_app = nullptr; + GBAApp::GBAApp(int& argc, char* argv[]) : QApplication(argc, argv) - , m_window(&m_configController) { + g_app = this; + #ifdef BUILD_SDL SDL_Init(SDL_INIT_NOPARACHUTE); #endif@@ -31,30 +35,53 @@
QApplication::setApplicationName(projectName); QApplication::setApplicationVersion(projectVersion); + Window* w = new Window(&m_configController); + m_windows[0] = w; + #ifndef Q_OS_MAC - m_window.show(); + w->show(); #endif GBAArguments args; if (m_configController.parseArguments(&args, argc, argv)) { - m_window.argumentsPassed(&args); + w->argumentsPassed(&args); } else { - m_window.loadConfig(); + w->loadConfig(); } freeArguments(&args); AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(m_configController.getQtOption("audioDriver").toInt())); - m_window.controller()->reloadAudioDriver(); + w->controller()->reloadAudioDriver(); + w->controller()->setMultiplayerController(&m_multiplayer); #ifdef Q_OS_MAC - m_window.show(); + w->show(); #endif } bool GBAApp::event(QEvent* event) { if (event->type() == QEvent::FileOpen) { - m_window.controller()->loadGame(static_cast<QFileOpenEvent*>(event)->file()); + m_windows[0]->controller()->loadGame(static_cast<QFileOpenEvent*>(event)->file()); return true; } return QApplication::event(event); } + +Window* GBAApp::newWindowInternal() { + Window* w = new Window(&m_configController, m_multiplayer.attached()); + m_windows[m_multiplayer.attached()] = w; + w->setAttribute(Qt::WA_DeleteOnClose); +#ifndef Q_OS_MAC + w->show(); +#endif + w->loadConfig(); + w->controller()->setMultiplayerController(&m_multiplayer); +#ifdef Q_OS_MAC + w->show(); +#endif + return w; +} + +Window* GBAApp::newWindow() { + return g_app->newWindowInternal(); +}
M
src/platform/qt/GBAApp.h
→
src/platform/qt/GBAApp.h
@@ -9,11 +9,16 @@
#include <QApplication> #include "ConfigController.h" -#include "Window.h" +#include "MultiplayerController.h" + +extern "C" { +#include "gba/sio.h" +} namespace QGBA { class GameController; +class Window; class GBAApp : public QApplication { Q_OBJECT@@ -21,12 +26,17 @@
public: GBAApp(int& argc, char* argv[]); + static Window* newWindow(); + protected: bool event(QEvent*); private: + Window* newWindowInternal(); + ConfigController m_configController; - Window m_window; + Window* m_windows[MAX_GBAS]; + MultiplayerController m_multiplayer; }; }
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -178,7 +178,7 @@ delete m_renderer;
delete[] m_drawContext; } -void GameController::setMultiplayerController(std::shared_ptr<MultiplayerController> controller) { +void GameController::setMultiplayerController(MultiplayerController* controller) { if (controller == m_multiplayer) { return; }@@ -192,7 +192,7 @@ if (!m_multiplayer) {
return; } m_multiplayer->detachGame(this); - m_multiplayer.reset(); + m_multiplayer = nullptr; } void GameController::setOverride(const GBACartridgeOverride& override) {
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -63,8 +63,8 @@
void setInputController(InputController* controller) { m_inputController = controller; } void setOverrides(Configuration* overrides) { m_threadContext.overrides = overrides; } - void setMultiplayerController(std::shared_ptr<MultiplayerController> controller); - std::shared_ptr<MultiplayerController> multiplayerController() { return m_multiplayer; } + void setMultiplayerController(MultiplayerController* controller); + MultiplayerController* multiplayerController() { return m_multiplayer; } void clearMultiplayerController(); void setOverride(const GBACartridgeOverride& override);@@ -191,7 +191,7 @@
int m_stateSlot; InputController* m_inputController; - std::shared_ptr<MultiplayerController> m_multiplayer; + MultiplayerController* m_multiplayer; struct GameControllerLux : GBALuminanceSource { GameController* p;
M
src/platform/qt/PaletteView.cpp
→
src/platform/qt/PaletteView.cpp
@@ -83,7 +83,7 @@ if (start + length > 512) {
length = 512 - start; } m_controller->threadInterrupt(); - QString filename = QFileDialog::getSaveFileName(this, tr("Export palette"), QString(), tr("Windows PAL (*.pal)")); + QString filename = QFileDialog::getSaveFileName(this, tr("Export palette"), QString(), tr("Windows PAL (*.pal);;Adobe Color Table (*.act)")); if (filename.isNull()) { m_controller->threadContinue(); return;
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -19,6 +19,7 @@ #include "CheatsView.h"
#include "ConfigController.h" #include "DisplayGL.h" #include "GameController.h" +#include "GBAApp.h" #include "GBAKeyEditor.h" #include "GDBController.h" #include "GDBWindow.h"@@ -604,7 +605,7 @@ GBAGetGameTitle(m_controller->thread()->gba, gameTitle);
title = (gameTitle); } - std::shared_ptr<MultiplayerController> multiplayer = m_controller->multiplayerController(); + MultiplayerController* multiplayer = m_controller->multiplayerController(); if (multiplayer && multiplayer->attached() > 1) { title += tr(" - Player %1 of %2").arg(m_playerId + 1).arg(multiplayer->attached()); }@@ -712,21 +713,7 @@
fileMenu->addSeparator(); QAction* multiWindow = new QAction(tr("New multiplayer window"), fileMenu); connect(multiWindow, &QAction::triggered, [this]() { - std::shared_ptr<MultiplayerController> multiplayer = m_controller->multiplayerController(); - if (!multiplayer) { - multiplayer = std::make_shared<MultiplayerController>(); - m_controller->setMultiplayerController(multiplayer); - } - Window* w2 = new Window(m_config, multiplayer->attached()); - w2->setAttribute(Qt::WA_DeleteOnClose); -#ifndef Q_OS_MAC - w2->show(); -#endif - w2->loadConfig(); - w2->controller()->setMultiplayerController(multiplayer); -#ifdef Q_OS_MAC - w2->show(); -#endif + GBAApp::newWindow(); }); addControlledAction(fileMenu, multiWindow, "multiWindow");