6. SDL_bool SDL_RemoveTimer(SDL_TimerID id): 删除给定id的定时器,返回值表示是否删除成功.
示例源码:
#include "SDL.h" void testfunc() { } Uint32 callback(Uint32 interval, void *param) { SDL_Log("current time: %d ms.\n", SDL_GetTicks()); return interval; } int main() { Uint32 start32; Uint32 loop_count = 50000; Uint64 start, now; if (SDL_Init(SDL_INIT_TIMER) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL Timer SubSystem: %s\n", SDL_GetError()); } start32 = SDL_GetTicks(); start = SDL_GetPerformanceCounter(); for (Uint32 i = 0; i < loop_count; ++i) { testfunc(); } SDL_Log("%d times function call take %d ms\n", loop_count, SDL_GetTicks() - start32); now = SDL_GetPerformanceCounter(); SDL_Log("%d times function call take %f ms \n", loop_count, (double)(now - start) * 1000 / SDL_GetPerformanceFrequency()); SDL_TimerID timer = SDL_AddTimer(100, callback, NULL); if (NULL == timer) { SDL_Log("add timer fail: %s\n", SDL_GetError()); } Uint32 test = 100; while (test--) { SDL_Delay(100); } if (SDL_TRUE != SDL_RemoveTimer(timer)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Remove timer fail: %s\n", SDL_GetError()); } <span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>SDL_Quit(); return 0; }