Skip to content

Commit

Permalink
Allow further customization of strafe helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kugelrund committed May 19, 2022
1 parent 77fa56c commit d78864e
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 11 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ Default: `4.0`.
Scale of the text for speed display.
Default: `0.9`.

#### `cg_strafeHelperSpeedX` (#)

Horizontal offset of the text for speed display, relative to the center of the screen.
Default: `0.0` (center of the screen).

#### `cg_strafeHelperSpeedY` (#)

Vertical offset of the text for speed display, relative to the strafe helper.
Expand All @@ -86,6 +91,12 @@ Default: `0.0` (directly under the strafe helper).
Vertical position of the strafe helper.
Default: `50.0`.

#### `cg_strafeHelperColor[...]` (0.0 - 1.0)

Color components (red, green, blue, alpha) for different strafe helper elements.
These are `Accelerating`, `Optimal`, `CenterMarker` and `Speed`.
Colors can be set more conveniently with the corresponding commands.

### Cosmetics

#### `g_saber_color` (color)
Expand Down Expand Up @@ -128,3 +139,11 @@ Default: `0`.

Create an automatic save when a checkpoint is reached in checkpoint mode.
Default: `0`.

## New Commands

### HUD

#### `strafeHelperColor[...] <r> <g> <b> <a>` (components in range 0.0 to 1.0)

Sets the color for one of the strafe helper elements `Accelerating`, `Optimal`, `CenterMarker` or `Speed` to the given red, green, blue and alpha values.
70 changes: 70 additions & 0 deletions code/cgame/cg_consolecmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,71 @@ static void CG_InfoUp_f( void )
// cg.showInformation = qfalse;
}

static void CG_SetStrafeHelperColorAccelerating_f( void ) {
if (cgi_Argc() != 5) {
Com_Printf("Usage: strafeHelperColorAccelerating <red 0-1> <green 0-1> <blue 0-1> <alpha 0-1>\n" );
Com_Printf("Current color is: %f %f %f %f\n",
cg_strafeHelperColorAcceleratingR.value,
cg_strafeHelperColorAcceleratingG.value,
cg_strafeHelperColorAcceleratingB.value,
cg_strafeHelperColorAcceleratingA.value);
return;
}
cgi_Cvar_Set("cg_strafeHelperColorAcceleratingR", CG_Argv(1));
cgi_Cvar_Set("cg_strafeHelperColorAcceleratingG", CG_Argv(2));
cgi_Cvar_Set("cg_strafeHelperColorAcceleratingB", CG_Argv(3));
cgi_Cvar_Set("cg_strafeHelperColorAcceleratingA", CG_Argv(4));
}

static void CG_SetStrafeHelperColorOptimal_f( void ) {
if (cgi_Argc() != 5) {
Com_Printf("Usage: strafeHelperColorOptimal <red 0-1> <green 0-1> <blue 0-1> <alpha 0-1>\n" );
Com_Printf("Current color is: %f %f %f %f\n",
cg_strafeHelperColorOptimalR.value,
cg_strafeHelperColorOptimalG.value,
cg_strafeHelperColorOptimalB.value,
cg_strafeHelperColorOptimalA.value);
return;
}
cgi_Cvar_Set("cg_strafeHelperColorOptimalR", CG_Argv(1));
cgi_Cvar_Set("cg_strafeHelperColorOptimalG", CG_Argv(2));
cgi_Cvar_Set("cg_strafeHelperColorOptimalB", CG_Argv(3));
cgi_Cvar_Set("cg_strafeHelperColorOptimalA", CG_Argv(4));
}

static void CG_SetStrafeHelperColorCenterMarker_f( void ) {
if (cgi_Argc() != 5) {
Com_Printf("Usage: strafeHelperColorCenterMarker <red 0-1> <green 0-1> <blue 0-1> <alpha 0-1>\n" );
Com_Printf("Current color is: %f %f %f %f\n",
cg_strafeHelperColorCenterMarkerR.value,
cg_strafeHelperColorCenterMarkerG.value,
cg_strafeHelperColorCenterMarkerB.value,
cg_strafeHelperColorCenterMarkerA.value);
return;
}
cgi_Cvar_Set("cg_strafeHelperColorCenterMarkerR", CG_Argv(1));
cgi_Cvar_Set("cg_strafeHelperColorCenterMarkerG", CG_Argv(2));
cgi_Cvar_Set("cg_strafeHelperColorCenterMarkerB", CG_Argv(3));
cgi_Cvar_Set("cg_strafeHelperColorCenterMarkerA", CG_Argv(4));
}

