Merge pull request #1088 from ConHuevosGuey/master

Added a player speed display that prints the players speed and ground speed at the top right corner. The function can be toggled on using cl_showspeed 1.
This commit is contained in:
Yamagi 2024-03-19 19:17:12 +01:00 committed by GitHub
commit 6c21caa55d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 68 additions and 1 deletions

View file

@ -143,6 +143,11 @@ Set `0` by default.
* **cl_showfps**: Shows the framecounter. Set to `2` for more and to
`3` for even more informations.
* **cl_showspeed**: Shows the players speed. Set to `1` to display both
overall speed and (horizontal speed) in Quake Units (QU) respectfully at
the top right corner of the screen. Set to `2` to show only the horizontal
speed under the crosshair.
* **cl_model_preview_start**: start frame value in multiplayer model preview.
`-1` - don't show animation. Defaults to `84` for show salute animation.

View file

@ -43,6 +43,7 @@ cvar_t *cl_footsteps;
cvar_t *cl_timeout;
cvar_t *cl_predict;
cvar_t *cl_showfps;
cvar_t *cl_showspeed;
cvar_t *cl_gun;
cvar_t *cl_add_particles;
cvar_t *cl_add_lights;
@ -513,6 +514,7 @@ CL_InitLocal(void)
cl_noskins = Cvar_Get("cl_noskins", "0", 0);
cl_predict = Cvar_Get("cl_predict", "1", 0);
cl_showfps = Cvar_Get("cl_showfps", "0", CVAR_ARCHIVE);
cl_showspeed = Cvar_Get("cl_showspeed", "0", CVAR_ARCHIVE);
cl_upspeed = Cvar_Get("cl_upspeed", "200", 0);
cl_forwardspeed = Cvar_Get("cl_forwardspeed", "200", 0);

View file

@ -66,6 +66,8 @@ int crosshair_width, crosshair_height;
extern cvar_t *cl_showfps;
extern cvar_t *crosshair_scale;
extern cvar_t *cl_showspeed;
extern float GetPlayerSpeed();
void SCR_TimeRefresh_f(void);
void SCR_Loading_f(void);
@ -1447,6 +1449,57 @@ SCR_DrawLayout(void)
// ----
void
SCR_DrawSpeed(void)
{
if (cl_showspeed->value < 1) //Disabled, do nothing
return;
char spd_str[32];
float speed, speedxy;
float scale = SCR_GetConsoleScale();
int str_len, xPos, yPos = 0;
GetPlayerSpeed(&speed, &speedxy);
snprintf(spd_str, sizeof(spd_str), "%6.2f (%6.2f) QU/s", speed, speedxy);
str_len = scale * (strlen(spd_str) * 8 + 2);
if (cl_showspeed->value == 1) //Draw speed and xy speed at top right
{
xPos = viddef.width - str_len;
if (cl_showfps->value == 1 || cl_showfps->value == 2) // If showfps is enabled, draw it underneath
{
yPos = scale * 10;
}
else if (cl_showfps->value > 2)
{
yPos = scale * 20;
}
DrawStringScaled(xPos, yPos, spd_str, scale);
SCR_AddDirtyPoint(xPos, yPos);
SCR_AddDirtyPoint(viddef.width, yPos);
}
else if (cl_showspeed->value > 1) //Draw only xy speed under the crosshair
{
if (scale != 1) // Check if low resolution
{
scale -= 1;
}
snprintf(spd_str, sizeof(spd_str), "%6.2f", speedxy);
str_len = scale * (strlen(spd_str) * 8 + 2);
yPos = scr_vrect.y + (scr_vrect.height / 2) + (scale * 10);
xPos = scr_vrect.x + (scr_vrect.width / 2) - (str_len / 2);
DrawStringScaled(xPos, yPos, spd_str, scale);
SCR_AddDirtyPoint(xPos, yPos);
SCR_AddDirtyPoint(xPos + str_len, yPos);
}
}
void
SCR_Framecounter(void) {
long long newtime;
@ -1648,6 +1701,7 @@ SCR_UpdateScreen(void)
V_RenderView(separation[i]);
SCR_DrawStats();
SCR_DrawSpeed();
if (cl.frame.playerstate.stats[STAT_LAYOUTS] & 1)
{

View file

@ -341,6 +341,12 @@ PM_Friction(void)
vel[2] = vel[2] * newspeed;
}
//Used for speedoomter display.
void GetPlayerSpeed(float* speed, float* speedxy) {
*speedxy = sqrt(pml.velocity[0] * pml.velocity[0] + pml.velocity[1] * pml.velocity[1]);
*speed = VectorLength(pml.velocity);
}
/*
* Handles user intended acceleration
*/