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 loadPatch(const QString& path);
76 void openGame();
77 void closeGame();
78 void setPaused(bool paused);
79 void reset();
80 void frameAdvance();
81 void keyPressed(int key);
82 void keyReleased(int key);
83 void setAudioBufferSamples(int samples);
84 void setFPSTarget(float fps);
85 void loadState(int slot);
86 void saveState(int slot);
87 void setVideoSync(bool);
88 void setAudioSync(bool);
89 void setFrameskip(int);
90 void setTurbo(bool, bool forced = true);
91 void setAVStream(GBAAVStream*);
92 void clearAVStream();
93
94 void setLogLevel(int);
95 void enableLogLevel(int);
96 void disableLogLevel(int);
97
98private slots:
99 void crashGame(const QString& crashMessage);
100
101#ifdef BUILD_SDL
102 void testSDLEvents();
103
104private:
105 GBASDLEvents m_sdlEvents;
106 int m_activeButtons;
107#endif
108
109private:
110 void updateKeys();
111
112 uint32_t* m_drawContext;
113 GBAThread m_threadContext;
114 GBAVideoSoftwareRenderer* m_renderer;
115 int m_activeKeys;
116 int m_logLevels;
117
118 bool m_gameOpen;
119 bool m_dirmode;
120
121 QString m_fname;
122 QString m_bios;
123 QString m_patch;
124
125 QThread* m_audioThread;
126 AudioProcessor* m_audioProcessor;
127
128 QMutex m_pauseMutex;
129 bool m_pauseAfterFrame;
130
131 bool m_videoSync;
132 bool m_audioSync;
133 bool m_turbo;
134 bool m_turboForced;
135
136 InputController* m_inputController;
137};
138
139}
140
141#endif