Fix point_camera transmit state in multiplayer

This commit is contained in:
ficool2
2025-07-25 11:50:03 +01:00
committed by EricS-Valve
parent 57a8b644af
commit 4111c27ed7
3 changed files with 35 additions and 17 deletions

View File

@@ -145,9 +145,11 @@ CBaseEntity *CreateInfoCameraLink( CBaseEntity *pTarget, CPointCamera *pCamera )
//-----------------------------------------------------------------------------
void PointCameraSetupVisibility( CBaseEntity *pPlayer, int area, unsigned char *pvs, int pvssize )
{
int nPlayerIndex = pPlayer->entindex();
for ( CPointCamera *pCameraEnt = GetPointCameraList(); pCameraEnt != NULL; pCameraEnt = pCameraEnt->m_pNext )
{
pCameraEnt->SetActive( false );
pCameraEnt->TransmitToPlayer( nPlayerIndex, false );
}
intp nNext;
@@ -175,7 +177,7 @@ void PointCameraSetupVisibility( CBaseEntity *pPlayer, int area, unsigned char *
if ( pCameraEnt )
{
engine->AddOriginToPVS( pCameraEnt->GetAbsOrigin() );
pCameraEnt->SetActive( true );
pCameraEnt->TransmitToPlayer( nPlayerIndex, true );
}
}
}

View File

@@ -52,6 +52,9 @@ CPointCamera::CPointCamera()
m_bFogEnable = false;
m_bFogRadial = false;
// By default, transmit to everyone
m_bitsTransmitPlayers.SetAll();
g_PointCameraList.Insert( this );
}
@@ -74,34 +77,43 @@ void CPointCamera::Spawn( void )
SetActive( m_bIsOn );
}
//-----------------------------------------------------------------------------
// Purpose: Transmit only to players who are in PVS of the camera and its link
// See PointCameraSetupVisibility
//-----------------------------------------------------------------------------
int CPointCamera::ShouldTransmit( const CCheckTransmitInfo* pInfo )
{
if ( m_bitsTransmitPlayers.IsBitSet( pInfo->m_pClientEnt->m_EdictIndex ) )
return FL_EDICT_ALWAYS;
return FL_EDICT_DONTSEND;
}
//-----------------------------------------------------------------------------
// Purpose: Override ShouldTransmit since we want to be sent even though we don't have a model, etc.
// All that matters is if we are in the pvs.
//-----------------------------------------------------------------------------
int CPointCamera::UpdateTransmitState()
{
if ( m_bActive )
{
return SetTransmitState( FL_EDICT_ALWAYS );
}
else
{
return SetTransmitState( FL_EDICT_DONTSEND );
}
return SetTransmitState( FL_EDICT_FULLCHECK );
}
//-----------------------------------------------------------------------------
// Purpose: Toggle networking of the camera to the specified player
//-----------------------------------------------------------------------------
void CPointCamera::TransmitToPlayer( int nPlayerIndex, bool bTransmit )
{
if ( bTransmit )
m_bitsTransmitPlayers.Set( nPlayerIndex );
else
m_bitsTransmitPlayers.Clear( nPlayerIndex );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPointCamera::SetActive( bool bActive )
{
// If the mapmaker's told the camera it's off, it enforces inactive state
if ( !m_bIsOn )
{
bActive = false;
}
if ( m_bActive != bActive )
{
m_bActive = bActive;

View File

@@ -29,7 +29,9 @@ public:
// Tell the client that this camera needs to be rendered
void SetActive( bool bActive );
int UpdateTransmitState(void);
int ShouldTransmit( const CCheckTransmitInfo* pInfo );
int UpdateTransmitState( void );
void TransmitToPlayer( int nPlayerIndex, bool bTransmit );
void ChangeFOVThink( void );
@@ -56,6 +58,8 @@ private:
// Allows the mapmaker to control whether a camera is active or not
bool m_bIsOn;
CBitVec< MAX_PLAYERS > m_bitsTransmitPlayers;
public:
CPointCamera *m_pNext;
};