- added debouncing option
- added some gif for presentation
This commit is contained in:
@@ -21,9 +21,31 @@ static int print_keycode(int keycode, t_plr *plr)
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int should_ignore_keypress(const struct timeval *current_time, t_game *game)
|
||||
{
|
||||
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 = (game->last_keypress_time.tv_sec % 1000) * 1000 + game->last_keypress_time.tv_usec / 1000;
|
||||
is_less = (current_milliseconds - last_milliseconds) < DEBOUNCE_TIME;
|
||||
|
||||
if (!is_less)
|
||||
game->last_keypress_time = *current_time;
|
||||
return is_less;
|
||||
}
|
||||
|
||||
|
||||
int hook_action(t_game *game)
|
||||
{
|
||||
int is_action;
|
||||
struct timeval current_time;
|
||||
|
||||
gettimeofday(¤t_time, NULL);
|
||||
if (should_ignore_keypress(¤t_time, game))
|
||||
return (0);
|
||||
|
||||
is_action = 0;
|
||||
if (is_esc(game->k_hook, &is_action))
|
||||
|
||||
Reference in New Issue
Block a user