-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.c
More file actions
38 lines (25 loc) · 772 Bytes
/
Copy pathlogic.c
File metadata and controls
38 lines (25 loc) · 772 Bytes
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
#include "logic.h"
#include <game/interface.h>
i32 logic_perform(void *args) {
ThreadData *const td = (ThreadData *)args;
GameState *const state = (GameState *)td->state;
mutex_t *const lock = (mutex_t *)td->lock;
const i64 delay = 1000000 / state->tickrate;
i64 start_time, end_time;
while (!game_should_exit(state)) {
start_time = platform_time_usec();
if (game_is_paused(state)) {
game_paused_tick(state, lock);
platform_sleep(50);
continue;
}
game_tick(state, lock);
if (state->tick % 16 == 0)
game_lazy_tick(state, lock);
state->tick++;
end_time = platform_time_usec();
if ((end_time - start_time) < delay)
platform_usleep(delay - (end_time - start_time));
}
return 0;
}