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.

257 lines
9.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "playerlocaldata.h"
  9. #include "player.h"
  10. #include "mathlib/mathlib.h"
  11. #include "entitylist.h"
  12. #include "SkyCamera.h"
  13. #include "playernet_vars.h"
  14. #include "fogcontroller.h"
  15. #include "tier0/vprof.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. //=============================================================================
  19. BEGIN_SEND_TABLE_NOBASE( CPlayerLocalData, DT_Local )
  20. SendPropArray3 (SENDINFO_ARRAY3(m_chAreaBits), SendPropInt(SENDINFO_ARRAY(m_chAreaBits), 8, SPROP_UNSIGNED)),
  21. SendPropArray3 (SENDINFO_ARRAY3(m_chAreaPortalBits), SendPropInt(SENDINFO_ARRAY(m_chAreaPortalBits), 8, SPROP_UNSIGNED)),
  22. SendPropInt (SENDINFO(m_iHideHUD), HIDEHUD_BITCOUNT, SPROP_UNSIGNED),
  23. SendPropFloat (SENDINFO(m_flFOVRate), 0, SPROP_NOSCALE ),
  24. SendPropInt (SENDINFO(m_bDucked), 1, SPROP_UNSIGNED ),
  25. SendPropInt (SENDINFO(m_bDucking), 1, SPROP_UNSIGNED ),
  26. SendPropInt (SENDINFO(m_bInDuckJump), 1, SPROP_UNSIGNED ),
  27. SendPropFloat (SENDINFO(m_flDucktime), 12, SPROP_ROUNDDOWN|SPROP_CHANGES_OFTEN, 0.0f, 2048.0f ),
  28. SendPropFloat (SENDINFO(m_flDuckJumpTime), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ),
  29. SendPropFloat (SENDINFO(m_flJumpTime), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ),
  30. #if PREDICTION_ERROR_CHECK_LEVEL > 1
  31. SendPropFloat (SENDINFO(m_flFallVelocity), 32, SPROP_NOSCALE ),
  32. SendPropFloat ( SENDINFO_VECTORELEM(m_vecPunchAngle, 0), 32, SPROP_NOSCALE|SPROP_CHANGES_OFTEN ),
  33. SendPropFloat ( SENDINFO_VECTORELEM(m_vecPunchAngle, 1), 32, SPROP_NOSCALE|SPROP_CHANGES_OFTEN ),
  34. SendPropFloat ( SENDINFO_VECTORELEM(m_vecPunchAngle, 2), 32, SPROP_NOSCALE|SPROP_CHANGES_OFTEN ),
  35. SendPropFloat ( SENDINFO_VECTORELEM(m_vecPunchAngleVel, 0), 32, SPROP_NOSCALE|SPROP_CHANGES_OFTEN ),
  36. SendPropFloat ( SENDINFO_VECTORELEM(m_vecPunchAngleVel, 1), 32, SPROP_NOSCALE|SPROP_CHANGES_OFTEN ),
  37. SendPropFloat ( SENDINFO_VECTORELEM(m_vecPunchAngleVel, 2), 32, SPROP_NOSCALE|SPROP_CHANGES_OFTEN ),
  38. #else
  39. SendPropFloat (SENDINFO(m_flFallVelocity), 17, SPROP_CHANGES_OFTEN, -4096.0f, 4096.0f ),
  40. SendPropVector (SENDINFO(m_vecPunchAngle), -1, SPROP_COORD|SPROP_CHANGES_OFTEN),
  41. SendPropVector (SENDINFO(m_vecPunchAngleVel), -1, SPROP_COORD),
  42. #endif
  43. SendPropInt (SENDINFO(m_bDrawViewmodel), 1, SPROP_UNSIGNED ),
  44. SendPropInt (SENDINFO(m_bWearingSuit), 1, SPROP_UNSIGNED ),
  45. SendPropBool (SENDINFO(m_bPoisoned)),
  46. SendPropFloat (SENDINFO(m_flStepSize), 16, SPROP_ROUNDUP, 0.0f, 128.0f ),
  47. SendPropInt (SENDINFO(m_bAllowAutoMovement),1, SPROP_UNSIGNED ),
  48. // 3d skybox data
  49. SendPropInt(SENDINFO_STRUCTELEM(m_skybox3d.scale), 12),
  50. SendPropVector (SENDINFO_STRUCTELEM(m_skybox3d.origin), -1, SPROP_COORD),
  51. SendPropInt (SENDINFO_STRUCTELEM(m_skybox3d.area), 8, SPROP_UNSIGNED ),
  52. SendPropInt( SENDINFO_STRUCTELEM( m_skybox3d.fog.enable ), 1, SPROP_UNSIGNED ),
  53. SendPropInt( SENDINFO_STRUCTELEM( m_skybox3d.fog.blend ), 1, SPROP_UNSIGNED ),
  54. SendPropVector( SENDINFO_STRUCTELEM(m_skybox3d.fog.dirPrimary), -1, SPROP_COORD),
  55. SendPropInt( SENDINFO_STRUCTELEM( m_skybox3d.fog.colorPrimary ), 32, SPROP_UNSIGNED ),
  56. SendPropInt( SENDINFO_STRUCTELEM( m_skybox3d.fog.colorSecondary ), 32, SPROP_UNSIGNED ),
  57. SendPropFloat( SENDINFO_STRUCTELEM( m_skybox3d.fog.start ), 0, SPROP_NOSCALE ),
  58. SendPropFloat( SENDINFO_STRUCTELEM( m_skybox3d.fog.end ), 0, SPROP_NOSCALE ),
  59. SendPropFloat( SENDINFO_STRUCTELEM( m_skybox3d.fog.maxdensity ), 0, SPROP_NOSCALE ),
  60. SendPropEHandle( SENDINFO_STRUCTELEM( m_PlayerFog.m_hCtrl ) ),
  61. // audio data
  62. SendPropVector( SENDINFO_STRUCTARRAYELEM( m_audio.localSound, 0 ), -1, SPROP_COORD),
  63. SendPropVector( SENDINFO_STRUCTARRAYELEM( m_audio.localSound, 1 ), -1, SPROP_COORD),
  64. SendPropVector( SENDINFO_STRUCTARRAYELEM( m_audio.localSound, 2 ), -1, SPROP_COORD),
  65. SendPropVector( SENDINFO_STRUCTARRAYELEM( m_audio.localSound, 3 ), -1, SPROP_COORD),
  66. SendPropVector( SENDINFO_STRUCTARRAYELEM( m_audio.localSound, 4 ), -1, SPROP_COORD),
  67. SendPropVector( SENDINFO_STRUCTARRAYELEM( m_audio.localSound, 5 ), -1, SPROP_COORD),
  68. SendPropVector( SENDINFO_STRUCTARRAYELEM( m_audio.localSound, 6 ), -1, SPROP_COORD),
  69. SendPropVector( SENDINFO_STRUCTARRAYELEM( m_audio.localSound, 7 ), -1, SPROP_COORD),
  70. SendPropInt( SENDINFO_STRUCTELEM( m_audio.soundscapeIndex ), 17, 0 ),
  71. SendPropInt( SENDINFO_STRUCTELEM( m_audio.localBits ), NUM_AUDIO_LOCAL_SOUNDS, SPROP_UNSIGNED ),
  72. SendPropEHandle( SENDINFO_STRUCTELEM( m_audio.ent ) ),
  73. END_SEND_TABLE()
  74. BEGIN_SIMPLE_DATADESC( fogplayerparams_t )
  75. DEFINE_FIELD( m_hCtrl, FIELD_EHANDLE ),
  76. DEFINE_FIELD( m_flTransitionTime, FIELD_FLOAT ),
  77. DEFINE_FIELD( m_OldColor, FIELD_COLOR32 ),
  78. DEFINE_FIELD( m_flOldStart, FIELD_FLOAT ),
  79. DEFINE_FIELD( m_flOldEnd, FIELD_FLOAT ),
  80. DEFINE_FIELD( m_NewColor, FIELD_COLOR32 ),
  81. DEFINE_FIELD( m_flNewStart, FIELD_FLOAT ),
  82. DEFINE_FIELD( m_flNewEnd, FIELD_FLOAT ),
  83. END_DATADESC()
  84. BEGIN_SIMPLE_DATADESC( fogparams_t )
  85. DEFINE_FIELD( enable, FIELD_BOOLEAN ),
  86. DEFINE_FIELD( blend, FIELD_BOOLEAN ),
  87. DEFINE_FIELD( dirPrimary, FIELD_VECTOR ),
  88. DEFINE_FIELD( colorPrimary, FIELD_COLOR32 ),
  89. DEFINE_FIELD( colorSecondary, FIELD_COLOR32 ),
  90. DEFINE_FIELD( start, FIELD_FLOAT ),
  91. DEFINE_FIELD( end, FIELD_FLOAT ),
  92. DEFINE_FIELD( farz, FIELD_FLOAT ),
  93. DEFINE_FIELD( maxdensity, FIELD_FLOAT ),
  94. DEFINE_FIELD( colorPrimaryLerpTo, FIELD_COLOR32 ),
  95. DEFINE_FIELD( colorSecondaryLerpTo, FIELD_COLOR32 ),
  96. DEFINE_FIELD( startLerpTo, FIELD_FLOAT ),
  97. DEFINE_FIELD( endLerpTo, FIELD_FLOAT ),
  98. DEFINE_FIELD( lerptime, FIELD_TIME ),
  99. DEFINE_FIELD( duration, FIELD_FLOAT ),
  100. END_DATADESC()
  101. BEGIN_SIMPLE_DATADESC( sky3dparams_t )
  102. DEFINE_FIELD( scale, FIELD_INTEGER ),
  103. DEFINE_FIELD( origin, FIELD_VECTOR ),
  104. DEFINE_FIELD( area, FIELD_INTEGER ),
  105. DEFINE_EMBEDDED( fog ),
  106. END_DATADESC()
  107. BEGIN_SIMPLE_DATADESC( audioparams_t )
  108. DEFINE_AUTO_ARRAY( localSound, FIELD_VECTOR ),
  109. DEFINE_FIELD( soundscapeIndex, FIELD_INTEGER ),
  110. DEFINE_FIELD( localBits, FIELD_INTEGER ),
  111. DEFINE_FIELD( ent, FIELD_EHANDLE ),
  112. END_DATADESC()
  113. BEGIN_SIMPLE_DATADESC( CPlayerLocalData )
  114. DEFINE_AUTO_ARRAY( m_chAreaBits, FIELD_CHARACTER ),
  115. DEFINE_AUTO_ARRAY( m_chAreaPortalBits, FIELD_CHARACTER ),
  116. DEFINE_FIELD( m_iHideHUD, FIELD_INTEGER ),
  117. DEFINE_FIELD( m_flFOVRate, FIELD_FLOAT ),
  118. DEFINE_FIELD( m_vecOverViewpoint, FIELD_VECTOR ),
  119. DEFINE_FIELD( m_bDucked, FIELD_BOOLEAN ),
  120. DEFINE_FIELD( m_bDucking, FIELD_BOOLEAN ),
  121. DEFINE_FIELD( m_bInDuckJump, FIELD_BOOLEAN ),
  122. DEFINE_FIELD( m_flDucktime, FIELD_TIME ),
  123. DEFINE_FIELD( m_flDuckJumpTime, FIELD_TIME ),
  124. DEFINE_FIELD( m_flJumpTime, FIELD_TIME ),
  125. DEFINE_FIELD( m_nStepside, FIELD_INTEGER ),
  126. DEFINE_FIELD( m_flFallVelocity, FIELD_FLOAT ),
  127. DEFINE_FIELD( m_nOldButtons, FIELD_INTEGER ),
  128. DEFINE_FIELD( m_flOldForwardMove, FIELD_FLOAT ),
  129. DEFINE_FIELD( m_vecPunchAngle, FIELD_VECTOR ),
  130. DEFINE_FIELD( m_vecPunchAngleVel, FIELD_VECTOR ),
  131. DEFINE_FIELD( m_bDrawViewmodel, FIELD_BOOLEAN ),
  132. DEFINE_FIELD( m_bWearingSuit, FIELD_BOOLEAN ),
  133. DEFINE_FIELD( m_bPoisoned, FIELD_BOOLEAN ),
  134. DEFINE_FIELD( m_flStepSize, FIELD_FLOAT ),
  135. DEFINE_FIELD( m_bAllowAutoMovement, FIELD_BOOLEAN ),
  136. DEFINE_EMBEDDED( m_skybox3d ),
  137. DEFINE_EMBEDDED( m_PlayerFog ),
  138. DEFINE_EMBEDDED( m_fog ),
  139. DEFINE_EMBEDDED( m_audio ),
  140. // "Why don't we save this field, grandpa?"
  141. //
  142. // "You see Billy, trigger_vphysics_motion uses vPhysics to touch the player,
  143. // so if the trigger is Disabled via an input while the player is inside it,
  144. // the trigger won't get its EndTouch until the player moves. Since touchlinks
  145. // aren't saved and restored, if the we save before EndTouch is called, it
  146. // will never be called after we load."
  147. //DEFINE_FIELD( m_bSlowMovement, FIELD_BOOLEAN ),
  148. END_DATADESC()
  149. //-----------------------------------------------------------------------------
  150. // Purpose: Constructor.
  151. //-----------------------------------------------------------------------------
  152. CPlayerLocalData::CPlayerLocalData()
  153. {
  154. #ifdef _DEBUG
  155. m_vecOverViewpoint.Init();
  156. m_vecPunchAngle.Init();
  157. #endif
  158. m_audio.soundscapeIndex = 0;
  159. m_audio.localBits = 0;
  160. m_audio.ent.Set( NULL );
  161. m_pOldSkyCamera = NULL;
  162. m_bDrawViewmodel = true;
  163. }
  164. void CPlayerLocalData::UpdateAreaBits( CBasePlayer *pl, unsigned char chAreaPortalBits[MAX_AREA_PORTAL_STATE_BYTES] )
  165. {
  166. Vector origin = pl->EyePosition();
  167. unsigned char tempBits[32];
  168. COMPILE_TIME_ASSERT( sizeof( tempBits ) >= sizeof( ((CPlayerLocalData*)0)->m_chAreaBits ) );
  169. int i;
  170. int area = engine->GetArea( origin );
  171. engine->GetAreaBits( area, tempBits, sizeof( tempBits ) );
  172. for ( i=0; i < m_chAreaBits.Count(); i++ )
  173. {
  174. if ( tempBits[i] != m_chAreaBits[ i ] )
  175. {
  176. m_chAreaBits.Set( i, tempBits[i] );
  177. }
  178. }
  179. for ( i=0; i < MAX_AREA_PORTAL_STATE_BYTES; i++ )
  180. {
  181. if ( chAreaPortalBits[i] != m_chAreaPortalBits[i] )
  182. m_chAreaPortalBits.Set( i, chAreaPortalBits[i] );
  183. }
  184. }
  185. //-----------------------------------------------------------------------------
  186. // Purpose: Fills in CClientData values for local player just before sending over wire
  187. // Input : player -
  188. //-----------------------------------------------------------------------------
  189. void ClientData_Update( CBasePlayer *pl )
  190. {
  191. // HACKHACK: for 3d skybox
  192. // UNDONE: Support multiple sky cameras?
  193. CSkyCamera *pSkyCamera = GetCurrentSkyCamera();
  194. if ( pSkyCamera != pl->m_Local.m_pOldSkyCamera )
  195. {
  196. pl->m_Local.m_pOldSkyCamera = pSkyCamera;
  197. pl->m_Local.m_skybox3d.CopyFrom(pSkyCamera->m_skyboxData);
  198. }
  199. else if ( !pSkyCamera )
  200. {
  201. pl->m_Local.m_skybox3d.area = 255;
  202. }
  203. }
  204. //-----------------------------------------------------------------------------
  205. // Purpose:
  206. //-----------------------------------------------------------------------------
  207. void UpdateAllClientData( void )
  208. {
  209. VPROF( "UpdateAllClientData" );
  210. int i;
  211. CBasePlayer *pl;
  212. for ( i = 1; i <= gpGlobals->maxClients; i++ )
  213. {
  214. pl = ( CBasePlayer * )UTIL_PlayerByIndex( i );
  215. if ( !pl )
  216. continue;
  217. ClientData_Update( pl );
  218. }
  219. }