-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButtonComboInfoDown.cpp
More file actions
71 lines (60 loc) · 3.4 KB
/
Copy pathButtonComboInfoDown.cpp
File metadata and controls
71 lines (60 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "ButtonComboInfoDown.h"
#include "logger.h"
#include <ranges>
ButtonComboInfoDown::ButtonComboInfoDown(
std::string label,
const ButtonComboModule_ControllerTypes controllerMask,
const ButtonComboModule_Buttons combo,
const ButtonComboModule_ComboCallback callback,
void *context,
const bool observer) : ButtonComboInfoIF(std::move(label), controllerMask, combo, callback, context, observer) {
DEBUG_FUNCTION_LINE_INFO("Created ButtonComboInfoDown: \"%s\", combo: %08X, controllerMask: %08X. Observer %d", mLabel.c_str(), mCombo, mControllerMask, observer);
}
ButtonComboInfoDown::~ButtonComboInfoDown() {
DEBUG_FUNCTION_LINE_INFO("Deleted ButtonComboInfoDown: \"%s\", combo: %08X, controllerMask: %08X. Observer %d", mLabel.c_str(), mCombo, mControllerMask, mIsObserver);
}
int ButtonComboInfoDown::UpdateInput(
const ButtonComboModule_ControllerTypes controller,
const std::span<uint32_t> pressedButtons) {
if ((mControllerMask & controller) == 0) {
return -1;
}
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 -1;
}
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 [%p]", mCombo, controller, pressedButtons.size(), pressedButtons.back(), mLabel.c_str(), getHandle().handle);
int activatedIndex = -1;
for (auto [index, pressedButton] : std::views::enumerate(pressedButtons)) {
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) {
DEBUG_FUNCTION_LINE("Calling callback [%p](controller: %08X, context: %p) for \"%s\" [handle: %p], pressed down %08X", mCallback, controller, mContext, mLabel.c_str(), getHandle().handle, mCombo);
mCallback(controller, getHandle(), mContext);
activatedIndex = index;
} else {
DEBUG_FUNCTION_LINE_WARN("Callback was null for combo %p", getHandle().handle);
}
}
prevButtonCombo = pressedButton;
}
return activatedIndex;
}
ButtonComboModule_Error ButtonComboInfoDown::setHoldDuration(uint32_t) {
return BUTTON_COMBO_MODULE_ERROR_SUCCESS;
}
ButtonComboModule_ButtonComboInfoEx ButtonComboInfoDown::getComboInfoEx() const {
return {.type = mIsObserver ? BUTTON_COMBO_MODULE_COMBO_TYPE_PRESS_DOWN_OBSERVER : BUTTON_COMBO_MODULE_COMBO_TYPE_PRESS_DOWN,
.basicCombo = {.controllerMask = mControllerMask, .combo = mCombo},
.optionalHoldForXMs = 0};
}
void ButtonComboInfoDown::resetPrevInput() {
for (uint32_t i = 0; i < std::size(mHoldInformation); ++i) {
mHoldInformation[i] = {};
mHoldInformation[i].prevButtonCombo = 0xFFFFFFFF;
}
}