src/platform/qt/GameController.h (view raw)
1/* Copyright (c) 2013-2014 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_GAME_CONTROLLER
7#define QGBA_GAME_CONTROLLER
8
9#include <QFile>
10#include <QImage>
11#include <QObject>
12#include <QMutex>
13#include <QString>
14
15extern "C" {
16#include "gba-sensors.h"
17#include "gba-thread.h"
18#ifdef BUILD_SDL
19#include "sdl-events.h"
20#endif
21}
22
23struct GBAAudio;
24struct GBAVideoSoftwareRenderer;
25
26class QThread;
27
28namespace QGBA {
29
30class AudioProcessor;
31class InputController;
32
33class GameController : public QObject {
34Q_OBJECT
35
36public:
37 static const bool VIDEO_SYNC = false;
38 static const bool AUDIO_SYNC = true;
39
40 GameController(QObject* parent = nullptr);
41 ~GameController();
42
43 const uint32_t* drawContext() const { return m_drawContext; }
44 GBAThread* thread() { return &m_threadContext; }
45
46 void threadInterrupt();
47 void threadContinue();
48
49 bool isPaused();
50 bool isLoaded() { return m_gameOpen; }
51
52 bool audioSync() const { return m_audioSync; }
53 bool videoSync() const { return m_videoSync; }
54
55 void setInputController(InputController* controller) { m_inputController = controller; }
56
57#ifdef USE_GDB_STUB
58 ARMDebugger* debugger();
59 void setDebugger(ARMDebugger*);
60#endif
61
62signals:
63 void frameAvailable(const uint32_t*);
64 void gameStarted(GBAThread*);
65 void gameStopped(GBAThread*);
66 void gamePaused(GBAThread*);
67 void gameUnpaused(GBAThread*);
68 void gameCrashed(const QString& errorMessage);
69 void stateLoaded(GBAThread*);
70
71 void postLog(int level, const QString& log);
72
73public slots:
74 void loadGame(const QString& path, bool dirmode = false);
75 void loadBIOS(const QString& path);
76 void setSkipBIOS(bool);
77 void loadPatch(const QString& path);
78 void openGame();
79 void closeGame();
80 void setPaused(bool paused);
81 void reset();
82 void frameAdvance();
83 void setRewind(bool enable, int capacity, int interval);
84 void rewind(int states = 0);
85 void keyPressed(int key);
86 void keyReleased(int key);
87 void clearKeys();
88 void setAudioBufferSamples(int samples);
89 void setFPSTarget(float fps);
90 void loadState(int slot);
91 void saveState(int slot);
92 void setVideoSync(bool);
93 void setAudioSync(bool);
94 void setFrameskip(int);
95 void setTurbo(bool, bool forced = true);
96 void setAVStream(GBAAVStream*);
97 void clearAVStream();
98 void setLuminanceValue(uint8_t value) { m_luxValue = value; }
99
100 void setRealTime();
101 void setFixedTime(const QDateTime& time);
102 void setFakeEpoch(const QDateTime& time);
103
104 void setLogLevel(int);
105 void enableLogLevel(int);
106 void disableLogLevel(int);
107
108private slots:
109 void crashGame(const QString& crashMessage);
110
111#ifdef BUILD_SDL
112 void testSDLEvents();
113
114private:
115 GBASDLEvents m_sdlEvents;
116 int m_activeButtons;
117#endif
118
119private:
120 void updateKeys();
121 void redoSamples(int samples);
122
123 uint32_t* m_drawContext;
124 GBAThread m_threadContext;
125 GBAVideoSoftwareRenderer* m_renderer;
126 int m_activeKeys;
127 int m_logLevels;
128
129 bool m_gameOpen;
130 bool m_dirmode;
131
132 QString m_fname;
133 QString m_bios;
134 QString m_patch;
135
136 QThread* m_audioThread;
137 AudioProcessor* m_audioProcessor;
138
139 QMutex m_pauseMutex;
140 bool m_pauseAfterFrame;
141
142 bool m_videoSync;
143 bool m_audioSync;
144 bool m_turbo;
145 bool m_turboForced;
146
147 InputController* m_inputController;
148
149 struct GameControllerLux : GBALuminanceSource {
150 GameController* p;
151 uint8_t value;
152 } m_lux;
153 uint8_t m_luxValue;
154
155 struct GameControllerRTC : GBARTCSource {
156 GameController* p;
157 enum {
158 NO_OVERRIDE,
159 FIXED,
160 FAKE_EPOCH
161 } override;
162 int64_t value;
163 } m_rtc;
164};
165
166}
167
168#endif