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#pragma once
7
8#include <QMutex>
9#include <QList>
10#include <QObject>
11
12#include <mgba/core/lockstep.h>
13#ifdef M_CORE_GBA
14#include <mgba/internal/gba/sio/lockstep.h>
15#endif
16#ifdef M_CORE_GB
17#include <mgba/internal/gb/sio/lockstep.h>
18#endif
19
20#include <memory>
21
22struct GBSIOLockstepNode;
23struct GBASIOLockstepNode;
24
25namespace QGBA {
26
27class CoreController;
28
29class MultiplayerController : public QObject {
30Q_OBJECT
31
32public:
33 MultiplayerController();
34 ~MultiplayerController();
35
36 bool attachGame(CoreController*);
37 void detachGame(CoreController*);
38
39 int attached();
40 int playerId(CoreController*);
41
42signals:
43 void gameAttached();
44 void gameDetached();
45
46private:
47 struct Player {
48 Player(CoreController* controller, GBSIOLockstepNode* node);
49 Player(CoreController* controller, GBASIOLockstepNode* node);
50
51 CoreController* controller;
52 GBSIOLockstepNode* gbNode = nullptr;
53 GBASIOLockstepNode* gbaNode = nullptr;
54 int awake = 1;
55 int32_t cyclesPosted = 0;
56 unsigned waitMask = 0;
57 };
58 union {
59 mLockstep m_lockstep;
60#ifdef M_CORE_GB
61 GBSIOLockstep m_gbLockstep;
62#endif
63#ifdef M_CORE_GBA
64 GBASIOLockstep m_gbaLockstep;
65#endif
66 };
67 QList<Player> m_players;
68 QMutex m_lock;
69};
70
71}