Subversion Repositories eduke32

Rev

Rev 7986 | Rev 8293 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 Plagman 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
4541 hendricks2 20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
5 Plagman 21
 
22
Original Source: 1996 - Todd Replogle
23
Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
2456 hendricks2 24
Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
5 Plagman 25
*/
26
//-------------------------------------------------------------------------
27
 
28
//***************************************************************************
29
//
30
// Public header for CONTROL.C.
31
//
32
//***************************************************************************
33
 
5662 terminx 34
#pragma once
35
 
4747 terminx 36
#ifndef control_public_h_
37
#define control_public_h_
4766 hendricks2 38
#ifdef __cplusplus
39
extern "C" {
5 Plagman 40
#endif
41
 
42
 
43
//***************************************************************************
44
//
45
// DEFINES
46
//
47
//***************************************************************************
48
 
49
#define MAXGAMEBUTTONS      64
50
 
7181 terminx 51
#define BUTTON(x) ((CONTROL_ButtonState >> ((uint64_t)(x))) & 1)
52
#define BUTTONHELD(x) ((CONTROL_ButtonHeldState >> ((uint64_t)(x))) & 1)
1144 terminx 53
 
7181 terminx 54
#define BUTTONJUSTPRESSED(x) (BUTTON(x) && !BUTTONHELD(x))
55
#define BUTTONRELEASED(x) (!BUTTON(x) && BUTTONHELD(x))
56
#define BUTTONSTATECHANGED(x) (BUTTON(x) != BUTTONHELD(x))
5 Plagman 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
   {
1346 terminx 98
   int32_t   button0;
99
   int32_t   button1;
5 Plagman 100
   direction dir;
101
   } UserInput;
102
 
103
typedef struct
104
   {
1346 terminx 105
   int32_t     dx;
106
   int32_t     dy;
107
   int32_t     dz;
108
   int32_t     dyaw;
109
   int32_t     dpitch;
110
   int32_t     droll;
7947 hendricks2 111
   int32_t     mousex;
112
   int32_t     mousey;
5 Plagman 113
   } ControlInfo;
114
 
115
typedef enum
116
   {
117
   controltype_keyboard,
118
   controltype_keyboardandmouse,
119
   controltype_keyboardandjoystick
120
   } controltype;
121
 
122
typedef enum
123
   {
124
   controldevice_keyboard,
125
   controldevice_mouse,
126
   controldevice_joystick
127
   } controldevice;
128
 
7968 hendricks2 129
enum GameControllerButton : int
130
{
131
    GAMECONTROLLER_BUTTON_INVALID = -1,
132
    GAMECONTROLLER_BUTTON_A,
133
    GAMECONTROLLER_BUTTON_B,
134
    GAMECONTROLLER_BUTTON_X,
135
    GAMECONTROLLER_BUTTON_Y,
136
    GAMECONTROLLER_BUTTON_BACK,
137
    GAMECONTROLLER_BUTTON_GUIDE,
138
    GAMECONTROLLER_BUTTON_START,
139
    GAMECONTROLLER_BUTTON_LEFTSTICK,
140
    GAMECONTROLLER_BUTTON_RIGHTSTICK,
141
    GAMECONTROLLER_BUTTON_LEFTSHOULDER,
142
    GAMECONTROLLER_BUTTON_RIGHTSHOULDER,
143
    GAMECONTROLLER_BUTTON_DPAD_UP,
144
    GAMECONTROLLER_BUTTON_DPAD_DOWN,
145
    GAMECONTROLLER_BUTTON_DPAD_LEFT,
146
    GAMECONTROLLER_BUTTON_DPAD_RIGHT,
147
    GAMECONTROLLER_BUTTON_MAX
148
};
5 Plagman 149
 
7968 hendricks2 150
enum GameControllerAxis : int
151
{
152
    GAMECONTROLLER_AXIS_INVALID = -1,
153
    GAMECONTROLLER_AXIS_LEFTX,
154
    GAMECONTROLLER_AXIS_LEFTY,
155
    GAMECONTROLLER_AXIS_RIGHTX,
156
    GAMECONTROLLER_AXIS_RIGHTY,
157
    GAMECONTROLLER_AXIS_TRIGGERLEFT,
158
    GAMECONTROLLER_AXIS_TRIGGERRIGHT,
159
    GAMECONTROLLER_AXIS_MAX
160
};
161
 
7992 hendricks2 162
enum class LastSeenInput : unsigned char
163
{
164
    Keyboard,
165
    Joystick,
166
};
167
 
5 Plagman 168
//***************************************************************************
169
//
170
// GLOBALS
171
//
172
//***************************************************************************
173
 
7181 terminx 174
extern bool CONTROL_Started;
175
extern bool CONTROL_MousePresent;
176
extern bool CONTROL_JoyPresent;
177
extern bool CONTROL_MouseEnabled;
178
extern bool CONTROL_JoystickEnabled;
5 Plagman 179
 
7181 terminx 180
extern uint64_t CONTROL_ButtonState;
181
extern uint64_t CONTROL_ButtonHeldState;
5 Plagman 182
 
7992 hendricks2 183
extern LastSeenInput CONTROL_LastSeenInput;
7181 terminx 184
 
7992 hendricks2 185
 
5 Plagman 186
//***************************************************************************
187
//
188
// PROTOTYPES
189
//
190
//***************************************************************************
191
 
3124 helixhorne 192
//void CONTROL_MapKey( int32_t which, kb_scancode key1, kb_scancode key2 );
6334 terminx 193
void CONTROL_MapButton(int whichfunction, int whichbutton, int doubleclicked, controldevice device);
194
void CONTROL_DefineFlag( int which, int toggle );
195
int CONTROL_FlagActive( int which );
5 Plagman 196
void CONTROL_ClearAssignments( void );
2940 helixhorne 197
// void CONTROL_GetFunctionInput( void );
5 Plagman 198
void CONTROL_GetInput( ControlInfo *info );
7181 terminx 199
void CONTROL_ClearButton( int whichbutton );
7898 hendricks2 200
void CONTROL_ClearAllButtons( void );
2664 terminx 201
extern float CONTROL_MouseSensitivity;
7181 terminx 202
bool CONTROL_Startup(controltype which, int32_t ( *TimeFunction )( void ), int32_t ticspersecond);
5 Plagman 203
void CONTROL_Shutdown( void );
204
 
6334 terminx 205
void CONTROL_MapAnalogAxis(int whichaxis, int whichanalog, controldevice device);
3200 terminx 206
void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t direction, controldevice device);
207
void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldevice device);
7986 hendricks2 208
void CONTROL_SetAnalogAxisInvert(int32_t whichaxis, int32_t invert, controldevice device);
5 Plagman 209
 
