You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

116 line
3.4 KiB

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