Qt: Ability to prevent opposing directional input
Jeffrey Pfau jeffrey@endrift.com
Mon, 23 Mar 2015 00:11:19 -0700
8 files changed,
83 insertions(+),
38 deletions(-)
M
CHANGES
→
CHANGES
@@ -31,6 +31,7 @@ - Controller profiles for setting different bindings for different controllers
- Ability to lock aspect ratio - Local link cable support - Ability to switch which game controller is in use per instance + - Ability to prevent opposing directional input Bugfixes: - ARM7: Extend prefetch by one stage - GBA Audio: Support 16-bit writes to FIFO audio
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -33,6 +33,7 @@ : QObject(parent)
, m_drawContext(new uint32_t[256 * 256]) , m_threadContext() , m_activeKeys(0) + , m_inactiveKeys(0) , m_logLevels(0) , m_gameOpen(false) , m_audioThread(new QThread(this))@@ -390,17 +391,38 @@
void GameController::keyPressed(int key) { int mappedKey = 1 << key; m_activeKeys |= mappedKey; + if (!m_inputController->allowOpposing()) { + if ((m_activeKeys & 0x30) == 0x30) { + m_inactiveKeys |= mappedKey ^ 0x30; + m_activeKeys ^= mappedKey ^ 0x30; + } + if ((m_activeKeys & 0xC0) == 0xC0) { + m_inactiveKeys |= mappedKey ^ 0xC0; + m_activeKeys ^= mappedKey ^ 0xC0; + } + } updateKeys(); } void GameController::keyReleased(int key) { int mappedKey = 1 << key; m_activeKeys &= ~mappedKey; + if (!m_inputController->allowOpposing()) { + if (mappedKey & 0x30) { + m_activeKeys |= m_inactiveKeys & (0x30 ^ mappedKey); + m_inactiveKeys &= ~0x30; + } + if (mappedKey & 0xC0) { + m_activeKeys |= m_inactiveKeys & (0xC0 ^ mappedKey); + m_inactiveKeys &= ~0xC0; + } + } updateKeys(); } void GameController::clearKeys() { m_activeKeys = 0; + m_inactiveKeys = 0; updateKeys(); }@@ -549,6 +571,7 @@ int activeKeys = m_activeKeys;
#ifdef BUILD_SDL activeKeys |= m_activeButtons; #endif + activeKeys &= ~m_inactiveKeys; m_threadContext.activeKeys = activeKeys; }
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -152,6 +152,7 @@ GBAThread m_threadContext;
GBAVideoSoftwareRenderer* m_renderer; GBACheatDevice m_cheatDevice; int m_activeKeys; + int m_inactiveKeys; int m_logLevels; bool m_gameOpen;
M
src/platform/qt/InputController.cpp
→
src/platform/qt/InputController.cpp
@@ -28,6 +28,7 @@ , m_playerId(playerId)
, m_config(nullptr) , m_gamepadTimer(nullptr) , m_playerAttached(false) + , m_allowOpposing(false) { GBAInputMapInit(&m_inputMap);@@ -70,6 +71,7 @@ }
void InputController::setConfiguration(ConfigController* config) { m_config = config; + setAllowOpposing(config->getOption("allowOpposingDirections").toInt()); loadConfiguration(KEYBOARD); #ifdef BUILD_SDL GBASDLEventsLoadConfig(&s_sdlEvents, config->input());
M
src/platform/qt/InputController.h
→
src/platform/qt/InputController.h
@@ -41,6 +41,9 @@ void saveConfiguration(uint32_t type = KEYBOARD);
void saveProfile(uint32_t type, const QString& profile); const char* profileForType(uint32_t type); + bool allowOpposing() const { return m_allowOpposing; } + void setAllowOpposing(bool allowOpposing) { m_allowOpposing = allowOpposing; } + GBAKey mapKeyboard(int key) const; void bindKey(uint32_t type, int key, GBAKey);@@ -73,6 +76,7 @@
GBAInputMap m_inputMap; ConfigController* m_config; int m_playerId; + bool m_allowOpposing; #ifdef BUILD_SDL static int s_sdlInited;
M
src/platform/qt/SettingsView.cpp
→
src/platform/qt/SettingsView.cpp
@@ -31,6 +31,7 @@ loadSetting("rewindEnable", m_ui.rewind);
loadSetting("rewindBufferInterval", m_ui.rewindInterval); loadSetting("rewindBufferCapacity", m_ui.rewindCapacity); loadSetting("resampleVideo", m_ui.resampleVideo); + loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections); QString idleOptimization = loadSetting("idleOptimization"); if (idleOptimization == "ignore") {@@ -81,6 +82,7 @@ saveSetting("rewindEnable", m_ui.rewind);
saveSetting("rewindBufferInterval", m_ui.rewindInterval); saveSetting("rewindBufferCapacity", m_ui.rewindCapacity); saveSetting("resampleVideo", m_ui.resampleVideo); + saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections); switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) { case IDLE_LOOP_IGNORE:@@ -130,7 +132,7 @@ }
void SettingsView::loadSetting(const char* key, QAbstractButton* field) { QString option = loadSetting(key); - field->setChecked(option != "0"); + field->setChecked(!option.isNull() && option != "0"); } void SettingsView::loadSetting(const char* key, QComboBox* field) {
M
src/platform/qt/SettingsView.ui
→
src/platform/qt/SettingsView.ui
@@ -6,8 +6,8 @@ <property name="geometry">
<rect> <x>0</x> <y>0</y> - <width>355</width> - <height>501</height> + <width>360</width> + <height>569</height> </rect> </property> <property name="sizePolicy">@@ -198,6 +198,34 @@ </widget>
</item> </layout> </item> + <item row="8" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>FPS target:</string> + </property> + </widget> + </item> + <item row="8" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QSpinBox" name="fpsTarget"> + <property name="maximum"> + <number>240</number> + </property> + <property name="value"> + <number>60</number> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_11"> + <property name="text"> + <string>frames per second</string> + </property> + </widget> + </item> + </layout> + </item> <item row="9" column="0" colspan="2"> <widget class="Line" name="line"> <property name="orientation">@@ -282,35 +310,21 @@ </widget>
</item> </layout> </item> - <item row="8" column="0"> - <widget class="QLabel" name="label_3"> + <item row="17" column="0" colspan="2"> + <widget class="Line" name="line_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="18" column="0"> + <widget class="QLabel" name="label_15"> <property name="text"> - <string>FPS target:</string> + <string>Idle loops</string> </property> </widget> </item> - <item row="8" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QSpinBox" name="fpsTarget"> - <property name="maximum"> - <number>240</number> - </property> - <property name="value"> - <number>60</number> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_11"> - <property name="text"> - <string>frames per second</string> - </property> - </widget> - </item> - </layout> - </item> - <item row="17" column="1"> + <item row="18" column="1"> <widget class="QComboBox" name="idleOptimization"> <item> <property name="text">@@ -329,17 +343,10 @@ </property>
</item> </widget> </item> - <item row="16" column="0" colspan="2"> - <widget class="Line" name="line_4"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> - </item> - <item row="17" column="0"> - <widget class="QLabel" name="label_15"> + <item row="16" column="1"> + <widget class="QCheckBox" name="allowOpposingDirections"> <property name="text"> - <string>Idle loops</string> + <string>Allow opposing input directions</string> </property> </widget> </item>
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -789,6 +789,11 @@ rewindBufferInterval->connect([this](const QVariant& value) {
m_controller->setRewind(m_config->getOption("rewindEnable").toInt(), m_config->getOption("rewindBufferCapacity").toInt(), value.toInt()); }, this); + ConfigOption* allowOpposingDirections = m_config->addOption("allowOpposingDirections"); + allowOpposingDirections->connect([this](const QVariant& value) { + m_inputController.setAllowOpposing(value.toBool()); + }, this); + QMenu* other = new QMenu(tr("Other"), this); m_shortcutController->addMenu(other); m_shortcutController->addFunctions(other, [this]() {