static void CG_SetStrafeHelperColorSpeed_f( void ) {
if (cgi_Argc() != 5) {
Com_Printf("Usage: strafeHelperColorSpeed <red 0-1> <green 0-1> <blue 0-1> <alpha 0-1>\n" );
Com_Printf("Current color is: %f %f %f %f\n",
cg_strafeHelperColorSpeedR.value,
cg_strafeHelperColorSpeedG.value,
cg_strafeHelperColorSpeedB.value,
cg_strafeHelperColorSpeedA.value);
return;
}
cgi_Cvar_Set("cg_strafeHelperColorSpeedR", CG_Argv(1));
cgi_Cvar_Set("cg_strafeHelperColorSpeedG", CG_Argv(2));
cgi_Cvar_Set("cg_strafeHelperColorSpeedB", CG_Argv(3));
cgi_Cvar_Set("cg_strafeHelperColorSpeedA", CG_Argv(4));
}


typedef struct {
char *cmd;
void (*function)(void);
Expand Down Expand Up @@ -217,6 +282,11 @@ Ghoul2 Insert End
{ "dpinvprev", CG_DPPrevInventory_f },
{ "dpforcenext", CG_DPNextForcePower_f },
{ "dpforceprev", CG_DPPrevForcePower_f },

{ "strafeHelperColorAccelerating", CG_SetStrafeHelperColorAccelerating_f },
{ "strafeHelperColorOptimal", CG_SetStrafeHelperColorOptimal_f },
{ "strafeHelperColorCenterMarker", CG_SetStrafeHelperColorCenterMarker_f },
{ "strafeHelperColorSpeed", CG_SetStrafeHelperColorSpeed_f },
};


Expand Down
1 change: 1 addition & 0 deletions code/cgame/cg_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,7 @@ static void CG_DrawStrafeHelper( void ) {
params.height = cg_strafeHelperHeight.value;
params.y = cg_strafeHelperY.value;
params.speed_scale = cg_strafeHelperSpeedScale.value;
params.speed_x = cg_strafeHelperSpeedX.value;
params.speed_y = cg_strafeHelperSpeedY.value;
StrafeHelper_Draw( &params, SCREEN_WIDTH, SCREEN_HEIGHT );
}
Expand Down
17 changes: 17 additions & 0 deletions code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,25 @@ extern vmCvar_t cg_strafeHelperCenterMarker;
extern vmCvar_t cg_strafeHelperHeight;
extern vmCvar_t cg_strafeHelperScale;
extern vmCvar_t cg_strafeHelperSpeedScale;
extern vmCvar_t cg_strafeHelperSpeedX;
extern vmCvar_t cg_strafeHelperSpeedY;
extern vmCvar_t cg_strafeHelperY;
extern vmCvar_t cg_strafeHelperColorAcceleratingR;
extern vmCvar_t cg_strafeHelperColorAcceleratingG;
extern vmCvar_t cg_strafeHelperColorAcceleratingB;
extern vmCvar_t cg_strafeHelperColorAcceleratingA;
extern vmCvar_t cg_strafeHelperColorOptimalR;
extern vmCvar_t cg_strafeHelperColorOptimalG;
extern vmCvar_t cg_strafeHelperColorOptimalB;
extern vmCvar_t cg_strafeHelperColorOptimalA;
extern vmCvar_t cg_strafeHelperColorCenterMarkerR;
extern vmCvar_t cg_strafeHelperColorCenterMarkerG;
extern vmCvar_t cg_strafeHelperColorCenterMarkerB;
extern vmCvar_t cg_strafeHelperColorCenterMarkerA;
extern vmCvar_t cg_strafeHelperColorSpeedR;
extern vmCvar_t cg_strafeHelperColorSpeedG;
extern vmCvar_t cg_strafeHelperColorSpeedB;
extern vmCvar_t cg_strafeHelperColorSpeedA;

