Skip to content

Commit c7bd4af

Browse files
authored
Cache ObjectCaps call inside PlayerUse (#991)
Not really useful, discovered while testing on 3rd party plugins that ObjectCaps was being called unnecessarily more than once per entity
1 parent fee10d8 commit c7bd4af

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

regamedll/dlls/player.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4248,11 +4248,15 @@ void CBasePlayer::PlayerUse()
42484248
}
42494249
}
42504250

4251+
int caps;
4252+
int iClosestCaps = 0;
4253+
42514254
if (!pClosest)
42524255
{
42534256
while ((pObject = UTIL_FindEntityInSphere(pObject, pev->origin, MAX_PLAYER_USE_RADIUS)))
42544257
{
4255-
if (pObject->ObjectCaps() & (FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE | FCAP_ONOFF_USE))
4258+
caps = pObject->ObjectCaps();
4259+
if (caps & (FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE | FCAP_ONOFF_USE))
42564260
{
42574261
// TODO: PERFORMANCE- should this check be done on a per case basis AFTER we've determined that
42584262
// this object is actually usable? This dot is being done for every object within PLAYER_SEARCH_RADIUS
@@ -4267,11 +4271,21 @@ void CBasePlayer::PlayerUse()
42674271
{
42684272
flMaxDot = flDot;
42694273
pClosest = pObject;
4274+
#ifdef REGAMEDLL_FIXES
4275+
iClosestCaps = caps;
4276+
#endif
42704277
}
42714278
}
42724279
}
42734280
}
4281+
#ifdef REGAMEDLL_FIXES
4282+
else // catch new hostages caps
4283+
{
4284+
iClosestCaps = pClosest->ObjectCaps();
4285+
}
42744286

4287+
caps = iClosestCaps;
4288+
#endif
42754289
pObject = pClosest;
42764290

42774291
// Found an object
@@ -4280,8 +4294,9 @@ void CBasePlayer::PlayerUse()
42804294
if (!useNewHostages || CanSeeUseable(this, pObject))
42814295
{
42824296
// TODO: traceline here to prevent +USEing buttons through walls
4297+
#ifndef REGAMEDLL_FIXES
42834298
int caps = pObject->ObjectCaps();
4284-
4299+
#endif
42854300
if (m_afButtonPressed & IN_USE)
42864301
EMIT_SOUND(ENT(pev), CHAN_ITEM, "common/wpn_select.wav", 0.4, ATTN_NORM);
42874302

@@ -4295,7 +4310,12 @@ void CBasePlayer::PlayerUse()
42954310
}
42964311
// UNDONE: Send different USE codes for ON/OFF. Cache last ONOFF_USE object to send 'off' if you turn away
42974312
// BUGBUG This is an "off" use
4298-
else if ((m_afButtonReleased & IN_USE) && (pObject->ObjectCaps() & FCAP_ONOFF_USE))
4313+
else if ((m_afButtonReleased & IN_USE)
4314+
#ifdef REGAMEDLL_FIXES
4315+
&& (caps & FCAP_ONOFF_USE))
4316+
#else
4317+
&& (pObject->ObjectCaps() & FCAP_ONOFF_USE))
4318+
#endif
42994319
{
43004320
pObject->Use(this, this, USE_SET, 0);
43014321
}

0 commit comments

Comments
 (0)