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.

182 lines
3.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef ENTS_SHARED_H
  7. #define ENTS_SHARED_H
  8. #include <protocol.h>
  9. #include <iserver.h>
  10. #include "clientframe.h"
  11. #include "packed_entity.h"
  12. #include "iclientnetworkable.h"
  13. #ifdef _WIN32
  14. #pragma once
  15. #endif
  16. typedef intp SerializedEntityHandle_t;
  17. enum
  18. {
  19. SERIALIZED_ENTITY_HANDLE_INVALID = (SerializedEntityHandle_t)0,
  20. };
  21. abstract_class ISerializedEntities
  22. {
  23. public:
  24. virtual SerializedEntityHandle_t AllocateSerializedEntity( char const *pFile, int nLine ) = 0;
  25. virtual void ReleaseSerializedEntity( SerializedEntityHandle_t handle ) = 0;
  26. virtual SerializedEntityHandle_t CopySerializedEntity( SerializedEntityHandle_t handle, char const *pFile, int nLine ) = 0;
  27. };
  28. extern ISerializedEntities *g_pSerializedEntities;
  29. enum
  30. {
  31. ENTITY_SENTINEL = 9999 // larger number than any real entity number
  32. };
  33. // Used to classify entity update types in DeltaPacketEntities.
  34. enum UpdateType
  35. {
  36. EnterPVS = 0, // Entity came back into pvs, create new entity if one doesn't exist
  37. LeavePVS, // Entity left pvs
  38. DeltaEnt, // There is a delta for this entity.
  39. PreserveEnt, // Entity stays alive but no delta ( could be LOD, or just unchanged )
  40. Finished, // finished parsing entities successfully
  41. Failed, // parsing error occured while reading entities
  42. };
  43. // Flags for delta encoding header
  44. enum
  45. {
  46. FHDR_ZERO = 0x0000,
  47. FHDR_LEAVEPVS = 0x0001,
  48. FHDR_DELETE = 0x0002,
  49. FHDR_ENTERPVS = 0x0004,
  50. };
  51. class CEntityInfo
  52. {
  53. public:
  54. CEntityInfo() {
  55. m_nOldEntity = -1;
  56. m_nNewEntity = -1;
  57. m_nHeaderBase = -1;
  58. }
  59. virtual ~CEntityInfo() {};
  60. CClientFrame *m_pFrom;
  61. CClientFrame *m_pTo;
  62. int m_nOldEntity; // current entity index in m_pFrom
  63. int m_nNewEntity; // current entity index in m_pTo
  64. int m_nHeaderBase;
  65. int m_nHeaderCount;
  66. UpdateType m_UpdateType;
  67. bool m_bAsDelta;
  68. inline void NextOldEntity( void )
  69. {
  70. if ( m_pFrom )
  71. {
  72. m_nOldEntity = m_pFrom->transmit_entity.FindNextSetBit( m_nOldEntity+1 );
  73. if ( m_nOldEntity < 0 )
  74. {
  75. // Sentinel/end of list....
  76. m_nOldEntity = ENTITY_SENTINEL;
  77. }
  78. }
  79. else
  80. {
  81. m_nOldEntity = ENTITY_SENTINEL;
  82. }
  83. }
  84. inline int GetNextOldEntity( int startEntity )
  85. {
  86. if ( m_pFrom )
  87. {
  88. int nextEntity = m_pFrom->transmit_entity.FindNextSetBit( startEntity+1 );
  89. if ( nextEntity < 0 )
  90. {
  91. // Sentinel/end of list....
  92. nextEntity = ENTITY_SENTINEL;
  93. }
  94. return nextEntity;
  95. }
  96. else
  97. {
  98. return ENTITY_SENTINEL;
  99. }
  100. }
  101. inline void NextNewEntity( void )
  102. {
  103. m_nNewEntity = m_pTo->transmit_entity.FindNextSetBit( m_nNewEntity+1 );
  104. if ( m_nNewEntity < 0 )
  105. {
  106. // Sentinel/end of list....
  107. m_nNewEntity = ENTITY_SENTINEL;
  108. }
  109. }
  110. };
  111. // PostDataUpdate calls are stored in a list until all ents have been updated.
  112. class CPostDataUpdateCall
  113. {
  114. public:
  115. int m_iEnt;
  116. DataUpdateType_t m_UpdateType;
  117. };
  118. // Passed around the read functions.
  119. class CEntityReadInfo : public CEntityInfo
  120. {
  121. public:
  122. CEntityReadInfo()
  123. { m_nPostDataUpdateCalls = 0;
  124. m_nLocalPlayerBits = 0;
  125. m_nOtherPlayerBits = 0;
  126. m_UpdateType = PreserveEnt;
  127. m_DecodeEntity = g_pSerializedEntities->AllocateSerializedEntity( __FILE__, __LINE__ );
  128. }
  129. ~CEntityReadInfo()
  130. {
  131. g_pSerializedEntities->ReleaseSerializedEntity( m_DecodeEntity );
  132. }
  133. SerializedEntityHandle_t m_DecodeEntity;
  134. bf_read *m_pBuf;
  135. int m_UpdateFlags; // from the subheader
  136. bool m_bIsEntity;
  137. int m_nBaseline; // what baseline index do we use (0/1)
  138. bool m_bUpdateBaselines; // update baseline while parsing snaphsot
  139. int m_nLocalPlayerBits; // profiling data
  140. int m_nOtherPlayerBits; // profiling data
  141. CPostDataUpdateCall m_PostDataUpdateCalls[MAX_EDICTS];
  142. int m_nPostDataUpdateCalls;
  143. };
  144. #endif // ENTS_SHARED_H