Skip to content

Commit

Permalink
XYZ Speedometer option
Browse files Browse the repository at this point in the history
  • Loading branch information
taysta committed Dec 24, 2023
1 parent bdaddf2 commit fbc5630
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion codemp/cgame/cg_consolecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,8 @@ static bitInfo_T speedometerSettings[] = { // MAX_WEAPON_TWEAKS tweaks (24)
{ "Disable speedometer colors"},//11
{ "Array Colors 1" },//12
{ "Array Colors 2" },//13
{ "Old Speedgraph" }//14
{ "Old Speedgraph" },//14
{ "XYZ Speed" }//15
};
static const int MAX_SPEEDOMETER_SETTINGS = ARRAY_LEN(speedometerSettings);

Expand Down
11 changes: 9 additions & 2 deletions codemp/cgame/hud_strafehelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ void DF_SetPhysics() {
void DF_SetCGAZ() {
DF_SetFrameTime();
state.cgaz.currentSpeed = sqrtf(state.velocity[0] * state.velocity[0] + state.velocity[1] * state.velocity[1]); // is this right?
state.cgaz.currentspeedXYZ = sqrtf(state.velocity[0] * state.velocity[0] + state.velocity[1] * state.velocity[1] + state.velocity[2] * state.velocity[2]); // is this right?
DF_SetVelocityAngles();
state.cgaz.wishspeed = DF_GetWishspeed(state.cmd);
state.cgaz.v = state.cgaz.currentSpeed;
Expand Down Expand Up @@ -1843,15 +1844,21 @@ void DF_DrawSpeedometer(void) {
const char* accelStr, * accelStr2, * accelStr3;
char speedStr[32] = { 0 }, speedStr2[32] = { 0 }, speedStr3[32] = { 0 };
vec4_t colorSpeed = { 1, 1, 1, 1 };
const float currentSpeed = state.cgaz.currentSpeed;
float currentSpeed;
static float lastSpeed = 0, previousAccels[ACCEL_SAMPLES];
const float accel = currentSpeed - lastSpeed;
float accel;
float total, avgAccel, groundSpeedColor, groundSpeedsColor, currentSpeedColor;
int t, i;
static unsigned int index;
static int lastupdate, jumpsCounter = 0;
static qboolean clearOnNextJump = qfalse;

if(cg_speedometer.integer & SPEEDOMETER_XYZ)
currentSpeed = state.cgaz.currentspeedXYZ;
else
currentSpeed = state.cgaz.currentSpeed;

accel = currentSpeed - lastSpeed;
lastSpeed = currentSpeed;

if (currentSpeed > state.cgaz.wishspeed && !(cg_speedometer.integer & SPEEDOMETER_COLORS))
Expand Down
2 changes: 2 additions & 0 deletions codemp/cgame/hud_strafehelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ qboolean DF_HasAutoJump();
#define SPEEDOMETER_JUMPSCOLORS1 (1<<12)
#define SPEEDOMETER_JUMPSCOLORS2 (1<<13)
#define SPEEDOMETER_SPEEDGRAPHOLD (1<<14)
#define SPEEDOMETER_XYZ (1<<15)

//Miscellaneous
#define SPEEDOMETER_NUM_SAMPLES 500
Expand Down Expand Up @@ -152,6 +153,7 @@ typedef struct {
float frametime;
float wishspeed;
float currentspeed;
float currentspeedXYZ;
vec3_t velocityAngles;
float currentSpeed;
qboolean wasOnGround;
Expand Down

0 comments on commit fbc5630

Please sign in to comment.