SDL standard library

Dependents:   H261_encoder

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SDL_timer.h Source File

SDL_timer.h

Go to the documentation of this file.
00001 /*
00002   Simple DirectMedia Layer
00003   Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
00004 
00005   This software is provided 'as-is', without any express or implied
00006   warranty.  In no event will the authors be held liable for any damages
00007   arising from the use of this software.
00008 
00009   Permission is granted to anyone to use this software for any purpose,
00010   including commercial applications, and to alter it and redistribute it
00011   freely, subject to the following restrictions:
00012 
00013   1. The origin of this software must not be misrepresented; you must not
00014      claim that you wrote the original software. If you use this software
00015      in a product, an acknowledgment in the product documentation would be
00016      appreciated but is not required.
00017   2. Altered source versions must be plainly marked as such, and must not be
00018      misrepresented as being the original software.
00019   3. This notice may not be removed or altered from any source distribution.
00020 */
00021 
00022 #ifndef _SDL_timer_h
00023 #define _SDL_timer_h
00024 
00025 /**
00026  *  \file SDL_timer.h
00027  *
00028  *  Header for the SDL time management routines.
00029  */
00030 
00031 #include "SDL_stdinc.h"
00032 #include "SDL_error.h"
00033 
00034 #include "begin_code.h"
00035 /* Set up for C function definitions, even when using C++ */
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 /**
00041  * \brief Get the number of milliseconds since the SDL library initialization.
00042  *
00043  * \note This value wraps if the program runs for more than ~49 days.
00044  */
00045 extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
00046 
00047 /**
00048  * \brief Compare SDL ticks values, and return true if A has passed B
00049  *
00050  * e.g. if you want to wait 100 ms, you could do this:
00051  *  Uint32 timeout = SDL_GetTicks() + 100;
00052  *  while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
00053  *      ... do work until timeout has elapsed
00054  *  }
00055  */
00056 #define SDL_TICKS_PASSED(A, B)  ((Sint32)((B) - (A)) <= 0)
00057 
00058 /**
00059  * \brief Get the current value of the high resolution counter
00060  */
00061 extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void);
00062 
00063 /**
00064  * \brief Get the count per second of the high resolution counter
00065  */
00066 extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceFrequency(void);
00067 
00068 /**
00069  * \brief Wait a specified number of milliseconds before returning.
00070  */
00071 extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
00072 
00073 /**
00074  *  Function prototype for the timer callback function.
00075  *
00076  *  The callback function is passed the current timer interval and returns
00077  *  the next timer interval.  If the returned value is the same as the one
00078  *  passed in, the periodic alarm continues, otherwise a new alarm is
00079  *  scheduled.  If the callback returns 0, the periodic alarm is cancelled.
00080  */
00081 typedef Uint32 (SDLCALL * SDL_TimerCallback) (Uint32 interval, void *param);
00082 
00083 /**
00084  * Definition of the timer ID type.
00085  */
00086 typedef int SDL_TimerID;
00087 
00088 /**
00089  * \brief Add a new timer to the pool of timers already running.
00090  *
00091  * \return A timer ID, or NULL when an error occurs.
00092  */
00093 extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
00094                                                  SDL_TimerCallback callback,
00095                                                  void *param);
00096 
00097 /**
00098  * \brief Remove a timer knowing its ID.
00099  *
00100  * \return A boolean value indicating success or failure.
00101  *
00102  * \warning It is not safe to remove a timer multiple times.
00103  */
00104 extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id);
00105 
00106 
00107 /* Ends C function definitions when using C++ */
00108 #ifdef __cplusplus
00109 }
00110 #endif
00111 #include "close_code.h"
00112 
00113 #endif /* _SDL_timer_h */
00114 
00115 /* vi: set ts=4 sw=4 expandtab: */