diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /mp/src/game/shared/test_ehandle.cpp | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/game/shared/test_ehandle.cpp')
| -rw-r--r-- | mp/src/game/shared/test_ehandle.cpp | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/mp/src/game/shared/test_ehandle.cpp b/mp/src/game/shared/test_ehandle.cpp new file mode 100644 index 00000000..42f27ba2 --- /dev/null +++ b/mp/src/game/shared/test_ehandle.cpp @@ -0,0 +1,125 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//
+//=============================================================================//
+
+#include "cbase.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+// In this test, the server makes an entity (call it A) that has an EHANDLE to another
+// entity (call it B). Intitially, A is sent to the client but B is not. Later,
+// the server decides to send B to the client too. At that point, without resending A's EHANDLE,
+// the client's EHANDLE should access B.
+
+#if defined( GAME_DLL )
+
+ // ------------------------------------------------------------------------------------ //
+ // The main entity class (class A).
+ // ------------------------------------------------------------------------------------ //
+ class CHandleTest : public CBaseEntity
+ {
+ public:
+ DECLARE_CLASS( CHandleTest, CBaseEntity );
+ DECLARE_SERVERCLASS();
+
+ CHandleTest()
+ {
+ m_bSendHandle = false;
+ }
+
+ virtual int UpdateTransmitState()
+ {
+ // ALWAYS transmit to all clients.
+ return SetTransmitState( FL_EDICT_ALWAYS );
+ }
+
+ virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways )
+ {
+ if ( pInfo->m_pTransmitEdict->Get( entindex() ) )
+ return;
+
+ BaseClass::SetTransmit( pInfo, bAlways );
+
+ // Force the thing we're pointing at to be sent too?
+ if ( m_bSendHandle )
+ m_Handle->SetTransmit( pInfo, bAlways );
+ }
+
+ CNetworkHandle( CBaseEntity, m_Handle );
+ CNetworkVar( bool, m_bSendHandle );
+ };
+
+ IMPLEMENT_SERVERCLASS_ST( CHandleTest, DT_HandleTest )
+ SendPropEHandle( SENDINFO( m_Handle ) ),
+ SendPropInt( SENDINFO( m_bSendHandle ) )
+ END_SEND_TABLE()
+
+ LINK_ENTITY_TO_CLASS( handle_test, CHandleTest );
+
+
+ // ------------------------------------------------------------------------------------ //
+ // The class pointed to by the handle.
+ // ------------------------------------------------------------------------------------ //
+ class CHandleDummy : public CBaseEntity
+ {
+ DECLARE_CLASS( CHandleDummy, CBaseEntity );
+ public:
+ };
+ LINK_ENTITY_TO_CLASS( handle_dummy, CHandleDummy );
+
+ CHandle<CHandleTest> g_HandleTest;
+
+ // The test runs this command.
+ void CC_Test_EHandle()
+ {
+ if ( g_HandleTest.Get() )
+ {
+ g_HandleTest->m_bSendHandle = !g_HandleTest->m_bSendHandle;
+ }
+ else
+ {
+ CHandleTest *pHolder = CREATE_ENTITY( CHandleTest, "handle_test" );
+ pHolder->m_Handle = CREATE_ENTITY( CHandleDummy, "handle_dummy" );
+ pHolder->Spawn();
+ g_HandleTest = pHolder;
+ Msg( "Created EHANDLE test entity. Run this command again to transmit the second ent.\n" );
+ }
+ }
+ ConCommand Test_EHandle( "Test_EHandle", CC_Test_EHandle, 0, FCVAR_CHEAT );
+
+
+#else
+
+ class C_HandleTest : public C_BaseEntity
+ {
+ public:
+ DECLARE_CLASS( C_HandleTest, C_BaseEntity );
+ DECLARE_CLIENTCLASS();
+
+ C_HandleTest()
+ {
+ }
+
+ virtual void OnDataChanged( DataUpdateType_t type )
+ {
+ Msg( "m_bSendHandle: %d, m_Handle.Get: 0x%p\n", m_bSendHandle, m_Handle.Get() );
+ }
+
+ EHANDLE m_Handle;
+ bool m_bSendHandle;
+ };
+
+ IMPLEMENT_CLIENTCLASS_DT( C_HandleTest, DT_HandleTest, CHandleTest )
+ RecvPropEHandle( RECVINFO( m_Handle ) ),
+ RecvPropInt( RECVINFO( m_bSendHandle ) )
+ END_RECV_TABLE()
+
+
+#endif
+
+
|