src/platform/qt/MultiplayerController.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef QGBA_MULTIPLAYER_CONTROLLER
7#define QGBA_MULTIPLAYER_CONTROLLER
8
9#include <QMutex>
10#include <QList>
11#include <QObject>
12
13#include <mgba/core/lockstep.h>
14#ifdef M_CORE_GBA
15#include <mgba/internal/gba/sio/lockstep.h>
16#endif
17#ifdef M_CORE_GB
18#include <mgba/internal/gb/sio/lockstep.h>
19#endif
20
21struct GBSIOLockstepNode;
22struct GBASIOLockstepNode;
23
24namespace QGBA {
25
26class GameController;
27
28class MultiplayerController : public QObject {
29Q_OBJECT
30
31public:
32 MultiplayerController();
33
34 bool attachGame(GameController*);
35 void detachGame(GameController*);
36
37 int attached();
38 int playerId(GameController*);
39
40signals:
41 void gameAttached();
42 void gameDetached();
43
44private:
45 struct Player {
46 GameController* controller;
47 GBSIOLockstepNode* gbNode;
48 GBASIOLockstepNode* gbaNode;
49 int awake;
50 int32_t cyclesPosted;
51 unsigned waitMask;
52 };
53 union {
54 mLockstep m_lockstep;
55#ifdef M_CORE_GB
56 GBSIOLockstep m_gbLockstep;
57#endif
58#ifdef M_CORE_GBA
59 GBASIOLockstep m_gbaLockstep;
60#endif
61 };
62 QList<Player> m_players;
63 QMutex m_lock;
64};
65
66}
67#endif