From e4a14330e05a42717fe946eca0244e02fe4bd369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 28 Aug 2025 10:23:52 +0200 Subject: [PATCH] Correct comment, rename array --- UI/CustomButtonMappingScreen.cpp | 14 +++++++------- UI/CustomButtonMappingScreen.h | 2 +- UI/GamepadEmu.cpp | 16 ++++++++-------- UI/GamepadEmu.h | 9 +++++---- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/UI/CustomButtonMappingScreen.cpp b/UI/CustomButtonMappingScreen.cpp index 1efd0098ba..5fb308b180 100644 --- a/UI/CustomButtonMappingScreen.cpp +++ b/UI/CustomButtonMappingScreen.cpp @@ -133,7 +133,7 @@ void CustomButtonMappingScreen::CreateViews() { memset(array, 0, sizeof(array)); cfg = &g_Config.CustomButton[id_]; show = &g_Config.touchCustom[id_].show; - for (int i = 0; i < ARRAY_SIZE(customKeyList); i++) + for (int i = 0; i < ARRAY_SIZE(g_customKeyList); i++) array[i] = (0x01 == ((g_Config.CustomButton[id_].key >> i) & 0x01)); leftColumn->Add(new ButtonPreview(g_Config.iTouchButtonStyle == 0 ? customKeyShapes[cfg->shape].i : customKeyShapes[cfg->shape].l, @@ -183,7 +183,7 @@ void CustomButtonMappingScreen::CreateViews() { GridLayout *grid = vertLayout->Add(new GridLayout(gridsettings, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); // Button image and action are defined in GamepadEmu.h - for (int i = 0; i < ARRAY_SIZE(customKeyList); ++i) { + for (int i = 0; i < ARRAY_SIZE(g_customKeyList); ++i) { LinearLayout *row = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); row->SetSpacing(0); @@ -191,10 +191,10 @@ void CustomButtonMappingScreen::CreateViews() { row->Add(checkbox); Choice *choice; - if (customKeyList[i].i.isValid()) { - choice = new Choice(customKeyList[i].i, new LinearLayoutParams(1.0f)); + if (g_customKeyList[i].i.isValid()) { + choice = new Choice(g_customKeyList[i].i, new LinearLayoutParams(1.0f)); } else { - choice = new Choice(mc->T(KeyMap::GetPspButtonNameCharPointer(customKeyList[i].c)), new LinearLayoutParams(1.0f)); + choice = new Choice(mc->T(KeyMap::GetPspButtonNameCharPointer(g_customKeyList[i].c)), new LinearLayoutParams(1.0f)); } ChoiceEventHandler *choiceEventHandler = new ChoiceEventHandler(checkbox); @@ -207,9 +207,9 @@ void CustomButtonMappingScreen::CreateViews() { } } -static uint64_t arrayToInt(const bool ary[ARRAY_SIZE(CustomKeyData::customKeyList)]) { +static uint64_t arrayToInt(const bool ary[ARRAY_SIZE(CustomKeyData::g_customKeyList)]) { uint64_t value = 0; - for (int i = ARRAY_SIZE(CustomKeyData::customKeyList)-1; i >= 0; i--) { + for (int i = ARRAY_SIZE(CustomKeyData::g_customKeyList)-1; i >= 0; i--) { value |= ary[i] ? 1 : 0; if (i > 0) { value = value << 1; diff --git a/UI/CustomButtonMappingScreen.h b/UI/CustomButtonMappingScreen.h index 66fbf869ea..baf960a783 100644 --- a/UI/CustomButtonMappingScreen.h +++ b/UI/CustomButtonMappingScreen.h @@ -39,7 +39,7 @@ protected: private: void saveArray(); - bool array[ARRAY_SIZE(CustomKeyData::customKeyList)]{}; + bool array[ARRAY_SIZE(CustomKeyData::g_customKeyList)]{}; int id_; UI::ScrollView *rightScroll_ = nullptr; diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index 81d85c2c26..1df7540c6e 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -228,18 +228,18 @@ bool CustomButton::Touch(const TouchInput &input) { System_Vibrate(HAPTIC_VIRTUAL_KEY); if (!repeat_) { - for (int i = 0; i < ARRAY_SIZE(customKeyList); i++) { + for (int i = 0; i < ARRAY_SIZE(g_customKeyList); i++) { if (pspButtonBit_ & (1ULL << i)) { - controlMapper_->PSPKey(DEVICE_ID_TOUCH, customKeyList[i].c, (on_ && toggle_) ? KEY_UP : KEY_DOWN); + controlMapper_->PSPKey(DEVICE_ID_TOUCH, g_customKeyList[i].c, (on_ && toggle_) ? KEY_UP : KEY_DOWN); } } } on_ = toggle_ ? !on_ : true; } else if (!toggle_ && lastDown && !down) { if (!repeat_) { - for (int i = 0; i < ARRAY_SIZE(customKeyList); i++) { + for (int i = 0; i < ARRAY_SIZE(g_customKeyList); i++) { if (pspButtonBit_ & (1ULL << i)) { - controlMapper_->PSPKey(DEVICE_ID_TOUCH, customKeyList[i].c, KEY_UP); + controlMapper_->PSPKey(DEVICE_ID_TOUCH, g_customKeyList[i].c, KEY_UP); } } } @@ -259,15 +259,15 @@ void CustomButton::Update() { if (pressedFrames_ == 2*DOWN_FRAME) { pressedFrames_ = 0; } else if (pressedFrames_ == DOWN_FRAME) { - for (int i = 0; i < ARRAY_SIZE(customKeyList); i++) { + for (int i = 0; i < ARRAY_SIZE(g_customKeyList); i++) { if (pspButtonBit_ & (1ULL << i)) { - controlMapper_->PSPKey(DEVICE_ID_TOUCH, customKeyList[i].c, KEY_UP); + controlMapper_->PSPKey(DEVICE_ID_TOUCH, g_customKeyList[i].c, KEY_UP); } } } else if (on_ && pressedFrames_ == 0) { - for (int i = 0; i < ARRAY_SIZE(customKeyList); i++) { + for (int i = 0; i < ARRAY_SIZE(g_customKeyList); i++) { if (pspButtonBit_ & (1ULL << i)) { - controlMapper_->PSPKey(DEVICE_ID_TOUCH, customKeyList[i].c, KEY_DOWN); + controlMapper_->PSPKey(DEVICE_ID_TOUCH, g_customKeyList[i].c, KEY_DOWN); } } pressedFrames_ = 1; diff --git a/UI/GamepadEmu.h b/UI/GamepadEmu.h index 74c075e823..eae73e47f4 100644 --- a/UI/GamepadEmu.h +++ b/UI/GamepadEmu.h @@ -283,8 +283,8 @@ namespace CustomKeyData { ImageID i; // UI ImageID uint32_t c; // Key code }; - // NOTE: This list can be freely reordered, we store the keycode, not the index. - static const keyList customKeyList[] = { + // NOTE: This list can NOT be freely reordered! We store a bitmask of the indices. + static const keyList g_customKeyList[] = { { ImageID("I_SQUARE"), CTRL_SQUARE }, { ImageID("I_TRIANGLE"), CTRL_TRIANGLE }, { ImageID("I_CIRCLE"), CTRL_CIRCLE }, @@ -317,7 +317,6 @@ namespace CustomKeyData { { ImageID::invalid(), VIRTKEY_ANALOG_ROTATE_CW }, { ImageID::invalid(), VIRTKEY_ANALOG_ROTATE_CCW }, { ImageID::invalid(), VIRTKEY_PAUSE }, - { ImageID::invalid(), VIRTKEY_PAUSE_NO_MENU }, { ImageID::invalid(), VIRTKEY_RESET_EMULATION }, { ImageID::invalid(), VIRTKEY_DEVMENU }, #ifndef MOBILE_DEVICE @@ -330,8 +329,10 @@ namespace CustomKeyData { { ImageID::invalid(), VIRTKEY_PREVIOUS_SLOT }, { ImageID::invalid(), VIRTKEY_TOGGLE_TOUCH_CONTROLS }, { ImageID::invalid(), VIRTKEY_TOGGLE_DEBUGGER }, + { ImageID::invalid(), VIRTKEY_PAUSE_NO_MENU }, + // IMPORTANT: Only add at the end! }; - static_assert(ARRAY_SIZE(customKeyList) <= 64, "Too many key for a uint64_t bit mask"); + static_assert(ARRAY_SIZE(g_customKeyList) <= 64, "Too many key for a uint64_t bit mask"); }; // Gesture key only have virtual button that can work without constant press