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.

331 lines
8.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #if !defined( USERCMD_H )
  9. #define USERCMD_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "mathlib/vector.h"
  14. #include "utlvector.h"
  15. #include "imovehelper.h"
  16. #include "checksum_crc.h"
  17. class bf_read;
  18. class bf_write;
  19. class CEntityGroundContact
  20. {
  21. public:
  22. int entindex;
  23. float minheight;
  24. float maxheight;
  25. };
  26. #ifdef DOTA_DLL
  27. class CUnitOrders
  28. {
  29. public:
  30. CUnitOrders()
  31. {
  32. m_nOrderSequenceNumber = 0;
  33. }
  34. void Reset( void )
  35. {
  36. m_nUnits.RemoveAll();
  37. m_nOrderType = 0;
  38. m_nTargetIndex = 0;
  39. m_vPosition = vec3_origin;
  40. m_nAbilityIndex = 0;
  41. }
  42. int m_nOrderSequenceNumber;
  43. CUtlVector <int> m_nUnits;
  44. int m_nOrderType;
  45. int m_nTargetIndex;
  46. int m_nAbilityIndex;
  47. Vector m_vPosition;
  48. };
  49. #endif
  50. //#define KEEP_COMMAND_REPREDICTION_COUNT //define to keep a count of how many times we've predicted each command (for debugging)
  51. class CUserCmd
  52. {
  53. public:
  54. CUserCmd()
  55. {
  56. Reset();
  57. }
  58. virtual ~CUserCmd() { };
  59. void Reset()
  60. {
  61. command_number = 0;
  62. tick_count = 0;
  63. viewangles.Init();
  64. aimdirection.Init();
  65. forwardmove = 0.0f;
  66. sidemove = 0.0f;
  67. upmove = 0.0f;
  68. buttons = 0;
  69. impulse = 0;
  70. weaponselect = 0;
  71. weaponsubtype = 0;
  72. random_seed = 0;
  73. #ifndef CLIENT_DLL
  74. server_random_seed = 0;
  75. #endif
  76. mousedx = 0;
  77. mousedy = 0;
  78. hasbeenpredicted = false;
  79. #if defined( HL2_DLL ) || defined( HL2_CLIENT_DLL )
  80. entitygroundcontact.RemoveAll();
  81. #endif
  82. #ifdef DOTA_DLL
  83. dota_unitorders.Reset();
  84. #endif
  85. #if defined ( PORTAL2 )
  86. player_held_entity = 0;
  87. held_entity_was_grabbed_through_portal = 0;
  88. command_acknowledgements_pending = 0;
  89. predictedPortalTeleportations = 0;
  90. #endif // PORTAL2
  91. // TrackIR
  92. headangles.Init();
  93. headoffset.Init();
  94. // TrackIR
  95. #if defined( INFESTED_DLL ) || defined( DOTA_DLL )
  96. crosshairtrace = vec3_origin;
  97. #endif
  98. #ifdef INFESTED_DLL
  99. crosshair_entity = 0;
  100. forced_action = 0;
  101. sync_kill_ent = 0;
  102. skill_dest.Init();
  103. skill_dest_ent = 0;
  104. // NOTE: We can probably get rid of mousedx/dy for Infested - they only seem to be used by IFM and HL2 vehicles
  105. // headnangles/headoffset too
  106. #endif
  107. #if defined( KEEP_COMMAND_REPREDICTION_COUNT )
  108. debug_RepredictionCount = 0;
  109. #endif
  110. }
  111. CUserCmd& operator =( const CUserCmd& src )
  112. {
  113. if ( this == &src )
  114. return *this;
  115. command_number = src.command_number;
  116. tick_count = src.tick_count;
  117. viewangles = src.viewangles;
  118. aimdirection = src.aimdirection;
  119. forwardmove = src.forwardmove;
  120. sidemove = src.sidemove;
  121. upmove = src.upmove;
  122. buttons = src.buttons;
  123. impulse = src.impulse;
  124. weaponselect = src.weaponselect;
  125. weaponsubtype = src.weaponsubtype;
  126. random_seed = src.random_seed;
  127. #ifndef CLIENT_DLL
  128. server_random_seed = src.server_random_seed;
  129. #endif
  130. mousedx = src.mousedx;
  131. mousedy = src.mousedy;
  132. hasbeenpredicted = src.hasbeenpredicted;
  133. #if defined( HL2_DLL ) || defined( HL2_CLIENT_DLL )
  134. entitygroundcontact = src.entitygroundcontact;
  135. #endif
  136. #if defined ( PORTAL2 )
  137. player_held_entity = src.player_held_entity;
  138. held_entity_was_grabbed_through_portal = src.held_entity_was_grabbed_through_portal;
  139. command_acknowledgements_pending = src.command_acknowledgements_pending;
  140. predictedPortalTeleportations = src.predictedPortalTeleportations;
  141. #endif // PORTAL2
  142. // TrackIR
  143. headangles = src.headangles;
  144. headoffset = src.headoffset;
  145. // TrackIR
  146. #if defined( INFESTED_DLL ) || defined( DOTA_DLL )
  147. crosshairtrace = src.crosshairtrace;
  148. #endif
  149. #ifdef INFESTED_DLL
  150. crosshair_entity = src.crosshair_entity;
  151. forced_action = src.forced_action;
  152. sync_kill_ent = src.sync_kill_ent;
  153. skill_dest = src.skill_dest;
  154. skill_dest_ent = src.skill_dest_ent;
  155. #endif
  156. #ifdef DOTA_DLL
  157. dota_unitorders = src.dota_unitorders;
  158. #endif
  159. #if defined( KEEP_COMMAND_REPREDICTION_COUNT )
  160. debug_RepredictionCount = src.debug_RepredictionCount;
  161. #endif
  162. return *this;
  163. }
  164. CUserCmd( const CUserCmd& src )
  165. {
  166. *this = src;
  167. }
  168. CRC32_t GetChecksum( void ) const
  169. {
  170. CRC32_t crc;
  171. CRC32_Init( &crc );
  172. CRC32_ProcessBuffer( &crc, &command_number, sizeof( command_number ) );
  173. CRC32_ProcessBuffer( &crc, &tick_count, sizeof( tick_count ) );
  174. CRC32_ProcessBuffer( &crc, &viewangles, sizeof( viewangles ) );
  175. CRC32_ProcessBuffer( &crc, &aimdirection, sizeof( aimdirection ) );
  176. CRC32_ProcessBuffer( &crc, &forwardmove, sizeof( forwardmove ) );
  177. CRC32_ProcessBuffer( &crc, &sidemove, sizeof( sidemove ) );
  178. CRC32_ProcessBuffer( &crc, &upmove, sizeof( upmove ) );
  179. CRC32_ProcessBuffer( &crc, &buttons, sizeof( buttons ) );
  180. CRC32_ProcessBuffer( &crc, &impulse, sizeof( impulse ) );
  181. CRC32_ProcessBuffer( &crc, &weaponselect, sizeof( weaponselect ) );
  182. CRC32_ProcessBuffer( &crc, &weaponsubtype, sizeof( weaponsubtype ) );
  183. CRC32_ProcessBuffer( &crc, &random_seed, sizeof( random_seed ) );
  184. CRC32_ProcessBuffer( &crc, &mousedx, sizeof( mousedx ) );
  185. CRC32_ProcessBuffer( &crc, &mousedy, sizeof( mousedy ) );
  186. #if defined( INFESTED_DLL ) || defined( DOTA_DLL )
  187. CRC32_ProcessBuffer( &crc, &crosshairtrace, sizeof( crosshairtrace ) );
  188. #endif
  189. #if defined ( PORTAL2 )
  190. CRC32_ProcessBuffer( &crc, &player_held_entity, sizeof( player_held_entity ) );
  191. CRC32_ProcessBuffer( &crc, &held_entity_was_grabbed_through_portal, sizeof( held_entity_was_grabbed_through_portal ) );
  192. CRC32_ProcessBuffer( &crc, &command_acknowledgements_pending, sizeof( command_acknowledgements_pending ) );
  193. CRC32_ProcessBuffer( &crc, &predictedPortalTeleportations, sizeof( predictedPortalTeleportations ) );
  194. #endif // PORTAL2
  195. #ifdef INFESTED_DLL
  196. CRC32_ProcessBuffer( &crc, &crosshair_entity, sizeof( crosshair_entity ) );
  197. CRC32_ProcessBuffer( &crc, &forced_action, sizeof( forced_action ) );
  198. CRC32_ProcessBuffer( &crc, &sync_kill_ent, sizeof( sync_kill_ent ) );
  199. CRC32_ProcessBuffer( &crc, &skill_dest, sizeof( skill_dest ) );
  200. CRC32_ProcessBuffer( &crc, &skill_dest_ent, sizeof( skill_dest_ent ) );
  201. #endif
  202. CRC32_Final( &crc );
  203. return crc;
  204. }
  205. // For matching server and client commands for debugging
  206. int command_number;
  207. // the tick the client created this command
  208. int tick_count;
  209. // Player instantaneous view angles.
  210. QAngle viewangles;
  211. Vector aimdirection; // For pointing devices.
  212. // Intended velocities
  213. // forward velocity.
  214. float forwardmove;
  215. // sideways velocity.
  216. float sidemove;
  217. // upward velocity.
  218. float upmove;
  219. // Attack button states
  220. int buttons;
  221. // Impulse command issued.
  222. byte impulse;
  223. // Current weapon id
  224. int weaponselect;
  225. int weaponsubtype;
  226. int random_seed; // For shared random functions
  227. #ifndef CLIENT_DLL
  228. int server_random_seed; // Only the server populates this seed
  229. #endif
  230. short mousedx; // mouse accum in x from create move
  231. short mousedy; // mouse accum in y from create move
  232. // Client only, tracks whether we've predicted this command at least once
  233. bool hasbeenpredicted;
  234. // Back channel to communicate IK state
  235. #if defined( HL2_DLL ) || defined( HL2_CLIENT_DLL )
  236. CUtlVector< CEntityGroundContact > entitygroundcontact;
  237. #endif
  238. #if defined ( DOTA_DLL )
  239. CUnitOrders dota_unitorders;
  240. #endif
  241. #if defined ( PORTAL2 )
  242. // Portal 2's grab code is on the client to support multiplayer
  243. short player_held_entity;
  244. // This one is temporary-- some server code needs to know if this trace
  245. // went through a portal. This should go away when we move the grabcontrollers
  246. // down to the client as well.
  247. short held_entity_was_grabbed_through_portal;
  248. unsigned short command_acknowledgements_pending; //so we can properly sync portal teleportation angle changes. The server tells us the last command it acknowledged, now we also tell it how many acknowledgments we're waiting on (command_number - engine->GetLastAcknowledgedCommand())
  249. uint8 predictedPortalTeleportations; //should probably enumerate which transforms we went through if we want perfect accuracy
  250. #endif // PORTAL2
  251. // TrackIR
  252. QAngle headangles;
  253. Vector headoffset;
  254. // TrackIR
  255. #if defined( INFESTED_DLL ) || defined( DOTA_DLL )
  256. Vector crosshairtrace; // world location directly beneath the player's crosshair
  257. #endif
  258. #ifdef INFESTED_DLL
  259. short crosshair_entity; // index of the entity under the player's crosshair
  260. byte forced_action;
  261. short sync_kill_ent;
  262. Vector skill_dest;
  263. short skill_dest_ent;
  264. #endif
  265. #if defined( KEEP_COMMAND_REPREDICTION_COUNT )
  266. unsigned int debug_RepredictionCount;
  267. #endif
  268. };
  269. void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from );
  270. void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from );
  271. #endif // USERCMD_H