blob: af116b627691f383e4b7b16aa1b33acffcb3ad64 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <SDL2/SDL.h>
#include "./constants.h"
int last_frame_time = 0;
void delay(void) {
// logic to keep a fixed timestep
int time_to_wait = FRAME_TARGET_TIME - (SDL_GetTicks() - last_frame_time);
if(time_to_wait > 0 && time_to_wait <= FRAME_TARGET_TIME) {
SDL_Delay(time_to_wait);
}
}
float get_delta_time() {
// get a delta time factor converted to seconds
float delta_time = (SDL_GetTicks() - last_frame_time) / 1000.0f;
last_frame_time = SDL_GetTicks();
return delta_time;
}
|