From 03f8528315fa46c95991a34f3325d7b33ae5538c Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Sat, 02 May 2020 21:48:36 +0000
Subject: [PATCH] Update source to SDL2 2.0.12

---
 source/test/testsprite2.c |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/source/test/testsprite2.c b/source/test/testsprite2.c
index b0348f8..4de0b4b 100644
--- a/source/test/testsprite2.c
+++ b/source/test/testsprite2.c
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -37,6 +37,8 @@
 static SDL_Rect *velocities;
 static int sprite_w, sprite_h;
 static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
+static Uint32 next_fps_check, frames;
+static const Uint32 fps_check_delay = 5000;
 
 /* Number of iterations to move sprites - used for visual tests. */
 /* -1: infinite random moves (default); >=0: enables N deterministic moves */
@@ -244,6 +246,7 @@
 void
 loop()
 {
+    Uint32 now;
     int i;
     SDL_Event event;
 
@@ -261,13 +264,24 @@
         emscripten_cancel_main_loop();
     }
 #endif
+
+    frames++;
+    now = SDL_GetTicks();
+    if (SDL_TICKS_PASSED(now, next_fps_check)) {
+        /* Print out some timing information */
+        const Uint32 then = next_fps_check - fps_check_delay;
+        const double fps = ((double) frames * 1000) / (now - then);
+        SDL_Log("%2.2f frames per second\n", fps);
+        next_fps_check = now + fps_check_delay;
+        frames = 0;
+    }
+
 }
 
 int
 main(int argc, char *argv[])
 {
     int i;
-    Uint32 then, now, frames;
     Uint64 seed;
     const char *icon = "icon.bmp";
 
@@ -326,8 +340,8 @@
             }
         }
         if (consumed < 0) {
-            SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
-                    argv[0], SDLTest_CommonUsage(state));
+            static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", "[--iterations N]", "[num_sprites]", "[icon.bmp]", NULL };
+            SDLTest_CommonLogUsage(state, argv[0], options);
             quit(1);
         }
         i += consumed;
@@ -384,24 +398,17 @@
 
     /* Main render loop */
     frames = 0;
-    then = SDL_GetTicks();
+    next_fps_check = SDL_GetTicks() + fps_check_delay;
     done = 0;
 
 #ifdef __EMSCRIPTEN__
     emscripten_set_main_loop(loop, 0, 1);
 #else
     while (!done) {
-        ++frames;
         loop();
     }
 #endif
 
-    /* Print out some timing information */
-    now = SDL_GetTicks();
-    if (now > then) {
-        double fps = ((double) frames * 1000) / (now - then);
-        SDL_Log("%2.2f frames per second\n", fps);
-    }
     quit(0);
     return 0;
 }

--
Gitblit v1.9.3