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 91198f68bee3fd50
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
     1.1 --- a/src/timer/mint/SDL_systimer.c	Sun Aug 24 23:15:00 2014 +0200
     1.2 +++ b/src/timer/mint/SDL_systimer.c	Thu Aug 28 07:27:55 2014 +0200
     1.3 @@ -55,8 +55,6 @@
     1.4  /* The first ticks value of the application */
     1.5  static Uint32 start;
     1.6  
     1.7 -static int mint_present; /* can we use Syield() ? */
     1.8 -
     1.9  /* Timer  SDL_arraysize(Timer ),start/reset time */
    1.10  static Uint32 timerStart;
    1.11  
    1.12 @@ -66,8 +64,6 @@
    1.13  
    1.14  	/* Set first ticks value, one _hz_200 tic is 5ms */
    1.15  	start = readHz200Timer() * 5;
    1.16 -
    1.17 -	mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND);
    1.18  }
    1.19  
    1.20  Uint32 SDL_GetTicks (void)
    1.21 @@ -79,23 +75,32 @@
    1.22  
    1.23  void SDL_Delay (Uint32 ms)
    1.24  {
    1.25 -	Uint32 now;
    1.26 +	static Uint32 prev_now = 0;
    1.27 +	Uint32 now, cur_tick;
    1.28 +	int ran_bg_task = 0;
    1.29 +
    1.30 +	now = cur_tick = SDL_GetTicks();
    1.31  
    1.32  	/* No need to loop for delay below resolution */
    1.33  	if (ms<5) {
    1.34 -		SDL_AtariMint_BackgroundTasks();
    1.35 -		if (mint_present) {
    1.36 -			Syield();
    1.37 +		if (prev_now != now) {
    1.38 +			SDL_AtariMint_BackgroundTasks();
    1.39 +			prev_now = now;
    1.40  		}
    1.41  		return;
    1.42  	}
    1.43  
    1.44 -	now = SDL_GetTicks();
    1.45 -	while ((SDL_GetTicks()-now)<ms){
    1.46 +	while (cur_tick-now<ms){
    1.47 +		if (prev_now != cur_tick) {
    1.48 +			SDL_AtariMint_BackgroundTasks();
    1.49 +			prev_now = cur_tick;
    1.50 +			ran_bg_task = 1;
    1.51 +		}
    1.52 +		cur_tick = SDL_GetTicks();
    1.53 +	}
    1.54 +
    1.55 +	if (!ran_bg_task) {
    1.56  		SDL_AtariMint_BackgroundTasks();
    1.57 -		if (mint_present) {
    1.58 -			Syield();
    1.59 -		}
    1.60  	}
    1.61  }
    1.62