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-thread.h"
17#ifdef BUILD_SDL
18#include "sdl-events.h"
19#endif
20}
21
22struct GBAAudio;
23struct GBAVideoSoftwareRenderer;
24
25class QThread;
26
27namespace QGBA {
28
29class AudioProcessor;
30class InputController;
31
32class GameController : public QObject {
33Q_OBJECT
34
35public:
36 static const bool VIDEO_SYNC = false;
37 static const bool AUDIO_SYNC = true;
38
39 GameController(QObject* parent = nullptr);
40 ~GameController();
41
42 const uint32_t* drawContext() const { return m_drawContext; }
43 GBAThread* thread() { return &m_threadContext; }
44
45 void threadInterrupt();
46 void threadContinue();
47
48 bool isPaused();
49 bool isLoaded() { return m_gameOpen; }
50
51 bool audioSync() const { return m_audioSync; }
52 bool videoSync() const { return m_videoSync; }
53
54 void setInputController(InputController* controller) { m_inputController = controller; }
55
56#ifdef USE_GDB_STUB
57 ARMDebugger* debugger();
58 void setDebugger(ARMDebugger*);
59#endif
60
61signals:
62 void frameAvailable(const uint32_t*);
63 void gameStarted(GBAThread*);
64 void gameStopped(GBAThread*);
65 void gamePaused(GBAThread*);
66 void gameUnpaused(GBAThread*);
67 void gameCrashed(const QString& errorMessage);
68 void stateLoaded(GBAThread*);
69
70 void postLog(int level, const QString& log);
71
72public slots:
73 void loadGame(const QString& path, bool dirmode = false);
74 void loadBIOS(const QString& path);
75 void setSkipBIOS(bool);
76 void loadPatch(const QString& path);
77 void openGame();
78 void closeGame();
79 void setPaused(bool paused);
80 void reset();
81 void frameAdvance();
82 void keyPressed(int key);
83 void keyReleased(int key);
84 void setAudioBufferSamples(int samples);
85 void setFPSTarget(float fps);
86 void loadState(int slot);
87 void saveState(int slot);
88 void setVideoSync(bool);
89 void setAudioSync(bool);
90 void setFrameskip(int);
91 void setTurbo(bool, bool forced = true);
92 void setAVStream(GBAAVStream*);
93 void clearAVStream();
94
95 void setLogLevel(int);
96 void enableLogLevel(int);
97 void disableLogLevel(int);
98
99private slots:
100 void crashGame(const QString& crashMessage);
101
102#ifdef BUILD_SDL
103 void testSDLEvents();
104
105private:
106 GBASDLEvents m_sdlEvents;
107 int m_activeButtons;
108#endif
109
110private:
111 void updateKeys();
112
113 uint32_t* m_drawContext;
114 GBAThread m_threadContext;
115 GBAVideoSoftwareRenderer* m_renderer;
116 int m_activeKeys;
117 int m_logLevels;
118
119 bool m_gameOpen;
120 bool m_dirmode;
121
122 QString m_fname;
123 QString m_bios;
124 QString m_patch;
125
126 QThread* m_audioThread;
127 AudioProcessor* m_audioProcessor;
128
129 QMutex m_pauseMutex;
130 bool m_pauseAfterFrame;
131
132 bool m_videoSync;
133 bool m_audioSync;
134 bool m_turbo;
135 bool m_turboForced;
136
137 InputController* m_inputController;
138};
139
140}
141
142#endif