diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-17 17:15:32 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-17 17:15:32 +0100 |
commit | 05ad2085ab6ce4ffb280b21ce3f321b2bd75aa9e (patch) | |
tree | c6c521c8f2ad8df4477005b8225427b7459daf32 /src/ft_get_fps_count.c | |
parent | Merge branch 'back-to-pthread' (diff) | |
download | 42-cub3d-05ad2085ab6ce4ffb280b21ce3f321b2bd75aa9e.tar.gz 42-cub3d-05ad2085ab6ce4ffb280b21ce3f321b2bd75aa9e.tar.bz2 42-cub3d-05ad2085ab6ce4ffb280b21ce3f321b2bd75aa9e.tar.xz 42-cub3d-05ad2085ab6ce4ffb280b21ce3f321b2bd75aa9e.tar.zst 42-cub3d-05ad2085ab6ce4ffb280b21ce3f321b2bd75aa9e.zip |
fps counter is bav
Diffstat (limited to 'src/ft_get_fps_count.c')
-rw-r--r-- | src/ft_get_fps_count.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ft_get_fps_count.c b/src/ft_get_fps_count.c new file mode 100644 index 0000000..16306c1 --- /dev/null +++ b/src/ft_get_fps_count.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_key_loop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ +/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stddef.h> +#include <stdint.h> +#include <time.h> + +static float + ft_clock_to_ms(clock_t ticks) +{ + return ((ticks / (float)CLOCKS_PER_SEC) * 1000.0); +} + +#include <stdio.h> + +void + ft_get_fps_count(clock_t dt, t_cub *cl) +{ + static clock_t curr_time = 0; + + curr_time += dt; + if (dt > 0 && ft_clock_to_ms(curr_time) > 1000.0) + { + ft_sprintf(cl->fps_count, "fps: %ld", (uint32_t)CLOCKS_PER_SEC / dt); + curr_time -= CLOCKS_PER_SEC; + } +} |