all repos — mgba @ ccf584238b8518a8dfa52a45dcc4d0caac5a2ec6

mGBA Game Boy Advance Emulator

SDL: More responsive rumble
Jeffrey Pfau jeffrey@endrift.com
Fri, 16 Sep 2016 12:51:33 -0700
commit

ccf584238b8518a8dfa52a45dcc4d0caac5a2ec6

parent

a9c8a02cf903c40e5a365e3889e30029388161b3

3 files changed, 17 insertions(+), 3 deletions(-)

jump to
M CHANGESCHANGES

@@ -100,6 +100,7 @@ - Debugger: Add software breakpoint support to gdb

- Util: Add PRIz macro for libc versions that don't support %z - SDL: Increase default audio buffer size to 1024 samples - GBA: Add override for Pokemon Pinball: Ruby and Sapphire rumble + - SDL: More responsive rumble 0.4.1: (2016-07-11) Bugfixes:
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -25,7 +25,8 @@ #define GUI_MOD KMOD_CTRL

#endif #define GYRO_STEPS 100 -#define RUMBLE_PWM 20 +#define RUMBLE_PWM 16 +#define RUMBLE_STEPS 2 mLOG_DEFINE_CATEGORY(SDL_EVENTS, "SDL Events");

@@ -167,6 +168,7 @@ #if SDL_VERSION_ATLEAST(2, 0, 0)

player->rumble.d.setRumble = _mSDLSetRumble; CircleBufferInit(&player->rumble.history, RUMBLE_PWM); player->rumble.level = 0; + player->rumble.activeLevel = 0; player->rumble.p = player; #endif

@@ -568,6 +570,7 @@ struct mSDLRumble* sdlRumble = (struct mSDLRumble*) rumble;

if (!sdlRumble->p->joystick || !sdlRumble->p->joystick->haptic || !SDL_HapticRumbleSupported(sdlRumble->p->joystick->haptic)) { return; } + int8_t originalLevel = sdlRumble->level; sdlRumble->level += enable; if (CircleBufferSize(&sdlRumble->history) == RUMBLE_PWM) { int8_t oldLevel;

@@ -575,8 +578,17 @@ CircleBufferRead8(&sdlRumble->history, &oldLevel);

sdlRumble->level -= oldLevel; } CircleBufferWrite8(&sdlRumble->history, enable); - if (sdlRumble->level) { - SDL_HapticRumblePlay(sdlRumble->p->joystick->haptic, sdlRumble->level / (float) RUMBLE_PWM, 20); + if (sdlRumble->level == originalLevel) { + return; + } + float activeLevel = ceil(RUMBLE_STEPS * sdlRumble->level / (float) RUMBLE_PWM) / RUMBLE_STEPS; + if (fabsf(sdlRumble->activeLevel - activeLevel) < 0.75 / RUMBLE_STEPS) { + return; + } + sdlRumble->activeLevel = activeLevel; + if (sdlRumble->activeLevel > 0.5 / RUMBLE_STEPS) { + SDL_HapticRumbleStop(sdlRumble->p->joystick->haptic); + SDL_HapticRumblePlay(sdlRumble->p->joystick->haptic, activeLevel, 500); } else { SDL_HapticRumbleStop(sdlRumble->p->joystick->haptic); }
M src/platform/sdl/sdl-events.hsrc/platform/sdl/sdl-events.h

@@ -63,6 +63,7 @@ struct mRumble d;

struct mSDLPlayer* p; int level; + float activeLevel; struct CircleBuffer history; } rumble; #endif