mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 16:32:39 +00:00
okay so maybe the gravity rush fix might have slightly broken the joystick halfmode and key toggle
This commit is contained in:
parent
0a1b875124
commit
45cc82e925
@ -37,6 +37,17 @@ What structs are needed?
|
|||||||
InputBinding(key1, key2, key3)
|
InputBinding(key1, key2, key3)
|
||||||
ControllerOutput(button, axis) - we only need a const array of these, and one of the attr-s is
|
ControllerOutput(button, axis) - we only need a const array of these, and one of the attr-s is
|
||||||
always 0 BindingConnection(inputBinding (member), controllerOutput (ref to the array element))
|
always 0 BindingConnection(inputBinding (member), controllerOutput (ref to the array element))
|
||||||
|
|
||||||
|
Things to always test before pushing like a dumbass:
|
||||||
|
Button outputs
|
||||||
|
Axis outputs
|
||||||
|
Input hierarchy
|
||||||
|
Multi key inputs
|
||||||
|
Mouse to joystick
|
||||||
|
Key toggle
|
||||||
|
Joystick halfmode
|
||||||
|
|
||||||
|
Don't be an idiot and test only the changed part expecting everything else to not be broken
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Flags and values for varying purposes
|
// Flags and values for varying purposes
|
||||||
@ -51,6 +62,11 @@ std::list<u32> toggled_keys;
|
|||||||
std::list<BindingConnection> connections = std::list<BindingConnection>();
|
std::list<BindingConnection> connections = std::list<BindingConnection>();
|
||||||
|
|
||||||
ControllerOutput output_array[] = {
|
ControllerOutput output_array[] = {
|
||||||
|
// Important: these have to be the first, or else they will update in the wrong order
|
||||||
|
ControllerOutput(LEFTJOYSTICK_HALFMODE),
|
||||||
|
ControllerOutput(RIGHTJOYSTICK_HALFMODE),
|
||||||
|
ControllerOutput(KEY_TOGGLE),
|
||||||
|
|
||||||
// Button mappings
|
// Button mappings
|
||||||
ControllerOutput(OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TRIANGLE),
|
ControllerOutput(OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TRIANGLE),
|
||||||
ControllerOutput(OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_CIRCLE),
|
ControllerOutput(OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_CIRCLE),
|
||||||
@ -70,15 +86,13 @@ ControllerOutput output_array[] = {
|
|||||||
ControllerOutput(OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_RIGHT),
|
ControllerOutput(OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_RIGHT),
|
||||||
|
|
||||||
// Axis mappings
|
// Axis mappings
|
||||||
ControllerOutput(0, Input::Axis::LeftX), ControllerOutput(0, Input::Axis::LeftY),
|
ControllerOutput(0, Axis::LeftX),
|
||||||
ControllerOutput(0, Input::Axis::RightX), ControllerOutput(0, Input::Axis::RightY),
|
ControllerOutput(0, Axis::LeftY),
|
||||||
ControllerOutput(0, Input::Axis::TriggerLeft), ControllerOutput(0, Input::Axis::TriggerRight),
|
ControllerOutput(0, Axis::RightX),
|
||||||
|
ControllerOutput(0, Axis::RightY),
|
||||||
ControllerOutput(LEFTJOYSTICK_HALFMODE), ControllerOutput(RIGHTJOYSTICK_HALFMODE),
|
ControllerOutput(0, Axis::TriggerLeft),
|
||||||
ControllerOutput(KEY_TOGGLE),
|
ControllerOutput(0, Axis::TriggerRight),
|
||||||
|
};
|
||||||
// End marker to signify the end of the array
|
|
||||||
ControllerOutput(0, Input::Axis::AxisMax)};
|
|
||||||
|
|
||||||
// We had to go through 3 files of indirection just to update a flag
|
// We had to go through 3 files of indirection just to update a flag
|
||||||
void ToggleMouseEnabled() {
|
void ToggleMouseEnabled() {
|
||||||
@ -304,24 +318,14 @@ void ToggleKeyInList(u32 key) {
|
|||||||
|
|
||||||
void ControllerOutput::ResetUpdate() {
|
void ControllerOutput::ResetUpdate() {
|
||||||
state_changed = false;
|
state_changed = false;
|
||||||
if (button != 0) {
|
|
||||||
switch (button) {
|
|
||||||
case KEY_TOGGLE:
|
|
||||||
break;
|
|
||||||
default: // everything else
|
|
||||||
new_button_state = false;
|
new_button_state = false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (axis != Axis::AxisMax) {
|
|
||||||
new_param = 0;
|
new_param = 0;
|
||||||
} else {
|
|
||||||
LOG_DEBUG(Input, "Controller output with no values detected!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void ControllerOutput::AddUpdate(bool pressed, u32 param) {
|
void ControllerOutput::AddUpdate(bool pressed, u32 param) {
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
if (button != 0) {
|
if (button != 0) {
|
||||||
new_button_state |= pressed;
|
new_button_state |= pressed;
|
||||||
|
new_param = param;
|
||||||
} else if (axis != Axis::AxisMax) {
|
} else if (axis != Axis::AxisMax) {
|
||||||
float multiplier = 1.0;
|
float multiplier = 1.0;
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
@ -338,9 +342,6 @@ void ControllerOutput::AddUpdate(bool pressed, u32 param) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ControllerOutput::FinalizeUpdate() {
|
void ControllerOutput::FinalizeUpdate() {
|
||||||
if (!state_changed || (old_button_state == new_button_state && old_param == new_param)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
old_button_state = new_button_state;
|
old_button_state = new_button_state;
|
||||||
old_param = new_param;
|
old_param = new_param;
|
||||||
float touchpad_x = 0;
|
float touchpad_x = 0;
|
||||||
@ -355,12 +356,15 @@ void ControllerOutput::FinalizeUpdate() {
|
|||||||
break;
|
break;
|
||||||
case LEFTJOYSTICK_HALFMODE:
|
case LEFTJOYSTICK_HALFMODE:
|
||||||
leftjoystick_halfmode = new_button_state;
|
leftjoystick_halfmode = new_button_state;
|
||||||
|
// LOG_DEBUG(Input, "This is when we set the halfmode flag to {}",
|
||||||
|
// leftjoystick_halfmode);
|
||||||
break;
|
break;
|
||||||
case RIGHTJOYSTICK_HALFMODE:
|
case RIGHTJOYSTICK_HALFMODE:
|
||||||
rightjoystick_halfmode = new_button_state;
|
rightjoystick_halfmode = new_button_state;
|
||||||
break;
|
break;
|
||||||
case KEY_TOGGLE:
|
case KEY_TOGGLE:
|
||||||
if (new_button_state) {
|
if (new_button_state) {
|
||||||
|
// LOG_DEBUG(Input, "Toggling a button...");
|
||||||
ToggleKeyInList(new_param);
|
ToggleKeyInList(new_param);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -374,6 +378,8 @@ void ControllerOutput::FinalizeUpdate() {
|
|||||||
case Axis::LeftX:
|
case Axis::LeftX:
|
||||||
case Axis::LeftY:
|
case Axis::LeftY:
|
||||||
multiplier = leftjoystick_halfmode ? 0.5 : 1.0;
|
multiplier = leftjoystick_halfmode ? 0.5 : 1.0;
|
||||||
|
// LOG_DEBUG(Input, "This is where we use the halfmode flag that is {}",
|
||||||
|
// leftjoystick_halfmode);
|
||||||
break;
|
break;
|
||||||
case Axis::RightX:
|
case Axis::RightX:
|
||||||
case Axis::RightY:
|
case Axis::RightY:
|
||||||
@ -392,7 +398,9 @@ void ControllerOutput::FinalizeUpdate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePressedKeys(u32 value, bool is_pressed) {
|
// Updates the list of pressed keys with the given input.
|
||||||
|
// Returns whether the list was updated or not.
|
||||||
|
bool UpdatePressedKeys(u32 value, bool is_pressed) {
|
||||||
if (is_pressed) {
|
if (is_pressed) {
|
||||||
// Find the correct position for insertion to maintain order
|
// Find the correct position for insertion to maintain order
|
||||||
auto it =
|
auto it =
|
||||||
@ -402,6 +410,7 @@ void UpdatePressedKeys(u32 value, bool is_pressed) {
|
|||||||
// Insert only if 'value' is not already in the list
|
// Insert only if 'value' is not already in the list
|
||||||
if (it == pressed_keys.end() || it->first != value) {
|
if (it == pressed_keys.end() || it->first != value) {
|
||||||
pressed_keys.insert(it, {value, false});
|
pressed_keys.insert(it, {value, false});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Remove 'value' from the list if it's not pressed
|
// Remove 'value' from the list if it's not pressed
|
||||||
@ -409,16 +418,24 @@ void UpdatePressedKeys(u32 value, bool is_pressed) {
|
|||||||
std::find_if(pressed_keys.begin(), pressed_keys.end(),
|
std::find_if(pressed_keys.begin(), pressed_keys.end(),
|
||||||
[value](const std::pair<u32, bool>& pk) { return pk.first == value; });
|
[value](const std::pair<u32, bool>& pk) { return pk.first == value; });
|
||||||
if (it != pressed_keys.end()) {
|
if (it != pressed_keys.end()) {
|
||||||
pressed_keys.erase(it); // Remove the key entirely from the list
|
pressed_keys.erase(it);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a given binding's all keys are currently active.
|
// Check if a given binding's all keys are currently active.
|
||||||
bool IsInputActive(const InputBinding& i) {
|
bool IsInputActive(const InputBinding& i) {
|
||||||
// Extract keys from InputBinding and ignore unused (0) keys
|
// Extract keys from InputBinding and ignore unused (0) or virtually pressed keys
|
||||||
std::list<uint32_t> input_keys = {i.key1, i.key2, i.key3};
|
std::list<uint32_t> input_keys = {i.key1, i.key2, i.key3};
|
||||||
input_keys.remove(0);
|
input_keys.remove(0);
|
||||||
|
for (auto key = input_keys.begin(); key != input_keys.end();) {
|
||||||
|
if (std::find(toggled_keys.begin(), toggled_keys.end(), *key) != toggled_keys.end()) {
|
||||||
|
key = input_keys.erase(key); // Use the returned iterator
|
||||||
|
} else {
|
||||||
|
++key; // Increment only if no erase happened
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Iterator for pressed_keys, starting from the beginning
|
// Iterator for pressed_keys, starting from the beginning
|
||||||
auto pressed_it = pressed_keys.begin();
|
auto pressed_it = pressed_keys.begin();
|
||||||
@ -443,11 +460,8 @@ bool IsInputActive(const InputBinding& i) {
|
|||||||
}
|
}
|
||||||
++pressed_it;
|
++pressed_it;
|
||||||
}
|
}
|
||||||
|
if (!key_found) {
|
||||||
// If not found in pressed_keys, check in toggled_keys
|
return false;
|
||||||
if (!key_found &&
|
|
||||||
std::find(toggled_keys.begin(), toggled_keys.end(), key) == toggled_keys.end()) {
|
|
||||||
return false; // Key not found in either list
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,12 +481,14 @@ bool IsInputActive(const InputBinding& i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ActivateOutputsFromInputs() {
|
void ActivateOutputsFromInputs() {
|
||||||
|
// LOG_DEBUG(Input, "Start of an input frame...");
|
||||||
for (auto& it : pressed_keys) {
|
for (auto& it : pressed_keys) {
|
||||||
it.second = false;
|
it.second = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is the cleanest looking code I've ever written, too bad it is not working
|
// this is the cleanest looking code I've ever written, too bad it is not working
|
||||||
|
// (i left the last part in by accident, then it turnd out to still be true even after I thought
|
||||||
|
// everything is good) (but now it really should be fine)
|
||||||
for (auto& it : output_array) {
|
for (auto& it : output_array) {
|
||||||
it.ResetUpdate();
|
it.ResetUpdate();
|
||||||
}
|
}
|
||||||
@ -520,7 +536,6 @@ void UpdateMouse(GameController* controller) {
|
|||||||
controller->Axis(0, axis_y, GetAxis(-0x80, 0x80, 0));
|
controller->Axis(0, axis_y, GetAxis(-0x80, 0x80, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 MousePolling(void* param, Uint32 id, Uint32 interval) {
|
Uint32 MousePolling(void* param, Uint32 id, Uint32 interval) {
|
||||||
auto* data = (GameController*)param;
|
auto* data = (GameController*)param;
|
||||||
UpdateMouse(data);
|
UpdateMouse(data);
|
||||||
|
@ -263,7 +263,7 @@ public:
|
|||||||
|
|
||||||
u32 button;
|
u32 button;
|
||||||
Axis axis;
|
Axis axis;
|
||||||
int old_param, new_param;
|
s32 old_param, new_param;
|
||||||
bool old_button_state, new_button_state, state_changed;
|
bool old_button_state, new_button_state, state_changed;
|
||||||
|
|
||||||
ControllerOutput(const u32 b, Axis a = Axis::AxisMax) {
|
ControllerOutput(const u32 b, Axis a = Axis::AxisMax) {
|
||||||
@ -322,8 +322,9 @@ public:
|
|||||||
// Check if the 3 key input is currently active.
|
// Check if the 3 key input is currently active.
|
||||||
bool IsInputActive(const InputBinding& i);
|
bool IsInputActive(const InputBinding& i);
|
||||||
|
|
||||||
// Add/remove the input that generated the event to/from the held keys container.
|
// Updates the list of pressed keys with the given input.
|
||||||
void UpdatePressedKeys(u32 button, bool is_pressed);
|
// Returns whether the list was updated or not.
|
||||||
|
bool UpdatePressedKeys(u32 button, bool is_pressed);
|
||||||
|
|
||||||
void ActivateOutputsFromInputs();
|
void ActivateOutputsFromInputs();
|
||||||
|
|
||||||
|
@ -196,10 +196,12 @@ void WindowSDL::OnKeyboardMouseInput(const SDL_Event* event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add/remove it from the list
|
// add/remove it from the list
|
||||||
Input::UpdatePressedKeys(input_id, input_down);
|
bool inputs_changed = Input::UpdatePressedKeys(input_id, input_down);
|
||||||
|
|
||||||
// update bindings
|
// update bindings
|
||||||
|
if (inputs_changed) {
|
||||||
Input::ActivateOutputsFromInputs();
|
Input::ActivateOutputsFromInputs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowSDL::OnGamepadEvent(const SDL_Event* event) {
|
void WindowSDL::OnGamepadEvent(const SDL_Event* event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user