From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- engine/packed_entity.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 engine/packed_entity.cpp (limited to 'engine/packed_entity.cpp') diff --git a/engine/packed_entity.cpp b/engine/packed_entity.cpp new file mode 100644 index 0000000..9944f82 --- /dev/null +++ b/engine/packed_entity.cpp @@ -0,0 +1,117 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#include +#include +#include +#include "packed_entity.h" +#include "basetypes.h" +#include "changeframelist.h" +#include "dt_send.h" +#include "dt_send_eng.h" +#include "server_class.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +// -------------------------------------------------------------------------------------------------- // +// PackedEntity. +// -------------------------------------------------------------------------------------------------- // + +PackedEntity::PackedEntity() +{ + m_pData = NULL; + m_pChangeFrameList = NULL; + m_nSnapshotCreationTick = 0; + m_nShouldCheckCreationTick = 0; +} + +PackedEntity::~PackedEntity() +{ + FreeData(); + + if ( m_pChangeFrameList ) + { + m_pChangeFrameList->Release(); + m_pChangeFrameList = NULL; + } +} + + +bool PackedEntity::AllocAndCopyPadded( const void *pData, unsigned long size ) +{ + FreeData(); + + unsigned long nBytes = PAD_NUMBER( size, 4 ); + + // allocate the memory + m_pData = malloc( nBytes ); + + if ( !m_pData ) + { + Assert( m_pData ); + return false; + } + + Q_memcpy( m_pData, pData, size ); + SetNumBits( nBytes * 8 ); + + return true; +} + + +int PackedEntity::GetPropsChangedAfterTick( int iTick, int *iOutProps, int nMaxOutProps ) +{ + if ( m_pChangeFrameList ) + { + return m_pChangeFrameList->GetPropsChangedAfterTick( iTick, iOutProps, nMaxOutProps ); + } + else + { + // signal that we don't have a changelist + return -1; + } +} + + +const CSendProxyRecipients* PackedEntity::GetRecipients() const +{ + return m_Recipients.Base(); +} + + +int PackedEntity::GetNumRecipients() const +{ + return m_Recipients.Count(); +} + + +void PackedEntity::SetRecipients( const CUtlMemory &recipients ) +{ + m_Recipients.CopyArray( recipients.Base(), recipients.Count() ); +} + + +bool PackedEntity::CompareRecipients( const CUtlMemory &recipients ) +{ + if ( recipients.Count() != m_Recipients.Count() ) + return false; + + return memcmp( recipients.Base(), m_Recipients.Base(), sizeof( CSendProxyRecipients ) * m_Recipients.Count() ) == 0; +} + +void PackedEntity::SetServerAndClientClass( ServerClass *pServerClass, ClientClass *pClientClass ) +{ + m_pServerClass = pServerClass; + m_pClientClass = pClientClass; + if ( pServerClass ) + { + Assert( pServerClass->m_pTable ); + SetShouldCheckCreationTick( pServerClass->m_pTable->HasPropsEncodedAgainstTickCount() ); + } +} \ No newline at end of file -- cgit v1.2.3