From e9001601d00e1894d66d59fbb1792c4d4955b608 Mon Sep 17 00:00:00 2001 From: SmileyAG Date: Mon, 25 Dec 2023 20:53:46 +0400 Subject: [PATCH] Removed debug messages, map name and entities storing to std::vector as unnecessary --- cl_dll/cl_util.h | 2 + cl_dll/discord_integration.cpp | 2 +- cl_dll/hud.cpp | 15 ------ cl_dll/hud.h | 3 -- cl_dll/tri.cpp | 92 +++++++++------------------------- 5 files changed, 27 insertions(+), 87 deletions(-) diff --git a/cl_dll/cl_util.h b/cl_dll/cl_util.h index f558de63..252d2336 100644 --- a/cl_dll/cl_util.h +++ b/cl_dll/cl_util.h @@ -121,6 +121,8 @@ static size_t count_digits(int n) static size_t get_map_name(char* dest, size_t count) { + memset(dest, 0, count); + auto map_path = gEngfuncs.pfnGetLevelName(); const char* slash = strrchr(map_path, '/'); diff --git a/cl_dll/discord_integration.cpp b/cl_dll/discord_integration.cpp index 6514c45e..a3fd93e9 100644 --- a/cl_dll/discord_integration.cpp +++ b/cl_dll/discord_integration.cpp @@ -350,7 +350,7 @@ namespace discord_integration presence.details = gViewPort->m_szServerName; // Get the map name and icon. - gHUD.SetMapName(map_name, ARRAYSIZE(map_name), false); + get_map_name(map_name, ARRAYSIZE(map_name)); if (map_name[0]) { // We specifically don't want to convert the map name that will be shown when hovering over the map icon (presence.largeImageText), so that why it got moved above. diff --git a/cl_dll/hud.cpp b/cl_dll/hud.cpp index cc8e2eff..178da140 100644 --- a/cl_dll/hud.cpp +++ b/cl_dll/hud.cpp @@ -533,7 +533,6 @@ void CHud :: Init( void ) m_pCvarPlayTeamSoundsVolume = CVAR_CREATE("cl_team_sounds_volume", "1.0", FCVAR_ARCHIVE); m_pShowServerTriggers = CVAR_CREATE("cl_show_server_triggers", "1", FCVAR_ARCHIVE); m_pShowServerTriggersAlpha = CVAR_CREATE("cl_show_server_triggers_alpha", "120", FCVAR_ARCHIVE); - m_pShowServerTriggersForceUpdate = CVAR_CREATE("cl_show_server_triggers_force_update", "1", FCVAR_ARCHIVE); cl_lw = gEngfuncs.pfnGetCvarPointer( "cl_lw" ); CVAR_CREATE("showtriggers", "0", 0); @@ -959,17 +958,3 @@ bool CHud::IsTriggerForSinglePlayer(color24 rendercolor) return false; } - -void CHud::SetMapName(char name[], size_t size, bool lowercase) -{ - memset(name, 0, size); - get_map_name(name, size); - if (lowercase && name[0]) - { - unsigned char *tptr = (unsigned char *)name; - while (*tptr) { - *tptr = tolower(*tptr); - tptr++; - } - } -} diff --git a/cl_dll/hud.h b/cl_dll/hud.h index 102f0f34..1964a126 100644 --- a/cl_dll/hud.h +++ b/cl_dll/hud.h @@ -646,7 +646,6 @@ class CHud cvar_t *m_pShowServerTriggers; cvar_t *m_pShowServerTriggersAlpha; - cvar_t *m_pShowServerTriggersForceUpdate; int m_iFontHeight; @@ -787,8 +786,6 @@ class CHud bool IsTriggerForSinglePlayer(color24 rendercolor); - void SetMapName(char name[], size_t size, bool lowercase); - HSPRITE white_sprite = 0; }; diff --git a/cl_dll/tri.cpp b/cl_dll/tri.cpp index 2fc17c71..36a25d0b 100644 --- a/cl_dll/tri.cpp +++ b/cl_dll/tri.cpp @@ -105,71 +105,39 @@ void DrawAACuboid(triangleapi_s *pTriAPI, Vector corner1, Vector corner2) pTriAPI->End(); } -static std::vector trigger_entities; -char map_name[64]; -static char map_name_old[64]; - -void UpdateServerTriggers() +void DrawServerTriggers() { - if (map_name[0]) + if ((gHUD.m_pShowServerTriggers->value > 0) && (gHUD.m_pShowServerTriggers->value != 2.0f)) { - if ((strcmp(map_name, map_name_old)) || (gHUD.m_pShowServerTriggersForceUpdate->value > 0)) + for (int e = 0; e < MAX_EDICTS; ++e) { - if ((gHUD.m_pShowServerTriggers->value == 3.0f) && (gHUD.m_pShowServerTriggersForceUpdate->value < 1.0f)) // Debug - gEngfuncs.Con_DPrintf("UpdateServerTriggersOnMapChange: map changed!\n"); - - trigger_entities.clear(); - - for (int e = 0; e < MAX_EDICTS; ++e) + cl_entity_t* ent = gEngfuncs.GetEntityByIndex(e); + if (ent) { - cl_entity_t* ent = gEngfuncs.GetEntityByIndex(e); - if (ent) + if (ent->model) { - if (ent->model) + if ((ent->curstate.rendermode == kRenderTransColor) && (ent->curstate.renderfx == kRenderFxTrigger)) { - if ((ent->curstate.rendermode == kRenderTransColor) && (ent->curstate.renderfx == kRenderFxTrigger)) + color24 colors = ent->curstate.rendercolor; + if (!gHUD.IsTriggerForSinglePlayer(colors)) { - trigger_entities.emplace_back(ent); - } - } - } - } + gEngfuncs.pTriAPI->RenderMode(kRenderTransAdd); + gEngfuncs.pTriAPI->CullFace(TRI_NONE); - gEngfuncs.Con_DPrintf("UpdateServerTriggersOnMapChange: triggers updated!\n"); - } - } - else - { - if (gHUD.m_pShowServerTriggers->value == 3.0f) // Debug - gEngfuncs.Con_DPrintf("UpdateServerTriggersOnMapChange: map not found, then we clear vectors!\n"); + 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); - trigger_entities.clear(); - } -} + Vector mins = ent->curstate.mins; + Vector maxs = ent->curstate.maxs; + Vector origin = ent->curstate.origin; + Vector absmin = origin + mins; + Vector absmax = origin + maxs; -void DrawServerTriggers() -{ - if (!trigger_entities.empty()) - { - for (size_t i = 0; i < trigger_entities.size(); i++) - { - color24 rendercolor = trigger_entities[i]->curstate.rendercolor; - if (!gHUD.IsTriggerForSinglePlayer(rendercolor)) - { - gEngfuncs.pTriAPI->RenderMode(kRenderTransAdd); - gEngfuncs.pTriAPI->CullFace(TRI_NONE); - - float r = rendercolor.r, g = rendercolor.g, b = rendercolor.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 = trigger_entities[i]->curstate.mins; - Vector maxs = trigger_entities[i]->curstate.maxs; - Vector origin = trigger_entities[i]->curstate.origin; - Vector absmin = origin + mins; - Vector absmax = origin + maxs; - - DrawAACuboid(gEngfuncs.pTriAPI, absmin, absmax); + DrawAACuboid(gEngfuncs.pTriAPI, absmin, absmax); + } + } + } } } } @@ -200,20 +168,8 @@ void CL_DLLEXPORT HUD_DrawTransparentTriangles( void ) if (gEngfuncs.pTriAPI->SpriteTexture(const_cast(gEngfuncs.GetSpritePointer(gHUD.white_sprite)), 0)) { - gHUD.SetMapName(map_name, ARRAYSIZE(map_name), true); - if ((gHUD.m_pShowServerTriggers->value > 0) && (gHUD.m_pShowServerTriggers->value != 2.0f)) - { - UpdateServerTriggers(); - DrawServerTriggers(); - } + DrawServerTriggers(); gEngfuncs.pTriAPI->RenderMode(kRenderNormal); - - // Saved old map name in static variable to differ it with new map name - if (map_name[0]) - { - memset(map_name_old, 0, sizeof(map_name_old)); - strncpy(map_name_old, map_name, sizeof(map_name_old) - 1); - } } }