all repos — mgba @ e6377f2e6a8902a780f8caa4d40e1768963eb12d

mGBA Game Boy Advance Emulator

GBA: Add player IDs to allow multiple controller profiles to be used at once
Jeffrey Pfau jeffrey@endrift.com
Sun, 15 Mar 2015 23:48:35 -0700
commit

e6377f2e6a8902a780f8caa4d40e1768963eb12d

parent

51b8c862b969390582cb39b3ac98239cdea9a4b1

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

@@ -19,8 +19,9 @@ }

using namespace QGBA; -InputController::InputController(QObject* parent) +InputController::InputController(int playerId, QObject* parent) : QObject(parent) + , m_playerId(playerId) , m_config(nullptr) , m_gamepadTimer(nullptr) {

@@ -28,9 +29,8 @@ GBAInputMapInit(&m_inputMap);

#ifdef BUILD_SDL m_sdlEvents.bindings = &m_inputMap; - GBASDLInitEvents(&m_sdlEvents); + GBASDLInitEvents(&m_sdlEvents, playerId); GBASDLInitBindings(&m_inputMap); - SDL_JoystickEventState(SDL_QUERY); m_gamepadTimer = new QTimer(this); connect(m_gamepadTimer, SIGNAL(timeout()), this, SLOT(testGamepad()));
M src/platform/qt/InputController.hsrc/platform/qt/InputController.h

@@ -31,7 +31,7 @@

public: static const uint32_t KEYBOARD = 0x51545F4B; - InputController(QObject* parent = nullptr); + InputController(int playerId = 0, QObject* parent = nullptr); ~InputController(); void setConfiguration(ConfigController* config);

@@ -67,6 +67,7 @@ bool hasPendingEvent(GBAKey) const;

GBAInputMap m_inputMap; ConfigController* m_config; + int m_playerId; #ifdef BUILD_SDL GBASDLEvents m_sdlEvents;
M src/platform/qt/MultiplayerController.cppsrc/platform/qt/MultiplayerController.cpp

@@ -61,3 +61,11 @@ }

MutexUnlock(&m_lockstep.mutex); controller->threadContinue(); } + +int MultiplayerController::attached() { + int num; + MutexLock(&m_lockstep.mutex); + num = m_lockstep.attached; + MutexUnlock(&m_lockstep.mutex); + return num; +}
M src/platform/qt/MultiplayerController.hsrc/platform/qt/MultiplayerController.h

@@ -22,6 +22,8 @@

bool attachGame(GameController*); void detachGame(GameController*); + int attached(); + private: GBASIOLockstep m_lockstep; };
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -37,13 +37,14 @@ }

using namespace QGBA; -Window::Window(ConfigController* config, QWidget* parent) +Window::Window(ConfigController* config, int playerId, QWidget* parent) : QMainWindow(parent) , m_logView(new LogView()) , m_stateWindow(nullptr) , m_screenWidget(new WindowBackground()) , m_logo(":/res/mgba-1024.png") , m_config(config) + , m_inputController(playerId) #ifdef USE_FFMPEG , m_videoView(nullptr) #endif

@@ -55,6 +56,7 @@ , m_gdbController(nullptr)

#endif , m_mruMenu(nullptr) , m_shortcutController(new ShortcutController(this)) + , m_playerId(playerId) { setWindowTitle(PROJECT_NAME); setFocusPolicy(Qt::StrongFocus);

@@ -532,7 +534,7 @@ if (!multiplayer) {

multiplayer = std::make_shared<MultiplayerController>(); m_controller->setMultiplayerController(multiplayer); } - Window* w2 = new Window(m_config); + Window* w2 = new Window(m_config, multiplayer->attached()); w2->setAttribute(Qt::WA_DeleteOnClose); w2->loadConfig(); w2->controller()->setMultiplayerController(multiplayer);
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -39,7 +39,7 @@ class Window : public QMainWindow {

Q_OBJECT public: - Window(ConfigController* config, QWidget* parent = nullptr); + Window(ConfigController* config, int playerId = 0, QWidget* parent = nullptr); virtual ~Window(); GameController* controller() { return m_controller; }

@@ -134,6 +134,7 @@ QTimer m_fpsTimer;

QList<QString> m_mruFiles; QMenu* m_mruMenu; ShortcutController* m_shortcutController; + int m_playerId; #ifdef USE_FFMPEG VideoView* m_videoView;
M src/platform/sdl/main.csrc/platform/sdl/main.c

@@ -101,7 +101,7 @@ GBASDLInitAudio(&renderer.audio, &context);

renderer.events.bindings = &inputMap; GBASDLInitBindings(&inputMap); - GBASDLInitEvents(&renderer.events); + GBASDLInitEvents(&renderer.events, 0); GBASDLEventsLoadConfig(&renderer.events, GBAConfigGetInput(&config)); context.overrides = GBAConfigGetOverrides(&config);
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -21,13 +21,13 @@ #endif

static int _openContexts = 0; -bool GBASDLInitEvents(struct GBASDLEvents* context) { +bool GBASDLInitEvents(struct GBASDLEvents* context, int playerId) { if (!_openContexts && SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { return false; } ++_openContexts; SDL_JoystickEventState(SDL_ENABLE); - context->joystick = SDL_JoystickOpen(0); + context->joystick = SDL_JoystickOpen(playerId); #if !SDL_VERSION_ATLEAST(2, 0, 0) SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); #endif
M src/platform/sdl/sdl-events.hsrc/platform/sdl/sdl-events.h

@@ -28,7 +28,7 @@ int windowUpdated;

#endif }; -bool GBASDLInitEvents(struct GBASDLEvents*); +bool GBASDLInitEvents(struct GBASDLEvents*, int playerId); void GBASDLDeinitEvents(struct GBASDLEvents*); void GBASDLInitBindings(struct GBAInputMap* inputMap);