From ea86510df216646246f21266023c7cc3943b80f3 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 30 Mar 2020 14:52:21 +0200 Subject: Timings fix --- src/ft_time.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/ft_time.c') 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); +} -- cgit v1.2.3