-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.c
37 lines (33 loc) · 1.33 KB
/
time.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* time.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ecarvalh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/10 23:57:09 by ecarvalh #+# #+# */
/* Updated: 2024/10/19 16:34:46 by ecarvalh ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void time_update(void);
int event_quit(void);
void time_update(void)
{
static struct timeval now = {0};
static struct timeval before = {0};
t_ime *time;
time = &g()->time;
if (gettimeofday(&now, NULL) < 0)
{
perror("time_now - gettimeofday");
event_quit();
}
time->dt = (now.tv_sec - before.tv_sec) + (now.tv_usec - before.tv_usec)
/ 1000000.0;
if (time->dt > 0)
time->fps = 1.0 / time->dt;
else
time->fps = 0;
before = now;
}