Timers

/*
  timer.c
  
  SDL Example
  Use SDL's timer system to call a
  function progressively faster
  
  Bill Kendrick
  1/2000
*/


#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>


int flag;


Uint32 setflag(Uint32 interval)
{
  flag = 1;
  
  return(interval / 2);
}


int main(int argc, char * argv[])
{
  int i;
  
  
  /* Init SDL: */
  
  SDL_Init(SDL_INIT_TIMER);

  
  /* Set the timer: */
  
  flag = 0;
  SDL_SetTimer(10000, setflag);
  
  
  /* A little 25-second loop: */
  
  for (i = 0; i < 20; i++)
    {
      /* Show a countdown: */
      
      printf("%d\n", 20 - i);
      
      
      /* Show if the flag was set
	 during the last second.
	 (Clear it, too): */
      
      if (flag == 1)
	{
	  printf("Flag was set!\n");
	  flag = 0;
	}
      
      SDL_Delay(1000);
    }
  
  
  /* Close up and quit: */
  
  SDL_Quit();
  
  return(0);
}