atari:timer: Throttles calls to BackgroundTask function, to avoid it being called too frequently. SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Thu, 28 Aug 2014 07:27:55 +0200
branchSDL-1.2
changeset 9119 8f68bee3fd50
parent 9116 baafc044e241
child 9124 e6320f77cd2e
atari:timer: Throttles calls to BackgroundTask function, to avoid it being called too frequently.
src/timer/mint/SDL_systimer.c
--- a/src/timer/mint/SDL_systimer.c	Sun Aug 24 23:15:00 2014 +0200
+++ b/src/timer/mint/SDL_systimer.c	Thu Aug 28 07:27:55 2014 +0200
@@ -55,8 +55,6 @@
 /* The first ticks value of the application */
 static Uint32 start;
 
-static int mint_present; /* can we use Syield() ? */
-
 /* Timer  SDL_arraysize(Timer ),start/reset time */
 static Uint32 timerStart;
 
@@ -66,8 +64,6 @@
 
 	/* Set first ticks value, one _hz_200 tic is 5ms */
 	start = readHz200Timer() * 5;
-
-	mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND);
 }
 
 Uint32 SDL_GetTicks (void)
@@ -79,23 +75,32 @@
 
 void SDL_Delay (Uint32 ms)
 {
-	Uint32 now;
+	static Uint32 prev_now = 0;
+	Uint32 now, cur_tick;
+	int ran_bg_task = 0;
+
+	now = cur_tick = SDL_GetTicks();
 
 	/* No need to loop for delay below resolution */
 	if (ms<5) {
-		SDL_AtariMint_BackgroundTasks();
-		if (mint_present) {
-			Syield();
+		if (prev_now != now) {
+			SDL_AtariMint_BackgroundTasks();
+			prev_now = now;
 		}
 		return;
 	}
 
-	now = SDL_GetTicks();
-	while ((SDL_GetTicks()-now)<ms){
+	while (cur_tick-now<ms){
+		if (prev_now != cur_tick) {
+			SDL_AtariMint_BackgroundTasks();
+			prev_now = cur_tick;
+			ran_bg_task = 1;
+		}
+		cur_tick = SDL_GetTicks();
+	}
+
+	if (!ran_bg_task) {
 		SDL_AtariMint_BackgroundTasks();
-		if (mint_present) {
-			Syield();
-		}
 	}
 }