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 loadPatch(const QString& path);
61 void openGame();
62 void closeGame();
63 void setPaused(bool paused);
64 void reset();
65 void frameAdvance();
66 void keyPressed(int key);
67 void keyReleased(int key);
68 void setAudioBufferSamples(int samples);
69 void setFPSTarget(float fps);
70 void loadState(int slot);
71 void saveState(int slot);
72 void setVideoSync(bool);
73 void setAudioSync(bool);
74 void setTurbo(bool, bool forced = true);
75
76#ifdef BUILD_SDL
77private slots:
78 void testSDLEvents();
79
80private:
81 GBASDLEvents m_sdlEvents;
82 int m_activeButtons;
83#endif
84
85private:
86 void updateKeys();
87
88 uint32_t* m_drawContext;
89 GBAThread m_threadContext;
90 GBAVideoSoftwareRenderer* m_renderer;
91 int m_activeKeys;
92
93 bool m_gameOpen;
94 bool m_dirmode;
95
96 QString m_fname;
97 QString m_bios;
98 QString m_patch;
99
100 QThread* m_audioThread;
101 AudioProcessor* m_audioProcessor;
102
103 QMutex m_pauseMutex;
104 bool m_pauseAfterFrame;
105
106 bool m_videoSync;
107 bool m_audioSync;
108 bool m_turbo;
109 bool m_turboForced;
110};
111
112}
113
114#endif