Fixed joysick halfmodes, and possibly the last update on input hierarchy

This commit is contained in:
kalaposfos13 2024-11-15 09:04:43 +01:00
parent 1efd247584
commit e43d60edaa
2 changed files with 26 additions and 10 deletions

View File

@ -334,23 +334,25 @@ void ControllerOutput::update(bool pressed, u32 param) {
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, "Joystick multiplier set to {}", multiplier);
break; break;
case Axis::RightX: case Axis::RightX:
case Axis::RightY: case Axis::RightY:
multiplier = rightjoystick_halfmode ? 0.5 : 1.0; multiplier = rightjoystick_halfmode ? 0.5 : 1.0;
//LOG_DEBUG(Input, "Joystick multiplier set to {}", multiplier);
break; break;
case Axis::TriggerLeft: case Axis::TriggerLeft:
case Axis::TriggerRight: case Axis::TriggerRight:
// todo: verify this works (This probably works from testing, // todo: verify this works (This probably works from testing,
// but needs extra info (multiple input to the same trigger?)) // but needs extra info (multiple input to the same trigger?))
axis_value = SDL_clamp((pressed ? (s32)param : 0) * multiplier, 0, 127); axis_value = SDL_clamp((pressed ? (s32)param : 0), 0, 127);
controller->Axis(0, axis, GetAxis(0, 0x80, axis_value)); controller->Axis(0, axis, GetAxis(0, 0x80, axis_value));
return; return;
default: default:
break; break;
} }
axis_value = SDL_clamp((pressed ? (s32)param : 0) * multiplier, -127, 127); axis_value = SDL_clamp((pressed ? (s32)param : 0), -127, 127);
int ax = GetAxis(-0x80, 0x80, axis_value); int ax = GetAxis(-0x80, 0x80, axis_value * multiplier);
controller->Axis(0, axis, ax); controller->Axis(0, axis, ax);
} else { } else {
LOG_DEBUG(Input, "Controller output with no values detected!"); LOG_DEBUG(Input, "Controller output with no values detected!");
@ -372,10 +374,10 @@ void ControllerOutput::addUpdate(bool pressed, u32 param) {
controller->CheckButton(0, button, pressed); controller->CheckButton(0, button, pressed);
break; break;
case LEFTJOYSTICK_HALFMODE: case LEFTJOYSTICK_HALFMODE:
leftjoystick_halfmode = pressed; leftjoystick_halfmode |= pressed;
break; break;
case RIGHTJOYSTICK_HALFMODE: case RIGHTJOYSTICK_HALFMODE:
rightjoystick_halfmode = pressed; rightjoystick_halfmode |= pressed;
break; break;
case KEY_TOGGLE: case KEY_TOGGLE:
if (pressed) { if (pressed) {
@ -392,22 +394,24 @@ void ControllerOutput::addUpdate(bool pressed, u32 param) {
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, "Left joystick multiplier set to {}", multiplier);
break; break;
case Axis::RightX: case Axis::RightX:
case Axis::RightY: case Axis::RightY:
multiplier = rightjoystick_halfmode ? 0.5 : 1.0; multiplier = rightjoystick_halfmode ? 0.5 : 1.0;
LOG_DEBUG(Input, " Right joystick multiplier set to {}", multiplier);
break; break;
case Axis::TriggerLeft: case Axis::TriggerLeft:
case Axis::TriggerRight: case Axis::TriggerRight:
// todo: verify this works // todo: verify this works
axis_value = SDL_clamp((pressed ? (s32)param : 0) * multiplier + axis_value, 0, 127); axis_value = SDL_clamp((pressed ? (s32)param : 0) + axis_value, 0, 127);
controller->Axis(0, axis, GetAxis(0, 0x80, axis_value)); controller->Axis(0, axis, GetAxis(0, 0x80, axis_value));
return; return;
default: default:
break; break;
} }
axis_value = SDL_clamp((pressed ? (s32)param : 0) * multiplier + axis_value, -127, 127); axis_value = SDL_clamp(((pressed ? (s32)param : 0)+ axis_value) , -127, 127);
controller->Axis(0, axis, GetAxis(-0x80, 0x80, axis_value)); controller->Axis(0, axis, GetAxis(-0x80, 0x80, axis_value * multiplier));
// LOG_INFO(Input, "Axis value delta: {} final value: {}", (pressed ? a_value : 0), // LOG_INFO(Input, "Axis value delta: {} final value: {}", (pressed ? a_value : 0),
// axis_value); // axis_value);
} else { } else {
@ -458,9 +462,9 @@ bool isInputActive(const InputBinding& i) {
while (pressed_it != pressed_end && pressed_it->first <= key) { while (pressed_it != pressed_end && pressed_it->first <= key) {
if (pressed_it->first == key) { if (pressed_it->first == key) {
if (!pressed_it->second) { if (!pressed_it->second) {
key_found = true;
flags_to_set.push_back(&pressed_it->second); // Collect pointer if flag is not already set flags_to_set.push_back(&pressed_it->second); // Collect pointer if flag is not already set
} }
key_found = true;
++pressed_it; // Move to the next key in pressed_keys ++pressed_it; // Move to the next key in pressed_keys
break; break;
} }
@ -478,6 +482,7 @@ bool isInputActive(const InputBinding& i) {
*flag = true; *flag = true;
} }
LOG_DEBUG(Input, "Input found: {}", i.toString());
return true; // All keys are active return true; // All keys are active
} }

View File

@ -283,6 +283,12 @@ public:
std::string toString() const { std::string toString() const {
return fmt::format("({}, {}, {})", button, (int)axis, axis_value); return fmt::format("({}, {}, {})", button, (int)axis, axis_value);
} }
inline bool isButton() const {
return axis == Axis::AxisMax && button != 0;
}
inline bool isAxis() const {
return axis != Axis::AxisMax && button == 0;
}
void update(bool pressed, u32 param = 0); void update(bool pressed, u32 param = 0);
// Off events are not counted // Off events are not counted
void addUpdate(bool pressed, u32 param = 0); void addUpdate(bool pressed, u32 param = 0);
@ -300,7 +306,12 @@ public:
output = out; output = out;
} }
bool operator<(const BindingConnection& other) const { bool operator<(const BindingConnection& other) const {
return binding < other.binding; if (binding < other.binding) {
return true;
}
// false, except if the first is a button and second is an axis,
// in which case the button is higher priority
return output->isButton() && other.output->isAxis();
} }
}; };