Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache ObjectCaps call inside PlayerUse #991

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4248,11 +4248,15 @@ void CBasePlayer::PlayerUse()
}
}

int caps;
int iClosestCaps = 0;

if (!pClosest)
{
while ((pObject = UTIL_FindEntityInSphere(pObject, pev->origin, MAX_PLAYER_USE_RADIUS)))
{
if (pObject->ObjectCaps() & (FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE | FCAP_ONOFF_USE))
caps = pObject->ObjectCaps();
if (caps & (FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE | FCAP_ONOFF_USE))
{
// TODO: PERFORMANCE- should this check be done on a per case basis AFTER we've determined that
// this object is actually usable? This dot is being done for every object within PLAYER_SEARCH_RADIUS
Expand All @@ -4267,11 +4271,21 @@ void CBasePlayer::PlayerUse()
{
flMaxDot = flDot;
pClosest = pObject;
#ifdef REGAMEDLL_FIXES
iClosestCaps = caps;
#endif
}
}
}
}
#ifdef REGAMEDLL_FIXES
else // catch new hostages caps
{
iClosestCaps = pClosest->ObjectCaps();
}

caps = iClosestCaps;
#endif
pObject = pClosest;

// Found an object
Expand All @@ -4280,8 +4294,9 @@ void CBasePlayer::PlayerUse()
if (!useNewHostages || CanSeeUseable(this, pObject))
{
// TODO: traceline here to prevent +USEing buttons through walls
#ifndef REGAMEDLL_FIXES
int caps = pObject->ObjectCaps();

#endif
if (m_afButtonPressed & IN_USE)
EMIT_SOUND(ENT(pev), CHAN_ITEM, "common/wpn_select.wav", 0.4, ATTN_NORM);

Expand All @@ -4295,7 +4310,12 @@ void CBasePlayer::PlayerUse()
}
// UNDONE: Send different USE codes for ON/OFF. Cache last ONOFF_USE object to send 'off' if you turn away
// BUGBUG This is an "off" use
else if ((m_afButtonReleased & IN_USE) && (pObject->ObjectCaps() & FCAP_ONOFF_USE))
else if ((m_afButtonReleased & IN_USE)
#ifdef REGAMEDLL_FIXES
&& (caps & FCAP_ONOFF_USE))
#else
&& (pObject->ObjectCaps() & FCAP_ONOFF_USE))
#endif
{
pObject->Use(this, this, USE_SET, 0);
}
Expand Down
Loading