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 gameFailed();
70 void stateLoaded(GBAThread*);
71
72 void postLog(int level, const QString& log);
73
74public slots:
75 void loadGame(const QString& path, bool dirmode = false);
76 void loadBIOS(const QString& path);
77 void setSkipBIOS(bool);
78 void loadPatch(const QString& path);
79 void openGame();
80 void closeGame();
81 void setPaused(bool paused);
82 void reset();
83 void frameAdvance();
84 void setRewind(bool enable, int capacity, int interval);
85 void rewind(int states = 0);
86 void keyPressed(int key);
87 void keyReleased(int key);
88 void clearKeys();
89 void setAudioBufferSamples(int samples);
90 void setFPSTarget(float fps);
91 void loadState(int slot);
92 void saveState(int slot);
93 void setVideoSync(bool);
94 void setAudioSync(bool);
95 void setFrameskip(int);
96 void setTurbo(bool, bool forced = true);
97 void setAVStream(GBAAVStream*);
98 void clearAVStream();
99 void setLuminanceValue(uint8_t value) { m_luxValue = value; }
100
101 void setRealTime();
102 void setFixedTime(const QDateTime& time);
103 void setFakeEpoch(const QDateTime& time);
104
105 void setLogLevel(int);
106 void enableLogLevel(int);
107 void disableLogLevel(int);
108
109private slots:
110 void crashGame(const QString& crashMessage);
111
112#ifdef BUILD_SDL
113 void testSDLEvents();
114
115private:
116 GBASDLEvents m_sdlEvents;
117 int m_activeButtons;
118#endif
119
120private:
121 void updateKeys();
122 void redoSamples(int samples);
123
124 uint32_t* m_drawContext;
125 GBAThread m_threadContext;
126 GBAVideoSoftwareRenderer* m_renderer;
127 int m_activeKeys;
128 int m_logLevels;
129
130 bool m_gameOpen;
131 bool m_dirmode;
132
133 QString m_fname;
134 QString m_bios;
135 QString m_patch;
136
137 QThread* m_audioThread;
138 AudioProcessor* m_audioProcessor;
139
140 QMutex m_pauseMutex;
141 bool m_pauseAfterFrame;
142
143 bool m_videoSync;
144 bool m_audioSync;
145 bool m_turbo;
146 bool m_turboForced;
147
148 InputController* m_inputController;
149
150 struct GameControllerLux : GBALuminanceSource {
151 GameController* p;
152 uint8_t value;
153 } m_lux;
154 uint8_t m_luxValue;
155
156 struct GameControllerRTC : GBARTCSource {
157 GameController* p;
158 enum {
159 NO_OVERRIDE,
160 FIXED,
161 FAKE_EPOCH
162 } override;
163 int64_t value;
164 } m_rtc;
165};
166
167}
168
169#endif