summaryrefslogtreecommitdiff
path: root/include/SDL_timer.h
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2013-10-20 20:42:55 -0700
committerSam Lantinga <slouken@libsdl.org>2013-10-20 20:42:55 -0700
commitee2991652cf03e5f0ef29176981a5c0da376326c (patch)
tree1654e9be4f8edc960edb07ba66d4046887aad9cb /include/SDL_timer.h
parent42b4cbb3717b2b9ce0b86892efc1838116d940c2 (diff)
Added a macro SDL_TICKS_PASSED() to correctly compare two 32-bit tick values.
Went through the code and used the macro and fixed a couple places that were using incorrect timestamp comparisons.
Diffstat (limited to 'include/SDL_timer.h')
-rw-r--r--include/SDL_timer.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/SDL_timer.h b/include/SDL_timer.h
index e065cf4f9f..28ab415b40 100644
--- a/include/SDL_timer.h
+++ b/include/SDL_timer.h
@@ -45,6 +45,17 @@ extern "C" {
extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
/**
+ * \brief Compare SDL ticks values, and return true if A has passed B
+ *
+ * e.g. if you want to wait 100 ms, you could do this:
+ * Uint32 timeout = SDL_GetTicks() + 100;
+ * while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
+ * ... do work until timeout has elapsed
+ * }
+ */
+#define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
+
+/**
* \brief Get the current value of the high resolution counter
*/
extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void);