Browse Source

Particle Physics: clamp deltatime

Godzil 1 year ago
parent
commit
9a4228d092
1 changed files with 7 additions and 1 deletions
  1. 7 1
      source/app.cpp

+ 7 - 1
source/app.cpp

@@ -55,11 +55,17 @@ void application::update()
     /* Let's make sure we are running at the expected framerate */
     uint32_t now = SDL_GetTicks();
     int32_t timeToWait = MILLISECS_PER_FRAME - (now - this->millisecsPreviousFrame);
-    if (timeToWait > 0) // && timeToWait <= MILLISECS_PER_FRAME)
+    if ((timeToWait > 0) && (timeToWait <= MILLISECS_PER_FRAME))
     {
         SDL_Delay(timeToWait);
     }
     double deltaTime = (SDL_GetTicks() - this->millisecsPreviousFrame) / 1000.0;
+
+    /* clamp maximum deltatime to avoid weird behaviours */
+    if (deltaTime > 0.016)
+    {
+        deltaTime = 0.016;
+    }
     this->millisecsPreviousFrame = SDL_GetTicks();