diff --git a/Quake/draw.h b/Quake/draw.h index 28276b88e..392cc6197 100644 --- a/Quake/draw.h +++ b/Quake/draw.h @@ -39,6 +39,7 @@ void Draw_Fill (cb_context_t *cbx, int x, int y, int w, int h, int c, float alph void Draw_FadeScreen (cb_context_t *cbx); void Draw_String (cb_context_t *cbx, int x, int y, const char *str); void Draw_String_3D (cb_context_t *cbx, vec3_t coords, float size, const char *str); +void Draw_String_WithSize (cb_context_t *cbx, int x, int y, const char *str, float size); qpic_t *Draw_PicFromWad2 (const char *name, unsigned int texflags); qpic_t *Draw_PicFromWad (const char *name); qpic_t *Draw_CachePic (const char *path); diff --git a/Quake/gl_draw.c b/Quake/gl_draw.c index afdef7866..e70e5d442 100644 --- a/Quake/gl_draw.c +++ b/Quake/gl_draw.c @@ -454,7 +454,7 @@ void Draw_Init (void) Draw_FillCharacterQuad ================ */ -static void Draw_FillCharacterQuad (int x, int y, char num, basicvertex_t *output, int rotation) +static void Draw_FillCharacterQuad_WithSize (int x, int y, char num, basicvertex_t *output, int rotation, float textSize) { int row, col; float frow, fcol, size; @@ -471,9 +471,9 @@ static void Draw_FillCharacterQuad (int x, int y, char num, basicvertex_t *outpu float texcoords[4][2] = { {x, y}, - {x + 8, y}, - {x + 8, y + 8}, - {x, y + 8}, + {x + textSize, y}, + {x + textSize, y + textSize}, + {x, y + textSize}, }; corner_verts[0].position[0] = texcoords[(rotation + 0) % 4][0]; @@ -508,6 +508,11 @@ static void Draw_FillCharacterQuad (int x, int y, char num, basicvertex_t *outpu output[5] = corner_verts[0]; } +static void Draw_FillCharacterQuad (int x, int y, char num, basicvertex_t *output, int rotation) +{ + Draw_FillCharacterQuad_WithSize (x, y, num, output, rotation, 8.f); +} + /* ================ Draw_Character @@ -542,13 +547,13 @@ void Draw_Character (cb_context_t *cbx, int x, int y, int num) Draw_String ================ */ -void Draw_String (cb_context_t *cbx, int x, int y, const char *str) +void Draw_String_WithSize (cb_context_t *cbx, int x, int y, const char *str, float size) { int num_verts = 0; int i; const char *tmp; - if (y <= -8) + if (y <= -size) return; // totally off screen for (tmp = str; *tmp != 0; ++tmp) @@ -563,10 +568,10 @@ void Draw_String (cb_context_t *cbx, int x, int y, const char *str) { if (*str != 32) { - Draw_FillCharacterQuad (x, y, *str, vertices + i * 6, 0); + Draw_FillCharacterQuad_WithSize (x, y, *str, vertices + i * 6, 0, size); i++; } - x += 8; + x += size; } vulkan_globals.vk_cmd_bind_vertex_buffers (cbx->cb, 0, 1, &buffer, &buffer_offset); @@ -576,6 +581,11 @@ void Draw_String (cb_context_t *cbx, int x, int y, const char *str) vulkan_globals.vk_cmd_draw (cbx->cb, num_verts, 1, 0, 0); } +void Draw_String (cb_context_t *cbx, int x, int y, const char *str) +{ + Draw_String_WithSize (cbx, x, y, str, 8.f); +} + /* ============= Draw_Pic -- johnfitz -- modified diff --git a/Quake/gl_screen.c b/Quake/gl_screen.c index 123284acc..de054ada5 100644 --- a/Quake/gl_screen.c +++ b/Quake/gl_screen.c @@ -89,6 +89,7 @@ cvar_t scr_conscale = {"scr_conscale", "1", CVAR_ARCHIVE}; cvar_t scr_crosshairscale = {"scr_crosshairscale", "1", CVAR_ARCHIVE}; cvar_t scr_showfps = {"scr_showfps", "0", CVAR_NONE}; cvar_t scr_clock = {"scr_clock", "0", CVAR_NONE}; +cvar_t scr_showspeed = {"scr_showspeed", "1", CVAR_NONE}; // johnfitz cvar_t scr_usekfont = {"scr_usekfont", "0", CVAR_NONE}; // 2021 re-release @@ -545,6 +546,7 @@ void SCR_Init (void) Cvar_RegisterVariable (&scr_crosshairscale); Cvar_RegisterVariable (&scr_showfps); Cvar_RegisterVariable (&scr_clock); + Cvar_RegisterVariable (&scr_showspeed); // johnfitz Cvar_RegisterVariable (&scr_usekfont); // 2021 re-release Cvar_SetCallback (&scr_fov, SCR_Callback_refdef); @@ -698,6 +700,47 @@ void SCR_DrawClock (cb_context_t *cbx) } } +/* +============== +SCR_DrawSpeed +============== +*/ +void SCR_DrawSpeed (cb_context_t *cbx) +{ + if (cl.intermission || !scr_showspeed.value) + return; + + float maxSpeedFillWidth = 600; // if speed >= val, then speedometer is completely filled + float scale = scr_sbarscale.value; + float width = 140.f * scale; + float height = 12.f * scale; + float x = ((float)vid.width / 2.f) - (width / 2.f); + float y = (float)vid.height - height - ((float)Sbar_HudHeight () * scale); + + float textLeftOffset = 10.f * scale; + float textHeight = 8.f * scale; + float textY = y + (height / 2) - (textHeight / 2); + float textX = x + textLeftOffset; + + char st[4]; + float speed = VectorLength (cl.velocity); + sprintf (st, "%-3d", (int)speed); + int speedWidth = (int)(fmin (1.f, speed / maxSpeedFillWidth) * width); + + static int bgColor = -1; + static int fillColor = -1; + if (bgColor == -1) + { + bgColor = TexMgr_NearestColor (20, 20, 0); + fillColor = TexMgr_NearestColor (40, 30, 15); + } + + GL_SetCanvas (cbx, CANVAS_DEFAULT); + Draw_Fill (cbx, x, y, width, height, bgColor, 1.f); // entire speedometer + Draw_Fill (cbx, x, y, speedWidth, height, fillColor, 1.f); // speed fill on speedometer + Draw_String_WithSize (cbx, textX, textY, st, textHeight); +} + /* ============== SCR_DrawDevStats @@ -1142,6 +1185,7 @@ static void SCR_DrawGUI (void *unused) SCR_DrawFPS (cbx); // johnfitz SCR_DrawClock (cbx); // johnfitz SCR_DrawConsole (cbx); + SCR_DrawSpeed (cbx); M_Draw (cbx); } diff --git a/Quake/gl_texmgr.c b/Quake/gl_texmgr.c index 593b19098..2ae3e7c75 100644 --- a/Quake/gl_texmgr.c +++ b/Quake/gl_texmgr.c @@ -566,6 +566,33 @@ void TexMgr_LoadPalette (void) ((byte *)&d_8to24table_conchars[0])[3] = 0; } +/* +================ +TexMgr_NearestColor +================ +*/ +int TexMgr_NearestColor (int r, int g, int b) +{ + byte *curColor = (byte *)d_8to24table; + int nearestColor = 0; + int nearestDist = INT_MAX; + int cursor = 0; + + while (curColor[3] != 0) // last color is transparent + { + int colorDist = (r - curColor[0]) * (r - curColor[0]) + (g - curColor[1]) * (g - curColor[1]) + (b - curColor[2]) * (b - curColor[2]); + if (colorDist < nearestDist) + { + nearestColor = cursor; + nearestDist = colorDist; + } + curColor += 4; + cursor += 1; + } + + return nearestColor; +} + /* ================ TexMgr_NewGame diff --git a/Quake/gl_texmgr.h b/Quake/gl_texmgr.h index 9adf6bb7d..cfdae1ba8 100644 --- a/Quake/gl_texmgr.h +++ b/Quake/gl_texmgr.h @@ -110,6 +110,7 @@ void TexMgr_Init (void); void TexMgr_DeleteTextureObjects (void); void TexMgr_CollectGarbage (void); void TexMgr_LoadPalette (void); +int TexMgr_NearestColor (int r, int g, int b); // IMAGE LOADING gltexture_t *TexMgr_LoadImage ( diff --git a/Quake/sbar.c b/Quake/sbar.c index f1accbdd6..b3a5ba271 100644 --- a/Quake/sbar.c +++ b/Quake/sbar.c @@ -1384,3 +1384,19 @@ void Sbar_FinaleOverlay (cb_context_t *cbx) pic = Draw_CachePic ("gfx/finale.lmp"); Draw_Pic (cbx, (320 - pic->width) / 2, 16, pic, 1.0f, false); // johnfitz -- stretched menus } + +/* +================== +Sbar_HudHeight +================== +*/ +int Sbar_HudHeight (void) +{ + int height = 0; + if (scr_viewsize.value <= 110 && sb_sbar) + height += sb_sbar->height; + if (scr_viewsize.value <= 100 && sb_ibar) + height += sb_ibar->height; + + return height; +} \ No newline at end of file diff --git a/Quake/sbar.h b/Quake/sbar.h index 3155bb7a0..1ec48dcef 100644 --- a/Quake/sbar.h +++ b/Quake/sbar.h @@ -39,4 +39,6 @@ void Sbar_IntermissionOverlay (cb_context_t *cbx); void Sbar_FinaleOverlay (cb_context_t *cbx); +int Sbar_HudHeight (void); + #endif /* _QUAKE_SBAR_H */