Subversion Repositories eduke32

Rev

Rev 8536 | 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
 
8776 terminx 42
#include "mouse.h"
5 Plagman 43
 
44
//***************************************************************************
45
//
46
// DEFINES
47
//
48
//***************************************************************************
49
 
50
#define MAXGAMEBUTTONS      64
51
 
7181 terminx 52
#define BUTTON(x) ((CONTROL_ButtonState >> ((uint64_t)(x))) & 1)
53
#define BUTTONHELD(x) ((CONTROL_ButtonHeldState >> ((uint64_t)(x))) & 1)
1144 terminx 54
 
7181 terminx 55
#define BUTTONJUSTPRESSED(x) (BUTTON(x) && !BUTTONHELD(x))
56
#define BUTTONRELEASED(x) (!BUTTON(x) && BUTTONHELD(x))
57
#define BUTTONSTATECHANGED(x) (BUTTON(x) != BUTTONHELD(x))
5 Plagman 58
 
59
 
60
//***************************************************************************
61
//
62
// TYPEDEFS
63
//
64
//***************************************************************************
65
typedef enum
66
   {
67
   axis_up,
68
   axis_down,
69
   axis_left,
70
   axis_right
71
   } axisdirection;
72
 
73
typedef enum
74
   {
75
   analog_turning=0,
76
   analog_strafing=1,
77
   analog_lookingupanddown=2,
78
   analog_elevation=3,
79
   analog_rolling=4,
80
   analog_moving=5,
81
   analog_maxtype
82
   } analogcontrol;
83
 
84
typedef enum
85
   {
86
   dir_North,
87
   dir_NorthEast,
88
   dir_East,
89
   dir_SouthEast,
90
   dir_South,
91
   dir_SouthWest,
92
   dir_West,
93
   dir_NorthWest,
94
   dir_None
95
   } direction;
96
 
97
typedef struct
98
   {
1346 terminx 99
   int32_t   button0;
100
   int32_t   button1;
5 Plagman 101
   direction dir;
102
   } UserInput;
103
 
104
typedef struct
105
   {
1346 terminx 106
   int32_t     dx;
107
   int32_t     dy;
108
   int32_t     dz;
109
   int32_t     dyaw;
110
   int32_t     dpitch;
111
   int32_t     droll;
7947 hendricks2 112
   int32_t     mousex;
113
   int32_t     mousey;
5 Plagman 114
   } ControlInfo;
115
 
116
typedef enum
117
   {
118
   controltype_keyboard,
119
   controltype_keyboardandmouse,
120
   controltype_keyboardandjoystick
121
   } controltype;
122
 
123
typedef enum
124
   {
125
   controldevice_keyboard,
126
   controldevice_mouse,
127
   controldevice_joystick
128
   } controldevice;
129
 
7968 hendricks2 130
enum GameControllerButton : int
131
{
132
    GAMECONTROLLER_BUTTON_INVALID = -1,
133
    GAMECONTROLLER_BUTTON_A,
134
    GAMECONTROLLER_BUTTON_B,
135
    GAMECONTROLLER_BUTTON_X,
136
    GAMECONTROLLER_BUTTON_Y,
137
    GAMECONTROLLER_BUTTON_BACK,
138
    GAMECONTROLLER_BUTTON_GUIDE,
139
    GAMECONTROLLER_BUTTON_START,
140
    GAMECONTROLLER_BUTTON_LEFTSTICK,
141
    GAMECONTROLLER_BUTTON_RIGHTSTICK,
142
    GAMECONTROLLER_BUTTON_LEFTSHOULDER,
143
    GAMECONTROLLER_BUTTON_RIGHTSHOULDER,
144
    GAMECONTROLLER_BUTTON_DPAD_UP,
145
    GAMECONTROLLER_BUTTON_DPAD_DOWN,
146
    GAMECONTROLLER_BUTTON_DPAD_LEFT,
147
    GAMECONTROLLER_BUTTON_DPAD_RIGHT,
148
    GAMECONTROLLER_BUTTON_MAX
149
};
5 Plagman 150
 
7968 hendricks2 151
enum GameControllerAxis : int
152
{
153
    GAMECONTROLLER_AXIS_INVALID = -1,
154
    GAMECONTROLLER_AXIS_LEFTX,
155
    GAMECONTROLLER_AXIS_LEFTY,
156
    GAMECONTROLLER_AXIS_RIGHTX,
157
    GAMECONTROLLER_AXIS_RIGHTY,
158
    GAMECONTROLLER_AXIS_TRIGGERLEFT,
159
    GAMECONTROLLER_AXIS_TRIGGERRIGHT,
160
    GAMECONTROLLER_AXIS_MAX
161
};
162
 
7992 hendricks2 163
enum class LastSeenInput : unsigned char
164
{
165
    Keyboard,
166
    Joystick,
167
};
168
 
5 Plagman 169
//***************************************************************************
170
//
171
// GLOBALS
172
//
173
//***************************************************************************
174
 
7181 terminx 175
extern bool CONTROL_Started;
176
extern bool CONTROL_MousePresent;
177
extern bool CONTROL_JoyPresent;
178
extern bool CONTROL_MouseEnabled;
179
extern bool CONTROL_JoystickEnabled;
5 Plagman 180
 
7181 terminx 181
extern uint64_t CONTROL_ButtonState;
182
extern uint64_t CONTROL_ButtonHeldState;
5 Plagman 183
 
7992 hendricks2 184
extern LastSeenInput CONTROL_LastSeenInput;
7181 terminx 185
 
7992 hendricks2 186
 
5 Plagman 187
//***************************************************************************
188
//
189
// PROTOTYPES
190
//
191
//***************************************************************************
192
 
8303 hendricks2 193
void CONTROL_MapKey( int32_t which, kb_scancode key1, kb_scancode key2 );
6334 terminx 194
void CONTROL_MapButton(int whichfunction, int whichbutton, int doubleclicked, controldevice device);
195
void CONTROL_DefineFlag( int which, int toggle );
196
int CONTROL_FlagActive( int which );
5 Plagman 197
void CONTROL_ClearAssignments( void );
2940 helixhorne 198
// void CONTROL_GetFunctionInput( void );
5 Plagman 199
void CONTROL_GetInput( ControlInfo *info );
7181 terminx 200
void CONTROL_ClearButton( int whichbutton );
7898 hendricks2 201
void CONTROL_ClearAllButtons( void );
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
 
8293 hendricks2 254
void CONTROL_GetUserInput(UserInput *);
255
void CONTROL_ClearUserInput(UserInput *);
7521 hendricks2 256
 
3209 helixhorne 257
////////////////////
258
 
813 terminx 259
#define CONTROL_NUM_FLAGS   64
7181 terminx 260
extern int32_t CONTROL_ButtonFlags[CONTROL_NUM_FLAGS];
813 terminx 261
 
4766 hendricks2 262
#ifdef __cplusplus
263
}
5 Plagman 264
#endif
265
#endif