Team Fortress 2 Source Code as on 22/4/2020
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.

116 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include <malloc.h>
  9. #include <string.h>
  10. #include <assert.h>
  11. #include "packed_entity.h"
  12. #include "basetypes.h"
  13. #include "changeframelist.h"
  14. #include "dt_send.h"
  15. #include "dt_send_eng.h"
  16. #include "server_class.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. // -------------------------------------------------------------------------------------------------- //
  20. // PackedEntity.
  21. // -------------------------------------------------------------------------------------------------- //
  22. PackedEntity::PackedEntity()
  23. {
  24. m_pData = NULL;
  25. m_pChangeFrameList = NULL;
  26. m_nSnapshotCreationTick = 0;
  27. m_nShouldCheckCreationTick = 0;
  28. }
  29. PackedEntity::~PackedEntity()
  30. {
  31. FreeData();
  32. if ( m_pChangeFrameList )
  33. {
  34. m_pChangeFrameList->Release();
  35. m_pChangeFrameList = NULL;
  36. }
  37. }
  38. bool PackedEntity::AllocAndCopyPadded( const void *pData, unsigned long size )
  39. {
  40. FreeData();
  41. unsigned long nBytes = PAD_NUMBER( size, 4 );
  42. // allocate the memory
  43. m_pData = malloc( nBytes );
  44. if ( !m_pData )
  45. {
  46. Assert( m_pData );
  47. return false;
  48. }
  49. Q_memcpy( m_pData, pData, size );
  50. SetNumBits( nBytes * 8 );
  51. return true;
  52. }
  53. int PackedEntity::GetPropsChangedAfterTick( int iTick, int *iOutProps, int nMaxOutProps )
  54. {
  55. if ( m_pChangeFrameList )
  56. {
  57. return m_pChangeFrameList->GetPropsChangedAfterTick( iTick, iOutProps, nMaxOutProps );
  58. }
  59. else
  60. {
  61. // signal that we don't have a changelist
  62. return -1;
  63. }
  64. }
  65. const CSendProxyRecipients* PackedEntity::GetRecipients() const
  66. {
  67. return m_Recipients.Base();
  68. }
  69. int PackedEntity::GetNumRecipients() const
  70. {
  71. return m_Recipients.Count();
  72. }
  73. void PackedEntity::SetRecipients( const CUtlMemory<CSendProxyRecipients> &recipients )
  74. {
  75. m_Recipients.CopyArray( recipients.Base(), recipients.Count() );
  76. }
  77. bool PackedEntity::CompareRecipients( const CUtlMemory<CSendProxyRecipients> &recipients )
  78. {
  79. if ( recipients.Count() != m_Recipients.Count() )
  80. return false;
  81. return memcmp( recipients.Base(), m_Recipients.Base(), sizeof( CSendProxyRecipients ) * m_Recipients.Count() ) == 0;
  82. }
  83. void PackedEntity::SetServerAndClientClass( ServerClass *pServerClass, ClientClass *pClientClass )
  84. {
  85. m_pServerClass = pServerClass;
  86. m_pClientClass = pClientClass;
  87. if ( pServerClass )
  88. {
  89. Assert( pServerClass->m_pTable );
  90. SetShouldCheckCreationTick( pServerClass->m_pTable->HasPropsEncodedAgainstTickCount() );
  91. }
  92. }