all repos — mgba @ a10a84aa89568caf0897c229b96eb41076f53059

mGBA Game Boy Advance Emulator

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