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.

180 lines
4.1 KiB

  1. //========= Copyright 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. class CUserCmd
  27. {
  28. public:
  29. CUserCmd()
  30. {
  31. Reset();
  32. }
  33. virtual ~CUserCmd() { };
  34. void Reset()
  35. {
  36. command_number = 0;
  37. tick_count = 0;
  38. viewangles.Init();
  39. forwardmove = 0.0f;
  40. sidemove = 0.0f;
  41. upmove = 0.0f;
  42. buttons = 0;
  43. impulse = 0;
  44. weaponselect = 0;
  45. weaponsubtype = 0;
  46. random_seed = 0;
  47. #ifdef GAME_DLL
  48. server_random_seed = 0;
  49. #endif
  50. mousedx = 0;
  51. mousedy = 0;
  52. hasbeenpredicted = false;
  53. #if defined( HL2_DLL ) || defined( HL2_CLIENT_DLL )
  54. entitygroundcontact.RemoveAll();
  55. #endif
  56. }
  57. CUserCmd& operator =( const CUserCmd& src )
  58. {
  59. if ( this == &src )
  60. return *this;
  61. command_number = src.command_number;
  62. tick_count = src.tick_count;
  63. viewangles = src.viewangles;
  64. forwardmove = src.forwardmove;
  65. sidemove = src.sidemove;
  66. upmove = src.upmove;
  67. buttons = src.buttons;
  68. impulse = src.impulse;
  69. weaponselect = src.weaponselect;
  70. weaponsubtype = src.weaponsubtype;
  71. random_seed = src.random_seed;
  72. #ifdef GAME_DLL
  73. server_random_seed = src.server_random_seed;
  74. #endif
  75. mousedx = src.mousedx;
  76. mousedy = src.mousedy;
  77. hasbeenpredicted = src.hasbeenpredicted;
  78. #if defined( HL2_DLL ) || defined( HL2_CLIENT_DLL )
  79. entitygroundcontact = src.entitygroundcontact;
  80. #endif
  81. return *this;
  82. }
  83. CUserCmd( const CUserCmd& src )
  84. {
  85. *this = src;
  86. }
  87. CRC32_t GetChecksum( void ) const
  88. {
  89. CRC32_t crc;
  90. CRC32_Init( &crc );
  91. CRC32_ProcessBuffer( &crc, &command_number, sizeof( command_number ) );
  92. CRC32_ProcessBuffer( &crc, &tick_count, sizeof( tick_count ) );
  93. CRC32_ProcessBuffer( &crc, &viewangles, sizeof( viewangles ) );
  94. CRC32_ProcessBuffer( &crc, &forwardmove, sizeof( forwardmove ) );
  95. CRC32_ProcessBuffer( &crc, &sidemove, sizeof( sidemove ) );
  96. CRC32_ProcessBuffer( &crc, &upmove, sizeof( upmove ) );
  97. CRC32_ProcessBuffer( &crc, &buttons, sizeof( buttons ) );
  98. CRC32_ProcessBuffer( &crc, &impulse, sizeof( impulse ) );
  99. CRC32_ProcessBuffer( &crc, &weaponselect, sizeof( weaponselect ) );
  100. CRC32_ProcessBuffer( &crc, &weaponsubtype, sizeof( weaponsubtype ) );
  101. CRC32_ProcessBuffer( &crc, &random_seed, sizeof( random_seed ) );
  102. CRC32_ProcessBuffer( &crc, &mousedx, sizeof( mousedx ) );
  103. CRC32_ProcessBuffer( &crc, &mousedy, sizeof( mousedy ) );
  104. CRC32_Final( &crc );
  105. return crc;
  106. }
  107. // Allow command, but negate gameplay-affecting values
  108. void MakeInert( void )
  109. {
  110. viewangles = vec3_angle;
  111. forwardmove = 0.f;
  112. sidemove = 0.f;
  113. upmove = 0.f;
  114. buttons = 0;
  115. impulse = 0;
  116. }
  117. // For matching server and client commands for debugging
  118. int command_number;
  119. // the tick the client created this command
  120. int tick_count;
  121. // Player instantaneous view angles.
  122. QAngle viewangles;
  123. // Intended velocities
  124. // forward velocity.
  125. float forwardmove;
  126. // sideways velocity.
  127. float sidemove;
  128. // upward velocity.
  129. float upmove;
  130. // Attack button states
  131. int buttons;
  132. // Impulse command issued.
  133. byte impulse;
  134. // Current weapon id
  135. int weaponselect;
  136. int weaponsubtype;
  137. int random_seed; // For shared random functions
  138. #ifdef GAME_DLL
  139. int server_random_seed; // Only the server populates this seed
  140. #endif
  141. short mousedx; // mouse accum in x from create move
  142. short mousedy; // mouse accum in y from create move
  143. // Client only, tracks whether we've predicted this command at least once
  144. bool hasbeenpredicted;
  145. // Back channel to communicate IK state
  146. #if defined( HL2_DLL ) || defined( HL2_CLIENT_DLL )
  147. CUtlVector< CEntityGroundContact > entitygroundcontact;
  148. #endif
  149. };
  150. void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from );
  151. void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from );
  152. #endif // USERCMD_H