Skip to content

Commit

Permalink
Added: hud_starfeguide
Browse files Browse the repository at this point in the history
  • Loading branch information
Elinsrc committed Oct 7, 2024
1 parent 47aa327 commit 401e0b8
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ hud_jumpspeed [0/1] - Shows the player's speed at the moment of the jump, defaul
hud_jumpspeed_below_cross [0/1] - Adjusts the position of the jumpspeed to the sight, defaut value is 0.
hud_jumpspeed_height [0/1] - Adjusts the positio jumpspeed, defaut value is 0.
hud_strafeguide [0/1] - Shows strafeguide, default value is 0. Taken from OpenAG.
hud_strafeguide_zoom [0/1], defaut value is 1.
hud_strafeguide_height [value], defaut value 0.
hud_strafeguide_size [value], defaut value 0.
hud_watermark [0/1] - Shows client author and build date, defaut value is 1.
hud_rainbow [0/1] - Paints HUD rainbow, default value is 0. Taken from OpenAG.
Expand Down Expand Up @@ -82,7 +87,7 @@ cl_cross_top_line [0/1], defaut value 1.
cl_cross_bottom_line [0/1], defaut value 1.
cl_cross_left_line [0/1], defaut value 1.
cl_cross_right_line [0/1], defaut value 1.
cl_cross_dot [0/1] ,defaut value 1.
cl_cross_dot [0/1], defaut value 1.
cl_cross_dot_size [value], defaut value 1.
cl_cross_dot_color "r g b", defaut value "255 255 255".
Expand Down
2 changes: 2 additions & 0 deletions cl_dll/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ SRCS+=./hud_jumpspeed.cpp
SRCS+=./hud_update.cpp
SRCS+=./hud_crosshairs.cpp
SRCS+=./hud_watermark.cpp
SRCS+=./hud_debug.cpp
SRCS+=./hud_strafeguide.cpp
SRCS+=./in_camera.cpp
SRCS+=./input.cpp
SRCS+=./input_goldsource.cpp
Expand Down
1 change: 1 addition & 0 deletions cl_dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ set (CLDLL_SOURCES
hud_crosshairs.cpp
hud_watermark.cpp
hud_debug.cpp
hud_strafeguide.cpp
in_camera.cpp
input.cpp
input_goldsource.cpp
Expand Down
4 changes: 4 additions & 0 deletions cl_dll/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ void CHud::Init( void )
// OpenAG
m_pCvarColor = CVAR_CREATE( "hud_color", "", FCVAR_ARCHIVE );
CVAR_CREATE( "hud_weapon", "0", FCVAR_ARCHIVE );
m_pCvarDrawDeathNoticesAlways = CVAR_CREATE( "cl_draw_deathnotices_always", "0", FCVAR_ARCHIVE );
m_pCvarDrawMessagesAlways = CVAR_CREATE( "cl_draw_messages_always", "0", FCVAR_ARCHIVE );
//

CVAR_CREATE( "hud_vis", "0", FCVAR_ARCHIVE );
Expand Down Expand Up @@ -438,6 +440,7 @@ void CHud::Init( void )
m_Crosshair.Init();
m_Watermark.Init();
m_Debug.Init();
m_StrafeGuide.Init();
m_Rainbow.Init();
#if USE_VGUI
GetClientVoiceMgr()->Init(&g_VoiceStatusHelper, (vgui::Panel**)&gViewPort);
Expand Down Expand Up @@ -633,6 +636,7 @@ void CHud::VidInit( void )
m_Crosshair.VidInit();
m_Watermark.VidInit();
m_Debug.VidInit();
m_StrafeGuide.VidInit();
#if USE_VGUI
GetClientVoiceMgr()->VidInit();
#endif
Expand Down
4 changes: 4 additions & 0 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct HUDLIST
#include "hud_crosshairs.h"
#include "hud_watermark.h"
#include "hud_debug.h"
#include "hud_strafeguide.h"
#include "rainbow.h"

//
Expand Down Expand Up @@ -564,6 +565,8 @@ class CHud
int m_iRes;
cvar_t *m_pCvarStealMouse;
cvar_t *m_pCvarDraw;
cvar_t *m_pCvarDrawDeathNoticesAlways;
cvar_t *m_pCvarDrawMessagesAlways;

// OpenAg
cvar_t* m_pCvarColor;
Expand Down Expand Up @@ -629,6 +632,7 @@ class CHud
CHudCrosshair m_Crosshair;
CHudWatermark m_Watermark;
CHudDebug m_Debug;
CHudStrafeGuide m_StrafeGuide;
CRainbow m_Rainbow;
#if !USE_VGUI || USE_NOVGUI_SCOREBOARD
CHudScoreboard m_Scoreboard;
Expand Down
26 changes: 26 additions & 0 deletions cl_dll/hud_redraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,32 @@ int CHud::Redraw( float flTime, int intermission )
pList = pList->pNext;
}
}
else
{
// Hack to draw some HUDs even when hud_draw is 0.
if (!intermission && !(m_iHideHUDDisplay & HIDEHUD_ALL))
{
if (m_Crosshair.m_iFlags & HUD_ACTIVE)
m_Crosshair.Draw(flTime);

if (m_Speedometer.m_iFlags & HUD_ACTIVE)
m_Speedometer.Draw(flTime);

if (m_StrafeGuide.m_iFlags & HUD_ACTIVE)
m_StrafeGuide.Draw(flTime);

if (m_Jumpspeed.m_iFlags & HUD_ACTIVE)
m_Jumpspeed.Draw(flTime);

if (gHUD.m_pCvarDrawDeathNoticesAlways->value != 0.0f
&& m_DeathNotice.m_iFlags & HUD_ACTIVE)
m_DeathNotice.Draw(flTime);

if (gHUD.m_pCvarDrawMessagesAlways->value != 0.0f
&& m_Message.m_iFlags & HUD_ACTIVE)
m_Message.Draw(flTime);
}
}

