aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_time.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-30 14:52:21 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-30 14:52:21 +0200
commitea86510df216646246f21266023c7cc3943b80f3 (patch)
tree6144b21b6d5c0118b872c8e339be1c2870e21714 /src/ft_time.c
parentBug fix (diff)
download42-cub3d-ea86510df216646246f21266023c7cc3943b80f3.tar.gz
42-cub3d-ea86510df216646246f21266023c7cc3943b80f3.tar.bz2
42-cub3d-ea86510df216646246f21266023c7cc3943b80f3.tar.xz
42-cub3d-ea86510df216646246f21266023c7cc3943b80f3.tar.zst
42-cub3d-ea86510df216646246f21266023c7cc3943b80f3.zip
Timings fix
Diffstat (limited to 'src/ft_time.c')
-rw-r--r--src/ft_time.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/ft_time.c b/src/ft_time.c
index 2be702d..fb0b0d2 100644
--- a/src/ft_time.c
+++ b/src/ft_time.c
@@ -19,19 +19,28 @@
float
ft_clock_to_ms(clock_t ticks)
{
- return ((ticks * 1000.0) / (float)CLOCKS_PER_SEC);
+ return (ticks * 1000.0 / (float)CLOCKS_PER_SEC);
}
void
- ft_handle_firing(clock_t dt, t_cub *cl)
+ ft_handle_firing(clock_t before, t_cub *cl)
{
- static clock_t curr_time = 0;
+ static clock_t dt = 0;
+ clock_t curr;
- curr_time += dt;
- if (dt > 0 && ft_clock_to_ms(curr_time) > 300.0)
+ curr = clock();
+ dt += curr - before;
+ if (dt > 0 && ft_clock_to_ms(dt) > 700.0)
{
cl->plist.fire = 0;
- curr_time -= CLOCKS_PER_SEC;
+ dt = 0;
}
}
+void
+ ft_timings(clock_t before, t_cub *cl)
+{
+ if (cl->plist.fire == 1)
+ ft_handle_firing(before, cl);
+ ft_get_fps_count(before, cl);
+}