From af7631f5c8fda794656729881a7982779baa1bd7 Mon Sep 17 00:00:00 2001 From: SmileyAG Date: Mon, 25 Dec 2023 22:02:46 +0400 Subject: [PATCH] Added cl_show_server_triggers_* cvars (related to plugin PR) --- src/common/com_model.h | 2 +- src/common/const.h | 1 + src/game/client/cdll_int.cpp | 1 + src/game/client/entity.cpp | 8 +++ src/game/client/hud.cpp | 22 ++++++++ src/game/client/hud.h | 3 ++ src/game/client/tri.cpp | 98 ++++++++++++++++++++++++++++++++++++ 7 files changed, 134 insertions(+), 1 deletion(-) diff --git a/src/common/com_model.h b/src/common/com_model.h index 93806a6d..d2fa1219 100644 --- a/src/common/com_model.h +++ b/src/common/com_model.h @@ -13,7 +13,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 diff --git a/src/common/const.h b/src/common/const.h index 6ce6eece..f5765c7f 100644 --- a/src/common/const.h +++ b/src/common/const.h @@ -705,6 +705,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, }; typedef unsigned int func_t; diff --git a/src/game/client/cdll_int.cpp b/src/game/client/cdll_int.cpp index 95db50e5..9d5e1d22 100644 --- a/src/game/client/cdll_int.cpp +++ b/src/game/client/cdll_int.cpp @@ -284,6 +284,7 @@ int CL_DLLEXPORT HUD_VidInit(void) PM_ResetBHopDetection(); CResults::Get().Stop(); GetClientVoiceMgr()->VidInit(); + gHUD.white_sprite = gEngfuncs.pfnSPR_Load("sprites/white.spr"); return 1; } diff --git a/src/game/client/entity.cpp b/src/game/client/entity.cpp index 6c469d2b..43436997 100644 --- a/src/game/client/entity.cpp +++ b/src/game/client/entity.cpp @@ -22,6 +22,8 @@ extern IParticleMan *g_pParticleMan; ConVar r_dynamic_ent_light("r_dynamic_ent_light", "1", FCVAR_BHL_ARCHIVE); ConVar cl_hidecorpses("cl_hidecorpses", "0", FCVAR_BHL_ARCHIVE); +extern ConVar cl_show_server_triggers; +extern ConVar cl_show_server_triggers_alpha; void Game_AddObjects(void); @@ -54,6 +56,12 @@ int CL_DLLEXPORT HUD_AddEntity(int type, struct cl_entity_s *ent, const char *mo 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) && (cl_show_server_triggers.GetInt() == 2) && !gHUD.IsTriggerForSinglePlayer(ent->curstate.rendercolor)) + ent->curstate.renderamt = std::clamp(cl_show_server_triggers_alpha.GetFloat(), 0.0f, 255.0f); + // hide corpses option if (cl_hidecorpses.GetBool() && ent->curstate.renderfx == kRenderFxDeadPlayer) return 0; diff --git a/src/game/client/hud.cpp b/src/game/client/hud.cpp index 2967a45c..c99b5643 100644 --- a/src/game/client/hud.cpp +++ b/src/game/client/hud.cpp @@ -135,6 +135,8 @@ ConVar cl_autowepswitch("cl_autowepswitch", "1", FCVAR_BHL_ARCHIVE | FCVAR_USERI ConVar cl_righthand("cl_righthand", "0", FCVAR_BHL_ARCHIVE, "If enabled, activates the left-handed mode"); ConVar cl_viewmodel_fov("cl_viewmodel_fov", "0", FCVAR_BHL_ARCHIVE, "Sets the field-of-view for the viewmodel"); ConVar showtriggers("showtriggers", "0", 0, "Shows trigger brushes"); +ConVar cl_show_server_triggers("cl_show_server_triggers", "0", FCVAR_BHL_ARCHIVE, "Shows server triggers if transmitted in special way"); +ConVar cl_show_server_triggers_alpha("cl_show_server_triggers_alpha", "120", FCVAR_BHL_ARCHIVE); ConVar aghl_version("aghl_version", APP_VERSION, 0, "BugfixedHL version"); ConVar aghl_supports("aghl_supports", "0", 0, "Bitfield of features supported by this client"); @@ -605,6 +607,26 @@ void CHud::SaveEngineVersion() } } +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; +} + bool CHud::IsAG() { return m_bIsAg; diff --git a/src/game/client/hud.h b/src/game/client/hud.h index 45a85f9a..bb159b9d 100644 --- a/src/game/client/hud.h +++ b/src/game/client/hud.h @@ -137,6 +137,8 @@ class CHud CRainbow m_Rainbow; + HSPRITE white_sprite = 0; + //----------------------------------------------------- // HUD exports //----------------------------------------------------- @@ -148,6 +150,7 @@ class CHud void Shutdown(); void ApplyViewportSchemeSettings(vgui2::IScheme *pScheme); void SaveEngineVersion(); + bool IsTriggerForSinglePlayer(color24 rendercolor); /** * Returns whether DLL is installed onto AG mod. diff --git a/src/game/client/tri.cpp b/src/game/client/tri.cpp index 0b33c323..a8d15938 100644 --- a/src/game/client/tri.cpp +++ b/src/game/client/tri.cpp @@ -22,9 +22,59 @@ #include "particleman.h" #include "tri.h" +#include "com_model.h" + CSysModule *g_hParticleManModule = NULL; IParticleMan *g_pParticleMan = NULL; +extern ConVar cl_show_server_triggers; +extern ConVar cl_show_server_triggers_alpha; + +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(); +} + //--------------------------------------------------- // Particle Manager //--------------------------------------------------- @@ -86,6 +136,44 @@ void CL_DLLEXPORT HUD_DrawNormalTriangles(void) void RunEventList(void); #endif +void DrawServerTriggers() +{ + if ((cl_show_server_triggers.GetBool()) && (cl_show_server_triggers.GetInt() != 2)) + { + 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::clamp(cl_show_server_triggers_alpha.GetFloat(), 0.0f, 255.0f); + 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 @@ -103,4 +191,14 @@ void CL_DLLEXPORT HUD_DrawTransparentTriangles(void) if (g_pParticleMan) g_pParticleMan->Update(); + + if (gHUD.white_sprite == 0) + return; + + if (gEngfuncs.pTriAPI->SpriteTexture(const_cast(gEngfuncs.GetSpritePointer(gHUD.white_sprite)), 0)) + { + DrawServerTriggers(); + + gEngfuncs.pTriAPI->RenderMode(kRenderNormal); + } }