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.

107 lines
2.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include <string.h>
  9. #include <assert.h>
  10. #include "packed_entity.h"
  11. #include "basetypes.h"
  12. #include "changeframelist.h"
  13. #include "dt_send.h"
  14. #include "dt_send_eng.h"
  15. #include "server_class.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. // -------------------------------------------------------------------------------------------------- //
  19. // PackedEntity.
  20. // -------------------------------------------------------------------------------------------------- //
  21. PackedEntity::PackedEntity()
  22. {
  23. m_SerializedEntity = SERIALIZED_ENTITY_HANDLE_INVALID;
  24. m_pChangeFrameList = NULL;
  25. m_nSnapshotCreationTick = 0;
  26. m_nShouldCheckCreationTick = 0;
  27. }
  28. PackedEntity::~PackedEntity()
  29. {
  30. ReleasePackedData();
  31. if ( m_pChangeFrameList )
  32. {
  33. m_pChangeFrameList->Release();
  34. m_pChangeFrameList = NULL;
  35. }
  36. }
  37. void PackedEntity::ReleasePackedData()
  38. {
  39. if ( SERIALIZED_ENTITY_HANDLE_INVALID != m_SerializedEntity )
  40. {
  41. g_pSerializedEntities->ReleaseSerializedEntity( m_SerializedEntity );
  42. m_SerializedEntity = SERIALIZED_ENTITY_HANDLE_INVALID;
  43. }
  44. }
  45. void PackedEntity::CopyPackedData( SerializedEntityHandle_t handle )
  46. {
  47. ReleasePackedData();
  48. m_SerializedEntity = g_pSerializedEntities->CopySerializedEntity( handle, __FILE__, __LINE__ );
  49. return;
  50. }
  51. // Like copy, but just takes ownership of handle. Assumes that parent caller is done with entity and will NOT
  52. // call ReleaseSerializedEntity
  53. void PackedEntity::SetPackedData( SerializedEntityHandle_t handle )
  54. {
  55. if ( handle == m_SerializedEntity )
  56. return;
  57. ReleasePackedData();
  58. m_SerializedEntity = handle;
  59. return;
  60. }
  61. const CSendProxyRecipients* PackedEntity::GetRecipients() const
  62. {
  63. return m_Recipients.Base();
  64. }
  65. int PackedEntity::GetNumRecipients() const
  66. {
  67. return m_Recipients.Count();
  68. }
  69. void PackedEntity::SetRecipients( const CUtlMemory<CSendProxyRecipients> &recipients )
  70. {
  71. m_Recipients.CopyArray( recipients.Base(), recipients.Count() );
  72. }
  73. bool PackedEntity::CompareRecipients( const CUtlMemory<CSendProxyRecipients> &recipients ) const
  74. {
  75. if ( recipients.Count() != m_Recipients.Count() )
  76. return false;
  77. return memcmp( recipients.Base(), m_Recipients.Base(), sizeof( CSendProxyRecipients ) * m_Recipients.Count() ) == 0;
  78. }
  79. void PackedEntity::SetServerAndClientClass( ServerClass *pServerClass, ClientClass *pClientClass )
  80. {
  81. m_pServerClass = pServerClass;
  82. m_pClientClass = pClientClass;
  83. if ( pServerClass )
  84. {
  85. Assert( pServerClass->m_pTable );
  86. SetShouldCheckCreationTick( pServerClass->m_pTable->HasPropsEncodedAgainstTickCount() );
  87. }
  88. }