Skip to content

Commit

Permalink
Access hud_drawhistory_time and hud_fastswitch via cvar variables ins…
Browse files Browse the repository at this point in the history
…tead of CVAR_GET_FLOAT
  • Loading branch information
FreeSlave committed Jun 5, 2024
1 parent 59d44e2 commit 171b2cd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
16 changes: 13 additions & 3 deletions cl_dll/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ int CHudAmmo::Init( void )

Reset();

CVAR_CREATE( "hud_drawhistory_time", HISTORY_DRAW_TIME, 0 );
CVAR_CREATE( "hud_fastswitch", "0", FCVAR_ARCHIVE ); // controls whether or not weapons can be selected in one keypress
m_pCvarDrawHistoryTime = CVAR_CREATE( "hud_drawhistory_time", HISTORY_DRAW_TIME, 0 );
m_pCvarHudFastSwitch = CVAR_CREATE( "hud_fastswitch", "0", FCVAR_ARCHIVE ); // controls whether or not weapons can be selected in one keypress

m_iFlags |= HUD_ACTIVE; //!!!

Expand Down Expand Up @@ -600,7 +600,7 @@ void WeaponsResource::SelectSlot( int iSlot, int fAdvance, int iDirection )
return;

WEAPON *p = NULL;
bool fastSwitch = CVAR_GET_FLOAT( "hud_fastswitch" ) != 0;
bool fastSwitch = gHUD.m_Ammo.FastSwitchEnabled();

if ( ( gpActiveSel == NULL ) || ( gpActiveSel == (WEAPON *) 1 ) || ( iSlot != gpActiveSel->iSlot ) )
{
Expand Down Expand Up @@ -1378,6 +1378,16 @@ int CHudAmmo::DrawWList( float flTime )
return 1;
}

float CHudAmmo::DrawHistoryTime()
{
return m_pCvarDrawHistoryTime && m_pCvarDrawHistoryTime->value > 0 ? m_pCvarDrawHistoryTime->value : 5;
}

bool CHudAmmo::FastSwitchEnabled()
{
return m_pCvarHudFastSwitch && m_pCvarHudFastSwitch->value ? true : false;
}

/* =================================
GetSpriteList
Expand Down
9 changes: 3 additions & 6 deletions cl_dll/ammohistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ HistoryResource gHR;
#define AMMO_PICKUP_HEIGHT_MAX ( ScreenHeight - 100 )

#define MAX_ITEM_NAME 32
int HISTORY_DRAW_TIME = 5;

// keep a list of items
struct ITEM_INFO
Expand All @@ -53,12 +52,11 @@ void HistoryResource::AddToHistory( int iType, int iId, int iCount )
}

HIST_ITEM *freeslot = &rgAmmoHistory[iCurrentHistorySlot++]; // default to just writing to the first slot
HISTORY_DRAW_TIME = CVAR_GET_FLOAT( "hud_drawhistory_time" );

freeslot->type = iType;
freeslot->iId = iId;
freeslot->iCount = iCount;
freeslot->DisplayTime = gHUD.m_flTime + HISTORY_DRAW_TIME;
freeslot->DisplayTime = gHUD.m_flTime + gHUD.m_Ammo.DrawHistoryTime();
}

void HistoryResource::AddToHistory( int iType, const char *szName, int iCount, int packedColor )
Expand All @@ -85,8 +83,7 @@ void HistoryResource::AddToHistory( int iType, const char *szName, int iCount, i
freeslot->iCount = iCount;
freeslot->packedColor = packedColor;

HISTORY_DRAW_TIME = CVAR_GET_FLOAT( "hud_drawhistory_time" );
freeslot->DisplayTime = gHUD.m_flTime + HISTORY_DRAW_TIME;
freeslot->DisplayTime = gHUD.m_flTime + gHUD.m_Ammo.DrawHistoryTime();
}

void HistoryResource::CheckClearHistory( void )
Expand Down Expand Up @@ -115,7 +112,7 @@ int HistoryResource::DrawAmmoHistory( float flTime )
{
if( rgAmmoHistory[i].type )
{
rgAmmoHistory[i].DisplayTime = Q_min( rgAmmoHistory[i].DisplayTime, gHUD.m_flTime + HISTORY_DRAW_TIME );
rgAmmoHistory[i].DisplayTime = Q_min( rgAmmoHistory[i].DisplayTime, gHUD.m_flTime + gHUD.m_Ammo.DrawHistoryTime() );

if( rgAmmoHistory[i].DisplayTime <= flTime )
{
Expand Down
6 changes: 6 additions & 0 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class CHudAmmo : public CHudBase
return m_pWeapon;
}

float DrawHistoryTime();
bool FastSwitchEnabled();

private:
float m_fFade;
RGBA m_rgba;
Expand All @@ -168,6 +171,9 @@ class CHudAmmo : public CHudBase
int m_HUD_selection;
int m_HUD_buckets[WEAPON_SLOTS_HARDLIMIT];
int m_HUD_bucket_none;

cvar_t* m_pCvarDrawHistoryTime;
cvar_t* m_pCvarHudFastSwitch;
};

//
Expand Down

0 comments on commit 171b2cd

Please sign in to comment.