// are we in demo mode? do we need to draw the logo in the top corner?
if( m_iLogo )
Expand Down
171 changes: 171 additions & 0 deletions cl_dll/hud_strafeguide.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#define _USE_MATH_DEFINES
#include <cmath>
#include <complex>

#include "hud.h"
#include "cl_util.h"

#include "pm_defs.h"
#include "pm_movevars.h"
#include "ref_params.h"

enum border {
RED_GREEN,
GREEN_WHITE,
WHITE_GREEN,
GREEN_RED
};

int CHudStrafeGuide::Init()
{
m_iFlags = HUD_ACTIVE;

hud_strafeguide = CVAR_CREATE("hud_strafeguide", "0", FCVAR_ARCHIVE);
hud_strafeguide_zoom = CVAR_CREATE("hud_strafeguide_zoom", "1", FCVAR_ARCHIVE);
hud_strafeguide_height = CVAR_CREATE("hud_strafeguide_height", "0", FCVAR_ARCHIVE);
hud_strafeguide_size = CVAR_CREATE("hud_strafeguide_size", "0", FCVAR_ARCHIVE);

gHUD.AddHudElem(this);
return 0;
}

int CHudStrafeGuide::VidInit()
{
return 1;
}

int CHudStrafeGuide::Draw(float time)
{
if (hud_strafeguide->value == 0)
return 0;

double fov = CVAR_GET_FLOAT( "default_fov" ) / 180 * M_PI / 2;
double zoom = hud_strafeguide_zoom->value;

int size = gHUD.m_iFontHeight;
int height = ScreenHeight / 2 - 2*size;

if (hud_strafeguide_size->value != 0)
size = hud_strafeguide_size->value;

if (hud_strafeguide_height->value != 0)
height = hud_strafeguide_height->value;

for (int i = 0; i < 4; ++i) {
int r, g, b;
switch (i) {
case RED_GREEN: case WHITE_GREEN:
r = 0; g = 255; b = 0; break;
case GREEN_WHITE:
r = 255; g = 255; b = 255; break;
case GREEN_RED:
r = 255; g = 0; b = 0; break;
}

double boxLeftBase = -angles[i];
double boxRightBase = -angles[(i+1)%4];

if (std::abs(boxLeftBase - boxRightBase) < 1e-10)
continue;
if (boxLeftBase >= boxRightBase)
boxRightBase += 2 * M_PI;
if (std::abs(boxLeftBase - boxRightBase) < 1e-10)
continue;

for (int iCopy = -8; iCopy <= 8; ++iCopy) {
double boxLeft = boxLeftBase + iCopy * 2 * M_PI;
double boxRight = boxRightBase + iCopy * 2 * M_PI;
boxLeft *= zoom;
boxRight *= zoom;

if (std::abs(boxLeft) > fov && std::abs(boxRight) > fov && boxRight * boxLeft > 0)
continue;

boxLeft = boxLeft > fov ? fov : boxLeft < -fov ? -fov : boxLeft;
boxRight = boxRight > fov ? fov : boxRight < -fov ? -fov : boxRight;

boxLeft = std::tan(boxLeft ) / std::tan(fov);
boxRight = std::tan(boxRight) / std::tan(fov);

int boxLeftI = boxLeft / 1 * ScreenWidth / 2;
int boxRightI = boxRight/ 1 * ScreenWidth / 2;
boxLeftI += ScreenWidth / 2;
boxRightI += ScreenWidth / 2;

FillRGBA(boxLeftI, height, boxRightI-boxLeftI, size, r, g, b, 60);
}
}

return 0;
}

