[Change] Made force feedback a little more sophisticated.
This commit is contained in:
parent
99dc05be86
commit
3f205ce9f0
17
src/spfx.c
17
src/spfx.c
@ -22,6 +22,8 @@
|
||||
#define SPFX_CHUNK 32 /**< Chunk to allocate when needed. */
|
||||
#define SHAKE_VEL_MOD 0.0008 /**< Shake modifier. */
|
||||
|
||||
#define HAPTIC_UPDATE_INTERVAL 0.1 /**< Time between haptic updates. */
|
||||
|
||||
/* Special hardcoded effects.. */
|
||||
|
||||
/* Shake, AKA RUMBLE! */
|
||||
@ -35,6 +37,7 @@ extern SDL_Haptic* haptic; /**< From joystick.c */
|
||||
extern unsigned int haptic_query; /**< From joystick.c */
|
||||
static int haptic_rumble = -1; /**< Haptic rumble effect ID. */
|
||||
static SDL_HapticEffect haptic_rumbleEffect; /**< Haptic rumble effect. */
|
||||
static double haptic_lastUpdate = 0.; /**< Timer to update haptic effect again. */
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -315,8 +318,14 @@ static void spfx_update_layer(SPFX* layer, int* nlayer, const double dt) {
|
||||
void spfx_start(const double dt) {
|
||||
GLdouble bx, by, x, y;
|
||||
double inc;
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
/* Decrement the haptic timer. */
|
||||
if(haptic_lastUpdate > 0.)
|
||||
haptic_lastUpdate -= dt;
|
||||
#endif
|
||||
|
||||
if(shake_off == 1) return; /* Save the cycles. */
|
||||
|
||||
bx = SCREEN_W / 2;
|
||||
by = SCREEN_H / 2;
|
||||
|
||||
@ -364,7 +373,6 @@ void spfx_shake(double mod) {
|
||||
vect_pset(&shake_vel, SHAKE_VEL_MOD*shake_rad, RNGF() * 2. * M_PI);
|
||||
|
||||
/* Rumble if it wasn't rumbling before. */
|
||||
if(shake_off == 1)
|
||||
spfx_hapticRumble();
|
||||
|
||||
/* Notify that rumble is active. */
|
||||
@ -406,6 +414,10 @@ static void spfx_hapticRumble(void) {
|
||||
SDL_HapticEffect* efx;
|
||||
|
||||
if(haptic_rumble >= 0) {
|
||||
/* Not time to update yet. */
|
||||
if(haptic_lastUpdate > 0.)
|
||||
return;
|
||||
|
||||
/* Stop the effect if it was playing. */
|
||||
SDL_HapticStopEffect(haptic, haptic_rumble);
|
||||
|
||||
@ -419,6 +431,9 @@ static void spfx_hapticRumble(void) {
|
||||
|
||||
/* Run the new effect. */
|
||||
SDL_HapticRunEffect(haptic, haptic_rumble, 1);
|
||||
|
||||
/* Set timer again. */
|
||||
haptic_lastUpdate = HAPTIC_UPDATE_INTERVAL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user