Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cl_show_server_triggers_* cvars (related to plugin PR) #183

Merged
merged 17 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
490b311
Added cl_show_server_triggers_* cvars (related to plugin PR)
SmileyAG Dec 6, 2023
6a73219
Added IsTriggerForSinglePlayer function to rid from the triggers that…
SmileyAG Dec 8, 2023
f1b21e1
Added a new mode for displaying triggers via TriAPI which uses absmin…
SmileyAG Dec 14, 2023
546173c
Replaced multiple vectors with vector of structs for flexibility
SmileyAG Dec 14, 2023
5220f00
TriAPI triggers is only available for hardware mode
SmileyAG Dec 14, 2023
50bb16b
Fixed encoding issue in file
SmileyAG Dec 14, 2023
1cd0f44
Allow to draw triggers in software engine with HUD_AddEntity if cvar …
SmileyAG Dec 14, 2023
2eb7a3f
Supported TriAPI triggers for software engine too
SmileyAG Dec 14, 2023
f366884
Loading white sprite now with each call of HUD_VidInit instead of onc…
SmileyAG Dec 18, 2023
f772927
SetMapName: added option to disable forcing to lowercase for RPC
SmileyAG Dec 18, 2023
e900160
Removed debug messages, map name and entities storing to std::vector …
SmileyAG Dec 25, 2023
16b37db
cl_show_server_triggers should be always 0 by default
SmileyAG Dec 25, 2023
74bb50f
get_map_name: removed memset as extra code
SmileyAG Dec 30, 2023
7d1b778
Use boolean expression to check for the valid 'white_sprite'
SmileyAG Dec 30, 2023
a48b8a5
Use nested if statements for PR code in HUD_DrawTransparentTriangles …
SmileyAG Dec 30, 2023
32e5385
Replaced nested if statements with guard clauses for YaLTeR preferences
SmileyAG Dec 31, 2023
8e3cf45
Don't need IEngineStudio for hardware check since the code is compati…
SmileyAG Dec 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it should not be deleted imo

Why not? Is it preserved server-side too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eeeh, well, absmin/absmax triggers seems to be draw as should for the most of maps, but I had noticed that on some specific map (dyd_axn_plant) in a specific place it draw not the right size as should, so I'd keep that second mode for a reserve case, like if the main mode is would having some issues

Correct draw:

изображение

Wrong draw:

изображение

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
SmileyAG marked this conversation as resolved.
Show resolved Hide resolved
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>
SmileyAG marked this conversation as resolved.
Show resolved Hide resolved
#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);
SmileyAG marked this conversation as resolved.
Show resolved Hide resolved

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course! That depending through how many entities we want to iterate to find triggers!

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)
			{

According to the investigate from Solokiller, max edicts can be no more than 2047, anything higher than this will have cause crash: ValveSoftware/halflife#1777

Copy link
Contributor Author

@SmileyAG SmileyAG Dec 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also started to think might be it should controllable instead? Like if the map have a not much entities, then you don't want to do extra iterations and it will boost some performance, right? Since that code would run the each frame for updating triggers

Making some cvar like cl_show_server_triggers_entities_limit 2048

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CVar is definitely not the right solution here

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just leave it as is for now, since it doesn't run with showtriggers 0


#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