all repos — mgba @ b33e75daec0727bfa9a7b97aab7b50723d53eaa4

mGBA Game Boy Advance Emulator

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