mirror of https://github.com/mgba-emu/mgba.git
SDL: Add rumble PWM support
This commit is contained in:
parent
c6c57273b5
commit
9085bbb8a4
1
CHANGES
1
CHANGES
|
@ -16,6 +16,7 @@ Features:
|
||||||
- Memory inspector
|
- Memory inspector
|
||||||
- Screensaver can now be suspended while a game is running
|
- Screensaver can now be suspended while a game is running
|
||||||
- Load/save the most recent savestate slot
|
- Load/save the most recent savestate slot
|
||||||
|
- Support varible speed (PWM) rumble
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
- ARM7: Fix SWI and IRQ timings
|
- ARM7: Fix SWI and IRQ timings
|
||||||
- GBA Audio: Force audio FIFOs to 32-bit
|
- GBA Audio: Force audio FIFOs to 32-bit
|
||||||
|
|
|
@ -22,8 +22,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GYRO_STEPS 100
|
#define GYRO_STEPS 100
|
||||||
|
#define RUMBLE_PWM 35
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
static void _GBASDLSetRumble(struct GBARumble* rumble, int enable);
|
static void _GBASDLSetRumble(struct GBARumble* rumble, int enable);
|
||||||
|
#endif
|
||||||
static int32_t _GBASDLReadTiltX(struct GBARotationSource* rumble);
|
static int32_t _GBASDLReadTiltX(struct GBARotationSource* rumble);
|
||||||
static int32_t _GBASDLReadTiltY(struct GBARotationSource* rumble);
|
static int32_t _GBASDLReadTiltY(struct GBARotationSource* rumble);
|
||||||
static int32_t _GBASDLReadGyroZ(struct GBARotationSource* rumble);
|
static int32_t _GBASDLReadGyroZ(struct GBARotationSource* rumble);
|
||||||
|
@ -154,6 +157,8 @@ bool GBASDLAttachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
player->rumble.d.setRumble = _GBASDLSetRumble;
|
player->rumble.d.setRumble = _GBASDLSetRumble;
|
||||||
|
CircleBufferInit(&player->rumble.history, RUMBLE_PWM);
|
||||||
|
player->rumble.level = 0;
|
||||||
player->rumble.p = player;
|
player->rumble.p = player;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -531,8 +536,15 @@ static void _GBASDLSetRumble(struct GBARumble* rumble, int enable) {
|
||||||
if (!sdlRumble->p->haptic || !SDL_HapticRumbleSupported(sdlRumble->p->haptic)) {
|
if (!sdlRumble->p->haptic || !SDL_HapticRumbleSupported(sdlRumble->p->haptic)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (enable) {
|
sdlRumble->level += enable;
|
||||||
SDL_HapticRumblePlay(sdlRumble->p->haptic, 1.0f, 20);
|
if (CircleBufferSize(&sdlRumble->history) == RUMBLE_PWM) {
|
||||||
|
int8_t oldLevel;
|
||||||
|
CircleBufferRead8(&sdlRumble->history, &oldLevel);
|
||||||
|
sdlRumble->level -= oldLevel;
|
||||||
|
}
|
||||||
|
CircleBufferWrite8(&sdlRumble->history, enable);
|
||||||
|
if (sdlRumble->level) {
|
||||||
|
SDL_HapticRumblePlay(sdlRumble->p->haptic, sdlRumble->level / (float) RUMBLE_PWM, 20);
|
||||||
} else {
|
} else {
|
||||||
SDL_HapticRumbleStop(sdlRumble->p->haptic);
|
SDL_HapticRumbleStop(sdlRumble->p->haptic);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,9 @@ struct GBASDLPlayer {
|
||||||
struct GBASDLRumble {
|
struct GBASDLRumble {
|
||||||
struct GBARumble d;
|
struct GBARumble d;
|
||||||
struct GBASDLPlayer* p;
|
struct GBASDLPlayer* p;
|
||||||
|
|
||||||
|
int level;
|
||||||
|
struct CircleBuffer history;
|
||||||
} rumble;
|
} rumble;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue