all repos — mgba @ 38a4e9988f8c6c210b2fd70790ff1f0f7006515b

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-sensors.h"
 17#include "gba-thread.h"
 18#ifdef BUILD_SDL
 19#include "sdl-events.h"
 20#endif
 21}
 22
 23struct GBAAudio;
 24struct GBAVideoSoftwareRenderer;
 25
 26class QThread;
 27
 28namespace QGBA {
 29
 30class AudioProcessor;
 31class InputController;
 32
 33class GameController : public QObject {
 34Q_OBJECT
 35
 36public:
 37	static const bool VIDEO_SYNC = false;
 38	static const bool AUDIO_SYNC = true;
 39
 40	GameController(QObject* parent = nullptr);
 41	~GameController();
 42
 43	const uint32_t* drawContext() const { return m_drawContext; }
 44	GBAThread* thread() { return &m_threadContext; }
 45
 46	void threadInterrupt();
 47	void threadContinue();
 48
 49	bool isPaused();
 50	bool isLoaded() { return m_gameOpen; }
 51
 52	bool audioSync() const { return m_audioSync; }
 53	bool videoSync() const { return m_videoSync; }
 54
 55	void setInputController(InputController* controller) { m_inputController = controller; }
 56
 57#ifdef USE_GDB_STUB
 58	ARMDebugger* debugger();
 59	void setDebugger(ARMDebugger*);
 60#endif
 61
 62signals:
 63	void frameAvailable(const uint32_t*);
 64	void gameStarted(GBAThread*);
 65	void gameStopped(GBAThread*);
 66	void gamePaused(GBAThread*);
 67	void gameUnpaused(GBAThread*);
 68	void gameCrashed(const QString& errorMessage);
 69	void stateLoaded(GBAThread*);
 70
 71	void postLog(int level, const QString& log);
 72
 73public slots:
 74	void loadGame(const QString& path, bool dirmode = false);
 75	void loadBIOS(const QString& path);
 76	void setSkipBIOS(bool);
 77	void loadPatch(const QString& path);
 78	void openGame();
 79	void closeGame();
 80	void setPaused(bool paused);
 81	void reset();
 82	void frameAdvance();
 83	void keyPressed(int key);
 84	void keyReleased(int key);
 85	void setAudioBufferSamples(int samples);
 86	void setFPSTarget(float fps);
 87	void loadState(int slot);
 88	void saveState(int slot);
 89	void setVideoSync(bool);
 90	void setAudioSync(bool);
 91	void setFrameskip(int);
 92	void setTurbo(bool, bool forced = true);
 93	void setAVStream(GBAAVStream*);
 94	void clearAVStream();
 95	void setLuminanceValue(uint8_t value) { m_luxValue = value; }
 96
 97	void setLogLevel(int);
 98	void enableLogLevel(int);
 99	void disableLogLevel(int);
100
101private slots:
102	void crashGame(const QString& crashMessage);
103
104#ifdef BUILD_SDL
105	void testSDLEvents();
106
107private:
108	GBASDLEvents m_sdlEvents;
109	int m_activeButtons;
110#endif
111
112private:
113	void updateKeys();
114	void redoSamples(int samples);
115
116	uint32_t* m_drawContext;
117	GBAThread m_threadContext;
118	GBAVideoSoftwareRenderer* m_renderer;
119	int m_activeKeys;
120	int m_logLevels;
121
122	bool m_gameOpen;
123	bool m_dirmode;
124
125	QString m_fname;
126	QString m_bios;
127	QString m_patch;
128
129	QThread* m_audioThread;
130	AudioProcessor* m_audioProcessor;
131
132	QMutex m_pauseMutex;
133	bool m_pauseAfterFrame;
134
135	bool m_videoSync;
136	bool m_audioSync;
137	bool m_turbo;
138	bool m_turboForced;
139
140	InputController* m_inputController;
141
142	struct GameControllerLux : GBALuminanceSource {
143		GameController* p;
144		uint8_t value;
145	} m_lux;
146	uint8_t m_luxValue;
147};
148
149}
150
151#endif