Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] Adds implementation to SetGamepadVibration() on PLATFORM_WEB and updates it on PLATFORM_DESKTOP_SDL to handle duration #4410

Merged
merged 6 commits into from
Oct 21, 2024

Conversation

asdqwe
Copy link
Contributor

@asdqwe asdqwe commented Oct 21, 2024

Updated SetGamepadVibration() to handle duration (in ms) on PLATFORM_DESKTOP_SDL. Also renamed the left/rightMotor parameters to low/high as it's more commonly referenced (ref). Since a new parameter was added, this is a breaking change.

The PR can be tested with:

#include "raylib.h"
int main(void) {
    InitWindow(800, 450, "test");
    SetTargetFPS(60);
    while (!WindowShouldClose()) {

        if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_UP)) SetGamepadVibration(0, 1.0f, 1.0f, 300);
        if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) SetGamepadVibration(0, 0.0f, 1.0f, 300);
        if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT)) SetGamepadVibration(0, 1.0f, 0.0f, 300);
        if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) SetGamepadVibration(0, 0.0f, 0.0f, 300);
        if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_MIDDLE)) SetGamepadVibration(0, 1.0f, 1.0f, 0);

        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("Pres X, Y, B, A, Middle", 20, 20, 20, BLACK);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

@raysan5
Copy link
Owner

raysan5 commented Oct 21, 2024

@asdqwe I prefer to use the left/rightMotor convention (also used by MonoGame), I think it's a more clear naming for new users.

About the duration, I'm still considering adding it or not to the function, it works great with SDL because it mimics the same internal function but, how will it be managed on other platforms/backends? 🤔

@raysan5
Copy link
Owner

raysan5 commented Oct 21, 2024

@asdqwe Thanks for the info and the included references.

I saw that duration parameter is quite common (Android (ms), HTML5 (ms), Godot (sec/ms)) despite some APIs do not expose it directly (MonoGame, Unity).

Also, the vibration support was added after raylib 5.0, so it's still a good time to update this function, before next release.

My only concern is the duration resolution to use, afair all raylib timming functions work in seconds... but most vibrate APIs expect milliseconds... (only Godot uses seconds on start_joy_vibration()).

EDIT: Defold seems to manage vibration for iOS/Android with an extension and does not seem to define duration. GDevelop Vibrate() function expects duration in ms. love2d uses seconds for its vibrate function.

@raysan5
Copy link
Owner

raysan5 commented Oct 21, 2024

@asdqwe After reviewing some libraries and thinking about it, I prefer to use seconds. It would be consistent with other raylib timming functions.

@asdqwe asdqwe changed the title [rcore] Updates SetGamepadVibration() to handle duration on PLATFORM_DESKTOP_SDL [rcore] Adds implementation to SetGamepadVibration() on PLATFORM_WEB and updates it on PLATFORM_DESKTOP_SDL to handle duration Oct 21, 2024
@raysan5 raysan5 merged commit f8f6aa0 into raysan5:master Oct 21, 2024
13 checks passed
@raysan5
Copy link
Owner

raysan5 commented Oct 21, 2024

@asdqwe Thanks for the addition and review!

@asdqwe asdqwe deleted the fix-setgamepadvibration branch October 21, 2024 22:16
psxdev pushed a commit to raylib4Consoles/raylib that referenced this pull request Nov 18, 2024
…EB` and updates it on `PLATFORM_DESKTOP_SDL` to handle duration (raysan5#4410)

* Updates SetGamepadVibration()

* Handle MAX_GAMEPAD_VIBRATION_TIME

* Revert low/high parameters back to left/rightMotor

* Fix missin semicolon

* Convert duration to seconds

* Add SetGamepadVibration() implementation to PLATFORM_WEB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants