mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 08:22:32 +00:00
Initial axis-to-button logic
This commit is contained in:
parent
0067d741f4
commit
384e9637ee
@ -411,11 +411,16 @@ void ControllerOutput::ResetUpdate() {
|
|||||||
new_button_state = false;
|
new_button_state = false;
|
||||||
new_param = 0;
|
new_param = 0;
|
||||||
}
|
}
|
||||||
void ControllerOutput::AddUpdate(bool pressed, u32 param) {
|
void ControllerOutput::AddUpdate(bool pressed, bool analog, u32 param) {
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
if (button != 0) {
|
if (button != 0) {
|
||||||
new_button_state |= pressed;
|
if (analog) {
|
||||||
new_param = param;
|
new_button_state |= abs((s32)param) > 0x40;
|
||||||
|
} else {
|
||||||
|
new_button_state |= pressed;
|
||||||
|
new_param = param;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (axis != Axis::AxisMax) {
|
} else if (axis != Axis::AxisMax) {
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
case Axis::TriggerLeft:
|
case Axis::TriggerLeft:
|
||||||
@ -536,7 +541,7 @@ bool UpdatePressedKeys(u32 value, bool is_pressed) {
|
|||||||
}
|
}
|
||||||
// Check if a given binding's all keys are currently active.
|
// Check if a given binding's all keys are currently active.
|
||||||
// For now it also extracts the analog inputs' parameters.
|
// For now it also extracts the analog inputs' parameters.
|
||||||
bool IsInputActive(BindingConnection& connection) {
|
void IsInputActive(BindingConnection& connection, bool& active, bool& analog) {
|
||||||
InputBinding i = connection.binding;
|
InputBinding i = connection.binding;
|
||||||
// Extract keys from InputBinding and ignore unused (0) or toggled keys
|
// Extract keys from InputBinding and ignore unused (0) or toggled keys
|
||||||
std::list<u32> input_keys = {i.key1, i.key2, i.key3};
|
std::list<u32> input_keys = {i.key1, i.key2, i.key3};
|
||||||
@ -550,7 +555,8 @@ bool IsInputActive(BindingConnection& connection) {
|
|||||||
}
|
}
|
||||||
if (input_keys.empty()) {
|
if (input_keys.empty()) {
|
||||||
LOG_DEBUG(Input, "No actual inputs to check, returning true");
|
LOG_DEBUG(Input, "No actual inputs to check, returning true");
|
||||||
return true;
|
active = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterator for pressed_keys, starting from the beginning
|
// Iterator for pressed_keys, starting from the beginning
|
||||||
@ -581,16 +587,17 @@ bool IsInputActive(BindingConnection& connection) {
|
|||||||
for (auto rev_it = --pressed_keys.end(); (rev_it->first & 0x80000000) != 0; rev_it--) {
|
for (auto rev_it = --pressed_keys.end(); (rev_it->first & 0x80000000) != 0; rev_it--) {
|
||||||
if ((rev_it->first & 0xF00FFFFF) == (key & 0xF00FFFFF)) {
|
if ((rev_it->first & 0xF00FFFFF) == (key & 0xF00FFFFF)) {
|
||||||
connection.parameter = (u32)((s32)((rev_it->first & 0x0FF00000) >> 20) - 128);
|
connection.parameter = (u32)((s32)((rev_it->first & 0x0FF00000) >> 20) - 128);
|
||||||
LOG_DEBUG(Input, "Extracted the following param: {:X} from {:X}",
|
// LOG_DEBUG(Input, "Extracted the following param: {:X} from {:X}",
|
||||||
(s32)connection.parameter, rev_it->first);
|
// (s32)connection.parameter, rev_it->first);
|
||||||
key_found = true;
|
key_found = true;
|
||||||
|
analog = true;
|
||||||
flags_to_set.push_back(&rev_it->second);
|
flags_to_set.push_back(&rev_it->second);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!key_found) {
|
if (!key_found) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,14 +606,15 @@ bool IsInputActive(BindingConnection& connection) {
|
|||||||
is_fully_blocked &= *flag;
|
is_fully_blocked &= *flag;
|
||||||
}
|
}
|
||||||
if (is_fully_blocked) {
|
if (is_fully_blocked) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
for (bool* flag : flags_to_set) {
|
for (bool* flag : flags_to_set) {
|
||||||
*flag = true;
|
*flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG(Input, "Input found: {}", i.ToString());
|
LOG_DEBUG(Input, "Input found: {}", i.ToString());
|
||||||
return true; // All keys are active
|
active = true;
|
||||||
|
return; // All keys are active
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivateOutputsFromInputs() {
|
void ActivateOutputsFromInputs() {
|
||||||
@ -622,8 +630,9 @@ void ActivateOutputsFromInputs() {
|
|||||||
it.ResetUpdate();
|
it.ResetUpdate();
|
||||||
}
|
}
|
||||||
for (auto& it : connections) {
|
for (auto& it : connections) {
|
||||||
bool active = IsInputActive(it);
|
bool active = false, analog_input_detected = false;
|
||||||
it.output->AddUpdate(active, it.parameter);
|
IsInputActive(it, active, analog_input_detected);
|
||||||
|
it.output->AddUpdate(active, analog_input_detected, it.parameter);
|
||||||
}
|
}
|
||||||
for (auto& it : output_array) {
|
for (auto& it : output_array) {
|
||||||
it.FinalizeUpdate();
|
it.FinalizeUpdate();
|
||||||
|
@ -298,7 +298,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ResetUpdate();
|
void ResetUpdate();
|
||||||
void AddUpdate(bool pressed, u32 param = 0);
|
void AddUpdate(bool pressed, bool analog, u32 param = 0);
|
||||||
void FinalizeUpdate();
|
void FinalizeUpdate();
|
||||||
};
|
};
|
||||||
class BindingConnection {
|
class BindingConnection {
|
||||||
@ -327,8 +327,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool IsInputActive(BindingConnection& connection);
|
|
||||||
|
|
||||||
// Updates the list of pressed keys with the given input.
|
// Updates the list of pressed keys with the given input.
|
||||||
// Returns whether the list was updated or not.
|
// Returns whether the list was updated or not.
|
||||||
bool UpdatePressedKeys(u32 button, bool is_pressed);
|
bool UpdatePressedKeys(u32 button, bool is_pressed);
|
||||||
|
Loading…
Reference in New Issue
Block a user