1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1996, 2003 - 3D Realms Entertainment
4
5 This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
6
7 Duke Nukem 3D is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 Original Source: 1996 - Todd Replogle
23 Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
24 Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
25 */
26 //-------------------------------------------------------------------------
27
28 //***************************************************************************
29 //
30 // Public header for CONTROL.C.
31 //
32 //***************************************************************************
33
34 #ifndef _control_public
35 #define _control_public
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40
41 //***************************************************************************
42 //
43 // DEFINES
44 //
45 //***************************************************************************
46
47 #define MAXGAMEBUTTONS 64
48
49 #define BUTTON(x) CONTROL_Button(x)
50 #define BUTTONHELD(x) CONTROL_ButtonHeld(x)
51 #define BUTTONJUSTPRESSED(x) \
52 ( BUTTON( x ) && !BUTTONHELD( x ) )
53 #define BUTTONRELEASED(x) \
54 ( !BUTTON( x ) && BUTTONHELD( x ) )
55 #define BUTTONSTATECHANGED(x) \
56 ( BUTTON( x ) != BUTTONHELD( x ) )
57
58
59 //***************************************************************************
60 //
61 // TYPEDEFS
62 //
63 //***************************************************************************
64 typedef enum
65 {
66 axis_up,
67 axis_down,
68 axis_left,
69 axis_right
70 } axisdirection;
71
72 typedef enum
73 {
74 analog_turning=0,
75 analog_strafing=1,
76 analog_lookingupanddown=2,
77 analog_elevation=3,
78 analog_rolling=4,
79 analog_moving=5,
80 analog_maxtype
81 } analogcontrol;
82
83 typedef enum
84 {
85 dir_North,
86 dir_NorthEast,
87 dir_East,
88 dir_SouthEast,
89 dir_South,
90 dir_SouthWest,
91 dir_West,
92 dir_NorthWest,
93 dir_None
94 } direction;
95
96 typedef struct
97 {
98 boolean button0;
99 boolean button1;
100 direction dir;
101 } UserInput;
102
103 typedef struct
104 {
105 fixed dx;
106 fixed dy;
107 fixed dz;
108 fixed dyaw;
109 fixed dpitch;
110 fixed droll;
111 } ControlInfo;
112
113 typedef enum
114 {
115 controltype_keyboard,
116 controltype_keyboardandmouse,
117 controltype_keyboardandjoystick
118 } controltype;
119
120 typedef enum
121 {
122 controldevice_keyboard,
123 controldevice_mouse,
124 controldevice_joystick
125 } controldevice;
126
127 typedef enum
128 {
129 mousebutton_Left,
130 mousebutton_Right,
131 mousebutton_Middle,
132 mousebutton_Thumb,
133 mousebutton_WheelUp,
134 mousebutton_WheelDown
135 } mousebutton;
136
137 typedef enum
138 {
139 joybutton_A,
140 joybutton_B,
141 joybutton_X,
142 joybutton_Y,
143 joybutton_Back,
144 joybutton_Guide,
145 joybutton_Start,
146 joybutton_LeftStick,
147 joybutton_RightStick,
148 joybutton_LeftShoulder,
149 joybutton_RightShoulder,
150 joybutton_DpadUp,
151 joybutton_DpadDown,
152 joybutton_DpadLeft,
153 joybutton_DpadRight
154 } joybutton;
155
156
157 //***************************************************************************
158 //
159 // GLOBALS
160 //
161 //***************************************************************************
162
163 extern boolean CONTROL_MousePresent;
164 extern boolean CONTROL_JoyPresent;
165 extern boolean CONTROL_MouseEnabled;
166 extern boolean CONTROL_JoystickEnabled;
167 extern uint32 CONTROL_ButtonState1;
168 extern uint32 CONTROL_ButtonHeldState1;
169 extern uint32 CONTROL_ButtonState2;
170 extern uint32 CONTROL_ButtonHeldState2;
171
172
173 //***************************************************************************
174 //
175 // PROTOTYPES
176 //
177 //***************************************************************************
178
179 void CONTROL_MapKey( int32 which, kb_scancode key1, kb_scancode key2 );
180 void CONTROL_MapButton
181 (
182 int32 whichfunction,
183 int32 whichbutton,
184 boolean doubleclicked,
185 controldevice device
186 );
187 void CONTROL_DefineFlag( int32 which, boolean toggle );
188 boolean CONTROL_FlagActive( int32 which );
189 void CONTROL_ClearAssignments( void );
190 void CONTROL_GetUserInput( UserInput *info );
191 void CONTROL_GetInput( ControlInfo *info );
192 void CONTROL_ClearButton( int32 whichbutton );
193 void CONTROL_ClearUserInput( UserInput *info );
194 void CONTROL_WaitRelease( void );
195 void CONTROL_Ack( void );
196 void CONTROL_CenterJoystick
197 (
198 void ( *CenterCenter )( void ),
199 void ( *UpperLeft )( void ),
200 void ( *LowerRight )( void ),
201 void ( *CenterThrottle )( void ),
202 void ( *CenterRudder )( void )
203 );
204 int32 CONTROL_GetMouseSensitivity( void );
205 void CONTROL_SetMouseSensitivity( int32 newsensitivity );
206 void CONTROL_SetJoyAxisDead(int32 axis, int32 newdead); // 0-0x7fff
207 void CONTROL_SetJoyAxisSaturate(int32 axis, int32 newsatur); //0-0x7fff
208 boolean CONTROL_Startup
209 (
210 controltype which,
211 int32 ( *TimeFunction )( void ),
212 int32 ticspersecond
213 );
214 void CONTROL_Shutdown( void );
215
216 void CONTROL_SetDoubleClickDelay(int32 delay);
217 int32 CONTROL_GetDoubleClickDelay(void);
218
219 void CONTROL_MapAnalogAxis
220 (
221 int32 whichaxis,
222 int32 whichanalog,
223 controldevice device
224 );
225
226 void CONTROL_MapDigitalAxis
227 (
228 int32 whichaxis,
229 int32 whichfunction,
230 int32 direction,
231 controldevice device
232 );
233 void CONTROL_SetAnalogAxisScale
234 (
235 int32 whichaxis,
236 int32 axisscale,
237 controldevice device
238 );
239
240 void CONTROL_PrintKeyMap(void);
241 void CONTROL_PrintControlFlag(int32 which);
242 void CONTROL_PrintAxes( void );
243
CONTROL_Button(uint32 which)244 static inline boolean CONTROL_Button(uint32 which)
245 {
246 if (which > 63)
247 {
248 return FALSE;
249 }
250 else if (which > 31)
251 {
252 return ((CONTROL_ButtonState2 >> ((which-32))) & 1) == 1;
253 }
254 else
255 {
256 return ((CONTROL_ButtonState1 >> (which)) & 1) == 1;
257 }
258 }
259
CONTROL_ButtonHeld(uint32 which)260 static inline boolean CONTROL_ButtonHeld(uint32 which)
261 {
262 if (which > 63)
263 {
264 return FALSE;
265 }
266 else if (which > 31)
267 {
268 return ((CONTROL_ButtonHeldState2 >> ((which-32))) & 1) == 1;
269 }
270 else
271 {
272 return ((CONTROL_ButtonHeldState1 >> (which)) & 1) == 1;
273 }
274 }
275
276 #ifdef __cplusplus
277 };
278 #endif
279 #endif
280