Skip to content

Commit

Permalink
Added cl_show_server_triggers_* cvars (related to plugin PR) (#183)
Browse files Browse the repository at this point in the history
* Added cl_show_server_triggers_* cvars (related to plugin PR)

* Added IsTriggerForSinglePlayer function to rid from the triggers that unused in multiplayer

* Added a new mode for displaying triggers via TriAPI which uses absmin/absmax

* Replaced multiple vectors with vector of structs for flexibility

* TriAPI triggers is only available for hardware mode

* Fixed encoding issue in file

* Allow to draw triggers in software engine with HUD_AddEntity if cvar value above 0

* Supported TriAPI triggers for software engine too

* Loading white sprite now with each call of HUD_VidInit instead of once initialization to fix crash

* SetMapName: added option to disable forcing to lowercase for RPC

* Removed debug messages, map name and entities storing to std::vector as unnecessary

* cl_show_server_triggers should be always 0 by default

To not cost performance due of iterating through entities in cases when triggers are definitely not transmitted by plugin/server

* get_map_name: removed memset as extra code

* Use boolean expression to check for the valid 'white_sprite'

* Use nested if statements for PR code in HUD_DrawTransparentTriangles function

That done for versatility, since there is not much cases to check validity for

* Replaced nested if statements with guard clauses for YaLTeR preferences

* Don't need IEngineStudio for hardware check since the code is compatible with both engine versions from a while
  • Loading branch information
SmileyAG committed Dec 31, 2023
1 parent 0ad666a commit 7c35c77
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cl_dll/cdll_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ int CL_DLLEXPORT HUD_VidInit( void )

VGui_Startup();

gHUD.white_sprite = gEngfuncs.pfnSPR_Load("sprites/white.spr");

return 1;
}

Expand Down
13 changes: 13 additions & 0 deletions cl_dll/entity.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Client side entity management functions

#include <algorithm>
#include <memory.h>

#include "hud.h"
Expand All @@ -19,6 +20,12 @@
#include "discord_integration.h"

#include "particleman.h"

#include "r_studioint.h"

#undef min
#undef max

extern IParticleMan *g_pParticleMan;

void Game_AddObjects( void );
Expand Down Expand Up @@ -50,6 +57,12 @@ int CL_DLLEXPORT HUD_AddEntity( int type, struct cl_entity_s *ent, const char *m
break;
}

// show triggers that would be transferred from server-side with specific value in renderfx to differ it from other entities
// update: there is a new implementation of displaying triggers that allows you to display even when planes is stripped due to optimizations in updated map compiler
// so this code will only work if the value 2 is specified in the cvar, but it should not be deleted imo
if ((ent->curstate.rendermode == kRenderTransColor) && (ent->curstate.renderfx == kRenderFxTrigger) && (gHUD.m_pShowServerTriggers->value == 2.0f) && !gHUD.IsTriggerForSinglePlayer(ent->curstate.rendercolor))
ent->curstate.renderamt = std::min(255.0f, std::max(0.0f, gHUD.m_pShowServerTriggersAlpha->value));

// hide corpses option
if (gHUD.m_pCvarHideCorpses->value > 0 && ent->curstate.renderfx == kRenderFxDeadPlayer)
return 0;
Expand Down
21 changes: 21 additions & 0 deletions cl_dll/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ void CHud :: Init( void )
m_pCvarHideOtherPlayers = CVAR_CREATE("cl_hide_other_players", "0", 0);
m_pCvarColor = CVAR_CREATE( "hud_color", "", FCVAR_ARCHIVE );
m_pCvarPlayTeamSoundsVolume = CVAR_CREATE("cl_team_sounds_volume", "1.0", FCVAR_ARCHIVE);
m_pShowServerTriggers = CVAR_CREATE("cl_show_server_triggers", "0", FCVAR_ARCHIVE);
m_pShowServerTriggersAlpha = CVAR_CREATE("cl_show_server_triggers_alpha", "120", FCVAR_ARCHIVE);
cl_lw = gEngfuncs.pfnGetCvarPointer( "cl_lw" );
CVAR_CREATE("showtriggers", "0", 0);

Expand Down Expand Up @@ -937,3 +939,22 @@ float CHud::GetSensitivity( void )
return m_flMouseSensitivity;
}

bool CHud::IsTriggerForSinglePlayer(color24 rendercolor)
{
auto r = rendercolor.r;
auto g = rendercolor.g;
auto b = rendercolor.b;

if ((r == 128) && (g == 128) && (b == 128)) // trigger_autosave
return true;
else if ((r == 79) && (g == 255) && (b == 10)) // trigger_changelevel
return true;
else if ((r == 150) && (g == 75) && (b == 0)) // trigger_endsection
return true;
else if ((r == 238) && (g == 154) && (b == 77)) // trigger_monsterjump
return true;
else if ((r == 203) && (g == 103) && (b == 212)) // trigger_transition
return true;

return false;
}
6 changes: 6 additions & 0 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ class CHud
cvar_t *hud_classautokill;
cvar_t *hud_centerid;

cvar_t *m_pShowServerTriggers;
cvar_t *m_pShowServerTriggersAlpha;

int m_iFontHeight;

cvar_t* m_pCvarColor;
Expand Down Expand Up @@ -781,6 +784,9 @@ class CHud

float GetSensitivity();

bool IsTriggerForSinglePlayer(color24 rendercolor);

HSPRITE white_sprite = 0;
};

extern CHud gHUD;
Expand Down
2 changes: 2 additions & 0 deletions cl_dll/hudgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <vector>

#ifdef _WIN32
#include <winsani_in.h>
#include <Windows.h>
#include <winsani_out.h>
#endif

#ifdef __APPLE__
Expand Down
113 changes: 113 additions & 0 deletions cl_dll/tri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@

