sdltimer.inc 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // based on "sdl_timer.h" (2.0.14)
  2. {**
  3. * Get the number of milliseconds since the SDL library initialization.
  4. *
  5. * This value wraps if the program runs for more than ~49 days.
  6. *}
  7. function SDL_GetTicks: cuint32; cdecl;
  8. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetTicks' {$ENDIF} {$ENDIF};
  9. {**
  10. * Get the number of milliseconds since SDL library initialization.
  11. *
  12. * Note that you should not use the SDL_TICKS_PASSED macro with values
  13. * returned by this function, as that macro does clever math to compensate for
  14. * the 32-bit overflow every ~49 days that SDL_GetTicks() suffers from. 64-bit
  15. * values from this function can be safely compared directly.
  16. *}
  17. function SDL_GetTicks64: cuint64; cdecl;
  18. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetTicks64' {$ENDIF} {$ENDIF};
  19. {**
  20. * \brief Compare SDL ticks values, and return true if A has passed B
  21. *
  22. * e.g. if you want to wait 100 ms, you could do this:
  23. * Uint32 timeout = SDL_GetTicks() + 100;
  24. * while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) [
  25. * ... do work until timeout has elapsed
  26. * ]
  27. *}
  28. // #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
  29. { Type conversion unnecessary bc. types are declared in func. param. list! }
  30. function SDL_TICKS_PASSED(const A, B: cint32): Boolean;
  31. {**
  32. * Get the current value of the high resolution counter
  33. *}
  34. function SDL_GetPerformanceCounter: cuint64; cdecl;
  35. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetPerformanceCounter' {$ENDIF} {$ENDIF};
  36. {**
  37. * Get the count per second of the high resolution counter
  38. *}
  39. function SDL_GetPerformanceFrequency: cuint64; cdecl;
  40. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetPerformanceFrequency' {$ENDIF} {$ENDIF};
  41. {**
  42. * Wait a specified number of milliseconds before returning.
  43. *}
  44. procedure SDL_Delay(ms: cuint32); cdecl;
  45. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Delay' {$ENDIF} {$ENDIF};
  46. type
  47. {**
  48. * Function prototype for the timer callback function.
  49. *
  50. * The callback function is passed the current timer interval and returns
  51. * the next timer interval. If the returned value is the same as the one
  52. * passed in, the periodic alarm continues, otherwise a new alarm is
  53. * scheduled. If the callback returns 0, the periodic alarm is cancelled.
  54. *}
  55. PPSDL_TimerCallback = ^PSDL_TimerCallback;
  56. PSDL_TimerCallback = ^TSDL_TimerCallback;
  57. TSDL_TimerCallback = function(interval: cuint32; param: Pointer): cuint32; cdecl;
  58. {**
  59. * Definition of the timer ID type.
  60. *}
  61. PPSDL_TimerID = ^PSDL_TimerID;
  62. PSDL_TimerID = ^TSDL_TimerID;
  63. TSDL_TimerID = cint;
  64. {**
  65. * Add a new timer to the pool of timers already running.
  66. *
  67. * A timer ID, or NULL when an error occurs.
  68. *}
  69. function SDL_AddTimer(interval: cuint32; callback: TSDL_TimerCallback; param: Pointer): TSDL_TimerID; cdecl;
  70. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AddTimer' {$ENDIF} {$ENDIF};
  71. {**
  72. * Remove a timer knowing its ID.
  73. *
  74. * A boolean value indicating success or failure.
  75. *
  76. * It is not safe to remove a timer multiple times.
  77. *}
  78. function SDL_RemoveTimer(id: TSDL_TimerID): Boolean; cdecl;
  79. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RemoveTimer' {$ENDIF} {$ENDIF};