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