Subversion Repositories eduke32

Rev

Rev 7985 | 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
 
5 Plagman 162
//***************************************************************************
163
//
164
// GLOBALS
165
//
166
//***************************************************************************
167
 
7181 terminx 168
extern bool CONTROL_Started;
169
extern bool CONTROL_MousePresent;
170
extern bool CONTROL_JoyPresent;
171
extern bool CONTROL_MouseEnabled;
172
extern bool CONTROL_JoystickEnabled;
5 Plagman 173
 
7181 terminx 174
extern uint64_t CONTROL_ButtonState;
175
extern uint64_t CONTROL_ButtonHeldState;
5 Plagman 176
 
7181 terminx 177
 
5 Plagman 178
//***************************************************************************
179
//
180
// PROTOTYPES
181
//
182
//***************************************************************************
183
 
3124 helixhorne 184
//void CONTROL_MapKey( int32_t which, kb_scancode key1, kb_scancode key2 );
6334 terminx 185
void CONTROL_MapButton(int whichfunction, int whichbutton, int doubleclicked, controldevice device);
186
void CONTROL_DefineFlag( int which, int toggle );
187
int CONTROL_FlagActive( int which );
5 Plagman 188
void CONTROL_ClearAssignments( void );
2940 helixhorne 189
// void CONTROL_GetFunctionInput( void );
5 Plagman 190
void CONTROL_GetInput( ControlInfo *info );
7181 terminx 191
void CONTROL_ClearButton( int whichbutton );
7898 hendricks2 192
void CONTROL_ClearAllButtons( void );
2664 terminx 193
extern float CONTROL_MouseSensitivity;
7181 terminx 194
bool CONTROL_Startup(controltype which, int32_t ( *TimeFunction )( void ), int32_t ticspersecond);
5 Plagman 195
void CONTROL_Shutdown( void );
196
 
6334 terminx 197
void CONTROL_MapAnalogAxis(int whichaxis, int whichanalog, controldevice device);
3200 terminx 198
void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t direction, controldevice device);
199
void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldevice device);
7986 hendricks2 200
void CONTROL_SetAnalogAxisInvert(int32_t whichaxis, int32_t invert, controldevice device);
5 Plagman 201
 
7985 hendricks2 202
void CONTROL_ScanForControllers(void);
203
 
7970 hendricks2 204
int32_t CONTROL_GetGameControllerDigitalAxisPos(int32_t axis);
205
int32_t CONTROL_GetGameControllerDigitalAxisNeg(int32_t axis);
206
void CONTROL_ClearGameControllerDigitalAxisPos(int32_t axis);
207
void CONTROL_ClearGameControllerDigitalAxisNeg(int32_t axis);
208
 
3209 helixhorne 209
//void CONTROL_PrintKeyMap(void);
210
//void CONTROL_PrintControlFlag(int32_t which);
211
//void CONTROL_PrintAxes( void );
5 Plagman 212
 
3209 helixhorne 213
 
214
////////// KEY/MOUSE BIND STUFF //////////
215
 
3200 terminx 216
#define MAXBOUNDKEYS MAXKEYBOARDSCAN
3209 helixhorne 217
#define MAXMOUSEBUTTONS 10
808 terminx 218
 
7181 terminx 219
typedef struct
220
{
221
    const char *key;
222
    char *cmdstr;
808 terminx 223
    char repeat;
224
    char laststate;
7181 terminx 225
}
226
consolekeybind_t;
808 terminx 227
 
3209 helixhorne 228
// Direct use DEPRECATED:
7181 terminx 229
extern consolekeybind_t CONTROL_KeyBinds[MAXBOUNDKEYS+MAXMOUSEBUTTONS];
230
extern bool CONTROL_BindsEnabled;
834 terminx 231
 
3209 helixhorne 232
void CONTROL_ClearAllBinds(void);
7073 terminx 233
void CONTROL_BindKey(int i, char const * cmd, int repeat, char const * keyname);
234
void CONTROL_BindMouse(int i, char const * cmd, int repeat, char const * keyname);
6334 terminx 235
void CONTROL_FreeKeyBind(int i);
236
void CONTROL_FreeMouseBind(int i);
3209 helixhorne 237
 
7181 terminx 238
static inline int CONTROL_KeyIsBound(int const key)
3209 helixhorne 239
{
7181 terminx 240
    auto &bind = CONTROL_KeyBinds[key];
241
    return bind.cmdstr && bind.key;
3209 helixhorne 242
}
243
 
808 terminx 244
void CONTROL_ProcessBinds(void);
245
 
7521 hendricks2 246
#define CONTROL_GetUserInput(...)
247
#define CONTROL_ClearUserInput(...)
248
 
3209 helixhorne 249
////////////////////
250
 
813 terminx 251
#define CONTROL_NUM_FLAGS   64
7181 terminx 252
extern int32_t CONTROL_ButtonFlags[CONTROL_NUM_FLAGS];
253
extern bool CONTROL_SmoothMouse;
813 terminx 254
 
4766 hendricks2 255
#ifdef __cplusplus
256
}
5 Plagman 257
#endif
258
#endif