M PlayerAnimState/TempEnt: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Created page with 'This temporary entity will dispatch player animation events to onlooking clients in the animating player's PVS. It is not needed in singleplayer. T…')
 
(moved couple of funcs to the main page)
Line 37: Line 37:
g_TEPlayerAnimEvent.m_nData = nData;
g_TEPlayerAnimEvent.m_nData = nData;
g_TEPlayerAnimEvent.Create( filter, 0 );
g_TEPlayerAnimEvent.Create( filter, 0 );
}
void CMyPlayer::DoAnimationEvent( PlayerAnimEvent_t event, int nData )
{
m_PlayerAnimState->DoAnimationEvent( event, nData );
TE_PlayerAnimEvent( this, event, nData ); // Send to any clients who can see this guy.
}
}
</source>
</source>
Line 80: Line 73:
RecvPropInt( RECVINFO( m_nData ) )
RecvPropInt( RECVINFO( m_nData ) )
END_RECV_TABLE()
END_RECV_TABLE()
void C_MyPlayer::DoAnimationEvent( PlayerAnimEvent_t event, int nData )
{
if ( IsLocalPlayer() && prediction->InPrediction() && !prediction->IsFirstTimePredicted() ) )
return;
MDLCACHE_CRITICAL_SECTION();
m_PlayerAnimState->DoAnimationEvent( event, nData );
}
</source>
</source>


<< [[m_PlayerAnimState|Return to m_PlayerAnimState]] {{DISPLAYTITLE:m_PlayerAnimState/TempEnt}}
<< [[m_PlayerAnimState|Return to m_PlayerAnimState]] {{DISPLAYTITLE:m_PlayerAnimState/TempEnt}}

Revision as of 09:28, 1 February 2010

This temporary entity will dispatch player animation events to onlooking clients in the animating player's PVS. It is not needed in singleplayer.

The code can go anywhere, but your player CPP files are the best location.

Server

class CTEPlayerAnimEvent : public CBaseTempEntity
{
public:
	DECLARE_CLASS( CTEPlayerAnimEvent, CBaseTempEntity );
	DECLARE_SERVERCLASS();
	CTEPlayerAnimEvent( const char* name ) : CBaseTempEntity( name ) {}

	CNetworkHandle( CBasePlayer, m_hPlayer );
	CNetworkVar( int, m_iEvent );
	CNetworkVar( int, m_nData );
};

IMPLEMENT_SERVERCLASS_ST_NOBASE( CTEPlayerAnimEvent, DT_TEPlayerAnimEvent )
	SendPropEHandle( SENDINFO( m_hPlayer ) ),
	SendPropInt( SENDINFO( m_iEvent ), Q_log2( PLAYERANIMEVENT_COUNT ) + 1, SPROP_UNSIGNED ),
	SendPropInt( SENDINFO( m_nData ), 32 )
END_SEND_TABLE()

static CTEPlayerAnimEvent g_TEPlayerAnimEvent( "PlayerAnimEvent" );

void TE_PlayerAnimEvent( CBasePlayer* pPlayer, PlayerAnimEvent_t event, int nData )
{
	CPVSFilter filter( (const Vector&)pPlayer->EyePosition() );

	//Tony; use prediction rules.
	filter.UsePredictionRules();
	
	g_TEPlayerAnimEvent.m_hPlayer = pPlayer;
	g_TEPlayerAnimEvent.m_iEvent = event;
	g_TEPlayerAnimEvent.m_nData = nData;
	g_TEPlayerAnimEvent.Create( filter, 0 );
}

Client

#include "c_basetempentity.h"
#include "prediction.h"

class C_TEPlayerAnimEvent : public C_BaseTempEntity
{
public:
	DECLARE_CLASS( C_TEPlayerAnimEvent, C_BaseTempEntity );
	DECLARE_CLIENTCLASS();

	virtual void PostDataUpdate( DataUpdateType_t updateType )
	{
		// Create the effect.
		C_MyPlayer* pPlayer = (C_MyPlayer*)m_hPlayer.Get();
		if ( pPlayer && !pPlayer->IsDormant() )
			pPlayer->DoAnimationEvent( (PlayerAnimEvent_t)m_iEvent.Get(), m_nData )	
	}

public:
	CNetworkHandle( CBasePlayer, m_hPlayer );
	CNetworkVar( int, m_iEvent );
	CNetworkVar( int, m_nData );
};

IMPLEMENT_CLIENTCLASS_EVENT( C_TEPlayerAnimEvent, DT_TEPlayerAnimEvent, CTEPlayerAnimEvent );

BEGIN_RECV_TABLE_NOBASE( C_TEPlayerAnimEvent, DT_TEPlayerAnimEvent )
	RecvPropEHandle( RECVINFO( m_hPlayer ) ),
	RecvPropInt( RECVINFO( m_iEvent ) ),
	RecvPropInt( RECVINFO( m_nData ) )
END_RECV_TABLE()

<< Return to m_PlayerAnimState