misc/winutils/include/SDL_timer.h
author unc0rr
Fri, 13 Apr 2012 00:08:46 +0400
changeset 6883 70aec33185e2
parent 6560 ca07e6be08d0
child 7809 7d4fb2f35f4f
permissions -rw-r--r--
Support string constants
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6560
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     1
/*
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     3
    Copyright (C) 1997-2009 Sam Lantinga
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     4
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     9
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    13
    Lesser General Public License for more details.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    14
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    18
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    19
    Sam Lantinga
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    20
    slouken@libsdl.org
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    21
*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    22
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    23
#ifndef _SDL_timer_h
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    24
#define _SDL_timer_h
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    25
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    26
/** @file SDL_timer.h
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    27
 *  Header for the SDL time management routines
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    28
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    29
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    30
#include "SDL_stdinc.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    31
#include "SDL_error.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    32
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    33
#include "begin_code.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    34
/* Set up for C function definitions, even when using C++ */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    35
#ifdef __cplusplus
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    36
extern "C" {
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    37
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    38
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    39
/** This is the OS scheduler timeslice, in milliseconds */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    40
#define SDL_TIMESLICE		10
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    41
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    42
/** This is the maximum resolution of the SDL timer on all platforms */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    43
#define TIMER_RESOLUTION	10	/**< Experimentally determined */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    44
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    45
/**
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    46
 * Get the number of milliseconds since the SDL library initialization.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    47
 * Note that this value wraps if the program runs for more than ~49 days.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    48
 */ 
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    49
extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    50
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    51
/** Wait a specified number of milliseconds before returning */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    52
extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    53
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    54
/** Function prototype for the timer callback function */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    55
typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    56
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    57
/**
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    58
 * Set a callback to run after the specified number of milliseconds has
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    59
 * elapsed. The callback function is passed the current timer interval
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    60
 * and returns the next timer interval.  If the returned value is the 
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    61
 * same as the one passed in, the periodic alarm continues, otherwise a
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    62
 * new alarm is scheduled.  If the callback returns 0, the periodic alarm
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    63
 * is cancelled.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    64
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    65
 * To cancel a currently running timer, call SDL_SetTimer(0, NULL);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    66
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    67
 * The timer callback function may run in a different thread than your
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    68
 * main code, and so shouldn't call any functions from within itself.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    69
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    70
 * The maximum resolution of this timer is 10 ms, which means that if
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    71
 * you request a 16 ms timer, your callback will run approximately 20 ms
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    72
 * later on an unloaded system.  If you wanted to set a flag signaling
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    73
 * a frame update at 30 frames per second (every 33 ms), you might set a 
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    74
 * timer for 30 ms:
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    75
 *   @code SDL_SetTimer((33/10)*10, flag_update); @endcode
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    76
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    77
 * If you use this function, you need to pass SDL_INIT_TIMER to SDL_Init().
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    78
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    79
 * Under UNIX, you should not use raise or use SIGALRM and this function
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    80
 * in the same program, as it is implemented using setitimer().  You also
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    81
 * should not use this function in multi-threaded applications as signals
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    82
 * to multi-threaded apps have undefined behavior in some implementations.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    83
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    84
 * This function returns 0 if successful, or -1 if there was an error.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    85
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    86
extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, SDL_TimerCallback callback);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    87
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    88
/** @name New timer API
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    89
 * New timer API, supports multiple timers
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    90
 * Written by Stephane Peter <megastep@lokigames.com>
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    91
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    92
/*@{*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    93
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    94
/**
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    95
 * Function prototype for the new timer callback function.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    96
 * The callback function is passed the current timer interval and returns
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    97
 * the next timer interval.  If the returned value is the same as the one
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    98
 * passed in, the periodic alarm continues, otherwise a new alarm is
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    99
 * scheduled.  If the callback returns 0, the periodic alarm is cancelled.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   100
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   101
typedef Uint32 (SDLCALL *SDL_NewTimerCallback)(Uint32 interval, void *param);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   102
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   103
/** Definition of the timer ID type */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   104
typedef struct _SDL_TimerID *SDL_TimerID;
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   105
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   106
/** Add a new timer to the pool of timers already running.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   107
 *  Returns a timer ID, or NULL when an error occurs.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   108
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   109
extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   110
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   111
/**
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   112
 * Remove one of the multiple timers knowing its ID.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   113
 * Returns a boolean value indicating success.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   114
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   115
extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   116
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   117
/*@}*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   118
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   119
/* Ends C function definitions when using C++ */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   120
#ifdef __cplusplus
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   121
}
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   122
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   123
#include "close_code.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   124
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   125
#endif /* _SDL_timer_h */