Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #if !defined( PACKED_ENTITY_H )
  10. #define PACKED_ENTITY_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include <const.h>
  15. #include <basetypes.h>
  16. #include <mempool.h>
  17. #include <utlvector.h>
  18. #include <tier0/dbg.h>
  19. #include "common.h"
  20. #include "ents_shared.h"
  21. // This is extra spew to the files cltrace.txt + svtrace.txt
  22. // #define DEBUG_NETWORKING 1
  23. #if defined( DEBUG_NETWORKING )
  24. #include "convar.h"
  25. void SpewToFile( char const* pFmt, ... );
  26. extern ConVar sv_packettrace;
  27. #define TRACE_PACKET( text ) if ( sv_packettrace.GetInt() ) { SpewToFile text ; };
  28. #else
  29. #define TRACE_PACKET( text )
  30. #endif
  31. #define FLAG_IS_COMPRESSED (1<<31)
  32. class CSendProxyRecipients;
  33. class SendTable;
  34. class RecvTable;
  35. class ServerClass;
  36. class ClientClass;
  37. class CChangeFrameList;
  38. typedef intp SerializedEntityHandle_t;
  39. // Replaces entity_state_t.
  40. // This is what we send to clients.
  41. class PackedEntity
  42. {
  43. public:
  44. PackedEntity();
  45. ~PackedEntity();
  46. void SetNumBits( int nBits );
  47. int GetNumBits() const;
  48. int GetNumBytes() const;
  49. // Access the data in the entity.
  50. const SerializedEntityHandle_t GetPackedData() const;
  51. void ReleasePackedData();
  52. // Copy the data into the PackedEntity's data and make sure the # bytes allocated is
  53. // an integer multiple of 4.
  54. void CopyPackedData( SerializedEntityHandle_t handle );
  55. // Like copy, but just takes ownership of handle. Assumes that parent caller is done with entity and will NOT
  56. // call ReleaseSerializedEntity
  57. void SetPackedData( SerializedEntityHandle_t handle );
  58. // These are like Get/Set, except SnagChangeFrameList clears out the
  59. // PackedEntity's pointer since the usage model in sv_main is to keep
  60. // the same CChangeFrameList in the most recent PackedEntity for the
  61. // lifetime of an edict.
  62. //
  63. // When the PackedEntity is deleted, it deletes its current CChangeFrameList if it exists.
  64. void SetChangeFrameList( CChangeFrameList *pList );
  65. CChangeFrameList* GetChangeFrameList();
  66. const CChangeFrameList* GetChangeFrameList() const;
  67. CChangeFrameList* SnagChangeFrameList();
  68. // Access the recipients array.
  69. const CSendProxyRecipients* GetRecipients() const;
  70. int GetNumRecipients() const;
  71. void SetRecipients( const CUtlMemory<CSendProxyRecipients> &recipients );
  72. bool CompareRecipients( const CUtlMemory<CSendProxyRecipients> &recipients ) const;
  73. void SetSnapshotCreationTick( int nTick );
  74. int GetSnapshotCreationTick() const;
  75. void SetShouldCheckCreationTick( bool bState );
  76. bool ShouldCheckCreationTick() const;
  77. void SetServerAndClientClass( ServerClass *pServerClass, ClientClass *pClientClass );
  78. public:
  79. ServerClass *m_pServerClass; // Valid on the server
  80. ClientClass *m_pClientClass; // Valid on the client
  81. int m_nEntityIndex; // Entity index.
  82. CInterlockedInt m_ReferenceCount; // reference count;
  83. private:
  84. CUtlVector<CSendProxyRecipients> m_Recipients;
  85. SerializedEntityHandle_t m_SerializedEntity;
  86. CChangeFrameList *m_pChangeFrameList; // Only the most current
  87. // This is the tick this PackedEntity was created on
  88. unsigned int m_nSnapshotCreationTick : 31;
  89. unsigned int m_nShouldCheckCreationTick : 1;
  90. };
  91. inline const SerializedEntityHandle_t PackedEntity::GetPackedData() const
  92. {
  93. return m_SerializedEntity;
  94. }
  95. inline void PackedEntity::SetChangeFrameList( CChangeFrameList *pList )
  96. {
  97. Assert( !m_pChangeFrameList );
  98. m_pChangeFrameList = pList;
  99. }
  100. inline CChangeFrameList* PackedEntity::GetChangeFrameList()
  101. {
  102. return m_pChangeFrameList;
  103. }
  104. inline const CChangeFrameList* PackedEntity::GetChangeFrameList() const
  105. {
  106. return m_pChangeFrameList;
  107. }
  108. inline CChangeFrameList* PackedEntity::SnagChangeFrameList()
  109. {
  110. CChangeFrameList *pRet = m_pChangeFrameList;
  111. m_pChangeFrameList = NULL;
  112. return pRet;
  113. }
  114. inline void PackedEntity::SetSnapshotCreationTick( int nTick )
  115. {
  116. m_nSnapshotCreationTick = (unsigned int)nTick;
  117. }
  118. inline int PackedEntity::GetSnapshotCreationTick() const
  119. {
  120. return (int)m_nSnapshotCreationTick;
  121. }
  122. inline void PackedEntity::SetShouldCheckCreationTick( bool bState )
  123. {
  124. m_nShouldCheckCreationTick = bState ? 1 : 0;
  125. }
  126. inline bool PackedEntity::ShouldCheckCreationTick() const
  127. {
  128. return m_nShouldCheckCreationTick == 1 ? true : false;
  129. }
  130. #endif // PACKED_ENTITY_H