include/SDL_timer.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 28 May 2015 01:54:52 -0400
changeset 9671 0e1f57b051f4
parent 9619 b94b6d0bff0f
child 9847 adc0f20968ae
permissions -rw-r--r--
Windows GetBasePath should use GetModuleFileNameExW() and check for overflows.

Apparently you might get strange paths from GetModuleFileName(), such as
short path names or UNC filenames, so this avoids that problem. Since you have
to tapdance with linking different libraries and defining macros depending on
what Windows you plan to target, we dynamically load the API we need, which
works on all versions of Windows (on Win7, it'll load a compatibility wrapper
for the newer API location).

What a mess.

This also now does the right thing if there isn't enough space to store the
path, looping with a larger allocated buffer each try.

Fixes Bugzilla #2435.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@9619
     3
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
slouken@0
    21
slouken@0
    22
#ifndef _SDL_timer_h
slouken@0
    23
#define _SDL_timer_h
slouken@0
    24
slouken@1895
    25
/**
slouken@3407
    26
 *  \file SDL_timer.h
slouken@7191
    27
 *
slouken@3407
    28
 *  Header for the SDL time management routines.
slouken@1895
    29
 */
slouken@0
    30
slouken@1356
    31
#include "SDL_stdinc.h"
slouken@1358
    32
#include "SDL_error.h"
slouken@0
    33
slouken@0
    34
#include "begin_code.h"
slouken@0
    35
/* Set up for C function definitions, even when using C++ */
slouken@0
    36
#ifdef __cplusplus
slouken@0
    37
extern "C" {
slouken@0
    38
#endif
slouken@0
    39
slouken@3407
    40
/**
slouken@5111
    41
 * \brief Get the number of milliseconds since the SDL library initialization.
slouken@7191
    42
 *
slouken@5111
    43
 * \note This value wraps if the program runs for more than ~49 days.
slouken@1895
    44
 */
slouken@337
    45
extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
slouken@0
    46
slouken@3407
    47
/**
slouken@7857
    48
 * \brief Compare SDL ticks values, and return true if A has passed B
slouken@7857
    49
 *
slouken@7857
    50
 * e.g. if you want to wait 100 ms, you could do this:
slouken@7857
    51
 *  Uint32 timeout = SDL_GetTicks() + 100;
slouken@7857
    52
 *  while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
slouken@7857
    53
 *      ... do work until timeout has elapsed
slouken@7857
    54
 *  }
slouken@7857
    55
 */
slouken@7857
    56
#define SDL_TICKS_PASSED(A, B)  ((Sint32)((B) - (A)) <= 0)
slouken@7857
    57
slouken@7857
    58
/**
slouken@5514
    59
 * \brief Get the current value of the high resolution counter
slouken@5514
    60
 */
slouken@5514
    61
extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void);
slouken@5514
    62
slouken@5514
    63
/**
slouken@5514
    64
 * \brief Get the count per second of the high resolution counter
slouken@5514
    65
 */
slouken@5514
    66
extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceFrequency(void);
slouken@5514
    67
slouken@5514
    68
/**
slouken@5111
    69
 * \brief Wait a specified number of milliseconds before returning.
slouken@3407
    70
 */
slouken@337
    71
extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
slouken@0
    72
slouken@3407
    73
/**
slouken@3407
    74
 *  Function prototype for the timer callback function.
slouken@7191
    75
 *
slouken@3407
    76
 *  The callback function is passed the current timer interval and returns
slouken@3407
    77
 *  the next timer interval.  If the returned value is the same as the one
slouken@3407
    78
 *  passed in, the periodic alarm continues, otherwise a new alarm is
slouken@3407
    79
 *  scheduled.  If the callback returns 0, the periodic alarm is cancelled.
slouken@0
    80
 */
slouken@5111
    81
typedef Uint32 (SDLCALL * SDL_TimerCallback) (Uint32 interval, void *param);
slouken@0
    82
slouken@3407
    83
/**
slouken@5111
    84
 * Definition of the timer ID type.
slouken@3407
    85
 */
slouken@5111
    86
typedef int SDL_TimerID;
slouken@0
    87
slouken@3407
    88
/**
slouken@5111
    89
 * \brief Add a new timer to the pool of timers already running.
slouken@5111
    90
 *
slouken@5111
    91
 * \return A timer ID, or NULL when an error occurs.
slouken@0
    92
 */
slouken@1895
    93
extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
slouken@5111
    94
                                                 SDL_TimerCallback callback,
slouken@5111
    95
                                                 void *param);
slouken@0
    96
slouken@3407
    97
/**
slouken@5111
    98
 * \brief Remove a timer knowing its ID.
slouken@5111
    99
 *
slouken@5111
   100
 * \return A boolean value indicating success or failure.
slouken@5111
   101
 *
slouken@5111
   102
 * \warning It is not safe to remove a timer multiple times.
slouken@0
   103
 */
slouken@6119
   104
extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id);
slouken@0
   105
slouken@3407
   106
slouken@0
   107
/* Ends C function definitions when using C++ */
slouken@0
   108
#ifdef __cplusplus
slouken@0
   109
}
slouken@0
   110
#endif
slouken@0
   111
#include "close_code.h"
slouken@0
   112
slouken@0
   113
#endif /* _SDL_timer_h */
slouken@1895
   114
slouken@1895
   115
/* vi: set ts=4 sw=4 expandtab: */