From 196d310052bc312f17a3fb4b979ca6209ba6aeff Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 16 Feb 2021 10:48:24 -0800 Subject: [PATCH] Sacrifice fun for readability :( --- src/d_player.h | 4 ++-- src/k_hud.c | 24 +++++------------------- src/p_user.c | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 5ed5af013..f2883eaa2 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -697,8 +697,8 @@ typedef struct player_s tic_t jointime; // Timer when player joins game to change skin/color tic_t quittime; // Time elapsed since user disconnected, zero if connected - UINT8 typing_timer : 4; // Counts down while keystrokes are not emitted - UINT8 typing_duration : 6; // How long since resumed timer + UINT8 typing_timer; // Counts down while keystrokes are not emitted + UINT8 typing_duration; // How long since resumed timer #ifdef HWRENDER fixed_t fovadd; // adjust FOV for hw rendering diff --git a/src/k_hud.c b/src/k_hud.c index 2e635581d..53859fe62 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -2605,20 +2605,15 @@ static void K_DrawRivalTagForPlayer(fixed_t x, fixed_t y) V_DrawFixedPatch(x, y, FRACUNIT, V_HUDTRANS|V_SPLITSCREEN, kp_rival[blink], NULL); } -static boolean K_DrawTypingDot(fixed_t x, fixed_t y, UINT8 duration, player_t *p) +static void K_DrawTypingDot(fixed_t x, fixed_t y, UINT8 duration, player_t *p) { if (p->typing_duration > duration) { V_DrawFixedPatch(x, y, FRACUNIT, V_HUDTRANS|V_SPLITSCREEN, kp_typdot, NULL); - return true; - } - else - { - return false; } } -static boolean K_DrawTypingNotifier(fixed_t x, fixed_t y, player_t *p) +static void K_DrawTypingNotifier(fixed_t x, fixed_t y, player_t *p) { if (p->cmd.flags & TICCMD_TYPING) { @@ -2627,18 +2622,9 @@ static boolean K_DrawTypingNotifier(fixed_t x, fixed_t y, player_t *p) y += 4*FRACUNIT; /* spacing closer with the last two looks a better most of the time */ - (void) - ( - K_DrawTypingDot(x + 3*FRACUNIT, y, 15, p) && - K_DrawTypingDot(x + 6*FRACUNIT - FRACUNIT/3, y, 31, p) && - K_DrawTypingDot(x + 9*FRACUNIT - FRACUNIT/3, y, 47, p) - ); - - return true; - } - else - { - return false; + K_DrawTypingDot(x + 3*FRACUNIT, y, 15, p); + K_DrawTypingDot(x + 6*FRACUNIT - FRACUNIT/3, y, 31, p); + K_DrawTypingDot(x + 9*FRACUNIT - FRACUNIT/3, y, 47, p); } } diff --git a/src/p_user.c b/src/p_user.c index 6577b3eae..82c1da681 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -4590,6 +4590,12 @@ void P_PlayerThink(player_t *player) if (cmd->flags & TICCMD_TYPING) { + /* + typing_duration is slow to start and slow to stop. + + typing_timer counts down a grace period before the player is not + actually considered typing anymore. + */ if (cmd->flags & TICCMD_KEYSTROKE) { player->typing_timer = 15; @@ -4599,18 +4605,26 @@ void P_PlayerThink(player_t *player) player->typing_timer--; } + /* if we are in the grace period (including currently typing) */ if (player->typing_timer + player->typing_duration > 0) { - /* lag a little bit so we always get more than just a singular dot */ + /* + If one dot was already displayed, let the duration continue to + display two dots for a bit, before actually resetting. + */ if (player->typing_timer == 0 && (player->typing_duration < 16 || player->typing_duration > 39)) { player->typing_duration = 0; } - else + else if (player->typing_duration < 63) { player->typing_duration++; } + else + { + player->typing_duration = 0; + } } } else