From ea229edb2c175660546a226aa2610df2a0d81b24 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 21 Dec 2023 04:11:52 +0300 Subject: [PATCH] client: add hud_allow_hd cvar that increases available HUD spritesheet resolutions up to 1280 and 2560 --- cl_dll/ammo.cpp | 5 +---- cl_dll/cl_util.h | 21 +++++++++++++++++++++ cl_dll/hud.cpp | 6 ++---- cl_dll/hud.h | 1 + cl_dll/util.cpp | 7 +------ 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/cl_dll/ammo.cpp b/cl_dll/ammo.cpp index dd89495b..d8e0d10b 100644 --- a/cl_dll/ammo.cpp +++ b/cl_dll/ammo.cpp @@ -75,10 +75,7 @@ void WeaponsResource::LoadWeaponSprites( WEAPON *pWeapon ) { int i, iRes; - if( ScreenWidth < 640 ) - iRes = 320; - else - iRes = 640; + iRes = GetSpriteRes( ScreenWidth, ScreenHeight ); char sz[256]; diff --git a/cl_dll/cl_util.h b/cl_dll/cl_util.h index 65275c69..c5c25169 100644 --- a/cl_dll/cl_util.h +++ b/cl_dll/cl_util.h @@ -153,6 +153,27 @@ inline void PlaySound( int iSound, float vol ) { gEngfuncs.pfnPlaySoundByIndex( #define Q_min(a, b) (((a) < (b)) ? (a) : (b)) #define fabs(x) ((x) > 0 ? (x) : 0 - (x)) +inline int GetSpriteRes( int width, int height ) +{ + int i; + + if( width < 640 ) + i = 320; + else if( width < 1280 || !gHUD.m_pAllowHD->value ) + i = 640; + else + { + if( height <= 720 ) + i = 640; + else if( width <= 2560 || height <= 1600 ) + i = 1280; + else + i = 2560; + } + + return i; +} + void ScaleColors( int &r, int &g, int &b, int a ); #define DotProduct(x, y) ((x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2]) diff --git a/cl_dll/hud.cpp b/cl_dll/hud.cpp index 86f0f6cd..853f34da 100644 --- a/cl_dll/hud.cpp +++ b/cl_dll/hud.cpp @@ -379,6 +379,7 @@ void CHud::Init( void ) default_fov = CVAR_CREATE( "default_fov", "90", FCVAR_ARCHIVE ); m_pCvarStealMouse = CVAR_CREATE( "hud_capturemouse", "1", FCVAR_ARCHIVE ); m_pCvarDraw = CVAR_CREATE( "hud_draw", "1", FCVAR_ARCHIVE ); + m_pAllowHD = CVAR_CREATE ( "hud_allow_hd", "1", FCVAR_ARCHIVE ); cl_lw = gEngfuncs.pfnGetCvarPointer( "cl_lw" ); cl_viewbob = CVAR_CREATE( "cl_viewbob", "1", FCVAR_ARCHIVE ); @@ -483,10 +484,7 @@ void CHud::VidInit( void ) m_hsprLogo = 0; m_hsprCursor = 0; - if( ScreenWidth < 640 ) - m_iRes = 320; - else - m_iRes = 640; + m_iRes = GetSpriteRes( ScreenWidth, ScreenHeight ); // Only load this once if( !m_pSpriteList ) diff --git a/cl_dll/hud.h b/cl_dll/hud.h index 69c6646f..6bd3d9a3 100644 --- a/cl_dll/hud.h +++ b/cl_dll/hud.h @@ -557,6 +557,7 @@ public: int m_iRes; cvar_t *m_pCvarStealMouse; cvar_t *m_pCvarDraw; + cvar_t *m_pAllowHD; int m_iFontHeight; int DrawHudNumber( int x, int y, int iFlags, int iNumber, int r, int g, int b ); diff --git a/cl_dll/util.cpp b/cl_dll/util.cpp index ec5c796f..f12cd1b5 100644 --- a/cl_dll/util.cpp +++ b/cl_dll/util.cpp @@ -123,14 +123,9 @@ void VectorMA( const float *veca, float scale, const float *vecb, float *vecc ) HSPRITE LoadSprite( const char *pszName ) { - int i; + int i = GetSpriteRes( ScreenWidth, ScreenHeight ); char sz[256]; - if( ScreenWidth < 640 ) - i = 320; - else - i = 640; - sprintf( sz, pszName, i ); return SPR_Load( sz );