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