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 setFrameskip(int);
75 void setTurbo(bool, bool forced = true);
76 void setAVStream(GBAAVStream*);
77 void clearAVStream();
78
79#ifdef BUILD_SDL
80private slots:
81 void testSDLEvents();
82
83private:
84 GBASDLEvents m_sdlEvents;
85 int m_activeButtons;
86#endif
87
88private:
89 void updateKeys();
90
91 uint32_t* m_drawContext;
92 GBAThread m_threadContext;
93 GBAVideoSoftwareRenderer* m_renderer;
94 int m_activeKeys;
95
96 bool m_gameOpen;
97 bool m_dirmode;
98
99 QString m_fname;
100 QString m_bios;
101 QString m_patch;
102
103 QThread* m_audioThread;
104 AudioProcessor* m_audioProcessor;
105
106 QMutex m_pauseMutex;
107 bool m_pauseAfterFrame;
108
109 bool m_videoSync;
110 bool m_audioSync;
111 bool m_turbo;
112 bool m_turboForced;
113};
114
115}
116
117#endif