Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions source/ButtonComboInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,40 @@ bool ButtonComboInfoIF::conflictsWith(const ButtonComboModule_ButtonComboOptions

bool ButtonComboInfoIF::conflictsWith(const ButtonComboInfoIF &other) const {
return conflictsWith({other.mControllerMask, other.mCombo});
}

int32_t ButtonComboInfoIF::ControllerTypeToChanIndex(const ButtonComboModule_ControllerTypes type) {
switch (type) {
case BUTTON_COMBO_MODULE_CONTROLLER_VPAD_0: {
return 0;
}
case BUTTON_COMBO_MODULE_CONTROLLER_VPAD_1: {
return 1;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_0: {
return 2;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_1: {
return 3;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_2: {
return 4;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_3: {
return 5;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_4: {
return 6;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_5: {
return 7;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_6: {
return 8;
}
default:
break;
}

return -1;
}
2 changes: 2 additions & 0 deletions source/ButtonComboInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class ButtonComboInfoIF {
[[nodiscard]] virtual ButtonComboModule_ButtonComboInfoEx getComboInfoEx() const = 0;

protected:
static int32_t ControllerTypeToChanIndex(ButtonComboModule_ControllerTypes type);

ButtonComboModule_ComboStatus mStatus = BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS;
std::string mLabel;
ButtonComboModule_ControllerTypes mControllerMask = {};
Expand Down
15 changes: 11 additions & 4 deletions source/ButtonComboInfoDown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ void ButtonComboInfoDown::UpdateInput(
if ((mControllerMask & controller) == 0) {
return;
}
const auto chanIndex = ControllerTypeToChanIndex(controller);
if (chanIndex < 0 || static_cast<uint32_t>(chanIndex) >= std::size(mHoldInformation)) {
DEBUG_FUNCTION_LINE_WARN("ChanIndex is out of bounds %d", chanIndex);
return;
}

auto &[prevButtonCombo] = mHoldInformation[chanIndex];

DEBUG_FUNCTION_LINE_VERBOSE("[PRESS DOWN] Check button combo %08X on controller %08X (lastItem im pressedButtons (size %d) is %08X) for %s [%08X]", mCombo, controller, pressedButtons.size(), pressedButtons.back(), mLabel.c_str(), getHandle().handle);

for (const auto &pressedButton : pressedButtons) {
const bool prevButtonsIncludedCombo = (mPrevButtonPress & mCombo) == mCombo; // Make sure the combo can't be triggered on releasing
const bool buttonsPressedChanged = mPrevButtonPress != pressedButton; // Avoid "holding" the combo
const bool buttonsPressedMatchCombo = pressedButton == mCombo; // detect the actual combo
const bool prevButtonsIncludedCombo = (prevButtonCombo & mCombo) == mCombo; // Make sure the combo can't be triggered on releasing
const bool buttonsPressedChanged = prevButtonCombo != pressedButton; // Avoid "holding" the combo
const bool buttonsPressedMatchCombo = pressedButton == mCombo; // detect the actual combo

if (buttonsPressedChanged && buttonsPressedMatchCombo && !prevButtonsIncludedCombo) {
if (mCallback != nullptr) {
Expand All @@ -38,7 +45,7 @@ void ButtonComboInfoDown::UpdateInput(
DEBUG_FUNCTION_LINE_WARN("Callback was null for combo %08X", getHandle());
}
}
mPrevButtonPress = pressedButton;
prevButtonCombo = pressedButton;
}
}

Expand Down
6 changes: 5 additions & 1 deletion source/ButtonComboInfoDown.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ class ButtonComboInfoDown final : public ButtonComboInfoIF {
~ButtonComboInfoDown() override;

private:
typedef struct {
uint32_t prevButtonCombo;
} HoldInformation;

void UpdateInput(ButtonComboModule_ControllerTypes controller, std::span<uint32_t> pressedButtons) override;

ButtonComboModule_Error setHoldDuration(uint32_t uint32) override;

[[nodiscard]] ButtonComboModule_ButtonComboInfoEx getComboInfoEx() const override;

uint32_t mPrevButtonPress = {};
HoldInformation mHoldInformation[9] = {}; // one for each controller
};
40 changes: 1 addition & 39 deletions source/ButtonComboInfoHold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,6 @@

#include <logger.h>

namespace {
int32_t controllerTypeToChanIndex(const ButtonComboModule_ControllerTypes type) {
switch (type) {
case BUTTON_COMBO_MODULE_CONTROLLER_VPAD_0: {
return 0;
}
case BUTTON_COMBO_MODULE_CONTROLLER_VPAD_1: {
return 1;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_0: {
return 2;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_1: {
return 3;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_2: {
return 4;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_3: {
return 5;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_4: {
return 6;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_5: {
return 7;
}
case BUTTON_COMBO_MODULE_CONTROLLER_WPAD_6: {
return 8;
}
default:
break;
}

return -1;
}
} // namespace

ButtonComboInfoHold::ButtonComboInfoHold(std::string label,
const ButtonComboModule_ControllerTypes controllerMask,
const ButtonComboModule_Buttons combo,
Expand All @@ -64,7 +26,7 @@ void ButtonComboInfoHold::UpdateInput(const ButtonComboModule_ControllerTypes co
if ((mControllerMask & controller) == 0) {
return;
}
const auto chanIndex = controllerTypeToChanIndex(controller);
const auto chanIndex = ControllerTypeToChanIndex(controller);
if (chanIndex < 0 || static_cast<uint32_t>(chanIndex) >= std::size(mHoldInformation)) {
DEBUG_FUNCTION_LINE_WARN("ChanIndex is out of bounds %d", chanIndex);
return;
Expand Down