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;
25
26class GameController : public QObject {
27Q_OBJECT
28
29public:
30 static const bool VIDEO_SYNC = false;
31 static const bool AUDIO_SYNC = true;
32
33 GameController(QObject* parent = nullptr);
34 ~GameController();
35
36 const uint32_t* drawContext() const { return m_drawContext; }
37 GBAThread* thread() { return &m_threadContext; }
38
39 bool isPaused();
40 bool isLoaded() { return m_gameOpen; }
41
42#ifdef USE_GDB_STUB
43 ARMDebugger* debugger();
44 void setDebugger(ARMDebugger*);
45#endif
46
47signals:
48 void frameAvailable(const uint32_t*);
49 void gameStarted(GBAThread*);
50 void gameStopped(GBAThread*);
51 void gamePaused(GBAThread*);
52 void gameUnpaused(GBAThread*);
53 void stateLoaded(GBAThread*);
54
55 void postLog(int level, const QString& log);
56
57public slots:
58 void loadGame(const QString& path, bool dirmode = false);
59 void loadBIOS(const QString& path);
60 void closeGame();
61 void setPaused(bool paused);
62 void reset();
63 void frameAdvance();
64 void keyPressed(int key);
65 void keyReleased(int key);
66 void setAudioBufferSamples(int samples);
67 void setFPSTarget(float fps);
68 void loadState(int slot);
69 void saveState(int slot);
70 void setVideoSync(bool);
71 void setAudioSync(bool);
72 void setTurbo(bool, bool forced = true);
73
74#ifdef BUILD_SDL
75private slots:
76 void testSDLEvents();
77
78private:
79 GBASDLEvents m_sdlEvents;
80 int m_activeButtons;
81#endif
82
83private:
84 void updateKeys();
85
86 uint32_t* m_drawContext;
87 GBAThread m_threadContext;
88 GBAVideoSoftwareRenderer* m_renderer;
89 int m_activeKeys;
90
91 bool m_gameOpen;
92 QString m_bios;
93
94 QThread* m_audioThread;
95 AudioProcessor* m_audioProcessor;
96
97 QMutex m_pauseMutex;
98 bool m_pauseAfterFrame;
99
100 bool m_videoSync;
101 bool m_audioSync;
102 bool m_turbo;
103 bool m_turboForced;
104};
105
106}
107
108#endif