all repos — mgba @ b2193d919150c9f5cc6eb8ede7361f20ec01328b

mGBA Game Boy Advance Emulator

Qt: Key autofire
Jeffrey Pfau jeffrey@endrift.com
Mon, 28 Dec 2015 14:54:05 -0500
commit

b2193d919150c9f5cc6eb8ede7361f20ec01328b

parent

50d4b31b58bd48db0c8b45fb91b77aa7cae6c456

M CHANGESCHANGES

@@ -9,6 +9,7 @@ - Support for GLSL shaders

- ROM information view - Support for VBA-style cheat codes - Savestates now store creation timestamps + - Key autofire Bugfixes: - Util: Fix PowerPC PNG read/write pixel order - VFS: Fix VFileReadline and remove _vfdReadline
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -50,6 +50,8 @@ , m_turboSpeed(-1)

, m_wasPaused(false) , m_audioChannels{ true, true, true, true, true, true } , m_videoLayers{ true, true, true, true, true } + , m_autofire{} + , m_autofireStatus{} , m_inputController(nullptr) , m_multiplayer(nullptr) , m_stateSlot(1)

@@ -204,6 +206,7 @@ connect(this, SIGNAL(gameStarted(GBAThread*)), m_audioProcessor, SLOT(start()));

connect(this, SIGNAL(gamePaused(GBAThread*)), m_audioProcessor, SLOT(pause())); connect(this, SIGNAL(gameUnpaused(GBAThread*)), m_audioProcessor, SLOT(start())); connect(this, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(pollEvents())); + connect(this, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(updateAutofire())); } GameController::~GameController() {

@@ -596,6 +599,14 @@ m_inactiveKeys = 0;

updateKeys(); } +void GameController::setAutofire(int key, bool enable) { + if (key >= GBA_KEY_MAX || key < 0) { + return; + } + m_autofire[key] = enable; + m_autofireStatus[key] = 0; +} + void GameController::setAudioBufferSamples(int samples) { if (m_audioProcessor) { threadInterrupt();

@@ -979,3 +990,18 @@

m_activeButtons = m_inputController->pollEvents(); updateKeys(); } + +void GameController::updateAutofire() { + // TODO: Move all key events onto the CPU thread...somehow + for (int k = 0; k < GBA_KEY_MAX; ++k) { + if (!m_autofire[k]) { + continue; + } + m_autofireStatus[k] ^= 1; + if (m_autofireStatus[k]) { + keyPressed(k); + } else { + keyReleased(k); + } + } +}
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -118,6 +118,7 @@ void stopRewinding();

void keyPressed(int key); void keyReleased(int key); void clearKeys(); + void setAutofire(int key, bool enable); void setAudioBufferSamples(int samples); void setAudioSampleRate(unsigned rate); void setAudioChannelEnabled(int channel, bool enable = true);

@@ -161,6 +162,7 @@ void openGame(bool bios = false);

void crashGame(const QString& crashMessage); void pollEvents(); + void updateAutofire(); private: void updateKeys();

@@ -201,6 +203,9 @@ bool m_wasPaused;

bool m_audioChannels[6]; bool m_videoLayers[5]; + + bool m_autofire[GBA_KEY_MAX]; + int m_autofireStatus[GBA_KEY_MAX]; int m_stateSlot; GBASerializedState* m_backupLoadState;
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -1270,6 +1270,69 @@ connect(exitFullScreen, SIGNAL(triggered()), this, SLOT(exitFullScreen()));

exitFullScreen->setShortcut(QKeySequence("Esc")); addHiddenAction(frameMenu, exitFullScreen, "exitFullScreen"); + QMenu* autofireMenu = new QMenu(tr("Autofire"), this); + m_shortcutController->addMenu(autofireMenu); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_A, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_A, false); + }, QKeySequence("W"), tr("Autofire A"), "autofireA"); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_B, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_B, false); + }, QKeySequence("Q"), tr("Autofire B"), "autofireB"); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_L, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_L, false); + }, QKeySequence(), tr("Autofire L"), "autofireL"); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_R, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_R, false); + }, QKeySequence(), tr("Autofire R"), "autofireR"); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_START, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_START, false); + }, QKeySequence(), tr("Autofire Start"), "autofireStart"); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_SELECT, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_SELECT, false); + }, QKeySequence(), tr("Autofire Select"), "autofireSelect"); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_UP, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_UP, false); + }, QKeySequence(), tr("Autofire Up"), "autofireUp"); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_RIGHT, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_RIGHT, false); + }, QKeySequence(), tr("Autofire Right"), "autofireRight"); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_DOWN, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_DOWN, false); + }, QKeySequence(), tr("Autofire Down"), "autofireDown"); + + m_shortcutController->addFunctions(autofireMenu, [this]() { + m_controller->setAutofire(GBA_KEY_LEFT, true); + }, [this]() { + m_controller->setAutofire(GBA_KEY_LEFT, false); + }, QKeySequence(), tr("Autofire Left"), "autofireLeft"); + foreach (QAction* action, m_gameActions) { action->setDisabled(true); }