From 495c58e53f38015754aca178d1b9ad5aff6970d9 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 29 Sep 2022 14:03:29 -0700 Subject: [PATCH] Add V_STRINGDANCE -- dancing letters They do a wiggle~ --- src/v_video.c | 39 ++++++++++++++++++++++++++++++++++++--- src/v_video.h | 5 +++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 8ed5ed53f..0e85bf2fa 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -36,6 +36,7 @@ // SRB2Kart #include "k_hud.h" +#include "i_time.h" // Each screen is [vid.width*vid.height]; UINT8 *screens[5]; @@ -1636,6 +1637,14 @@ UINT8 *V_GetStringColormap(INT32 colorflags) #endif } +INT32 V_DanceYOffset(INT32 counter) +{ + const INT32 duration = 16; + const INT32 step = (I_GetTime() + counter) % duration; + + return abs(step - (duration / 2)) - (duration / 4); +} + // Writes a single character (draw WHITE if bit 7 set) // void V_DrawCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed) @@ -2044,9 +2053,13 @@ void V_DrawStringScaled( boolean uppercase; boolean notcolored; + boolean dance; + boolean nodanceoverride; + INT32 dancecounter; + fixed_t cx, cy; - fixed_t cxoff; + fixed_t cxoff, cyoff; fixed_t cw; INT32 spacing; @@ -2057,6 +2070,14 @@ void V_DrawStringScaled( uppercase = !( flags & V_ALLOWLOWERCASE ); flags &= ~(V_FLIP);/* These two (V_ALLOWLOWERCASE) share a bit. */ + dance = (flags & V_STRINGDANCE) != 0; + nodanceoverride = !dance; + dancecounter = 0; + + /* Some of these flags get overloaded in this function so + don't pass them on. */ + flags &= ~(V_PARAMMASK); + if (colormap == NULL) { colormap = V_GetStringColormap(( flags & V_CHARCOLORMASK )); @@ -2247,8 +2268,9 @@ void V_DrawStringScaled( cx = x; cy = y; + cyoff = 0; - for (; ( c = *s ); ++s) + for (; ( c = *s ); ++s, ++dancecounter) { switch (c) { @@ -2267,18 +2289,29 @@ void V_DrawStringScaled( ( ( c & 0x7f )<< V_CHARCOLORSHIFT )& V_CHARCOLORMASK); } + if (nodanceoverride) + { + dance = false; + } + } + else if (c == V_STRINGDANCE) + { + dance = true; } else if (cx < right) { if (uppercase) c = toupper(c); + if (dance) + cyoff = V_DanceYOffset(dancecounter) * FRACUNIT; + c -= font->start; if (c >= 0 && c < font->size && font->font[c]) { cw = SHORT (font->font[c]->width) * dupx; cxoff = (*dim_fn)(scale, chw, hchw, dupx, &cw); - V_DrawFixedPatch(cx + cxoff, cy, scale, + V_DrawFixedPatch(cx + cxoff, cy + cyoff, scale, flags, font->font[c], colormap); cx += cw; } diff --git a/src/v_video.h b/src/v_video.h index 9564bca15..35be68b2f 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -84,6 +84,9 @@ void V_CubeApply(RGBA_t *input); // Bottom 8 bits are used for parameter (screen or character) #define V_PARAMMASK 0x000000FF +// strings/characters only +#define V_STRINGDANCE 0x00000002 + // flags hacked in scrn (not supported by all functions (see src)) // patch scaling uses bits 9 and 10 #define V_SCALEPATCHSHIFT 8 @@ -220,6 +223,8 @@ void V_DrawPromptBack(INT32 boxheight, INT32 color); #define V__IntegerStringWidth( scale,option,font,string ) \ (V_StringScaledWidth(scale,FRACUNIT,FRACUNIT,option,font,string) / FRACUNIT) +INT32 V_DanceYOffset(INT32 counter); + // draw a single character void V_DrawCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed); // draw a single character, but for the chat