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 ) 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 ) for ( CPointCamera *pCameraEnt = GetPointCameraList(); pCameraEnt != NULL; pCameraEnt = pCameraEnt->m_pNext )
{ {
pCameraEnt->SetActive( false ); pCameraEnt->TransmitToPlayer( nPlayerIndex, false );
} }
intp nNext; intp nNext;
@@ -175,7 +177,7 @@ void PointCameraSetupVisibility( CBaseEntity *pPlayer, int area, unsigned char *
if ( pCameraEnt ) if ( pCameraEnt )
{ {
engine->AddOriginToPVS( pCameraEnt->GetAbsOrigin() ); engine->AddOriginToPVS( pCameraEnt->GetAbsOrigin() );
pCameraEnt->SetActive( true ); pCameraEnt->TransmitToPlayer( nPlayerIndex, true );
} }
} }
} }

View File

@@ -52,6 +52,9 @@ CPointCamera::CPointCamera()
m_bFogEnable = false; m_bFogEnable = false;
m_bFogRadial = false; m_bFogRadial = false;
// By default, transmit to everyone
m_bitsTransmitPlayers.SetAll();
g_PointCameraList.Insert( this ); g_PointCameraList.Insert( this );
} }
@@ -74,34 +77,43 @@ void CPointCamera::Spawn( void )
SetActive( m_bIsOn ); 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. // 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. // All that matters is if we are in the pvs.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int CPointCamera::UpdateTransmitState() int CPointCamera::UpdateTransmitState()
{ {
if ( m_bActive ) return SetTransmitState( FL_EDICT_FULLCHECK );
{
return SetTransmitState( FL_EDICT_ALWAYS );
}
else
{
return SetTransmitState( FL_EDICT_DONTSEND );
}
} }
//-----------------------------------------------------------------------------
// 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: // Purpose:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CPointCamera::SetActive( bool bActive ) 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 ) if ( m_bActive != bActive )
{ {
m_bActive = bActive; m_bActive = bActive;

View File

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