Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding bxt_hud_jumpdistance #340

Merged
merged 5 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions BunnymodXT/cvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ namespace CVars
CVarWrapper bxt_hud_jumpspeed("bxt_hud_jumpspeed", "0");
CVarWrapper bxt_hud_jumpspeed_offset("bxt_hud_jumpspeed_offset", "");
CVarWrapper bxt_hud_jumpspeed_anchor("bxt_hud_jumpspeed_anchor", "0.5 1");
CVarWrapper bxt_hud_jumpdistance("bxt_hud_jumpdistance", "0");
CVarWrapper bxt_hud_jumpdistance_offset("bxt_hud_jumpdistance_offset", "");
CVarWrapper bxt_hud_jumpdistance_anchor("bxt_hud_jumpdistance_anchor", "0.5 1");
CVarWrapper bxt_hud_health("bxt_hud_health", "0");
CVarWrapper bxt_hud_health_offset("bxt_hud_health_offset", "");
CVarWrapper bxt_hud_health_anchor("bxt_hud_health_anchor", "0.5 1");
Expand Down Expand Up @@ -319,6 +322,9 @@ namespace CVars
&bxt_hud_jumpspeed,
&bxt_hud_jumpspeed_offset,
&bxt_hud_jumpspeed_anchor,
&bxt_hud_jumpdistance,
&bxt_hud_jumpdistance_offset,
&bxt_hud_jumpdistance_anchor,
&bxt_hud_health,
&bxt_hud_health_offset,
&bxt_hud_health_anchor,
Expand Down
3 changes: 3 additions & 0 deletions BunnymodXT/cvars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ namespace CVars
extern CVarWrapper bxt_hud_jumpspeed;
extern CVarWrapper bxt_hud_jumpspeed_offset;
extern CVarWrapper bxt_hud_jumpspeed_anchor;
extern CVarWrapper bxt_hud_jumpdistance;
extern CVarWrapper bxt_hud_jumpdistance_offset;
extern CVarWrapper bxt_hud_jumpdistance_anchor;
extern CVarWrapper bxt_hud_health;
extern CVarWrapper bxt_hud_health_offset;
extern CVarWrapper bxt_hud_health_anchor;
Expand Down
53 changes: 53 additions & 0 deletions BunnymodXT/hud_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,58 @@ namespace CustomHud
vecCopy(player.velocity, prevVel);
}

static void DrawJumpDistance(float flTime)
{
static float prevOrigin[3] = { 0.0f, 0.0f, 0.0f };
static float prevPlayerOrigin[3] = { 0.0f, 0.0f, 0.0f };
static float prevVel[3] = { 0.0f, 0.0f, 0.0f };

if (CVars::bxt_hud_jumpdistance.GetBool())
{
static bool inJump = false;
static double jumpDistance = 0.0;

// 1 = jumpdistance will update when velocity is reasonably positive
// not 1 = jumpdistance will update when velocity changes, eg just falling
if (!inJump && (
(((CVars::bxt_hud_jumpdistance.GetInt() == 1) ?
player.velocity[2] > 0.0f : player.velocity[2] != 0.0f) && prevVel[2] == 0.0f) ||
(player.velocity[2] > 0.0f && prevVel[2] < 0.0f)))
{
inJump = true;

// by the time the instantaneous velocity is here
// there is already displacement, which is in the previous frame
vecCopy(prevPlayerOrigin, prevOrigin);
}
else if (inJump && ((player.velocity[2] == 0.0f && prevVel[2] < 0.0f)))
{
inJump = false;

// add 16*2 because of player size can reach the edge of the block up to 16 unit
double distance = length(player.origin[0] - prevOrigin[0], player.origin[1] - prevOrigin[1]) + 32.0;

if (distance > 150.0 || CVars::bxt_hud_jumpdistance.GetInt() != 1) // from uq_jumpstats default
{
jumpDistance = distance;
}
}
else if (player.origin[2] == prevPlayerOrigin[2])
{
// walking
inJump = false;
}

int x, y;
GetPosition(CVars::bxt_hud_jumpdistance_offset, CVars::bxt_hud_jumpdistance_anchor, &x, &y, 0, -4 * NumberHeight);
DrawNumber(static_cast<int>(trunc(jumpDistance)), x, y, hudColor[0], hudColor[1], hudColor[2]);
}

vecCopy(player.origin, prevPlayerOrigin);
vecCopy(player.velocity, prevVel);
}


void DrawTimer(float flTime)
{
if (CVars::bxt_hud_timer.GetBool())
Expand Down Expand Up @@ -1558,6 +1610,7 @@ namespace CustomHud
DrawViewangles(flTime);
DrawSpeedometer(flTime);
DrawJumpspeed(flTime);
DrawJumpDistance(flTime);
DrawTimer(flTime);
DrawDistance(flTime);
DrawEntityInfo(flTime);
Expand Down
3 changes: 3 additions & 0 deletions BunnymodXT/modules/ClientDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,9 @@ void ClientDLL::RegisterCVarsAndCommands()
REG(bxt_hud_jumpspeed);
REG(bxt_hud_jumpspeed_offset);
REG(bxt_hud_jumpspeed_anchor);
REG(bxt_hud_jumpdistance);
REG(bxt_hud_jumpdistance_offset);
REG(bxt_hud_jumpdistance_anchor);
REG(bxt_hud_health);
REG(bxt_hud_health_offset);
REG(bxt_hud_health_anchor);
Expand Down