/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ /* Updated: 2024/10/17 15:05:15 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" #include void vector_from_rotation(t_point_double *vec, double angle, double norm) { vec->x = sin(angle) * norm; vec->y = -cos(angle) * norm; } void write_err(const char *str, ...) { va_list args; va_start(args, str); write(2, "Error\n", 6); while (str) { write(2, str, ft_strlen(str)); str = va_arg(args, const char *); } } /* FOR BONUS static long get_nanos(void) { struct timespec ts; timespec_get(&ts, TIME_UTC); return ((long)ts.tv_sec * 1000000000L + ts.tv_nsec); } void timedloop(void (*f)(void)) { static long last_time = 0; const long new_time = get_nanos(); static bool checked = false; if (new_time - last_time >= 1000000000L / FPS) { if (checked) last_time += 1000000000L / FPS; else last_time = new_time; checked = false; f(); } else checked = true; } */ void timedloop(void (*f)(void)) { static int ticks; if (ticks % 100 == 0) f(); ticks++; }