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.

180 lines
5.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: implements various common send proxies
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "recvproxy.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. void RecvProxy_IntSubOne( const CRecvProxyData *pData, void *pStruct, void *pOut )
  12. {
  13. int *pInt = (int *)pOut;
  14. *pInt = pData->m_Value.m_Int - 1;
  15. }
  16. void RecvProxy_ShortSubOne( const CRecvProxyData *pData, void *pStruct, void *pOut )
  17. {
  18. short *pInt = (short *)pOut;
  19. *pInt = pData->m_Value.m_Int - 1;
  20. }
  21. RecvProp RecvPropIntWithMinusOneFlag( char *pVarName, int offset, int sizeofVar, RecvVarProxyFn proxyFn )
  22. {
  23. return RecvPropInt( pVarName, offset, sizeofVar, 0, proxyFn );
  24. }
  25. //-----------------------------------------------------------------------------
  26. // Purpose: Okay, so we have to queue up the actual ehandle to entity lookup for the following reason:
  27. // If a player has an EHandle/CHandle to an object such as a weapon, since the player is in slot 1-31, then
  28. // if the weapon is created and given to the player in the same frame, then the weapon won't have been
  29. // created at the time we parse this EHandle index, since the player is ahead of every other entity in the
  30. // packet (except for the world).
  31. // So instead, we remember which ehandles need to be set and we set them after all network data has
  32. // been received. Sigh.
  33. // Input : *pData -
  34. // *pStruct -
  35. // *pOut -
  36. //-----------------------------------------------------------------------------
  37. void RecvProxy_IntToEHandle( const CRecvProxyData *pData, void *pStruct, void *pOut )
  38. {
  39. CBaseHandle *pEHandle = (CBaseHandle*)pOut;
  40. if ( pData->m_Value.m_Int == INVALID_NETWORKED_EHANDLE_VALUE )
  41. {
  42. *pEHandle = INVALID_EHANDLE;
  43. }
  44. else
  45. {
  46. int iEntity = pData->m_Value.m_Int & ((1 << MAX_EDICT_BITS) - 1);
  47. int iSerialNum = pData->m_Value.m_Int >> MAX_EDICT_BITS;
  48. pEHandle->Init( iEntity, iSerialNum );
  49. }
  50. }
  51. RecvProp RecvPropEHandle(
  52. char *pVarName,
  53. int offset,
  54. int sizeofVar,
  55. RecvVarProxyFn proxyFn )
  56. {
  57. return RecvPropInt( pVarName, offset, sizeofVar, 0, proxyFn );
  58. }
  59. RecvProp RecvPropBool(
  60. char *pVarName,
  61. int offset,
  62. int sizeofVar )
  63. {
  64. Assert( sizeofVar == sizeof( bool ) );
  65. return RecvPropInt( pVarName, offset, sizeofVar );
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Moveparent receive proxies
  69. //-----------------------------------------------------------------------------
  70. void RecvProxy_IntToMoveParent( const CRecvProxyData *pData, void *pStruct, void *pOut )
  71. {
  72. CHandle<C_BaseEntity> *pHandle = (CHandle<C_BaseEntity>*)pOut;
  73. RecvProxy_IntToEHandle( pData, pStruct, (CBaseHandle*)pHandle );
  74. }
  75. void RecvProxy_InterpolationAmountChanged( const CRecvProxyData *pData, void *pStruct, void *pOut )
  76. {
  77. // m_bSimulatedEveryTick & m_bAnimatedEveryTick are boolean
  78. if ( *((bool*)pOut) != (pData->m_Value.m_Int != 0) )
  79. {
  80. // Have the regular proxy store the data.
  81. RecvProxy_Int32ToInt8( pData, pStruct, pOut );
  82. C_BaseEntity *pEntity = (C_BaseEntity *) pStruct;
  83. pEntity->Interp_UpdateInterpolationAmounts( pEntity->GetVarMapping() );
  84. }
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose: Decodes a time value
  88. // Input : *pStruct - ( C_BaseEntity * ) used to flag animtime is changine
  89. // *pVarData -
  90. // *pIn -
  91. // objectID -
  92. //-----------------------------------------------------------------------------
  93. static void RecvProxy_Time( const CRecvProxyData *pData, void *pStruct, void *pOut )
  94. {
  95. float t;
  96. float clock_base;
  97. float offset;
  98. // Get msec offset
  99. offset = ( float )pData->m_Value.m_Int / 1000.0f;
  100. // Get base
  101. clock_base = floor( engine->GetLastTimeStamp() );
  102. // Add together and clamp to msec precision
  103. t = ClampToMsec( clock_base + offset );
  104. // Store decoded value
  105. *( float * )pOut = t;
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose:
  109. // Input : *pVarName -
  110. // sizeofVar -
  111. // Output : RecvProp
  112. //-----------------------------------------------------------------------------
  113. RecvProp RecvPropTime(
  114. char *pVarName,
  115. int offset,
  116. int sizeofVar/*=SIZEOF_IGNORE*/ )
  117. {
  118. // return RecvPropInt( pVarName, offset, sizeofVar, 0, RecvProxy_Time );
  119. return RecvPropFloat( pVarName, offset, sizeofVar );
  120. };
  121. //-----------------------------------------------------------------------------
  122. // Purpose: Okay, so we have to queue up the actual ehandle to entity lookup for the following reason:
  123. // If a player has an EHandle/CHandle to an object such as a weapon, since the player is in slot 1-31, then
  124. // if the weapon is created and given to the player in the same frame, then the weapon won't have been
  125. // created at the time we parse this EHandle index, since the player is ahead of every other entity in the
  126. // packet (except for the world).
  127. // So instead, we remember which ehandles need to be set and we set them after all network data has
  128. // been received. Sigh.
  129. // Input : *pData -
  130. // *pStruct -
  131. // *pOut -
  132. //-----------------------------------------------------------------------------
  133. #if !defined( NO_ENTITY_PREDICTION ) && defined( USE_PREDICTABLEID )
  134. static void RecvProxy_IntToPredictableId( const CRecvProxyData *pData, void *pStruct, void *pOut )
  135. {
  136. CPredictableId *pId = (CPredictableId*)pOut;
  137. Assert( pId );
  138. pId->SetRaw( pData->m_Value.m_Int );
  139. }
  140. //-----------------------------------------------------------------------------
  141. // Purpose:
  142. // Input : *pVarName -
  143. // sizeofVar -
  144. // Output : RecvProp
  145. //-----------------------------------------------------------------------------
  146. RecvProp RecvPropPredictableId(
  147. char *pVarName,
  148. int offset,
  149. int sizeofVar/*=SIZEOF_IGNORE*/ )
  150. {
  151. return RecvPropInt( pVarName, offset, sizeofVar, 0, RecvProxy_IntToPredictableId );
  152. }
  153. #endif