/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_get_fps_count.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ /* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include #include float ft_clock_to_ms(clock_t ticks) { return (ticks * 1000.0 / (float)CLOCKS_PER_SEC); } void ft_handle_firing(clock_t before, t_cub *cl) { static clock_t dt = 0; clock_t curr; int8_t weap_id; weap_id = cl->plist.handles_weapon; weap_id = (weap_id == 2) ? (1) : (weap_id); weap_id = (weap_id == 4) ? (2) : (weap_id); curr = clock(); dt += curr - before; if (dt > 0 && ft_clock_to_ms(dt) > cl->plist.weap_vel[weap_id]) { cl->plist.fire = 0; dt = 0; } } void ft_bad_boys_time(clock_t before, int8_t i, t_cub *cl) { static clock_t dt[32]; clock_t curr; curr = clock(); dt[i] += curr - before; if (cl->bad_boy[i].sleep == 1 && dt[i] > 0 && ft_clock_to_ms(dt[i]) > 500.0) { cl->bad_boy[i].sleep = 0; dt[i] = 0; } } void ft_timings(clock_t before, t_cub *cl) { int8_t i; i = 0; if (cl->plist.fire == 1) ft_handle_firing(before, cl); while (i < cl->mlist.sprite_nbr[13]) { ft_bad_boys_time(before, i, cl); i++; } }