]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/framework/UsercmdGen.h
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / framework / UsercmdGen.h
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 {
111         INHIBIT_SESSION = 0,
112         INHIBIT_ASYNC
113 } inhibit_t;
114
115 const int MAX_BUFFERED_USERCMD = 64;
116
117 class idUsercmdGen {
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__ */