Skip to content

Commit fbac91c

Browse files
authored
Reset crosshair on resets to fix spectator non-matching-to-player xhair (#1877)
This is kind of a guesswork if it'll fix the spectator seeing crosshair on player that it's not the player's actual crosshair, but I'm assuming the state haven't been refreshed properly especialy the timer till next crosshair refresh and maybe on map change and where player index changes it gets stuck with other player's crosshair. * fixes #1735
1 parent b64b551 commit fbac91c

File tree

5 files changed

+71
-1
lines changed

5 files changed

+71
-1
lines changed

src/game/client/hud_crosshair.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,17 @@ void CHudCrosshair::GetDrawPosition ( float *pX, float *pY, bool *pbBehindCamera
377377
ConVar cl_neo_scope_restrict_to_rectangle("cl_neo_scope_restrict_to_rectangle", "1", FCVAR_CHEAT,
378378
"Whether to enforce rectangular sniper scope shape regardless of screen ratio.", true, 0.0, true, 1.0);
379379

380+
#ifdef NEO
381+
382+
void CHudCrosshair::resetPlayersCrosshair()
383+
{
384+
V_memset(m_szLocalStrPlayersCrosshair, 0, sizeof(m_szLocalStrPlayersCrosshair));
385+
V_memset(m_playersCrosshairInfos, 0, sizeof(m_playersCrosshairInfos));
386+
V_memset(m_aflLastCheckedPlayersCrosshair, 0, sizeof(m_aflLastCheckedPlayersCrosshair));
387+
}
388+
389+
#endif // NEO
390+
380391
void CHudCrosshair::Paint( void )
381392
{
382393
if ( !m_pCrosshair )
@@ -502,7 +513,6 @@ void CHudCrosshair::Paint( void )
502513
if (bPlayerIdxValid)
503514
{
504515
bTakeSpecCrosshair = true;
505-
m_playersCrosshairInfos;
506516
bThisFrameRefreshCrosshair = false;
507517
pCrosshairInfo = &m_playersCrosshairInfos[iPlayerIdx];
508518
pszNeoCrosshair = pNeoPlayer->m_szNeoCrosshair.Get();

src/game/client/hud_crosshair.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class CHudCrosshair : public CHudElement, public vgui::Panel
4141
char m_szLocalStrPlayersCrosshair[MAX_PLAYERS][NEO_XHAIR_SEQMAX] = {};
4242
CrosshairInfo m_playersCrosshairInfos[MAX_PLAYERS] = {};
4343
float m_aflLastCheckedPlayersCrosshair[MAX_PLAYERS] = {};
44+
45+
void resetPlayersCrosshair();
4446
#endif
4547

4648
virtual void SetCrosshairAngle( const QAngle& angle );

src/game/client/neo/c_neo_player.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ C_NEO_Player::C_NEO_Player()
474474
m_bPreviouslyReloading = false;
475475
m_bLastTickInThermOpticCamo = false;
476476
m_bIsAllowedToToggleVision = false;
477+
m_bSpecRefreshedStates = false;
477478

478479
m_flTocFactor = 0.15f;
479480

@@ -1154,6 +1155,28 @@ void C_NEO_Player::PreThink( void )
11541155
m_flCamoAuxLastTime = 0;
11551156
}
11561157

1158+
// If spectating, won't be "alive/dead" so have its own
1159+
// path of resetting the cache of other players crosshair
1160+
// data on pre-round freeze time
1161+
if (IsLocalPlayer() && GetTeamNumber() == TEAM_SPECTATOR)
1162+
{
1163+
if (NEORules()->IsRoundPreRoundFreeze())
1164+
{
1165+
if (false == m_bSpecRefreshedStates)
1166+
{
1167+
if (CHudCrosshair *crosshair = GET_HUDELEMENT(CHudCrosshair))
1168+
{
1169+
crosshair->resetPlayersCrosshair();
1170+
}
1171+
}
1172+
m_bSpecRefreshedStates = true;
1173+
}
1174+
else
1175+
{
1176+
m_bSpecRefreshedStates = false;
1177+
}
1178+
}
1179+
11571180
if (IsAlive())
11581181
{
11591182
if (IsLocalPlayer() && m_bFirstAliveTick)
@@ -1168,6 +1191,12 @@ void C_NEO_Player::PreThink( void )
11681191
// so it could arrive too late.
11691192
CLocalPlayerFilter filter;
11701193
enginesound->SetPlayerDSP(filter, 0, true);
1194+
1195+
// Reset the cache of other players crosshair data on spawning in
1196+
if (CHudCrosshair *crosshair = GET_HUDELEMENT(CHudCrosshair))
1197+
{
1198+
crosshair->resetPlayersCrosshair();
1199+
}
11711200
}
11721201
}
11731202
else
@@ -1606,6 +1635,15 @@ void C_NEO_Player::Spawn( void )
16061635
}
16071636
}
16081637
}
1638+
1639+
// Only do cached crosshair reset for confirmed local player
1640+
if (IsLocalPlayer())
1641+
{
1642+
if (CHudCrosshair *crosshair = GET_HUDELEMENT(CHudCrosshair))
1643+
{
1644+
crosshair->resetPlayersCrosshair();
1645+
}
1646+
}
16091647
}
16101648

16111649
void C_NEO_Player::DoImpactEffect( trace_t &tr, int nDamageType )

src/game/client/neo/c_neo_player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class C_NEO_Player : public C_HL2MP_Player
252252
bool m_bFirstDeathTick;
253253
bool m_bPreviouslyReloading;
254254
bool m_bIsAllowedToToggleVision;
255+
bool m_bSpecRefreshedStates;
255256

256257
float m_flLastAirborneJumpOkTime;
257258
float m_flLastSuperJumpTime;

src/game/shared/neo/neo_gamerules.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "engine/IEngineSound.h"
1717
#include "filesystem.h"
1818
#include "hltvcamera.h"
19+
#include "hud_crosshair.h"
1920
#else
2021
#include "neo_player.h"
2122
#include "team.h"
@@ -745,6 +746,18 @@ void CNEORules::ClientSpawned(edict_t* pPlayer)
745746
}
746747
#endif
747748
#endif
749+
750+
#ifdef CLIENT_DLL
751+
// Reset other players crosshair cache on spawning in here
752+
C_NEO_Player *pLocalPlayer = C_NEO_Player::GetLocalNEOPlayer();
753+
if (pLocalPlayer->index == pPlayer->m_EdictIndex)
754+
{
755+
if (CHudCrosshair *crosshair = GET_HUDELEMENT(CHudCrosshair))
756+
{
757+
crosshair->resetPlayersCrosshair();
758+
}
759+
}
760+
#endif
748761
}
749762

750763
int CNEORules::DefaultFOV(void)
@@ -822,6 +835,12 @@ void CNEORules::ResetMapSessionCommon()
822835
m_pJuggernautItem = nullptr;
823836
m_pJuggernautPlayer = nullptr;
824837
m_bGotMatchWinner = false;
838+
#else // CLIENT_DLL
839+
// Reset other players crosshair cache on full map reset
840+
if (CHudCrosshair *crosshair = GET_HUDELEMENT(CHudCrosshair))
841+
{
842+
crosshair->resetPlayersCrosshair();
843+
}
825844
#endif
826845
}
827846

0 commit comments

Comments
 (0)