1 
2 //          Copyright 2018 - 2022 Michael D. Parker
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.sdl.bind.sdltimer;
8 
9 import bindbc.sdl.config;
10 import bindbc.sdl.bind.sdlstdinc : SDL_bool;
11 
12 extern(C) nothrow alias SDL_TimerCallback = uint function(uint interval, void* param);
13 alias SDL_TimerID = int;
14 
15 // This was added to SDL 2.0.1 as a macro, but it's
16 // useful & has no dependency on the library version,
17 // so it's here for 2.0.0 as well.
18 @nogc nothrow pure
19 bool SDL_TICKS_PASSED(uint A, uint B) {
20     pragma(inline, true);
21     return cast(int)(B - A) <= 0;
22 }
23 
24 static if(staticBinding) {
25     extern(C) @nogc nothrow {
26         uint SDL_GetTicks();
27         ulong SDL_GetPerformanceCounter();
28         ulong SDL_GetPerformanceFrequency();
29         void SDL_Delay(uint ms);
30         SDL_TimerID SDL_AddTimer(uint interval, SDL_TimerCallback callback, void* param);
31         SDL_bool SDL_RemoveTimer(SDL_TimerID id);
32         
33         static if(sdlSupport >= SDLSupport.sdl2018) {
34             ulong SDL_GetTicks64();
35         }
36     }
37 }
38 else {
39     extern(C) @nogc nothrow {
40         alias pSDL_GetTicks = uint function();
41         alias pSDL_GetPerformanceCounter = ulong function();
42         alias pSDL_GetPerformanceFrequency = ulong function();
43         alias pSDL_Delay = void function(uint ms);
44         alias pSDL_AddTimer = SDL_TimerID function(uint interval, SDL_TimerCallback callback, void* param);
45         alias pSDL_RemoveTimer = SDL_bool function(SDL_TimerID id);
46     }
47 
48     __gshared {
49         pSDL_GetTicks SDL_GetTicks;
50         pSDL_GetPerformanceCounter SDL_GetPerformanceCounter;
51         pSDL_GetPerformanceFrequency SDL_GetPerformanceFrequency;
52         pSDL_Delay SDL_Delay;
53         pSDL_AddTimer SDL_AddTimer;
54         pSDL_RemoveTimer SDL_RemoveTimer;
55     }
56     
57     static if(sdlSupport >= SDLSupport.sdl2018) {
58         extern(C) @nogc nothrow {
59             alias pSDL_GetTicks64 = ulong function();
60         }
61         __gshared {
62             pSDL_GetTicks64 SDL_GetTicks64;
63         }
64     }
65 }