all repos — mgba @ c300da9be6e85928dc6068aaadc3f9275e476418

mGBA Game Boy Advance Emulator

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#ifdef M_CORE_GB
49		Player(CoreController* controller, GBSIOLockstepNode* node);
50#endif
51#ifdef M_CORE_GBA
52		Player(CoreController* controller, GBASIOLockstepNode* node);
53#endif
54
55		CoreController* controller;
56		GBSIOLockstepNode* gbNode = nullptr;
57		GBASIOLockstepNode* gbaNode = nullptr;
58		int awake = 1;
59		int32_t cyclesPosted = 0;
60		unsigned waitMask = 0;
61	};
62	union {
63		mLockstep m_lockstep;
64#ifdef M_CORE_GB
65		GBSIOLockstep m_gbLockstep;
66#endif
67#ifdef M_CORE_GBA
68		GBASIOLockstep m_gbaLockstep;
69#endif
70	};
71	QList<Player> m_players;
72	QMutex m_lock;
73};
74
75}