void CG_NewClientinfo( int clientNum );
//
Expand Down
34 changes: 34 additions & 0 deletions code/cgame/cg_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,25 @@ vmCvar_t cg_strafeHelperCenterMarker;
vmCvar_t cg_strafeHelperHeight;
vmCvar_t cg_strafeHelperScale;
vmCvar_t cg_strafeHelperSpeedScale;
vmCvar_t cg_strafeHelperSpeedX;
vmCvar_t cg_strafeHelperSpeedY;
vmCvar_t cg_strafeHelperY;
vmCvar_t cg_strafeHelperColorAcceleratingR;
vmCvar_t cg_strafeHelperColorAcceleratingG;
vmCvar_t cg_strafeHelperColorAcceleratingB;
vmCvar_t cg_strafeHelperColorAcceleratingA;
vmCvar_t cg_strafeHelperColorOptimalR;
vmCvar_t cg_strafeHelperColorOptimalG;
vmCvar_t cg_strafeHelperColorOptimalB;
vmCvar_t cg_strafeHelperColorOptimalA;
vmCvar_t cg_strafeHelperColorCenterMarkerR;
vmCvar_t cg_strafeHelperColorCenterMarkerG;
vmCvar_t cg_strafeHelperColorCenterMarkerB;
vmCvar_t cg_strafeHelperColorCenterMarkerA;
vmCvar_t cg_strafeHelperColorSpeedR;
vmCvar_t cg_strafeHelperColorSpeedG;
vmCvar_t cg_strafeHelperColorSpeedB;
vmCvar_t cg_strafeHelperColorSpeedA;

typedef struct {
vmCvar_t *vmCvar;
Expand Down Expand Up @@ -445,8 +462,25 @@ Ghoul2 Insert End
{ &cg_strafeHelperHeight, "cg_strafeHelperHeight", "20", CVAR_ARCHIVE },
{ &cg_strafeHelperScale, "cg_strafeHelperScale", "4", CVAR_ARCHIVE },
{ &cg_strafeHelperSpeedScale, "cg_strafeHelperSpeedScale", "0.9", CVAR_ARCHIVE },
{ &cg_strafeHelperSpeedX, "cg_strafeHelperSpeedX", "0", CVAR_ARCHIVE },
{ &cg_strafeHelperSpeedY, "cg_strafeHelperSpeedY", "0", CVAR_ARCHIVE },
{ &cg_strafeHelperY, "cg_strafeHelperY", "50", CVAR_ARCHIVE },
{ &cg_strafeHelperColorAcceleratingR, "cg_strafeHelperColorAcceleratingR", "0.0", CVAR_ARCHIVE },
{ &cg_strafeHelperColorAcceleratingG, "cg_strafeHelperColorAcceleratingG", "0.5", CVAR_ARCHIVE },
{ &cg_strafeHelperColorAcceleratingB, "cg_strafeHelperColorAcceleratingB", "0.125", CVAR_ARCHIVE },
{ &cg_strafeHelperColorAcceleratingA, "cg_strafeHelperColorAcceleratingA", "0.375", CVAR_ARCHIVE },
{ &cg_strafeHelperColorOptimalR, "cg_strafeHelperColorOptimalR", "0.0", CVAR_ARCHIVE },
{ &cg_strafeHelperColorOptimalG, "cg_strafeHelperColorOptimalG", "1.0", CVAR_ARCHIVE },
{ &cg_strafeHelperColorOptimalB, "cg_strafeHelperColorOptimalB", "0.25", CVAR_ARCHIVE },
{ &cg_strafeHelperColorOptimalA, "cg_strafeHelperColorOptimalA", "0.75", CVAR_ARCHIVE },
{ &cg_strafeHelperColorCenterMarkerR, "cg_strafeHelperColorCenterMarkerR", "1.0", CVAR_ARCHIVE },
{ &cg_strafeHelperColorCenterMarkerG, "cg_strafeHelperColorCenterMarkerG", "1.0", CVAR_ARCHIVE },
{ &cg_strafeHelperColorCenterMarkerB, "cg_strafeHelperColorCenterMarkerB", "1.0", CVAR_ARCHIVE },
{ &cg_strafeHelperColorCenterMarkerA, "cg_strafeHelperColorCenterMarkerA", "0.75", CVAR_ARCHIVE },
{ &cg_strafeHelperColorSpeedR, "cg_strafeHelperColorSpeedR", "1.0", CVAR_ARCHIVE },
{ &cg_strafeHelperColorSpeedG, "cg_strafeHelperColorSpeedG", "1.0", CVAR_ARCHIVE },
{ &cg_strafeHelperColorSpeedB, "cg_strafeHelperColorSpeedB", "1.0", CVAR_ARCHIVE },
{ &cg_strafeHelperColorSpeedA, "cg_strafeHelperColorSpeedA", "0.9", CVAR_ARCHIVE },
};

