2006-04-13 20:47:06 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 1996, 2003 - 3D Realms Entertainment
|
|
|
|
|
|
|
|
This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
|
|
|
|
|
|
|
|
Duke Nukem 3D is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
Original Source: 1996 - Todd Replogle
|
|
|
|
Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
|
2012-03-12 04:47:04 +00:00
|
|
|
Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
|
2006-04-13 20:47:06 +00:00
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
//
|
|
|
|
// Public header for CONTROL.C.
|
|
|
|
//
|
|
|
|
//***************************************************************************
|
|
|
|
|
2016-03-14 00:07:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#ifndef control_public_h_
|
|
|
|
#define control_public_h_
|
2014-11-26 04:39:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
//
|
|
|
|
// DEFINES
|
|
|
|
//
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
#define MAXGAMEBUTTONS 64
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
#define BUTTON(x) ((CONTROL_ButtonState >> ((uint64_t)(x))) & 1)
|
|
|
|
#define BUTTONHELD(x) ((CONTROL_ButtonHeldState >> ((uint64_t)(x))) & 1)
|
2008-11-21 12:14:05 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
#define BUTTONJUSTPRESSED(x) (BUTTON(x) && !BUTTONHELD(x))
|
|
|
|
#define BUTTONRELEASED(x) (!BUTTON(x) && BUTTONHELD(x))
|
|
|
|
#define BUTTONSTATECHANGED(x) (BUTTON(x) != BUTTONHELD(x))
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
//
|
|
|
|
// TYPEDEFS
|
|
|
|
//
|
|
|
|
//***************************************************************************
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
axis_up,
|
|
|
|
axis_down,
|
|
|
|
axis_left,
|
|
|
|
axis_right
|
|
|
|
} axisdirection;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
analog_turning=0,
|
|
|
|
analog_strafing=1,
|
|
|
|
analog_lookingupanddown=2,
|
|
|
|
analog_elevation=3,
|
|
|
|
analog_rolling=4,
|
|
|
|
analog_moving=5,
|
|
|
|
analog_maxtype
|
|
|
|
} analogcontrol;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
dir_North,
|
|
|
|
dir_NorthEast,
|
|
|
|
dir_East,
|
|
|
|
dir_SouthEast,
|
|
|
|
dir_South,
|
|
|
|
dir_SouthWest,
|
|
|
|
dir_West,
|
|
|
|
dir_NorthWest,
|
|
|
|
dir_None
|
|
|
|
} direction;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t button0;
|
|
|
|
int32_t button1;
|
2006-04-13 20:47:06 +00:00
|
|
|
direction dir;
|
|
|
|
} UserInput;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t dx;
|
|
|
|
int32_t dy;
|
|
|
|
int32_t dz;
|
|
|
|
int32_t dyaw;
|
|
|
|
int32_t dpitch;
|
|
|
|
int32_t droll;
|
2019-08-11 20:52:50 +00:00
|
|
|
int32_t mousex;
|
|
|
|
int32_t mousey;
|
2006-04-13 20:47:06 +00:00
|
|
|
} ControlInfo;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
controltype_keyboard,
|
|
|
|
controltype_keyboardandmouse,
|
|
|
|
controltype_keyboardandjoystick
|
|
|
|
} controltype;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
controldevice_keyboard,
|
|
|
|
controldevice_mouse,
|
|
|
|
controldevice_joystick
|
|
|
|
} controldevice;
|
|
|
|
|
2019-08-13 09:15:49 +00:00
|
|
|
enum GameControllerButton : int
|
|
|
|
{
|
|
|
|
GAMECONTROLLER_BUTTON_INVALID = -1,
|
|
|
|
GAMECONTROLLER_BUTTON_A,
|
|
|
|
GAMECONTROLLER_BUTTON_B,
|
|
|
|
GAMECONTROLLER_BUTTON_X,
|
|
|
|
GAMECONTROLLER_BUTTON_Y,
|
|
|
|
GAMECONTROLLER_BUTTON_BACK,
|
|
|
|
GAMECONTROLLER_BUTTON_GUIDE,
|
|
|
|
GAMECONTROLLER_BUTTON_START,
|
|
|
|
GAMECONTROLLER_BUTTON_LEFTSTICK,
|
|
|
|
GAMECONTROLLER_BUTTON_RIGHTSTICK,
|
|
|
|
GAMECONTROLLER_BUTTON_LEFTSHOULDER,
|
|
|
|
GAMECONTROLLER_BUTTON_RIGHTSHOULDER,
|
|
|
|
GAMECONTROLLER_BUTTON_DPAD_UP,
|
|
|
|
GAMECONTROLLER_BUTTON_DPAD_DOWN,
|
|
|
|
GAMECONTROLLER_BUTTON_DPAD_LEFT,
|
|
|
|
GAMECONTROLLER_BUTTON_DPAD_RIGHT,
|
|
|
|
GAMECONTROLLER_BUTTON_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GameControllerAxis : int
|
|
|
|
{
|
|
|
|
GAMECONTROLLER_AXIS_INVALID = -1,
|
|
|
|
GAMECONTROLLER_AXIS_LEFTX,
|
|
|
|
GAMECONTROLLER_AXIS_LEFTY,
|
|
|
|
GAMECONTROLLER_AXIS_RIGHTX,
|
|
|
|
GAMECONTROLLER_AXIS_RIGHTY,
|
|
|
|
GAMECONTROLLER_AXIS_TRIGGERLEFT,
|
|
|
|
GAMECONTROLLER_AXIS_TRIGGERRIGHT,
|
|
|
|
GAMECONTROLLER_AXIS_MAX
|
|
|
|
};
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
//
|
|
|
|
// GLOBALS
|
|
|
|
//
|
|
|
|
//***************************************************************************
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
extern bool CONTROL_Started;
|
|
|
|
extern bool CONTROL_MousePresent;
|
|
|
|
extern bool CONTROL_JoyPresent;
|
|
|
|
extern bool CONTROL_MouseEnabled;
|
|
|
|
extern bool CONTROL_JoystickEnabled;
|
|
|
|
|
|
|
|
extern uint64_t CONTROL_ButtonState;
|
|
|
|
extern uint64_t CONTROL_ButtonHeldState;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
//
|
|
|
|
// PROTOTYPES
|
|
|
|
//
|
|
|
|
//***************************************************************************
|
|
|
|
|
2012-11-06 23:06:34 +00:00
|
|
|
//void CONTROL_MapKey( int32_t which, kb_scancode key1, kb_scancode key2 );
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_MapButton(int whichfunction, int whichbutton, int doubleclicked, controldevice device);
|
|
|
|
void CONTROL_DefineFlag( int which, int toggle );
|
|
|
|
int CONTROL_FlagActive( int which );
|
2006-04-13 20:47:06 +00:00
|
|
|
void CONTROL_ClearAssignments( void );
|
2012-08-20 21:24:54 +00:00
|
|
|
// void CONTROL_GetFunctionInput( void );
|
2006-04-13 20:47:06 +00:00
|
|
|
void CONTROL_GetInput( ControlInfo *info );
|
2018-11-18 18:08:53 +00:00
|
|
|
void CONTROL_ClearButton( int whichbutton );
|
2019-08-07 20:06:27 +00:00
|
|
|
void CONTROL_ClearAllButtons( void );
|
2012-05-17 23:54:43 +00:00
|
|
|
extern float CONTROL_MouseSensitivity;
|
2018-11-18 18:08:53 +00:00
|
|
|
bool CONTROL_Startup(controltype which, int32_t ( *TimeFunction )( void ), int32_t ticspersecond);
|
2006-04-13 20:47:06 +00:00
|
|
|
void CONTROL_Shutdown( void );
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_MapAnalogAxis(int whichaxis, int whichanalog, controldevice device);
|
2012-11-17 16:48:11 +00:00
|
|
|
void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t direction, controldevice device);
|
|
|
|
void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldevice device);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-08-13 09:15:58 +00:00
|
|
|
int32_t CONTROL_GetGameControllerDigitalAxisPos(int32_t axis);
|
|
|
|
int32_t CONTROL_GetGameControllerDigitalAxisNeg(int32_t axis);
|
|
|
|
void CONTROL_ClearGameControllerDigitalAxisPos(int32_t axis);
|
|
|
|
void CONTROL_ClearGameControllerDigitalAxisNeg(int32_t axis);
|
|
|
|
|
2012-11-18 15:44:18 +00:00
|
|
|
//void CONTROL_PrintKeyMap(void);
|
|
|
|
//void CONTROL_PrintControlFlag(int32_t which);
|
|
|
|
//void CONTROL_PrintAxes( void );
|
|
|
|
|
|
|
|
|
|
|
|
////////// KEY/MOUSE BIND STUFF //////////
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-17 16:48:11 +00:00
|
|
|
#define MAXBOUNDKEYS MAXKEYBOARDSCAN
|
2012-11-18 15:44:18 +00:00
|
|
|
#define MAXMOUSEBUTTONS 10
|
2008-06-29 10:40:37 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *key;
|
|
|
|
char *cmdstr;
|
2008-06-29 10:40:37 +00:00
|
|
|
char repeat;
|
|
|
|
char laststate;
|
2018-11-18 18:08:53 +00:00
|
|
|
}
|
|
|
|
consolekeybind_t;
|
2008-06-29 10:40:37 +00:00
|
|
|
|
2012-11-18 15:44:18 +00:00
|
|
|
// Direct use DEPRECATED:
|
2018-11-18 18:08:53 +00:00
|
|
|
extern consolekeybind_t CONTROL_KeyBinds[MAXBOUNDKEYS+MAXMOUSEBUTTONS];
|
|
|
|
extern bool CONTROL_BindsEnabled;
|
2008-06-29 10:40:37 +00:00
|
|
|
|
2012-11-18 15:44:18 +00:00
|
|
|
void CONTROL_ClearAllBinds(void);
|
2018-10-16 06:09:20 +00:00
|
|
|
void CONTROL_BindKey(int i, char const * cmd, int repeat, char const * keyname);
|
|
|
|
void CONTROL_BindMouse(int i, char const * cmd, int repeat, char const * keyname);
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_FreeKeyBind(int i);
|
|
|
|
void CONTROL_FreeMouseBind(int i);
|
2012-11-18 15:44:18 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
static inline int CONTROL_KeyIsBound(int const key)
|
2012-11-18 15:44:18 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
auto &bind = CONTROL_KeyBinds[key];
|
|
|
|
return bind.cmdstr && bind.key;
|
2012-11-18 15:44:18 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 10:40:37 +00:00
|
|
|
void CONTROL_ProcessBinds(void);
|
|
|
|
|
2019-04-08 06:27:24 +00:00
|
|
|
#define CONTROL_GetUserInput(...)
|
|
|
|
#define CONTROL_ClearUserInput(...)
|
|
|
|
|
2012-11-18 15:44:18 +00:00
|
|
|
////////////////////
|
|
|
|
|
2008-06-29 12:29:42 +00:00
|
|
|
#define CONTROL_NUM_FLAGS 64
|
2018-11-18 18:08:53 +00:00
|
|
|
extern int32_t CONTROL_ButtonFlags[CONTROL_NUM_FLAGS];
|
|
|
|
extern bool CONTROL_SmoothMouse;
|
2008-06-29 12:29:42 +00:00
|
|
|
|
2014-11-26 04:39:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
#endif
|