File tree 2 files changed +18
-5
lines changed 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 20
20
#include <stdbool.h>
21
21
#include <stdint.h>
22
22
23
+ #define FPS 60
24
+
23
25
extern void InitializePlatform (void );
24
26
25
27
/*
Original file line number Diff line number Diff line change 25
25
#include "platform.h"
26
26
27
27
static Uint32 LastTicks = 0 ;
28
+ static Uint32 TicksElapsed = 0 ;
28
29
29
30
void InitializePlatform (void )
30
31
{
@@ -33,11 +34,21 @@ void InitializePlatform(void)
33
34
34
35
Uint32 ToNextFrame (void )
35
36
{
36
- SDL_Delay (8 );
37
- Uint32 Ticks = SDL_GetTicks ();
38
- Uint32 Duration = Ticks - LastTicks ;
39
- LastTicks = Ticks ;
40
- return Duration ;
37
+ const Uint32 duration = 1000 / FPS ;
38
+ for (;;)
39
+ {
40
+ Uint32 Ticks = SDL_GetTicks ();
41
+ TicksElapsed += Ticks - LastTicks ;
42
+ LastTicks = Ticks ;
43
+ if (TicksElapsed <= duration )
44
+ {
45
+ SDL_Delay (1 );
46
+ continue ;
47
+ }
48
+ break ;
49
+ }
50
+ TicksElapsed -= duration ;
51
+ return duration ;
41
52
}
42
53
43
54
bool IsEnterGamePressingEvent (const SDL_Event * event )
You can’t perform that action at this time.
0 commit comments