include/SDL_timer.h
changeset 0 74212992fb08
child 251 b8688cfdc232
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/SDL_timer.h	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,118 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +#ifndef _SDL_timer_h
    1.32 +#define _SDL_timer_h
    1.33 +
    1.34 +/* Header for the SDL time management routines */
    1.35 +
    1.36 +#include "SDL_main.h"
    1.37 +#include "SDL_types.h"
    1.38 +
    1.39 +#include "begin_code.h"
    1.40 +/* Set up for C function definitions, even when using C++ */
    1.41 +#ifdef __cplusplus
    1.42 +extern "C" {
    1.43 +#endif
    1.44 +
    1.45 +/* This is the OS scheduler timeslice, in milliseconds */
    1.46 +#define SDL_TIMESLICE		10
    1.47 +
    1.48 +/* This is the maximum resolution of the SDL timer on all platforms */
    1.49 +#define TIMER_RESOLUTION	10	/* Experimentally determined */
    1.50 +
    1.51 +/* Get the number of milliseconds since the SDL library initialization.
    1.52 + * Note that this value wraps if the program runs for more than ~49 days.
    1.53 + */ 
    1.54 +extern DECLSPEC Uint32 SDL_GetTicks(void);
    1.55 +
    1.56 +/* Wait a specified number of milliseconds before returning */
    1.57 +extern DECLSPEC void SDL_Delay(Uint32 ms);
    1.58 +
    1.59 +/* Function prototype for the timer callback function */
    1.60 +typedef Uint32 (*SDL_TimerCallback)(Uint32 interval);
    1.61 +
    1.62 +/* Set a callback to run after the specified number of milliseconds has
    1.63 + * elapsed. The callback function is passed the current timer interval
    1.64 + * and returns the next timer interval.  If the returned value is the 
    1.65 + * same as the one passed in, the periodic alarm continues, otherwise a
    1.66 + * new alarm is scheduled.  If the callback returns 0, the periodic alarm
    1.67 + * is cancelled.
    1.68 + *
    1.69 + * To cancel a currently running timer, call SDL_SetTimer(0, NULL);
    1.70 + *
    1.71 + * The timer callback function may run in a different thread than your
    1.72 + * main code, and so shouldn't call any functions from within itself.
    1.73 + *
    1.74 + * The maximum resolution of this timer is 10 ms, which means that if
    1.75 + * you request a 16 ms timer, your callback will run approximately 20 ms
    1.76 + * later on an unloaded system.  If you wanted to set a flag signaling
    1.77 + * a frame update at 30 frames per second (every 33 ms), you might set a 
    1.78 + * timer for 30 ms:
    1.79 + *   SDL_SetTimer((33/10)*10, flag_update);
    1.80 + *
    1.81 + * If you use this function, you need to pass SDL_INIT_TIMER to SDL_Init().
    1.82 + *
    1.83 + * Under UNIX, you should not use raise or use SIGALRM and this function
    1.84 + * in the same program, as it is implemented using setitimer().  You also
    1.85 + * should not use this function in multi-threaded applications as signals
    1.86 + * to multi-threaded apps have undefined behavior in some implementations.
    1.87 + */
    1.88 +extern DECLSPEC int SDL_SetTimer(Uint32 interval, SDL_TimerCallback callback);
    1.89 +
    1.90 +/* New timer API, supports multiple timers
    1.91 + * Written by Stephane Peter <megastep@lokigames.com>
    1.92 + */
    1.93 +
    1.94 +/* Function prototype for the new timer callback function.
    1.95 + * The callback function is passed the current timer interval and returns
    1.96 + * the next timer interval.  If the returned value is the same as the one
    1.97 + * passed in, the periodic alarm continues, otherwise a new alarm is
    1.98 + * scheduled.  If the callback returns 0, the periodic alarm is cancelled.
    1.99 + */
   1.100 +typedef Uint32 (*SDL_NewTimerCallback)(Uint32 interval, void *param);
   1.101 +
   1.102 +/* Definition of the timer ID type */
   1.103 +typedef struct _SDL_TimerID *SDL_TimerID;
   1.104 +
   1.105 +/* Add a new timer to the pool of timers already running.
   1.106 +   Returns a timer ID, or NULL when an error occurs.
   1.107 + */
   1.108 +extern DECLSPEC SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param);
   1.109 +
   1.110 +/* Remove one of the multiple timers knowing its ID.
   1.111 + * Returns a boolean value indicating success.
   1.112 + */
   1.113 +extern DECLSPEC SDL_bool SDL_RemoveTimer(SDL_TimerID t);
   1.114 +
   1.115 +/* Ends C function definitions when using C++ */
   1.116 +#ifdef __cplusplus
   1.117 +}
   1.118 +#endif
   1.119 +#include "close_code.h"
   1.120 +
   1.121 +#endif /* _SDL_timer_h */