Skip to content

Commit

Permalink
Removed debug messages, map name and entities storing to std::vector …
Browse files Browse the repository at this point in the history
…as unnecessary
  • Loading branch information
SmileyAG committed Dec 30, 2023
1 parent f772927 commit e900160
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 87 deletions.
2 changes: 2 additions & 0 deletions cl_dll/cl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/discord_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 0 additions & 15 deletions cl_dll/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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++;
}
}
}
3 changes: 0 additions & 3 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ class CHud

cvar_t *m_pShowServerTriggers;
cvar_t *m_pShowServerTriggersAlpha;
cvar_t *m_pShowServerTriggersForceUpdate;

int m_iFontHeight;

Expand Down Expand Up @@ -787,8 +786,6 @@ class CHud

bool IsTriggerForSinglePlayer(color24 rendercolor);

void SetMapName(char name[], size_t size, bool lowercase);

HSPRITE white_sprite = 0;
};

Expand Down
92 changes: 24 additions & 68 deletions cl_dll/tri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,71 +105,39 @@ void DrawAACuboid(triangleapi_s *pTriAPI, Vector corner1, Vector corner2)
pTriAPI->End();
}

static std::vector<cl_entity_t*> 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);
}
}
}
}
}
}
Expand Down Expand Up @@ -200,20 +168,8 @@ void CL_DLLEXPORT HUD_DrawTransparentTriangles( void )

if (gEngfuncs.pTriAPI->SpriteTexture(const_cast<model_s*>(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);
}
}
}

0 comments on commit e900160

Please sign in to comment.