-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrealmain.c
50 lines (38 loc) · 808 Bytes
/
realmain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include "testlib.h"
#include "game.h"
#define min_time 18
#define max_time 100
int last_time;
int loop_once() {
int new_time;
InputState state = frame_inputstate();
if(state->quit_requested) {
lib_shutdown();
return 0;
}
/* check the time */
new_time = time_millis();
long old_delta = new_time - last_time;
if(old_delta < min_time) {
sleep_millis(min_time - old_delta);
new_time = time_millis();
}
long delta = new_time - last_time;
if(delta > max_time) {
delta = max_time;
}
begin_frame();
game_step(delta, state);
end_frame();
last_time = new_time;
return 1;
}
int real_main(int argc, char ** argv) {
int last_time = time_millis();
lib_init();
game_init();
while(loop_once()) {}
game_shutdown();
return 0;
}