mirror of https://github.com/mgba-emu/mgba.git
GBA: Add player IDs to allow multiple controller profiles to be used at once
This commit is contained in:
parent
51b8c862b9
commit
e6377f2e6a
|
@ -19,8 +19,9 @@ extern "C" {
|
|||
|
||||
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 @@ InputController::InputController(QObject* parent)
|
|||
|
||||
#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()));
|
||||
|
|
|
@ -31,7 +31,7 @@ Q_OBJECT
|
|||
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 @@ private:
|
|||
|
||||
GBAInputMap m_inputMap;
|
||||
ConfigController* m_config;
|
||||
int m_playerId;
|
||||
|
||||
#ifdef BUILD_SDL
|
||||
GBASDLEvents m_sdlEvents;
|
||||
|
|
|
@ -61,3 +61,11 @@ void MultiplayerController::detachGame(GameController* controller) {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ public:
|
|||
bool attachGame(GameController*);
|
||||
void detachGame(GameController*);
|
||||
|
||||
int attached();
|
||||
|
||||
private:
|
||||
GBASIOLockstep m_lockstep;
|
||||
};
|
||||
|
|
|
@ -37,13 +37,14 @@ extern "C" {
|
|||
|
||||
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 @@ Window::Window(ConfigController* config, QWidget* parent)
|
|||
#endif
|
||||
, m_mruMenu(nullptr)
|
||||
, m_shortcutController(new ShortcutController(this))
|
||||
, m_playerId(playerId)
|
||||
{
|
||||
setWindowTitle(PROJECT_NAME);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
@ -532,7 +534,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
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);
|
||||
|
|
|
@ -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 @@ private:
|
|||
QList<QString> m_mruFiles;
|
||||
QMenu* m_mruMenu;
|
||||
ShortcutController* m_shortcutController;
|
||||
int m_playerId;
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
VideoView* m_videoView;
|
||||
|
|
|
@ -101,7 +101,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
renderer.events.bindings = &inputMap;
|
||||
GBASDLInitBindings(&inputMap);
|
||||
GBASDLInitEvents(&renderer.events);
|
||||
GBASDLInitEvents(&renderer.events, 0);
|
||||
GBASDLEventsLoadConfig(&renderer.events, GBAConfigGetInput(&config));
|
||||
context.overrides = GBAConfigGetOverrides(&config);
|
||||
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
|
||||
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
|
||||
|
|
|
@ -28,7 +28,7 @@ struct GBASDLEvents {
|
|||
#endif
|
||||
};
|
||||
|
||||
bool GBASDLInitEvents(struct GBASDLEvents*);
|
||||
bool GBASDLInitEvents(struct GBASDLEvents*, int playerId);
|
||||
void GBASDLDeinitEvents(struct GBASDLEvents*);
|
||||
|
||||
void GBASDLInitBindings(struct GBAInputMap* inputMap);
|
||||
|
|
Loading…
Reference in New Issue