Skip to content

Commit

Permalink
Merge pull request #95 from erysdren/show_speed
Browse files Browse the repository at this point in the history
CLIENT: player debug info display cvar
  • Loading branch information
MotoLegacy authored Dec 10, 2024
2 parents d52ee23 + c1c726a commit 317da95
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
16 changes: 15 additions & 1 deletion source/client/draw.qc
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,18 @@ void(vector position, string text, vector size, vector rgb, float alpha, float d
else
x += (font_kerningamount[(chr - 33)] + 1) * (size_x/8);
}
};
};

void(vector pos, string label, vector v) Draw_FancyVector =
{
Draw_String(pos, label, [12, 12], [1, 1, 0], 1, 0);
Draw_String(pos + [32, 16], sprintf("X: %d", v.x), [12, 12], [1, 1, 1], 1, 0);
Draw_String(pos + [32, 32], sprintf("Y: %d", v.y), [12, 12], [1, 1, 1], 1, 0);
Draw_String(pos + [32, 48], sprintf("Z: %d", v.z), [12, 12], [1, 1, 1], 1, 0);
};

void(vector pos, string label, float f, string suffix) Draw_FancyFloat =
{
Draw_String(pos, label, [12, 12], [1, 1, 0], 1, 0);
Draw_String(pos + [32, 16], sprintf("%d %s", f, suffix), [12, 12], [1, 1, 1], 1, 0);
};
37 changes: 37 additions & 0 deletions source/client/hud.qc
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,41 @@ void(float width, float height) HUD_RoundStopWatch =
Draw_String([width - (getTextWidth(stopwatch, 12)) - 2, 16], stopwatch, [12, 12], [1, 1, 1], 1, 0);
}

/*******************
* HUD Debug Info *
*******************/

// set from CSQC_Ent_Update
vector player_velocity;

void(float width, float height) HUD_PlayerDebugInfo =
{
static float lastupstime;
static float lastups;

if (!cvar("scr_playerdebuginfo"))
return;

if ((time - lastupstime) >= 1.0 / 20)
{
lastups = vlen(player_velocity);
lastupstime = time;
}

vector pos = [cvar("scr_playerdebuginfo_x"), cvar("scr_playerdebuginfo_y")];
pos.x += GetUltraWideOffset();

drawfill(pos - [8, 8], [128, 192], [0, 0, 0], 0.75, 0);

Draw_FancyFloat(pos, "Speed:", lastups, "qu/s");

if (cvar("scr_playerdebuginfo") >= 2)
{
Draw_FancyVector(pos + [0, 36], "Angles:", getproperty(VF_ANGLES));
Draw_FancyVector(pos + [0, 106], "Origin:", getproperty(VF_ORIGIN));
}
};

/*******************
* HUD Draw *
*******************/
Expand Down Expand Up @@ -2014,6 +2049,8 @@ void(float width, float height) HUD_Draw =
HUD_Scores();

HUD_Achievements(width, height);

HUD_PlayerDebugInfo(width, height);

if (screenflash_duration > time)
HUD_Screenflash();
Expand Down
7 changes: 7 additions & 0 deletions source/client/main.qc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ noref void(float apiver, string enginename, float enginever) CSQC_Init =
autocvar(in_rumbleenabled, 1);
autocvar(in_aimassist, 0);

autocvar(scr_playerdebuginfo, 0);
autocvar(scr_playerdebuginfo_x, 64);
autocvar(scr_playerdebuginfo_y, 6);

// Runtime check if we're running this in WebASM/WebGL.
if (cvar_string("sys_platform") == "Web")
platform_is_web = true;
Expand Down Expand Up @@ -430,6 +434,9 @@ noref void(float isnew) CSQC_Ent_Update =
self.is_in_menu = readbyte();
self.is_spectator = readbyte();

// set for HUD_PlayerDebugInfo
player_velocity = self.velocity;

setmodelindex(self, self.modelindex);

if (self.is_spectator)
Expand Down

0 comments on commit 317da95

Please sign in to comment.