modules/SceCtrl: Use SDL_GameControllerRumble for sceCtrlSetActuator.

- fix rumble on xinput and add rumble support for DS4 and DS.

Co-authored-by: german77 <juangerman-13@hotmail.com>
This commit is contained in:
Zangetsu38 2021-07-18 18:17:49 +02:00 committed by Nicolas Jallamion
parent c01697d11b
commit 32e763c5f9
3 changed files with 7 additions and 13 deletions

View File

@ -24,7 +24,6 @@ enum SceTouchSamplingState {
struct Controller {
GameControllerPtr controller;
HapticPtr haptic;
int port;
};

View File

@ -95,7 +95,11 @@ int main(int argc, char *argv[]) {
return InitConfigFailed;
} else {
std::atexit(SDL_Quit);
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC | SDL_INIT_VIDEO) < 0) {
// Enable HIDAPI rumble. This prevents SDL from disabling motion on PS4 and PS5 controllers
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_GAMECONTROLLER | SDL_INIT_VIDEO) < 0) {
app::error_dialog("SDL initialisation failed.");
return SDLInitFailed;
}

View File

@ -317,10 +317,6 @@ static void add_new_controllers(CtrlState &state) {
Controller new_controller;
const GameControllerPtr controller(SDL_GameControllerOpen(joystick_index), SDL_GameControllerClose);
new_controller.controller = controller;
SDL_Haptic *haptic = SDL_HapticOpenFromJoystick(SDL_GameControllerGetJoystick(controller.get()));
SDL_HapticRumbleInit(haptic);
const HapticPtr handle(haptic, SDL_HapticClose);
new_controller.haptic = handle;
new_controller.port = reserve_port(state);
state.controllers.emplace(guid, new_controller);
state.controllers_num++;
@ -545,13 +541,8 @@ EXPORT(int, sceCtrlSetActuator, int port, const SceCtrlActuator *pState) {
for (const auto &controller : state.controllers) {
if (controller.second.port == port) {
SDL_Haptic *handle = controller.second.haptic.get();
if (pState->small == 0 && pState->large == 0) {
SDL_HapticRumbleStop(handle);
} else {
// TODO: Look into a better implementation to distinguish both motors when available
SDL_HapticRumblePlay(handle, ((pState->small * 1.0f) / 510.0f) + ((pState->large * 1.0f) / 510.0f), SDL_HAPTIC_INFINITY);
}
SDL_GameControllerRumble(controller.second.controller.get(), pState->small * 655.35f, pState->large * 655.35f, SDL_HAPTIC_INFINITY);
return 0;
}
}