Skip to content

Commit e2eb63a

Browse files
authored
Merge pull request #861 from ReactiveDrop/cl-showspectators
cl_showspectators
2 parents 526c35c + 98ecbad commit e2eb63a

5 files changed

Lines changed: 86 additions & 6 deletions

File tree

src/game/client/swarm/c_asw_player.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ BEGIN_NETWORK_TABLE( C_ASW_Player, DT_ASW_Player )
248248
RecvPropQAngles( RECVINFO( m_angEyeAngles ) ),
249249
RecvPropEHandle( RECVINFO( m_hInhabiting ) ),
250250
RecvPropEHandle( RECVINFO( m_hSpectating ) ),
251+
RecvPropInt( RECVINFO( m_iSpectatorIndexes ) ),
251252
RecvPropInt( RECVINFO( m_iHealth ) ),
252253
RecvPropEHandle( RECVINFO( m_pCurrentInfoMessage ) ),
253254
RecvPropFloat( RECVINFO( m_fMarineDeathTime ) ),

src/game/client/swarm/c_asw_player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class C_ASW_Player : public C_BasePlayer, public IASWPlayerAnimStateHelpers
146146
CInterpolatedVar< QAngle > m_iv_angEyeAngles;
147147
CNetworkHandle( C_ASW_Inhabitable_NPC, m_hInhabiting ); // our currently controlled marine
148148
CNetworkHandle( C_ASW_Inhabitable_NPC, m_hSpectating ); // the marine we're spectating when dead
149+
CNetworkVar( unsigned int, m_iSpectatorIndexes );
149150
const Vector& GetCrosshairTracePos() { return m_vecCrosshairTracePos; }
150151
void SetCrosshairTracePos( const Vector &vecPos ) { m_vecCrosshairTracePos = vecPos; }
151152
Vector m_vecCrosshairTracePos; // the world location directly beneath the player's crosshair

src/game/client/vgui_fpspanel.cpp

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "../common/xbox/xboxstubs.h"
2020
#ifdef INFESTED_DLL
2121
#include "c_asw_player.h"
22+
#include "c_playerresource.h"
2223
#include "c_asw_inhabitable_npc.h"
2324
#endif
2425

@@ -27,6 +28,7 @@
2728

2829
static ConVar cl_showfps( "cl_showfps", "0", FCVAR_RELEASE, "Draw fps meter at top of screen (1 = fps, 2 = smooth fps, 3 = server MS, 4 = Show FPS and Log to file )" );
2930
static ConVar cl_showpos( "cl_showpos", "0", FCVAR_RELEASE, "Draw current position at top of screen (1 = eyes, 2 = feet)" );
31+
static ConVar cl_showspectators( "cl_showspectators", "0", FCVAR_RELEASE, "Draw a list of spectators" );
3032
#ifdef INFESTED_DLL
3133
static ConVar cl_showpos_npc( "cl_showpos_npc", "-1", FCVAR_NONE, "If the player is controlling or spectating an NPC, use the NPC's position, angles, and velocity instead; -1 = 1 if asw_allow_detach is 0, 0 otherwise" );
3234
extern ConVar asw_allow_detach;
@@ -184,7 +186,8 @@ bool CFPSPanel::ShouldDraw( void )
184186
if ( g_bDisplayParticlePerformance )
185187
return true;
186188
if ( ( !cl_showfps.GetInt() || ( gpGlobals->absoluteframetime <= 0 ) ) &&
187-
( !cl_showpos.GetInt() ) )
189+
( !cl_showpos.GetInt() ) &&
190+
( !cl_showspectators.GetInt() ) )
188191
{
189192
m_bLastDraw = false;
190193
return false;
@@ -278,12 +281,12 @@ void CFPSPanel::Paint()
278281

279282
float flTotalTime = 0.0f;
280283
float flPeakTime = 0.0f;
281-
for ( int i = 0; i < SERVER_TIME_HISTORY; ++i )
284+
for ( int j = 0; j < SERVER_TIME_HISTORY; ++j )
282285
{
283-
flTotalTime += m_pServerTimes[i];
284-
if ( flPeakTime < m_pServerTimes[i] )
286+
flTotalTime += m_pServerTimes[j];
287+
if ( flPeakTime < m_pServerTimes[j] )
285288
{
286-
flPeakTime = m_pServerTimes[i];
289+
flPeakTime = m_pServerTimes[j];
287290
}
288291
}
289292
flTotalTime /= SERVER_TIME_HISTORY;
@@ -517,6 +520,59 @@ void CFPSPanel::Paint()
517520
}
518521
}
519522

