-
Notifications
You must be signed in to change notification settings - Fork 4
Care package: game_change, rumble, allow extensions if needed, tidy stubs #22
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
Changes from all commits
3bc3148
ad3c441
294cc99
5dca34f
14b1c5f
5fe7766
edec972
ca125b9
e9225f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ | |
| #include "platform.h" | ||
| #include "so_util.h" | ||
| #include "libyoyo.h" | ||
| #include "configuration.h" | ||
|
|
||
| int app_in_focus = 0; | ||
| int mouse_has_warped = 0; | ||
|
|
@@ -302,7 +301,7 @@ int update_inputs(SDL_Window *win) | |
| } | ||
| } | ||
|
|
||
| // Gamepad Input Code | ||
| // Synchronize gamepad<->yoyogamepad states | ||
| SDL_GameControllerUpdate(); | ||
| for (int i = 0; i < ARRAY_SIZE(sdl_controllers); i++) { | ||
| controller_t *controller = &sdl_controllers[i]; | ||
|
|
@@ -329,6 +328,33 @@ int update_inputs(SDL_Window *win) | |
| new_states[k++] = SDL_GameControllerGetButton(controller->controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT); | ||
| new_states[k++] = SDL_GameControllerGetButton(controller->controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); | ||
|
|
||
| // Handle rumble | ||
| if (!gmloader_config.disable_rumble) { | ||
| const double MAX_RUMBLE_D = 65535.0; | ||
|
|
||
| double left = (double)yoyo_gamepads[slot].motors[0]; | ||
| double right = (double)yoyo_gamepads[slot].motors[1]; | ||
|
|
||
| // Apply scale | ||
| if (gmloader_config.rumble_scale > 0.0) { | ||
| double scale = gmloader_config.rumble_scale; | ||
| left *= scale; | ||
| right *= scale; | ||
|
|
||
| // Clamp to [0.0, 1.0] | ||
| if (left > 1.0) left = 1.0; | ||
| if (left < 0.0) left = 0.0; | ||
| if (right > 1.0) right = 1.0; | ||
| if (right < 0.0) right = 0.0; | ||
| } | ||
|
|
||
| uint16_t left_motor = (uint16_t)(left * MAX_RUMBLE_D); | ||
| uint16_t right_motor = (uint16_t)(right * MAX_RUMBLE_D); | ||
| int duration_ms = (left_motor || right_motor) ? 10000 : 0; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10000 ms is 10 s
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GameMaker doesn't pass a duration in its arguments, instead handing control to the developer to explicitly turn rumble off. Therefore we need to pass a duration to SDL in its place, but since we don't know how long a developer may want rumble to last, I went with a larger threshold opting for safety. I think if a dev has rumble lasting longer than a few seconds they're insane, but you never know.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks for the explanation. That's what I suspected :) |
||
|
|
||
| SDL_GameControllerRumble(controller->controller, left_motor, right_motor, duration_ms); | ||
| } | ||
|
|
||
| for (int j = 0; j < ARRAY_SIZE(yoyo_gamepads[slot].buttons); j++) { | ||
| // down -> held or up -> cleared | ||
| yoyo_gamepads[slot].buttons[j] = (double)update_button(new_states[j], (int)yoyo_gamepads[slot].buttons[j]); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.