Permalink
Browse files

* Enforce a minimum fps for the update of the rumble simulation.

* Use real_dt when updating haptic devices not dt.
  • Loading branch information...
1 parent 231c31d commit a7da3e91d3e271460be603e1242951f3bb779164 @bobbens committed Jan 15, 2011
Showing with 45 additions and 16 deletions.
  1. +1 −1 src/naev.c
  2. +43 −14 src/spfx.c
  3. +1 −1 src/spfx.h
View
@@ -782,7 +782,7 @@ static void render_all (void)
dt = (paused) ? 0. : game_dt;
/* setup */
- spfx_begin(dt);
+ spfx_begin(dt, real_dt);
/* BG */
space_render(dt);
planets_render();
View
@@ -62,6 +62,7 @@ static double shake_force_mod = 0.; /**< Shake force modifier. */
static float shake_force_ang = 0.; /**< Shake force angle. */
static int shake_off = 1; /**< 1 if shake is not active. */
static perlin_data_t *shake_noise = NULL; /**< Shake noise. */
+static const double shake_fps_min = 1./10.; /**< Minimum fps to run shake update at. */
#if SDL_VERSION_ATLEAST(1,3,0)
@@ -453,29 +454,18 @@ static void spfx_update_layer( SPFX *layer, int *nlayer, const double dt )
/**
- * @brief Prepares the rendering for the special effects.
- *
- * Should be called at the beginning of the rendering loop.
- *
- * @param dt Current delta tick.
+ * @brief Updates the shake position.
*/
-void spfx_begin( const double dt )
+static void spfx_updateShake( double dt )
{
double mod, vmod, angle;
double force_x, force_y;
int forced;
- /* Defaults. */
- shake_set = 0;
+ /* Must still be on. */
if (shake_off)
return;
-#if SDL_VERSION_ATLEAST(1,3,0)
- /* Decrement the haptic timer. */
- if (haptic_lastUpdate > 0.)
- haptic_lastUpdate -= dt;
-#endif /* SDL_VERSION_ATLEAST(1,3,0) */
-
/* The shake decays over time */
forced = 0;
if (shake_force_mod > 0.) {
@@ -514,6 +504,45 @@ void spfx_begin( const double dt )
/* Update position. */
vect_cadd( &shake_pos, shake_vel.x * dt, shake_vel.y * dt );
+}
+
+
+/**
+ * @brief Prepares the rendering for the special effects.
+ *
+ * Should be called at the beginning of the rendering loop.
+ *
+ * @param dt Current delta tick.
+ * @param real_dt Real delta tick.
+ */
+void spfx_begin( const double dt, const double real_dt )
+{
+ double ddt;
+
+ /* Defaults. */
+ shake_set = 0;
+ if (shake_off)
+ return;
+
+#if SDL_VERSION_ATLEAST(1,3,0)
+ /* Decrement the haptic timer. */
+ if (haptic_lastUpdate > 0.)
+ haptic_lastUpdate -= real_dt; /* Based on real delta-tick. */
+#else /* SDL_VERSION_ATLEAST(1,3,0) */
+ (void) real_dt; /* Avoid warning. */
+#endif /* SDL_VERSION_ATLEAST(1,3,0) */
+
+ /* Micro basic simple control loop. */
+ if (dt > shake_fps_min) {
+ ddt = dt;
+ while (ddt > shake_fps_min) {
+ spfx_updateShake( shake_fps_min );
+ ddt -= shake_fps_min;
+ }
+ spfx_updateShake( ddt ); /* Leftover. */
+ }
+ else
+ spfx_updateShake( dt );
/* set the new viewport */
gl_matrixTranslate( shake_pos.x, shake_pos.y );
View
@@ -39,7 +39,7 @@ void spfx_clear (void);
/*
* get ready to rumble
*/
-void spfx_begin( const double dt );
+void spfx_begin( const double dt, const double real_dt );
void spfx_end (void);
void spfx_shake( double mod );
void spfx_getShake( double *x, double *y );

0 comments on commit a7da3e9

Please sign in to comment.