523+
if ( cl_showspectators.GetInt() )
524+
{
525+
FOR_EACH_VALID_SPLITSCREEN_PLAYER( hh )
526+
{
527+
C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer( hh );
528+
if ( !pPlayer )
529+
continue;
530+
531+
C_ASW_Inhabitable_NPC *pSpectating = pPlayer->m_hSpectating;
532+
if ( pSpectating && pSpectating->GetCommander() )
533+
{
534+
pPlayer = pSpectating->GetCommander();
535+
}
536+
537+
i += 3;
538+
539+
int nSpecCount = 0;
540+
for ( int id = 1; id <= 32; id += 1 )
541+
{
542+
if ( !g_PR->IsConnected( id ) )
543+
continue;
544+
545+
if ( g_PR->IsFakePlayer( id ) )
546+
continue;
547+
548+
if ( !( pPlayer->m_iSpectatorIndexes.Get() & ( 1u << id ) ) )
549+
continue;
550+
551+
nSpecCount++;
552+
i++;
553+
554+
char szSpecName[k_cchPersonaNameMax] = { 0 };
555+
Q_strncpy( szSpecName, g_PR->GetPlayerName( id ), sizeof( szSpecName ) );
556+
g_pMatSystemSurface->DrawColoredText( m_hFont, x, 2 + i * lineHeight,
557+
255, 255, 255, 255,
558+
" %s", szSpecName );
559+
}
560+
561+
if ( nSpecCount == 0 )
562+
{
563+
i -= 3;
564+
break;
565+
}
566+
567+
char szName[k_cchPersonaNameMax] = { 0 };
568+
Q_strncpy( szName, pPlayer->GetPlayerName(), sizeof( szName ) );
569+
570+
g_pMatSystemSurface->DrawColoredText( m_hFont, x, 2 + ( i - nSpecCount ) * lineHeight,
571+
255, 255, 255, 255,
572+
"Spectating %s (%d):", szName, nSpecCount );
573+
}
574+
}
575+
520576
if ( m_nLinesNeeded != i )
521577
{
522578
m_nLinesNeeded = i;

src/game/server/swarm/asw_player.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ IMPLEMENT_SERVERCLASS_ST( CASW_Player, DT_ASW_Player )
221221
SendPropQAngles( SENDINFO( m_angEyeAngles ), 10, SPROP_CHANGES_OFTEN, SendProxy_QAngles, SENDPROP_PLAYER_EYE_ANGLES_PRIORITY ),
222222
SendPropEHandle( SENDINFO( m_hInhabiting ) ),
223223
SendPropEHandle( SENDINFO( m_hSpectating ) ),
224+
SendPropInt( SENDINFO( m_iSpectatorIndexes ) ),
224225
SendPropFloat( SENDINFO( m_fMarineDeathTime ) ),
225226
SendPropEHandle( SENDINFO( m_hOrderingMarine ) ),
226227
SendPropEHandle( SENDINFO( m_pCurrentInfoMessage ) ),
@@ -250,6 +251,7 @@ BEGIN_DATADESC( CASW_Player )
250251
DEFINE_FIELD( m_vecLastMarineOrigin, FIELD_VECTOR ),
251252
DEFINE_FIELD( m_hInhabiting, FIELD_EHANDLE ),
252253
DEFINE_FIELD( m_hSpectating, FIELD_EHANDLE ),
254+
DEFINE_FIELD( m_iSpectatorIndexes, FIELD_INTEGER ),
253255
DEFINE_FIELD( m_vecStoredPosition, FIELD_VECTOR ),
254256
DEFINE_FIELD( m_pCurrentInfoMessage, FIELD_EHANDLE ),
255257
DEFINE_FIELD( m_iUseEntities, FIELD_INTEGER ),
@@ -441,6 +443,8 @@ CASW_Player::~CASW_Player()
441443
m_PlayerAnimState->Release();
442444
if ( ASWGameRules() )
443445
ASWGameRules()->SetMaxMarines( this );
446+
447+
SetSpectatingNPC( NULL );
444448
}
445449

446450
//------------------------------------------------------------------------------
@@ -556,9 +560,9 @@ void CASW_Player::PostThink()
556560
if (found_available_marine)
557561
{
558562
DevMsg(" Riflemod Drop-In. Switching player to marine 0\n");
563+
SetSpectatingNPC( NULL );
559564
pBotMarine->SetCommander( this );
560565
pBotMarine->GetMarineResource()->SetCommander( this );
561-
SetSpectatingNPC( NULL );
562566
SwitchMarine( 0, false );
563567
// reactivedrop: when player took marine under control
564568
// delay his primary attack to prevent immediate shooting at
@@ -693,6 +697,7 @@ void CASW_Player::Spawn()
693697
m_nChangingSlot = 0;
694698
m_bHasAwardedXP = false;
695699
m_bSentPromotedMessage = false;
700+
m_iSpectatorIndexes = 0;
696701

697702
m_flLastActiveTime = gpGlobals->curtime;
698703

@@ -2213,7 +2218,23 @@ void CASW_Player::SpectateNextMarine()
22132218

22142219
void CASW_Player::SetSpectatingNPC( CASW_Inhabitable_NPC *pSpectating )
22152220
{
2221+
unsigned int nOwnIndex = 1u << ( GetClientIndex() + 1 );
2222+
CASW_Inhabitable_NPC *pSpectatingPrevious = GetSpectatingNPC();
2223+
if ( pSpectatingPrevious && pSpectatingPrevious->GetCommander() )
2224+
{
2225+
pSpectatingPrevious->GetCommander()->m_iSpectatorIndexes &=~ nOwnIndex;
2226+
}
2227+
22162228
m_hSpectating = pSpectating;
2229+
2230+
if ( !pSpectating )
2231+
return;
2232+
2233+
CASW_Player *pPlayer = pSpectating->GetCommander();
2234+
if ( !pPlayer )
2235+
return;
2236+
2237+
pPlayer->m_iSpectatorIndexes |= nOwnIndex;
22172238
}
22182239

22192240
CASW_Inhabitable_NPC *CASW_Player::GetSpectatingNPC() const

src/game/server/swarm/asw_player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class CASW_Player : public CBaseMultiplayerPlayer, public IASWPlayerAnimStateHel
9191
CASW_Inhabitable_NPC *GetSpectatingNPC() const;
9292
HSCRIPT ScriptGetSpectatingNPC() const;
9393
CNetworkHandle( CASW_Inhabitable_NPC, m_hSpectating );
94+
CNetworkVar( unsigned int, m_iSpectatorIndexes );
9495
bool m_bLastAttackButton; // used to detect left clicks for cycling through marines
9596
bool m_bLastAttack2Button; // used to detect right clicks for cycling through marines
9697
bool m_bRequestedSpectator; // this player requested to be a spectator since the start of a match (won't be considered for leader, campaign votes, etc.)

0 commit comments

Comments
 (0)