diff --git a/builds/draw_bonus.o b/builds/draw_bonus.o index 32e056d..39af4e5 100644 Binary files a/builds/draw_bonus.o and b/builds/draw_bonus.o differ diff --git a/builds/fdf.o b/builds/fdf.o index 4da812a..7a0b4ba 100644 Binary files a/builds/fdf.o and b/builds/fdf.o differ diff --git a/builds/keypress_bonus.o b/builds/keypress_bonus.o index e61f364..c029373 100644 Binary files a/builds/keypress_bonus.o and b/builds/keypress_bonus.o differ diff --git a/builds/modifs.o b/builds/modifs.o index 322481c..643e720 100644 Binary files a/builds/modifs.o and b/builds/modifs.o differ diff --git a/builds/parse.o b/builds/parse.o index 4114d30..a8535f8 100644 Binary files a/builds/parse.o and b/builds/parse.o differ diff --git a/fdf b/fdf index 45533cb..25aab78 100755 Binary files a/fdf and b/fdf differ diff --git a/includes/fdf.h b/includes/fdf.h index 20a54db..fdb53b8 100644 --- a/includes/fdf.h +++ b/includes/fdf.h @@ -3,39 +3,42 @@ # include "../libft/includes/libft.h" # include -# include // for M_PI -# include // for open +# include // for M_PI +# include // for open +# include // for time +# include // for gettimeofday typedef struct s_fdf { - void *mlx_ptr; - void *win_ptr; - void *img_ptr; - char *img_addr; - int **map; - int offset; - int min_z; - int max_z; - int z_amplitude; - int altitude; - int win_size_x; - int win_size_y; - int img_size_x; - int img_size_y; - int map_size_x; - int map_size_y; - int map_width; - int map_height; - int rot_x; - int rot_y; - double rad_x; - double rad_y; - int mov_x; - int mov_y; - double zoom; - int img_bpp; - int img_sizel; - int img_endian; + void *mlx_ptr; + void *win_ptr; + void *img_ptr; + char *img_addr; + int **map; + int offset; + int min_z; + int max_z; + int z_amplitude; + int altitude; + int win_size_x; + int win_size_y; + int img_size_x; + int img_size_y; + int map_size_x; + int map_size_y; + int map_width; + int map_height; + int rot_x; + int rot_y; + double rad_x; + double rad_y; + int mov_x; + int mov_y; + double zoom; + int img_bpp; + int img_sizel; + int img_endian; + struct timeval last_keypress_time; } t_fdf; // fdf.c @@ -71,16 +74,17 @@ int **parse_map(t_fdf *fdf, int fd); // steps size for the hight transform with p and o // must be > 0 // 100 is small, 1 is the biggest -# define Z_HEIGHT 10 +# define Z_HEIGHT 50 // color for altitude # define COLOR_START 0xffffff -# define COLOR_END 0x00d700 -// R,G,B colors -// ex for col = 0x236ad0 -# define COLOR_R(col) ((col & 0xff0000) >> 16) // output 23 -# define COLOR_G(col) ((col & 0x00ff00) >> 8) // output 6a -# define COLOR_B(col) (col & 0x0000ff) // output d0 +/* +# define COLOR_END 0x1423e6 // blue +*/ +# define COLOR_END 0x00d700 // green + +// minimum time in milliseconds between two keypress +# define DEBOUNCE_TIME 60 # define ESCAPE 65307 # define UP 65362 diff --git a/srcs/fdf.c b/srcs/fdf.c index 8f3b760..97ab7c0 100644 --- a/srcs/fdf.c +++ b/srcs/fdf.c @@ -53,6 +53,8 @@ void init_offset(t_fdf *fdf) void init_fdf(t_fdf *fdf) { + struct timeval current_time; + fdf->win_size_x = 700; fdf->win_size_y = 700; fdf->img_size_x = fdf->win_size_x; @@ -71,6 +73,8 @@ void init_fdf(t_fdf *fdf) fdf->mov_x = (fdf->win_size_x - fdf->map_size_x) / 2; fdf->mov_y = (fdf->win_size_y - fdf->map_size_y) / 2; fdf->zoom = 0; + gettimeofday(¤t_time, NULL); + fdf->last_keypress_time = current_time; init_server(fdf); draw_image(fdf); } diff --git a/srcs/keypress_bonus.c b/srcs/keypress_bonus.c index 726b499..a32920f 100644 --- a/srcs/keypress_bonus.c +++ b/srcs/keypress_bonus.c @@ -34,6 +34,36 @@ void keypress_more(int keycode, t_fdf *fdf) fdf->altitude--; } +int should_ignore_keypress(const struct timeval *current_time, t_fdf *fdf) +{ + int is_less; + unsigned long current_milliseconds; + unsigned long last_milliseconds; + + current_milliseconds = (current_time->tv_sec % 1000) * 1000 + current_time->tv_usec / 1000; + last_milliseconds = (fdf->last_keypress_time.tv_sec % 1000) * 1000 + fdf->last_keypress_time.tv_usec / 1000; + is_less = (current_milliseconds - last_milliseconds) < DEBOUNCE_TIME; + + /* + [1 705 151 587 ,905 277,49579540-1000000] + 1 705 151 587 000 + 1 705 151 587 905 + 1 705 151 587 % 1000 = 587 + 587 * 1000 + 905 277 / 1000 = 587 000 + 905 = 587905 + + [836 763,836 066] + ft_putchar('['); + ft_putnbr(current_milliseconds); + ft_putchar(','); + ft_putnbr(last_milliseconds); + ft_putchar(']'); + */ + + if (!is_less) + fdf->last_keypress_time = *current_time; + return is_less; +} + /* ** Q -> move left ** D -> move right @@ -44,6 +74,11 @@ void keypress_more(int keycode, t_fdf *fdf) */ int keypress(int keycode, t_fdf *fdf) { + struct timeval current_time; + + gettimeofday(¤t_time, NULL); + if (should_ignore_keypress(¤t_time, fdf)) + return (0); if (keycode == ESCAPE) shut_down(fdf); else if (keycode == LEFT)