include/SDL_timer.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 25 Mar 2011 14:45:04 -0700
changeset 5514 6bd701987ba9
parent 5262 b530ef003506
child 5535 96594ac5fd1a
permissions -rw-r--r--
Added high resolution timing API: SDL_GetPerformanceCounter(), SDL_GetPerformanceFrequency()
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2011 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 #ifndef _SDL_timer_h
    24 #define _SDL_timer_h
    25 
    26 /**
    27  *  \file SDL_timer.h
    28  *  
    29  *  Header for the SDL time management routines.
    30  */
    31 
    32 #include "SDL_stdinc.h"
    33 #include "SDL_error.h"
    34 
    35 #include "begin_code.h"
    36 /* Set up for C function definitions, even when using C++ */
    37 #ifdef __cplusplus
    38 /* *INDENT-OFF* */
    39 extern "C" {
    40 /* *INDENT-ON* */
    41 #endif
    42 
    43 /**
    44  * \brief Get the number of milliseconds since the SDL library initialization.
    45  *  
    46  * \note This value wraps if the program runs for more than ~49 days.
    47  */
    48 extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
    49 
    50 /**
    51  * \brief Get the current value of the high resolution counter
    52  */
    53 extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void);
    54 
    55 /**
    56  * \brief Get the count per second of the high resolution counter
    57  */
    58 extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceFrequency(void);
    59 
    60 /**
    61  * \brief Wait a specified number of milliseconds before returning.
    62  */
    63 extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
    64 
    65 /**
    66  *  Function prototype for the timer callback function.
    67  *  
    68  *  The callback function is passed the current timer interval and returns
    69  *  the next timer interval.  If the returned value is the same as the one
    70  *  passed in, the periodic alarm continues, otherwise a new alarm is
    71  *  scheduled.  If the callback returns 0, the periodic alarm is cancelled.
    72  */
    73 typedef Uint32 (SDLCALL * SDL_TimerCallback) (Uint32 interval, void *param);
    74 
    75 /**
    76  * Definition of the timer ID type.
    77  */
    78 typedef int SDL_TimerID;
    79 
    80 /**
    81  * \brief Add a new timer to the pool of timers already running.
    82  *
    83  * \return A timer ID, or NULL when an error occurs.
    84  */
    85 extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
    86                                                  SDL_TimerCallback callback,
    87                                                  void *param);
    88 
    89 /**
    90  * \brief Remove a timer knowing its ID.
    91  *
    92  * \return A boolean value indicating success or failure.
    93  *
    94  * \warning It is not safe to remove a timer multiple times.
    95  */
    96 extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t);
    97 
    98 
    99 /* Ends C function definitions when using C++ */
   100 #ifdef __cplusplus
   101 /* *INDENT-OFF* */
   102 }
   103 /* *INDENT-ON* */
   104 #endif
   105 #include "close_code.h"
   106 
   107 #endif /* _SDL_timer_h */
   108 
   109 /* vi: set ts=4 sw=4 expandtab: */