UsercmdGen.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __USERCMDGEN_H__
  21. #define __USERCMDGEN_H__
  22. /*
  23. ===============================================================================
  24. Samples a set of user commands from player input.
  25. ===============================================================================
  26. */
  27. const int USERCMD_HZ = 60; // 60 frames per second
  28. const int USERCMD_MSEC = 1000 / USERCMD_HZ;
  29. // usercmd_t->button bits
  30. const int BUTTON_ATTACK = BIT(0);
  31. const int BUTTON_RUN = BIT(1);
  32. const int BUTTON_ZOOM = BIT(2);
  33. const int BUTTON_SCORES = BIT(3);
  34. const int BUTTON_MLOOK = BIT(4);
  35. const int BUTTON_5 = BIT(5);
  36. const int BUTTON_6 = BIT(6);
  37. const int BUTTON_7 = BIT(7);
  38. // usercmd_t->impulse commands
  39. const int IMPULSE_0 = 0; // weap 0
  40. const int IMPULSE_1 = 1; // weap 1
  41. const int IMPULSE_2 = 2; // weap 2
  42. const int IMPULSE_3 = 3; // weap 3
  43. const int IMPULSE_4 = 4; // weap 4
  44. const int IMPULSE_5 = 5; // weap 5
  45. const int IMPULSE_6 = 6; // weap 6
  46. const int IMPULSE_7 = 7; // weap 7
  47. const int IMPULSE_8 = 8; // weap 8
  48. const int IMPULSE_9 = 9; // weap 9
  49. const int IMPULSE_10 = 10; // weap 10
  50. const int IMPULSE_11 = 11; // weap 11
  51. const int IMPULSE_12 = 12; // weap 12
  52. const int IMPULSE_13 = 13; // weap reload
  53. const int IMPULSE_14 = 14; // weap next
  54. const int IMPULSE_15 = 15; // weap prev
  55. const int IMPULSE_16 = 16; // <unused>
  56. const int IMPULSE_17 = 17; // ready to play ( toggles ui_ready )
  57. const int IMPULSE_18 = 18; // center view
  58. const int IMPULSE_19 = 19; // show PDA/INV/MAP
  59. const int IMPULSE_20 = 20; // toggle team ( toggles ui_team )
  60. const int IMPULSE_21 = 21; // <unused>
  61. const int IMPULSE_22 = 22; // spectate
  62. const int IMPULSE_23 = 23; // <unused>
  63. const int IMPULSE_24 = 24; // <unused>
  64. const int IMPULSE_25 = 25; // <unused>
  65. const int IMPULSE_26 = 26; // <unused>
  66. const int IMPULSE_27 = 27; // <unused>
  67. const int IMPULSE_28 = 28; // vote yes
  68. const int IMPULSE_29 = 29; // vote no
  69. const int IMPULSE_40 = 40; // use vehicle
  70. // usercmd_t->flags
  71. const int UCF_IMPULSE_SEQUENCE = 0x0001; // toggled every time an impulse command is sent
  72. class usercmd_t {
  73. public:
  74. int gameFrame; // frame number
  75. int gameTime; // game time
  76. int duplicateCount; // duplication count for networking
  77. byte buttons; // buttons
  78. signed char forwardmove; // forward/backward movement
  79. signed char rightmove; // left/right movement
  80. signed char upmove; // up/down movement
  81. short angles[3]; // view angles
  82. short mx; // mouse delta x
  83. short my; // mouse delta y
  84. signed char impulse; // impulse command
  85. byte flags; // additional flags
  86. int sequence; // just for debugging
  87. public:
  88. void ByteSwap(); // on big endian systems, byte swap the shorts and ints
  89. bool operator==( const usercmd_t &rhs ) const;
  90. };
  91. typedef enum {
  92. INHIBIT_SESSION = 0,
  93. INHIBIT_ASYNC
  94. } inhibit_t;
  95. const int MAX_BUFFERED_USERCMD = 64;
  96. class idUsercmdGen {
  97. public:
  98. virtual ~idUsercmdGen( void ) {}
  99. // Sets up all the cvars and console commands.
  100. virtual void Init( void ) = 0;
  101. // Prepares for a new map.
  102. virtual void InitForNewMap( void ) = 0;
  103. // Shut down.
  104. virtual void Shutdown( void ) = 0;
  105. // Clears all key states and face straight.
  106. virtual void Clear( void ) = 0;
  107. // Clears view angles.
  108. virtual void ClearAngles( void ) = 0;
  109. // When the console is down or the menu is up, only emit default usercmd, so the player isn't moving around.
  110. // Each subsystem (session and game) may want an inhibit will OR the requests.
  111. virtual void InhibitUsercmd( inhibit_t subsystem, bool inhibit ) = 0;
  112. // Returns a buffered command for the given game tic.
  113. virtual usercmd_t TicCmd( int ticNumber ) = 0;
  114. // Called async at regular intervals.
  115. virtual void UsercmdInterrupt( void ) = 0;
  116. // Set a value that can safely be referenced by UsercmdInterrupt() for each key binding.
  117. virtual int CommandStringUsercmdData( const char *cmdString ) = 0;
  118. // Returns the number of user commands.
  119. virtual int GetNumUserCommands( void ) = 0;
  120. // Returns the name of a user command via index.
  121. virtual const char *GetUserCommandName( int index ) = 0;
  122. // Continuously modified, never reset. For full screen guis.
  123. virtual void MouseState( int *x, int *y, int *button, bool *down ) = 0;
  124. // Directly sample a button.
  125. virtual int ButtonState( int key ) = 0;
  126. // Directly sample a keystate.
  127. virtual int KeyState( int key ) = 0;
  128. // Directly sample a usercmd.
  129. virtual usercmd_t GetDirectUsercmd( void ) = 0;
  130. };
  131. extern idUsercmdGen *usercmdGen;
  132. #endif /* !__USERCMDGEN_H__ */