mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-05 21:44:40 +00:00
Added the timerID to the SDL timer callback
Fixes https://github.com/libsdl-org/SDL/issues/2593
This commit is contained in:
@@ -101,7 +101,7 @@ static int timer_delayAndGetTicks(void *arg)
|
||||
}
|
||||
|
||||
/* Test callback */
|
||||
static Uint32 SDLCALL timerTestCallback(Uint32 interval, void *param)
|
||||
static Uint32 SDLCALL timerTestCallback(void *param, SDL_TimerID timerID, Uint32 interval)
|
||||
{
|
||||
g_timerCallbackCalled = 1;
|
||||
|
||||
@@ -121,7 +121,7 @@ static Uint32 SDLCALL timerTestCallback(Uint32 interval, void *param)
|
||||
static int timer_addRemoveTimer(void *arg)
|
||||
{
|
||||
SDL_TimerID id;
|
||||
SDL_bool result;
|
||||
int result;
|
||||
int param;
|
||||
|
||||
/* Reset state */
|
||||
@@ -136,13 +136,13 @@ static int timer_addRemoveTimer(void *arg)
|
||||
/* Remove timer again and check that callback was not called */
|
||||
result = SDL_RemoveTimer(id);
|
||||
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
|
||||
SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
|
||||
SDLTest_AssertCheck(result == 0, "Check result value, expected: 0, got: %i", result);
|
||||
SDLTest_AssertCheck(g_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", g_timerCallbackCalled);
|
||||
|
||||
/* Try to remove timer again (should be a NOOP) */
|
||||
result = SDL_RemoveTimer(id);
|
||||
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
|
||||
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
|
||||
SDLTest_AssertCheck(result < 0, "Check result value, expected: <0, got: %i", result);
|
||||
|
||||
/* Reset state */
|
||||
param = SDLTest_RandomIntegerInRange(-1024, 1024);
|
||||
@@ -162,7 +162,7 @@ static int timer_addRemoveTimer(void *arg)
|
||||
/* Remove timer again and check that callback was called */
|
||||
result = SDL_RemoveTimer(id);
|
||||
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
|
||||
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
|
||||
SDLTest_AssertCheck(result < 0, "Check result value, expected: <0, got: %i", result);
|
||||
SDLTest_AssertCheck(g_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", g_timerCallbackCalled);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
|
||||
@@ -100,7 +100,7 @@ Run(void *data)
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
static Uint32 hit_timeout(Uint32 interval, void *param) {
|
||||
static Uint32 hit_timeout(void *param, SDL_TimerID timerID, Uint32 interval) {
|
||||
SDL_Log("Hit timeout! Sending SIGINT!");
|
||||
(void)raise(SIGINT);
|
||||
return 0;
|
||||
|
||||
@@ -50,16 +50,18 @@ static int test_sdl_delay_within_bounds(void) {
|
||||
static int ticks = 0;
|
||||
|
||||
static Uint32 SDLCALL
|
||||
ticktock(Uint32 interval, void *param)
|
||||
ticktock(void *param, SDL_TimerID timerID, Uint32 interval)
|
||||
{
|
||||
++ticks;
|
||||
return interval;
|
||||
}
|
||||
|
||||
static Uint32 SDLCALL
|
||||
callback(Uint32 interval, void *param)
|
||||
callback(void *param, SDL_TimerID timerID, Uint32 interval)
|
||||
{
|
||||
SDL_Log("Timer %" SDL_PRIu32 " : param = %d\n", interval, (int)(uintptr_t)param);
|
||||
int value = (int)(uintptr_t)param;
|
||||
SDL_assert( value == 1 || value == 2 || value == 3 );
|
||||
SDL_Log("Timer %" SDL_PRIu32 " : param = %d\n", interval, value);
|
||||
return interval;
|
||||
}
|
||||
|
||||
@@ -182,7 +184,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
start_perf = SDL_GetPerformanceCounter();
|
||||
for (i = 0; i < 1000000; ++i) {
|
||||
ticktock(0, NULL);
|
||||
ticktock(NULL, 0, 0);
|
||||
}
|
||||
now_perf = SDL_GetPerformanceCounter();
|
||||
SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now_perf - start_perf) * 1000) / SDL_GetPerformanceFrequency());
|
||||
|
||||
Reference in New Issue
Block a user