7985 hendricks2 210
void CONTROL_ScanForControllers(void);
211
 
7970 hendricks2 212
int32_t CONTROL_GetGameControllerDigitalAxisPos(int32_t axis);
213
int32_t CONTROL_GetGameControllerDigitalAxisNeg(int32_t axis);
214
void CONTROL_ClearGameControllerDigitalAxisPos(int32_t axis);
215
void CONTROL_ClearGameControllerDigitalAxisNeg(int32_t axis);
216
 
3209 helixhorne 217
//void CONTROL_PrintKeyMap(void);
218
//void CONTROL_PrintControlFlag(int32_t which);
219
//void CONTROL_PrintAxes( void );
5 Plagman 220
 
3209 helixhorne 221
 
222
////////// KEY/MOUSE BIND STUFF //////////
223
 
3200 terminx 224
#define MAXBOUNDKEYS MAXKEYBOARDSCAN
3209 helixhorne 225
#define MAXMOUSEBUTTONS 10
808 terminx 226
 
7181 terminx 227
typedef struct
228
{
229
    const char *key;
230
    char *cmdstr;
808 terminx 231
    char repeat;
232
    char laststate;
7181 terminx 233
}
234
consolekeybind_t;
808 terminx 235
 
3209 helixhorne 236
// Direct use DEPRECATED:
7181 terminx 237
extern consolekeybind_t CONTROL_KeyBinds[MAXBOUNDKEYS+MAXMOUSEBUTTONS];
238
extern bool CONTROL_BindsEnabled;
834 terminx 239
 
3209 helixhorne 240
void CONTROL_ClearAllBinds(void);
7073 terminx 241
void CONTROL_BindKey(int i, char const * cmd, int repeat, char const * keyname);
242
void CONTROL_BindMouse(int i, char const * cmd, int repeat, char const * keyname);
6334 terminx 243
void CONTROL_FreeKeyBind(int i);
244
void CONTROL_FreeMouseBind(int i);
3209 helixhorne 245
 
7181 terminx 246
static inline int CONTROL_KeyIsBound(int const key)
3209 helixhorne 247
{
7181 terminx 248
    auto &bind = CONTROL_KeyBinds[key];
249
    return bind.cmdstr && bind.key;
3209 helixhorne 250
}
251
 
808 terminx 252
void CONTROL_ProcessBinds(void);
253
 
7521 hendricks2 254
#define CONTROL_GetUserInput(...)
255
#define CONTROL_ClearUserInput(...)
256
 
3209 helixhorne 257
////////////////////
258
 
813 terminx 259
#define CONTROL_NUM_FLAGS   64
7181 terminx 260
extern int32_t CONTROL_ButtonFlags[CONTROL_NUM_FLAGS];
261
extern bool CONTROL_SmoothMouse;
813 terminx 262
 
4766 hendricks2 263
#ifdef __cplusplus
264
}
5 Plagman 265
#endif
266
#endif