test/testtimer.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 09 May 2006 07:26:58 +0000
changeset 1790 828a17e05192
parent 1769 290b5baf2fca
child 1662 782fd950bd46
child 1895 c121d94672cb
permissions -rw-r--r--
Date: Mon, 8 May 2006 14:19:30 -0700
From: Bob Ippolito
Subject: SDL trunk (r2346) and Mac OS X

The current state of the trunk doesn't quite compile on Mac OS X,
I've attached a series of patches that gets it to compile and kills a
few warnings.

sdl-trunk-r2346-dlcompat-warnings.diff:
The dlcompat thing is just loaded with incorrect type signatures ..
some of them have changed since 10.2 and others are just flat wrong.
This puts it in sync with the latest headers. People on 10.2 will get
the warnings instead of people with new kits.
slouken@0
     1
slouken@0
     2
/* Test program to check the resolution of the SDL timer on the current
slouken@0
     3
   platform
slouken@0
     4
*/
slouken@0
     5
slouken@0
     6
#include <stdlib.h>
slouken@0
     7
#include <stdio.h>
slouken@0
     8
slouken@0
     9
#include "SDL.h"
slouken@0
    10
slouken@0
    11
#define DEFAULT_RESOLUTION	1
slouken@0
    12
slouken@0
    13
static int ticks = 0;
slouken@0
    14
slouken@1769
    15
static Uint32 SDLCALL ticktock(Uint32 interval)
slouken@0
    16
{
slouken@0
    17
	++ticks;
slouken@0
    18
	return(interval);
slouken@0
    19
}
slouken@0
    20
slouken@1769
    21
static Uint32 SDLCALL callback(Uint32 interval, void *param)
slouken@0
    22
{
slouken@1615
    23
  printf("Timer %d : param = %d\n", interval, (int)(uintptr_t)param);
slouken@0
    24
  return interval;
slouken@0
    25
}
slouken@0
    26
slouken@0
    27
int main(int argc, char *argv[])
slouken@0
    28
{
slouken@0
    29
	int desired;
slouken@0
    30
	SDL_TimerID t1, t2, t3;
slouken@0
    31
slouken@0
    32
	if ( SDL_Init(SDL_INIT_TIMER) < 0 ) {
slouken@1484
    33
		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
icculus@1151
    34
		return(1);
slouken@0
    35
	}
slouken@0
    36
slouken@0
    37
	/* Start the timer */
slouken@0
    38
	desired = 0;
slouken@0
    39
	if ( argv[1] ) {
slouken@0
    40
		desired = atoi(argv[1]);
slouken@0
    41
	}
slouken@0
    42
	if ( desired == 0 ) {
slouken@0
    43
		desired = DEFAULT_RESOLUTION;
slouken@0
    44
	}
slouken@0
    45
	SDL_SetTimer(desired, ticktock);
slouken@0
    46
slouken@0
    47
	/* Wait 10 seconds */
slouken@0
    48
	printf("Waiting 10 seconds\n");
slouken@0
    49
	SDL_Delay(10*1000);
slouken@0
    50
slouken@0
    51
	/* Stop the timer */
slouken@0
    52
	SDL_SetTimer(0, NULL);
slouken@0
    53
slouken@0
    54
	/* Print the results */
slouken@0
    55
	if ( ticks ) {
slouken@0
    56
		fprintf(stderr,
slouken@0
    57
		"Timer resolution: desired = %d ms, actual = %f ms\n",
slouken@0
    58
					desired, (double)(10*1000)/ticks);
slouken@0
    59
	}
slouken@0
    60
	
slouken@0
    61
	/* Test multiple timers */
slouken@0
    62
	printf("Testing multiple timers...\n");
slouken@0
    63
	t1 = SDL_AddTimer(100, callback, (void*)1);
slouken@0
    64
	if(!t1)
slouken@766
    65
	  fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError());
slouken@0
    66
	t2 = SDL_AddTimer(50, callback, (void*)2);
slouken@0
    67
	if(!t2)
slouken@766
    68
	  fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError());
slouken@0
    69
	t3 = SDL_AddTimer(233, callback, (void*)3);
slouken@0
    70
	if(!t3)
slouken@766
    71
	  fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError());
slouken@0
    72
	
slouken@0
    73
	/* Wait 10 seconds */
slouken@0
    74
	printf("Waiting 10 seconds\n");
slouken@0
    75
	SDL_Delay(10*1000);
slouken@0
    76
slouken@0
    77
	printf("Removing timer 1 and waiting 5 more seconds\n");
slouken@0
    78
	SDL_RemoveTimer(t1);
slouken@0
    79
slouken@0
    80
	SDL_Delay(5*1000);
slouken@0
    81
slouken@0
    82
	SDL_RemoveTimer(t2);
slouken@0
    83
	SDL_RemoveTimer(t3);
slouken@0
    84
icculus@1151
    85
	SDL_Quit();
slouken@0
    86
	return(0);
slouken@0
    87
}