Skip to content

Commit

Permalink
Client: Use enum in bhop detection
Browse files Browse the repository at this point in the history
  • Loading branch information
tmp64 committed Oct 6, 2024
1 parent e1aa9f0 commit 8a31105
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/game/client/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const Color NoTeamColor::White = Color(216, 216, 216, 255);

CON_COMMAND(bhop_reset, "Resets BHop auto-detection if it was detected incorrectly")
{
if (gHUD.GetBHopCapState() != BHopCap::Auto)
if (gHUD.GetBHopCapState() != EBHopCap::AutoDetect)
{
ConPrintf("BHop auto-detection is disabled, nothing was done.\n");
}
Expand Down Expand Up @@ -721,9 +721,9 @@ float CHud::GetSensitivity(void)
return m_flMouseSensitivity;
}

BHopCap CHud::GetBHopCapState()
EBHopCap CHud::GetBHopCapState()
{
return (BHopCap)clamp(cl_bhopcap.GetInt(), (int)BHopCap::Disabled, (int)BHopCap::Auto);
return cl_bhopcap.GetEnumClamped<EBHopCap>();
}

bool CHud::IsHTMLEnabled()
Expand Down
9 changes: 2 additions & 7 deletions src/game/client/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ class IScheme;

class ConVar;

enum class BHopCap
{
Disabled = 0,
Enabled = 1,
Auto = 2
};
enum class EBHopCap;

enum class HudPart
{
Expand Down Expand Up @@ -201,7 +196,7 @@ class CHud
int MsgFunc_Fog(const char *pszName, int iSize, void *pbuf);

float GetSensitivity();
BHopCap GetBHopCapState();
EBHopCap GetBHopCapState();
bool IsHTMLEnabled();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/hud_redraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void CHud::Think(void)
}

// Update BHop state
int bhopCapState = (int)GetBHopCapState();
EBHopCap bhopCapState = GetBHopCapState();
if (PM_GetBHopCapState() != bhopCapState)
PM_SetBHopCapState(bhopCapState);

Expand Down
16 changes: 8 additions & 8 deletions src/pm_shared/pm_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ void PM_SetIsAG(int state)

#ifdef CLIENT_DLL

#define BHOP_DETECT_DELAY 0.3f
static constexpr float BHOP_DETECT_DELAY = 0.3f;

static int s_iOnGround;
static int s_iWaterlevel;
static int s_iMoveType;
static int s_iBHopState = 1;
static EBHopCap s_iBHopState = EBHopCap::Enabled;
static float s_flBHopCheckTime = 0.0f;

int PM_GetOnGround()
Expand All @@ -190,20 +190,20 @@ int PM_GetMoveType()
return s_iMoveType;
}

int PM_GetBHopCapState()
EBHopCap PM_GetBHopCapState()
{
return s_iBHopState;
}

void PM_SetBHopCapState(int state)
void PM_SetBHopCapState(EBHopCap state)
{
s_iBHopState = state;
PM_ResetBHopDetection();
}

void PM_ResetBHopDetection()
{
if (s_iBHopState == 2)
if (s_iBHopState == EBHopCap::AutoDetect)
{
// Autodetect
s_bBHopCap = false;
Expand Down Expand Up @@ -2739,9 +2739,9 @@ void PM_Jump(void)
// BHop autodetection
#ifdef CLIENT_DLL
float speed = sqrtf(pmove->velocity[0] * pmove->velocity[0] + pmove->velocity[1] * pmove->velocity[1]);
int isLongJumping = cansuperjump && (pmove->oldbuttons & IN_DUCK);
bool isLongJumping = cansuperjump && (pmove->oldbuttons & IN_DUCK);

if (s_iBHopState == 2 && s_flBHopCheckTime == 0 && speed >= pmove->maxspeed * BUNNYJUMP_MAX_SPEED_FACTOR && !isLongJumping)
if (s_iBHopState == EBHopCap::AutoDetect && s_flBHopCheckTime == 0 && speed >= pmove->maxspeed * BUNNYJUMP_MAX_SPEED_FACTOR && !isLongJumping)
{
s_flBHopCheckTime = pmove->time + (BHOP_DETECT_DELAY * 1000);
}
Expand Down Expand Up @@ -3496,7 +3496,7 @@ void PM_Move(struct playermove_s *ppmove, int server)
#ifdef CLIENT_DLL
s_iMoveType = pmove->movetype;

if (s_iBHopState == 2 && s_flBHopCheckTime > 0)
if (s_iBHopState == EBHopCap::AutoDetect && s_flBHopCheckTime > 0)
{
float speed = sqrtf(pmove->velocity[0] * pmove->velocity[0] + pmove->velocity[1] * pmove->velocity[1]);

Expand Down
14 changes: 12 additions & 2 deletions src/pm_shared/pm_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ char PM_FindTextureType(char *name);
void PM_SetIsAG(int state);

#ifdef CLIENT_DLL
enum class EBHopCap
{
Disabled = 0,
Enabled = 1,
AutoDetect = 2,

_Min = Disabled,
_Max = AutoDetect,
};

int PM_GetOnGround();
int PM_GetWaterLevel();
int PM_GetMoveType();
int PM_GetBHopCapState();
void PM_SetBHopCapState(int state);
EBHopCap PM_GetBHopCapState();
void PM_SetBHopCapState(EBHopCap state);
void PM_ResetBHopDetection();
#else
int PM_GetBHopCapEnabled();
Expand Down

0 comments on commit 8a31105

Please sign in to comment.