Skip to content

Commit 8171a9f

Browse files
committed
Optimize visibility cache from map to flat array
1 parent f6552f7 commit 8171a9f

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

src/game/server/neo/neo_player.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ CNEO_Player::CNEO_Player()
556556
m_flLastAirborneJumpOkTime = 0;
557557
m_flLastSuperJumpTime = 0;
558558
m_botThermOpticCamoDisruptedTimer.Invalidate();
559-
m_mapPlayerFogCache.SetLessFunc( DefLessFunc(int) );
559+
560560

561561
m_bFirstDeathTick = true;
562562
m_bCorpseSet = false;
@@ -1280,16 +1280,12 @@ bool CNEO_Player::IsHiddenByFog(CBaseEntity* target) const
12801280

12811281
// Check visibility cache for this player
12821282
int playerIndex = targetPlayer->entindex();
1283-
int cacheIndex = m_mapPlayerFogCache.Find(playerIndex);
1284-
1285-
// Ensure an entry exists for this player in the cache
1286-
if (cacheIndex == m_mapPlayerFogCache.InvalidIndex())
1283+
if (!IsIndexIntoPlayerArrayValid(playerIndex))
12871284
{
1288-
cacheIndex = m_mapPlayerFogCache.Insert(playerIndex, CNEO_Player_FogCacheEntry());
1289-
Assert(cacheIndex != m_mapPlayerFogCache.InvalidIndex());
1285+
return false;
12901286
}
12911287

1292-
CNEO_Player_FogCacheEntry& cacheEntry = m_mapPlayerFogCache.Element(cacheIndex);
1288+
CNEO_Player_FogCacheEntry& cacheEntry = m_playerFogCache[playerIndex];
12931289

12941290
// If cache is fresh (within 200ms human reaction time), use cached boolean result
12951291
if (gpGlobals->curtime - cacheEntry.m_flUpdateTime < 0.2f) // 200ms cache window

src/game/server/neo/neo_player.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class INEOPlayerAnimState;
1111
#include "simtimer.h"
1212
#include "soundenvelope.h"
1313
#include "utldict.h"
14-
#include "utlmap.h"
1514
#include "hl2mp_player.h"
1615
#include "in_buttons.h"
1716

@@ -337,7 +336,7 @@ class CNEO_Player : public CHL2MP_Player
337336
bool m_bSpectatorTakeoverPlayerPending{false};
338337

339338
// Cache for GetFogObscuredRatio for each player
340-
mutable CUtlMap<int, CNEO_Player_FogCacheEntry> m_mapPlayerFogCache;
339+
mutable CNEO_Player_FogCacheEntry m_playerFogCache[MAX_PLAYERS_ARRAY_SAFE];
341340

342341
private:
343342
CNEO_Player(const CNEO_Player&);

0 commit comments

Comments
 (0)