Updated SDL_TimerID to use the same type as other IDs in SDL

main
Sam Lantinga 2024-01-18 05:07:28 -08:00
parent bc3a71d400
commit d6a41f8f31
3 changed files with 8 additions and 12 deletions

View File

@ -137,7 +137,7 @@ typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval, void *param);
/** /**
* Definition of the timer ID type. * Definition of the timer ID type.
*/ */
typedef int SDL_TimerID; typedef Uint32 SDL_TimerID;
/** /**
* Call a callback function at a future time. * Call a callback function at a future time.

View File

@ -29,7 +29,7 @@
typedef struct SDL_Timer typedef struct SDL_Timer
{ {
int timerID; SDL_TimerID timerID;
SDL_TimerCallback callback; SDL_TimerCallback callback;
void *param; void *param;
Uint64 interval; Uint64 interval;
@ -40,7 +40,7 @@ typedef struct SDL_Timer
typedef struct SDL_TimerMap typedef struct SDL_TimerMap
{ {
int timerID; SDL_TimerID timerID;
SDL_Timer *timer; SDL_Timer *timer;
struct SDL_TimerMap *next; struct SDL_TimerMap *next;
} SDL_TimerMap; } SDL_TimerMap;
@ -50,7 +50,6 @@ typedef struct
{ {
/* Data used by the main thread */ /* Data used by the main thread */
SDL_Thread *thread; SDL_Thread *thread;
SDL_AtomicInt nextID;
SDL_TimerMap *timermap; SDL_TimerMap *timermap;
SDL_Mutex *timermap_lock; SDL_Mutex *timermap_lock;
@ -227,8 +226,6 @@ int SDL_InitTimers(void)
SDL_QuitTimers(); SDL_QuitTimers();
return -1; return -1;
} }
SDL_AtomicSet(&data->nextID, 1);
} }
return 0; return 0;
} }
@ -300,7 +297,7 @@ SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *para
return 0; return 0;
} }
} }
timer->timerID = SDL_AtomicIncRef(&data->nextID); timer->timerID = SDL_GetNextObjectID();
timer->callback = callback; timer->callback = callback;
timer->param = param; timer->param = param;
timer->interval = SDL_MS_TO_NS(interval); timer->interval = SDL_MS_TO_NS(interval);
@ -370,7 +367,7 @@ SDL_bool SDL_RemoveTimer(SDL_TimerID id)
typedef struct SDL_TimerMap typedef struct SDL_TimerMap
{ {
int timerID; SDL_TimerID timerID;
int timeoutID; int timeoutID;
Uint32 interval; Uint32 interval;
SDL_TimerCallback callback; SDL_TimerCallback callback;
@ -380,7 +377,6 @@ typedef struct SDL_TimerMap
typedef struct typedef struct
{ {
int nextID;
SDL_TimerMap *timermap; SDL_TimerMap *timermap;
} SDL_TimerData; } SDL_TimerData;
@ -423,7 +419,7 @@ SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *para
if (!entry) { if (!entry) {
return 0; return 0;
} }
entry->timerID = ++data->nextID; entry->timerID = SDL_GetNextObjectID();
entry->callback = callback; entry->callback = callback;
entry->param = param; entry->param = param;
entry->interval = interval; entry->interval = interval;

View File

@ -131,7 +131,7 @@ static int timer_addRemoveTimer(void *arg)
/* Set timer with a long delay */ /* Set timer with a long delay */
id = SDL_AddTimer(10000, timerTestCallback, NULL); id = SDL_AddTimer(10000, timerTestCallback, NULL);
SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)"); SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id); SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, id);
/* Remove timer again and check that callback was not called */ /* Remove timer again and check that callback was not called */
result = SDL_RemoveTimer(id); result = SDL_RemoveTimer(id);
@ -153,7 +153,7 @@ static int timer_addRemoveTimer(void *arg)
/* Set timer with a short delay */ /* Set timer with a short delay */
id = SDL_AddTimer(10, timerTestCallback, (void *)&param); id = SDL_AddTimer(10, timerTestCallback, (void *)&param);
SDLTest_AssertPass("Call to SDL_AddTimer(10, param)"); SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id); SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, id);
/* Wait to let timer trigger callback */ /* Wait to let timer trigger callback */
SDL_Delay(100); SDL_Delay(100);