diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-30 14:52:21 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-30 14:52:21 +0200 |
commit | ea86510df216646246f21266023c7cc3943b80f3 (patch) | |
tree | 6144b21b6d5c0118b872c8e339be1c2870e21714 | |
parent | Bug fix (diff) | |
download | 42-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
-rw-r--r-- | inc/cub3d.h | 5 | ||||
-rw-r--r-- | map/map_seven.cub | 4 | ||||
-rw-r--r-- | src/ft_get_fps_count.c | 14 | ||||
-rw-r--r-- | src/ft_key_loop.c | 2 | ||||
-rw-r--r-- | src/ft_time.c | 21 |
5 files changed, 28 insertions, 18 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h index 50f2bf3..02cb20d 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -234,8 +234,9 @@ void *ft_sfx_ooa_thread(void *vargp); */ float ft_clock_to_ms(clock_t ticks); -void ft_handle_firing(clock_t dt, t_cub *cl); -void ft_get_fps_count(clock_t delta_time, t_cub *cl); +void ft_timings(clock_t before, t_cub *cl); +void ft_handle_firing(clock_t before, t_cub *cl); +void ft_get_fps_count(clock_t before, t_cub *cl); /* ** ====== DELETION ====== diff --git a/map/map_seven.cub b/map/map_seven.cub index 5985113..50592ae 100644 --- a/map/map_seven.cub +++ b/map/map_seven.cub @@ -21,7 +21,7 @@ C 150,150,150 1000000000000000001 1000000000000000001 1000000000000000001 -1000000000000000001 10000000@0000000001 -10000000N0000000001 +1000000000000000001 +10200000N0000000201 1111111111111111111 diff --git a/src/ft_get_fps_count.c b/src/ft_get_fps_count.c index 1f717e8..990f0ea 100644 --- a/src/ft_get_fps_count.c +++ b/src/ft_get_fps_count.c @@ -17,19 +17,19 @@ #include <time.h> void - ft_get_fps_count(clock_t dt, t_cub *cl) + ft_get_fps_count(clock_t before, t_cub *cl) { - static clock_t curr_time = 0; + static clock_t dt = 0; static uint16_t ticks = 0; + clock_t curr; - curr_time += dt; + curr = clock(); + dt += curr - before; ticks += 1; - if (cl->plist.fire == 1) - ft_handle_firing(dt, cl); - if (dt > 0 && ft_clock_to_ms(curr_time) > 1000.0) + if (dt > 0 && ft_clock_to_ms(dt) > 1000.0) { ft_sprintf(cl->fps_count, "fps: %hu", ticks); ticks = 0; - curr_time -= CLOCKS_PER_SEC; + dt = 0; } } diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index 22975f8..9ca9185 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -112,6 +112,6 @@ int cl->moves = (cl->key_input[0] == -1) ? (0) : (cl->moves); begin_frame = clock(); ft_draw_scene(cl); - ft_get_fps_count(clock() - begin_frame, cl); + ft_timings(begin_frame, cl); return (0); } 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); +} |