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