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