int cvarTableSize = sizeof( cvarTable ) / sizeof( cvarTable[0] );
Expand Down
2 changes: 1 addition & 1 deletion code/speedrun/strafe_helper
39 changes: 35 additions & 4 deletions code/speedrun/strafe_helper_includes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,47 @@

extern "C" {

shi_ColorRGBA shi_getColorAccelerating() {
return {cg_strafeHelperColorAcceleratingR.value,
cg_strafeHelperColorAcceleratingG.value,
cg_strafeHelperColorAcceleratingB.value,
cg_strafeHelperColorAcceleratingA.value};
}

shi_ColorRGBA shi_getColorOptimal() {
return {cg_strafeHelperColorOptimalR.value,
cg_strafeHelperColorOptimalG.value,
cg_strafeHelperColorOptimalB.value,
cg_strafeHelperColorOptimalA.value};
}

shi_ColorRGBA shi_getColorCenterMarker() {
return {cg_strafeHelperColorCenterMarkerR.value,
cg_strafeHelperColorCenterMarkerG.value,
cg_strafeHelperColorCenterMarkerB.value,
cg_strafeHelperColorCenterMarkerA.value};
}

shi_ColorRGBA shi_getColorSpeed() {
return {cg_strafeHelperColorSpeedR.value,
cg_strafeHelperColorSpeedG.value,
cg_strafeHelperColorSpeedB.value,
cg_strafeHelperColorSpeedA.value};
}

void shi_drawFilledRectangle(const float x, const float y,
const float w, const float h, const vec4_t color)
const float w, const float h,
const shi_ColorRGBA color)
{
CG_FillRect(x, y, w, h, color);
const vec4_t color_converted = {color.r, color.g, color.b, color.a};
CG_FillRect(x, y, w, h, color_converted);
}

void shi_drawString(float x, float y, const char* string, float scale, const vec4_t color)
void shi_drawString(float x, float y, const char* string, float scale, const shi_ColorRGBA color)
{
const vec4_t color_converted = {color.r, color.g, color.b, color.a};
const float w = cgi_R_Font_StrLenPixels(string, cgs.media.qhFontMedium, scale);
cgi_R_Font_DrawString(x - w/2, y, string, color, cgs.media.qhFontMedium, -1, scale);
cgi_R_Font_DrawString(x - w/2, y, string, color_converted, cgs.media.qhFontMedium, -1, scale);
}

} // extern "C"
19 changes: 13 additions & 6 deletions code/speedrun/strafe_helper_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ extern "C" {
#include <math.h>
#include <stdio.h>

static const float shi_color_accelerating[4] = {0.0f, 0.5f, 0.125f, 0.375f};
static const float shi_color_optimal[4] = {0.0f, 1.0f, 0.25f, 0.75f};
static const float shi_color_center_marker[4] = {1.0f, 1.0f, 1.0f, 0.75f};
static const float shi_color_speed[4] = {1.0f, 1.0f, 1.0f, 0.9f};
struct shi_ColorRGBA {
float r;
float g;
float b;
float a;
};

void shi_drawFilledRectangle(float x, float y, float w, float h, const float color[4]);
void shi_drawString(float x, float y, const char* string, float scale, const float color[4]);
struct shi_ColorRGBA shi_getColorAccelerating(void);
struct shi_ColorRGBA shi_getColorOptimal(void);
struct shi_ColorRGBA shi_getColorCenterMarker(void);
struct shi_ColorRGBA shi_getColorSpeed(void);

void shi_drawFilledRectangle(float x, float y, float w, float h, struct shi_ColorRGBA color);
void shi_drawString(float x, float y, const char* string, float scale, struct shi_ColorRGBA color);

#ifdef __cplusplus
} // extern "C"
Expand Down

0 comments on commit d78864e

Please sign in to comment.