// Triangle rendering, if any

#include <algorithm>

#ifdef _WIN32
#include <winsani_in.h>
#include <Windows.h>
#include <winsani_out.h>
#endif

#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

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

Expand All @@ -22,6 +36,12 @@
#include "tri.h"
extern IParticleMan *g_pParticleMan;

#include "com_model.h"
#include "r_studioint.h"

#undef min
#undef max

/*
=================
HUD_DrawNormalTriangles
Expand All @@ -40,6 +60,89 @@ void CL_DLLEXPORT HUD_DrawNormalTriangles( void )
void RunEventList( void );
#endif

void DivideRGBABy255(float &r, float &g, float &b, float &a)
{
r /= 255.0f;
g /= 255.0f;
b /= 255.0f;
a /= 255.0f;
}

void DrawAACuboid(triangleapi_s *pTriAPI, Vector corner1, Vector corner2)
{
pTriAPI->Begin(TRI_QUADS);

pTriAPI->Vertex3f(corner1.x, corner1.y, corner1.z);
pTriAPI->Vertex3f(corner1.x, corner2.y, corner1.z);
pTriAPI->Vertex3f(corner2.x, corner2.y, corner1.z);
pTriAPI->Vertex3f(corner2.x, corner1.y, corner1.z);

pTriAPI->Vertex3f(corner1.x, corner1.y, corner1.z);
pTriAPI->Vertex3f(corner1.x, corner1.y, corner2.z);
pTriAPI->Vertex3f(corner1.x, corner2.y, corner2.z);
pTriAPI->Vertex3f(corner1.x, corner2.y, corner1.z);

pTriAPI->Vertex3f(corner1.x, corner1.y, corner1.z);
pTriAPI->Vertex3f(corner2.x, corner1.y, corner1.z);
pTriAPI->Vertex3f(corner2.x, corner1.y, corner2.z);
pTriAPI->Vertex3f(corner1.x, corner1.y, corner2.z);

pTriAPI->Vertex3f(corner2.x, corner2.y, corner2.z);
pTriAPI->Vertex3f(corner1.x, corner2.y, corner2.z);
pTriAPI->Vertex3f(corner1.x, corner1.y, corner2.z);
pTriAPI->Vertex3f(corner2.x, corner1.y, corner2.z);

pTriAPI->Vertex3f(corner2.x, corner2.y, corner2.z);
pTriAPI->Vertex3f(corner2.x, corner1.y, corner2.z);
pTriAPI->Vertex3f(corner2.x, corner1.y, corner1.z);
pTriAPI->Vertex3f(corner2.x, corner2.y, corner1.z);

pTriAPI->Vertex3f(corner2.x, corner2.y, corner2.z);
pTriAPI->Vertex3f(corner2.x, corner2.y, corner1.z);
pTriAPI->Vertex3f(corner1.x, corner2.y, corner1.z);
pTriAPI->Vertex3f(corner1.x, corner2.y, corner2.z);

pTriAPI->End();
}

void DrawServerTriggers()
{
if ((gHUD.m_pShowServerTriggers->value > 0) && (gHUD.m_pShowServerTriggers->value != 2.0f))
{
for (int e = 0; e < MAX_EDICTS; ++e)
{
cl_entity_t* ent = gEngfuncs.GetEntityByIndex(e);
if (ent)
{
if (ent->model)
{
if ((ent->curstate.rendermode == kRenderTransColor) && (ent->curstate.renderfx == kRenderFxTrigger))
{
color24 colors = ent->curstate.rendercolor;
if (!gHUD.IsTriggerForSinglePlayer(colors))
{
gEngfuncs.pTriAPI->RenderMode(kRenderTransAdd);
gEngfuncs.pTriAPI->CullFace(TRI_NONE);

float r = colors.r, g = colors.g, b = colors.b, a = std::min(255.0f, std::max(0.0f, gHUD.m_pShowServerTriggersAlpha->value));
DivideRGBABy255(r, g, b, a);
gEngfuncs.pTriAPI->Color4f(r, g, b, a);

Vector mins = ent->curstate.mins;
Vector maxs = ent->curstate.maxs;
Vector origin = ent->curstate.origin;
Vector absmin = origin + mins;
Vector absmax = origin + maxs;

DrawAACuboid(gEngfuncs.pTriAPI, absmin, absmax);
}
}
}
}
}
}
}

/*
=================
HUD_DrawTransparentTriangles
Expand All @@ -57,4 +160,14 @@ void CL_DLLEXPORT HUD_DrawTransparentTriangles( void )

if ( g_pParticleMan )
g_pParticleMan->Update();

if (!gHUD.white_sprite)
return;

if (!gEngfuncs.pTriAPI->SpriteTexture(const_cast<model_s*>(gEngfuncs.GetSpritePointer(gHUD.white_sprite)), 0))
return;

DrawServerTriggers();

gEngfuncs.pTriAPI->RenderMode(kRenderNormal);
}
2 changes: 1 addition & 1 deletion common/com_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define STUDIO_EVENTS 2

#define MAX_CLIENTS 32
#define MAX_EDICTS 900
#define MAX_EDICTS 2048

#define MAX_MODEL_NAME 64
#define MAX_MAP_HULLS 4
Expand Down
1 change: 1 addition & 0 deletions common/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ enum
kRenderFxGlowShell, // Glowing Shell
kRenderFxClampMinScale, // Keep this sprite from getting very small (SPRITES only!)
kRenderFxLightMultiplier, //CTM !!!CZERO added to tell the studiorender that the value in iuser2 is a lightmultiplier
kRenderFxTrigger = 241,
};


Expand Down

0 comments on commit 7c35c77

Please sign in to comment.