static double angleReduce(double a)
{
double tmp = std::fmod(a, 2*M_PI);
if (tmp < 0) tmp += 2*M_PI;
if (tmp > M_PI) tmp -= 2*M_PI;
return tmp;
}

void CHudStrafeGuide::Update(struct ref_params_s *pparams)
{
double frameTime = pparams->frametime;
auto input = std::complex<double>(pparams->cmd->forwardmove, pparams->cmd->sidemove);
double viewAngle = pparams->viewangles[1] / 180 * M_PI;

if (std::norm(input) == 0) {
for (int i = 0; i < 4; ++i) {
if (i < 2)
angles[i] = M_PI;
else
angles[i] = -M_PI;
}
return;
}

std::complex<double> velocity = lastSimvel;
lastSimvel = std::complex<double>(pparams->simvel[0], pparams->simvel[1]);

bool onground = pparams->onground;
double accelCoeff = onground ? pparams->movevars->accelerate : pparams->movevars->airaccelerate;
//TODO: grab the entity friction from somewhere. pparams->movevars->friction is sv_friction
//just use the default 1 for now
double frictionCoeff = 1;

double inputAbs = std::abs(input);
if (onground)
inputAbs = Q_min(inputAbs, pparams->movevars->maxspeed);
else
inputAbs = Q_min(inputAbs, 30);

input *= inputAbs / std::abs(input);

double uncappedAccel = accelCoeff * frictionCoeff * inputAbs * frameTime;
double velocityAbs = std::abs(velocity);

if (uncappedAccel >= 2 * velocityAbs)
angles[RED_GREEN] = M_PI;
else
angles[RED_GREEN] = std::acos(-uncappedAccel / velocityAbs / 2);

if (velocityAbs <= inputAbs)
angles[GREEN_WHITE] = 0;
else
angles[GREEN_WHITE] = std::acos(inputAbs / velocityAbs);

angles[GREEN_RED] = -angles[RED_GREEN];
angles[WHITE_GREEN] = -angles[GREEN_WHITE];

double inputAngle = std::log(input).imag();
double velocityAngle;

if (velocityAbs == 0)
velocityAngle = 0;
else
velocityAngle = std::log(velocity).imag();

for (int i = 0; i < 4; ++i) {
angles[i] += velocityAngle + inputAngle - viewAngle;
angles[i] = angleReduce(angles[i]);
}
}
21 changes: 21 additions & 0 deletions cl_dll/hud_strafeguide.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <complex>

class CHudStrafeGuide : public CHudBase
{
double angles[6] = {0.};

std::complex<double> lastSimvel = 0.;

cvar_t* hud_strafeguide;
cvar_t* hud_strafeguide_zoom;
cvar_t* hud_strafeguide_height;
cvar_t* hud_strafeguide_size;

public:
virtual int Init();
virtual int VidInit();
virtual int Draw(float time);

void Update(struct ref_params_s *ppmove);
};
1 change: 1 addition & 0 deletions cl_dll/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,7 @@ void DLLEXPORT V_CalcRefdef( struct ref_params_s *pparams )
// OpenAG
gHUD.m_Speedometer.UpdateSpeed(pparams->simvel);
gHUD.m_Jumpspeed.UpdateSpeed(pparams->simvel);
gHUD.m_StrafeGuide.Update(pparams);

// intermission / finale rendering
if( pparams->intermission )
Expand Down

0 comments on commit 401e0b8

Please sign in to comment.