forked from suyu/suyu
input_common: sdl: Only send last vibration command
This commit is contained in:
parent
54c359d1e3
commit
96b8a3ecac
1 changed files with 16 additions and 1 deletions
|
@ -652,12 +652,27 @@ bool SDLDriver::IsVibrationEnabled(const PadIdentifier& identifier) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLDriver::SendVibrations() {
|
void SDLDriver::SendVibrations() {
|
||||||
|
std::vector<VibrationRequest> filtered_vibrations{};
|
||||||
while (!vibration_queue.Empty()) {
|
while (!vibration_queue.Empty()) {
|
||||||
VibrationRequest request;
|
VibrationRequest request;
|
||||||
vibration_queue.Pop(request);
|
vibration_queue.Pop(request);
|
||||||
const auto joystick = GetSDLJoystickByGUID(request.identifier.guid.RawString(),
|
const auto joystick = GetSDLJoystickByGUID(request.identifier.guid.RawString(),
|
||||||
static_cast<int>(request.identifier.port));
|
static_cast<int>(request.identifier.port));
|
||||||
joystick->RumblePlay(request.vibration);
|
const auto it = std::find_if(filtered_vibrations.begin(), filtered_vibrations.end(),
|
||||||
|
[request](VibrationRequest vibration) {
|
||||||
|
return vibration.identifier == request.identifier;
|
||||||
|
});
|
||||||
|
if (it == filtered_vibrations.end()) {
|
||||||
|
filtered_vibrations.push_back(std::move(request));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*it = request;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& vibration : filtered_vibrations) {
|
||||||
|
const auto joystick = GetSDLJoystickByGUID(vibration.identifier.guid.RawString(),
|
||||||
|
static_cast<int>(vibration.identifier.port));
|
||||||
|
joystick->RumblePlay(vibration.vibration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue