2006-04-13 20:47:06 +00:00
|
|
|
/*
|
|
|
|
* control.c
|
|
|
|
* MACT library controller handling
|
2008-06-29 10:41:01 +00:00
|
|
|
*
|
2006-04-13 20:47:06 +00:00
|
|
|
* Derived from MACT386.LIB disassembly by Jonathon Fowler
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-11-18 18:12:33 +00:00
|
|
|
#include "_control.h"
|
|
|
|
#include "baselayer.h"
|
2006-12-21 12:53:11 +00:00
|
|
|
#include "compat.h"
|
2018-11-18 18:12:33 +00:00
|
|
|
#include "control.h"
|
|
|
|
#include "joystick.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "keyboard.h"
|
|
|
|
#include "mouse.h"
|
2008-07-12 23:44:07 +00:00
|
|
|
#include "osd.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "pragmas.h"
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
bool CONTROL_Started = false;
|
2018-11-18 18:12:33 +00:00
|
|
|
bool CONTROL_MouseEnabled = false;
|
|
|
|
bool CONTROL_MousePresent = false;
|
2018-11-18 18:08:53 +00:00
|
|
|
bool CONTROL_JoyPresent = false;
|
|
|
|
bool CONTROL_JoystickEnabled = false;
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
uint64_t CONTROL_ButtonState = 0;
|
|
|
|
uint64_t CONTROL_ButtonHeldState = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-08-14 05:25:22 +00:00
|
|
|
LastSeenInput CONTROL_LastSeenInput;
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
float CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
|
|
|
|
static int32_t CONTROL_NumMouseButtons = 0;
|
|
|
|
static int32_t CONTROL_NumJoyButtons = 0;
|
|
|
|
static int32_t CONTROL_NumJoyAxes = 0;
|
|
|
|
|
|
|
|
static controlflags CONTROL_Flags[CONTROL_NUM_FLAGS];
|
|
|
|
|
|
|
|
// static controlkeymaptype CONTROL_KeyMapping[CONTROL_NUM_FLAGS];
|
2018-11-18 18:12:33 +00:00
|
|
|
|
2019-09-19 12:02:11 +00:00
|
|
|
static int32_t CONTROL_MouseAxesScale[2];
|
2017-07-07 22:50:37 +00:00
|
|
|
|
2018-11-18 18:12:33 +00:00
|
|
|
static controlaxismaptype CONTROL_JoyAxesMap[MAXJOYAXES];
|
|
|
|
static controlaxistype CONTROL_JoyAxes[MAXJOYAXES];
|
|
|
|
static controlaxistype CONTROL_LastJoyAxes[MAXJOYAXES];
|
|
|
|
static int32_t CONTROL_JoyAxesScale[MAXJOYAXES];
|
2019-08-14 03:03:57 +00:00
|
|
|
static int8_t CONTROL_JoyAxesInvert[MAXJOYAXES];
|
2017-07-07 22:50:37 +00:00
|
|
|
|
2018-11-18 18:12:33 +00:00
|
|
|
static controlbuttontype CONTROL_MouseButtonMapping[MAXMOUSEBUTTONS];
|
2017-07-07 22:50:37 +00:00
|
|
|
|
|
|
|
static int32_t CONTROL_MouseButtonClicked[MAXMOUSEBUTTONS];
|
2018-11-18 18:12:33 +00:00
|
|
|
static int32_t CONTROL_MouseButtonClickedState[MAXMOUSEBUTTONS];
|
|
|
|
static int32_t CONTROL_MouseButtonClickedTime[MAXMOUSEBUTTONS];
|
|
|
|
static int32_t CONTROL_MouseButtonState[MAXMOUSEBUTTONS];
|
2017-07-07 22:50:37 +00:00
|
|
|
static uint8_t CONTROL_MouseButtonClickedCount[MAXMOUSEBUTTONS];
|
|
|
|
|
2018-11-18 18:12:33 +00:00
|
|
|
static controlbuttontype CONTROL_JoyButtonMapping[MAXJOYBUTTONS];
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
static int32_t CONTROL_JoyButtonClicked[MAXJOYBUTTONS];
|
2018-11-18 18:12:33 +00:00
|
|
|
static int32_t CONTROL_JoyButtonClickedState[MAXJOYBUTTONS];
|
|
|
|
static int32_t CONTROL_JoyButtonClickedTime[MAXJOYBUTTONS];
|
|
|
|
static int32_t CONTROL_JoyButtonState[MAXJOYBUTTONS];
|
2017-07-07 22:50:37 +00:00
|
|
|
static uint8_t CONTROL_JoyButtonClickedCount[MAXJOYBUTTONS];
|
|
|
|
|
2014-07-28 06:43:16 +00:00
|
|
|
static int32_t(*ExtGetTime)(void);
|
2012-08-20 21:24:54 +00:00
|
|
|
//static int32_t ticrate;
|
2018-11-18 18:08:53 +00:00
|
|
|
static uint8_t CONTROL_DoubleClickSpeed;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
int32_t CONTROL_ButtonFlags[CONTROL_NUM_FLAGS];
|
|
|
|
consolekeybind_t CONTROL_KeyBinds[MAXBOUNDKEYS + MAXMOUSEBUTTONS];
|
|
|
|
bool CONTROL_BindsEnabled = 0;
|
|
|
|
bool CONTROL_SmoothMouse = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
#define CONTROL_CheckRange(which) ((unsigned)which >= (unsigned)CONTROL_NUM_FLAGS)
|
2019-06-25 11:29:08 +00:00
|
|
|
#define BIND(x, s, r, k) do { Xfree(x.cmdstr); x.cmdstr = s; x.repeat = r; x.key = k; } while (0)
|
2012-11-20 01:33:25 +00:00
|
|
|
|
2012-11-18 15:44:18 +00:00
|
|
|
void CONTROL_ClearAllBinds(void)
|
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
for (int i=0; i<MAXBOUNDKEYS; i++)
|
2012-11-18 15:44:18 +00:00
|
|
|
CONTROL_FreeKeyBind(i);
|
2018-11-18 18:08:53 +00:00
|
|
|
for (int i=0; i<MAXMOUSEBUTTONS; i++)
|
2012-11-18 15:44:18 +00:00
|
|
|
CONTROL_FreeMouseBind(i);
|
|
|
|
}
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_BindKey(int i, char const * const cmd, int repeat, char const * const keyname)
|
2012-11-18 15:44:18 +00:00
|
|
|
{
|
2018-10-25 23:28:56 +00:00
|
|
|
BIND(CONTROL_KeyBinds[i], Xstrdup(cmd), repeat, keyname);
|
2012-11-18 15:44:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_BindMouse(int i, char const * const cmd, int repeat, char const * const keyname)
|
2012-11-18 15:44:18 +00:00
|
|
|
{
|
2018-10-25 23:28:56 +00:00
|
|
|
BIND(CONTROL_KeyBinds[MAXBOUNDKEYS + i], Xstrdup(cmd), repeat, keyname);
|
2012-11-18 15:44:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_FreeKeyBind(int i)
|
2012-11-18 15:44:18 +00:00
|
|
|
{
|
2012-11-20 01:33:25 +00:00
|
|
|
BIND(CONTROL_KeyBinds[i], NULL, 0, NULL);
|
2012-11-18 15:44:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_FreeMouseBind(int i)
|
2012-11-18 15:44:18 +00:00
|
|
|
{
|
2017-07-05 05:42:54 +00:00
|
|
|
BIND(CONTROL_KeyBinds[MAXBOUNDKEYS + i], NULL, 0, NULL);
|
2012-11-18 15:44:18 +00:00
|
|
|
}
|
|
|
|
|
2019-08-11 20:52:50 +00:00
|
|
|
static void CONTROL_GetMouseDelta(ControlInfo * info)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-11-18 18:05:03 +00:00
|
|
|
vec2_t input;
|
|
|
|
mouseReadPos(&input.x, &input.y);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:05:03 +00:00
|
|
|
vec2f_t finput = { float(input.x), float(input.y) };
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-17 16:47:47 +00:00
|
|
|
if (CONTROL_SmoothMouse)
|
2008-10-13 01:16:40 +00:00
|
|
|
{
|
2018-03-17 03:44:05 +00:00
|
|
|
static vec2_t last;
|
2018-11-18 18:05:03 +00:00
|
|
|
finput = { float(input.x + last.x) * 0.5f, float(input.y + last.y) * 0.5f };
|
|
|
|
last = input;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-09-19 12:02:00 +00:00
|
|
|
info->mousex = mulscale16(Blrintf(finput.x * 4.f * CONTROL_MouseSensitivity), CONTROL_MouseAxesScale[0]);
|
|
|
|
info->mousey = mulscale16(Blrintf(finput.y * 4.f * CONTROL_MouseSensitivity), CONTROL_MouseAxesScale[1]);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 21:24:54 +00:00
|
|
|
static int32_t CONTROL_GetTime(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
static int32_t t = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
t += 5;
|
|
|
|
return t;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
static void CONTROL_SetFlag(int which, int active)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return;
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
controlflags &flags = CONTROL_Flags[which];
|
|
|
|
|
|
|
|
if (flags.toggle == INSTANT_ONOFF)
|
|
|
|
flags.active = active;
|
|
|
|
else if (active)
|
|
|
|
flags.buttonheld = FALSE;
|
|
|
|
else if (flags.buttonheld == FALSE)
|
2008-08-24 09:01:17 +00:00
|
|
|
{
|
2017-07-07 22:50:37 +00:00
|
|
|
flags.buttonheld = TRUE;
|
|
|
|
flags.active = (flags.active ? FALSE : TRUE);
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-06 23:06:34 +00:00
|
|
|
#if 0
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t CONTROL_KeyboardFunctionPressed(int32_t which)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t key1 = 0, key2 = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
if (!CONTROL_Flags[which].used) return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-17 16:47:58 +00:00
|
|
|
if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key1].cmdstr)
|
2009-04-26 05:57:42 +00:00
|
|
|
key1 = KB_KeyDown[ CONTROL_KeyMapping[which].key1 ] ? TRUE : FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-17 16:47:58 +00:00
|
|
|
if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key2].cmdstr)
|
2009-04-26 05:57:42 +00:00
|
|
|
key2 = KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] ? TRUE : FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return key1 | key2;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_ClearKeyboardFunction(int32_t which)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
if (!CONTROL_Flags[which].used) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED)
|
|
|
|
KB_KeyDown[ CONTROL_KeyMapping[which].key1 ] = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED)
|
|
|
|
KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2012-11-06 23:06:34 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_DefineFlag(int which, int toggle)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
controlflags &flags = CONTROL_Flags[which];
|
|
|
|
|
|
|
|
flags.active = FALSE;
|
|
|
|
flags.buttonheld = FALSE;
|
|
|
|
flags.cleared = 0;
|
2018-11-18 18:08:53 +00:00
|
|
|
flags.toggle = toggle;
|
|
|
|
flags.used = TRUE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
int CONTROL_FlagActive(int which)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
return CONTROL_Flags[which].used;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-06 23:06:34 +00:00
|
|
|
#if 0
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_MapKey(int32_t which, kb_scancode key1, kb_scancode key2)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_KeyMapping[which].key1 = key1 ? key1 : KEYUNDEFINED;
|
|
|
|
CONTROL_KeyMapping[which].key2 = key2 ? key2 : KEYUNDEFINED;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_PrintKeyMap(void)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
for (i=0; i<CONTROL_NUM_FLAGS; i++)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2010-12-19 22:47:10 +00:00
|
|
|
initprintf("function %2d key1=%3x key2=%3x\n",
|
2006-09-02 02:34:29 +00:00
|
|
|
i, CONTROL_KeyMapping[i].key1, CONTROL_KeyMapping[i].key2);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_PrintControlFlag(int32_t which)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-12-19 22:47:10 +00:00
|
|
|
initprintf("function %2d active=%d used=%d toggle=%d buttonheld=%d cleared=%d\n",
|
2006-09-02 02:34:29 +00:00
|
|
|
which, CONTROL_Flags[which].active, CONTROL_Flags[which].used,
|
|
|
|
CONTROL_Flags[which].toggle, CONTROL_Flags[which].buttonheld,
|
|
|
|
CONTROL_Flags[which].cleared);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_PrintAxes(void)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
initprintf("numjoyaxes=%d\n", CONTROL_NumJoyAxes);
|
2009-04-26 05:57:42 +00:00
|
|
|
for (i=0; i<CONTROL_NumJoyAxes; i++)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
initprintf("axis=%d analog=%d digital1=%d digital2=%d\n",
|
2006-09-02 02:34:29 +00:00
|
|
|
i, CONTROL_JoyAxesMap[i].analogmap,
|
|
|
|
CONTROL_JoyAxesMap[i].minmap, CONTROL_JoyAxesMap[i].maxmap);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2012-11-18 15:44:18 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_MapButton(int whichfunction, int whichbutton, int doubleclicked, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlbuttontype *set;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(whichfunction)) whichfunction = BUTTONUNDEFINED;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_mouse:
|
2017-07-07 22:50:37 +00:00
|
|
|
if ((unsigned)whichbutton >= (unsigned)MAXMOUSEBUTTONS)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapButton: button %d out of valid range for %d mouse buttons.",
|
|
|
|
// whichbutton, CONTROL_NumMouseButtons);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set = CONTROL_MouseButtonMapping;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
2017-07-07 22:50:37 +00:00
|
|
|
if ((unsigned)whichbutton >= (unsigned)MAXJOYBUTTONS)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapButton: button %d out of valid range for %d joystick buttons.",
|
|
|
|
// whichbutton, CONTROL_NumJoyButtons);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set = CONTROL_JoyButtonMapping;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//Error("CONTROL_MapButton: invalid controller device type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doubleclicked)
|
|
|
|
set[whichbutton].doubleclicked = whichfunction;
|
|
|
|
else
|
|
|
|
set[whichbutton].singleclicked = whichfunction;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 22:50:37 +00:00
|
|
|
void CONTROL_MapAnalogAxis(int whichaxis, int whichanalog, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxismaptype *set;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-08-10 23:29:20 +00:00
|
|
|
if ((unsigned)whichanalog >= (unsigned)analog_maxtype && whichanalog != -1)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapAnalogAxis: analog function %d out of valid range for %d analog functions.",
|
|
|
|
// whichanalog, analog_maxtype);
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
2017-07-07 22:50:37 +00:00
|
|
|
if ((unsigned)whichaxis >= (unsigned)MAXJOYAXES)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d joystick axes.",
|
|
|
|
// whichaxis, MAXJOYAXES);
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set = CONTROL_JoyAxesMap;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
default:
|
|
|
|
//Error("CONTROL_MapAnalogAxis: invalid controller device type");
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set[whichaxis].analogmap = whichanalog;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t *set;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_mouse:
|
2019-09-19 12:02:11 +00:00
|
|
|
if ((unsigned) whichaxis >= ARRAY_SIZE(CONTROL_MouseAxesScale))
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d mouse axes.",
|
|
|
|
// whichaxis, MAXMOUSEAXES);
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set = CONTROL_MouseAxesScale;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
2017-07-07 22:50:37 +00:00
|
|
|
if ((unsigned) whichaxis >= (unsigned) MAXJOYAXES)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d joystick axes.",
|
|
|
|
// whichaxis, MAXJOYAXES);
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set = CONTROL_JoyAxesScale;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
default:
|
|
|
|
//Error("CONTROL_SetAnalogAxisScale: invalid controller device type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
set[whichaxis] = axisscale;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 03:03:57 +00:00
|
|
|
void CONTROL_SetAnalogAxisInvert(int32_t whichaxis, int32_t invert, controldevice device)
|
|
|
|
{
|
|
|
|
int8_t * set;
|
|
|
|
|
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case controldevice_joystick:
|
|
|
|
if ((unsigned) whichaxis >= (unsigned) MAXJOYAXES)
|
|
|
|
{
|
|
|
|
//Error("CONTROL_SetAnalogAxisInvert: axis %d out of valid range for %d joystick axes.",
|
|
|
|
// whichaxis, MAXJOYAXES);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
set = CONTROL_JoyAxesInvert;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//Error("CONTROL_SetAnalogAxisInvert: invalid controller device type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
set[whichaxis] = invert;
|
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t direction, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxismaptype *set;
|
|
|
|
|
|
|
|
if (CONTROL_CheckRange(whichfunction)) whichfunction = AXISUNDEFINED;
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
2017-07-07 22:50:37 +00:00
|
|
|
if ((unsigned) whichaxis >= (unsigned) MAXJOYAXES)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d joystick axes.",
|
|
|
|
// whichaxis, MAXJOYAXES);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
set = CONTROL_JoyAxesMap;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//Error("CONTROL_MapDigitalAxis: invalid controller device type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (direction) // JBF: this is all very much a guess. The ASM puzzles me.
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case axis_up:
|
|
|
|
case axis_left:
|
|
|
|
set[whichaxis].minmap = whichfunction;
|
|
|
|
break;
|
|
|
|
case axis_down:
|
|
|
|
case axis_right:
|
|
|
|
set[whichaxis].maxmap = whichfunction;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
void CONTROL_ClearAssignments(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes));
|
2019-08-14 03:03:57 +00:00
|
|
|
memset(CONTROL_JoyAxesInvert, 0, sizeof(CONTROL_JoyAxesInvert));
|
2018-11-18 18:08:53 +00:00
|
|
|
memset(CONTROL_JoyAxesMap, AXISUNDEFINED, sizeof(CONTROL_JoyAxesMap));
|
2006-09-02 02:34:29 +00:00
|
|
|
memset(CONTROL_JoyButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_JoyButtonMapping));
|
2012-11-06 23:06:34 +00:00
|
|
|
// memset(CONTROL_KeyMapping, KEYUNDEFINED, sizeof(CONTROL_KeyMapping));
|
2006-09-02 02:34:29 +00:00
|
|
|
memset(CONTROL_LastJoyAxes, 0, sizeof(CONTROL_LastJoyAxes));
|
2018-11-18 18:08:53 +00:00
|
|
|
memset(CONTROL_MouseButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_MouseButtonMapping));
|
|
|
|
|
|
|
|
for (int & i : CONTROL_MouseAxesScale)
|
|
|
|
i = NORMALAXISSCALE;
|
|
|
|
|
|
|
|
for (int & i : CONTROL_JoyAxesScale)
|
|
|
|
i = NORMALAXISSCALE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 05:25:22 +00:00
|
|
|
static int DoGetDeviceButtons(
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t buttons, int32_t tm,
|
|
|
|
int32_t NumButtons,
|
|
|
|
int32_t *DeviceButtonState,
|
|
|
|
int32_t *ButtonClickedTime,
|
|
|
|
int32_t *ButtonClickedState,
|
|
|
|
int32_t *ButtonClicked,
|
|
|
|
uint8_t *ButtonClickedCount
|
2008-06-29 10:41:01 +00:00
|
|
|
)
|
|
|
|
{
|
2012-08-20 21:24:54 +00:00
|
|
|
int32_t i=NumButtons-1;
|
2019-08-14 05:25:22 +00:00
|
|
|
int retval = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
for (; i>=0; i--)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
int const bs = (buttons >> i) & 1;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
DeviceButtonState[i] = bs;
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClickedState[i] = FALSE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (bs)
|
|
|
|
{
|
2019-08-14 05:25:22 +00:00
|
|
|
retval = 1;
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
if (ButtonClicked[i] == FALSE)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClicked[i] = TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (ButtonClickedCount[i] == 0 || tm > ButtonClickedTime[i])
|
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
ButtonClickedTime[i] = tm + CONTROL_DoubleClickSpeed;
|
2006-09-02 02:34:29 +00:00
|
|
|
ButtonClickedCount[i] = 1;
|
|
|
|
}
|
2008-06-29 10:41:01 +00:00
|
|
|
else if (tm < ButtonClickedTime[i])
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClickedState[i] = TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
ButtonClickedTime[i] = 0;
|
|
|
|
ButtonClickedCount[i] = 2;
|
|
|
|
}
|
|
|
|
}
|
2008-06-29 10:41:01 +00:00
|
|
|
else if (ButtonClickedCount[i] == 2)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClickedState[i] = TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2012-08-20 21:24:54 +00:00
|
|
|
|
2008-08-24 05:39:28 +00:00
|
|
|
continue;
|
2008-06-29 10:41:01 +00:00
|
|
|
}
|
2012-08-20 21:24:54 +00:00
|
|
|
|
2008-08-24 05:39:28 +00:00
|
|
|
if (ButtonClickedCount[i] == 2)
|
|
|
|
ButtonClickedCount[i] = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClicked[i] = FALSE;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2019-08-14 05:25:22 +00:00
|
|
|
|
|
|
|
return retval;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-06 23:06:34 +00:00
|
|
|
static void CONTROL_GetDeviceButtons(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
int32_t const t = ExtGetTime();
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_MouseEnabled)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
DoGetDeviceButtons(
|
|
|
|
MOUSE_GetButtons(), t,
|
|
|
|
CONTROL_NumMouseButtons,
|
|
|
|
CONTROL_MouseButtonState,
|
|
|
|
CONTROL_MouseButtonClickedTime,
|
|
|
|
CONTROL_MouseButtonClickedState,
|
|
|
|
CONTROL_MouseButtonClicked,
|
|
|
|
CONTROL_MouseButtonClickedCount
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_JoystickEnabled)
|
|
|
|
{
|
2019-08-14 05:25:22 +00:00
|
|
|
int retval = DoGetDeviceButtons(
|
2017-07-07 22:50:37 +00:00
|
|
|
JOYSTICK_GetButtons(), t,
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_NumJoyButtons,
|
|
|
|
CONTROL_JoyButtonState,
|
|
|
|
CONTROL_JoyButtonClickedTime,
|
|
|
|
CONTROL_JoyButtonClickedState,
|
|
|
|
CONTROL_JoyButtonClicked,
|
|
|
|
CONTROL_JoyButtonClickedCount
|
|
|
|
);
|
2019-08-14 05:25:22 +00:00
|
|
|
if (retval)
|
|
|
|
CONTROL_LastSeenInput = LastSeenInput::Joystick;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 05:25:22 +00:00
|
|
|
static int CONTROL_DigitizeAxis(int axis, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxistype *set, *lastset;
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
|
|
|
set = CONTROL_JoyAxes;
|
|
|
|
lastset = CONTROL_LastJoyAxes;
|
|
|
|
break;
|
|
|
|
|
2019-08-14 05:25:22 +00:00
|
|
|
default: return 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
|
|
|
|
2019-08-13 09:15:58 +00:00
|
|
|
set[axis].digitalClearedN = lastset[axis].digitalClearedN;
|
|
|
|
set[axis].digitalClearedP = lastset[axis].digitalClearedP;
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (set[axis].analog > 0)
|
|
|
|
{
|
2019-08-13 09:15:58 +00:00
|
|
|
set[axis].digitalClearedN = 0;
|
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
if (set[axis].analog > THRESHOLD || (set[axis].analog > MINTHRESHOLD && lastset[axis].digital == 1))
|
|
|
|
set[axis].digital = 1;
|
2019-08-13 09:15:58 +00:00
|
|
|
else
|
|
|
|
set[axis].digitalClearedP = 0;
|
2019-08-14 05:25:22 +00:00
|
|
|
|
|
|
|
return 1;
|
2008-06-29 10:41:01 +00:00
|
|
|
}
|
2019-08-13 09:15:58 +00:00
|
|
|
else if (set[axis].analog < 0)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2019-08-13 09:15:58 +00:00
|
|
|
set[axis].digitalClearedP = 0;
|
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
if (set[axis].analog < -THRESHOLD || (set[axis].analog < -MINTHRESHOLD && lastset[axis].digital == -1))
|
2006-09-02 02:34:29 +00:00
|
|
|
set[axis].digital = -1;
|
2019-08-13 09:15:58 +00:00
|
|
|
else
|
|
|
|
set[axis].digitalClearedN = 0;
|
2019-08-14 05:25:22 +00:00
|
|
|
|
|
|
|
return 1;
|
2019-08-13 09:15:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set[axis].digitalClearedN = 0;
|
|
|
|
set[axis].digitalClearedP = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2019-08-14 05:25:22 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
static void CONTROL_ScaleAxis(int axis, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxistype *set;
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t *scale;
|
2019-08-14 03:03:57 +00:00
|
|
|
int8_t * invert;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
|
|
|
set = CONTROL_JoyAxes;
|
|
|
|
scale = CONTROL_JoyAxesScale;
|
2019-08-14 03:03:57 +00:00
|
|
|
invert = CONTROL_JoyAxesInvert;
|
2006-09-02 02:34:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-08-14 03:03:57 +00:00
|
|
|
int const invertResult = !!invert[axis];
|
|
|
|
set[axis].analog = (mulscale16(set[axis].analog, scale[axis]) ^ -invertResult) + invertResult;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
static void CONTROL_ApplyAxis(int axis, ControlInfo *info, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxistype *set;
|
|
|
|
controlaxismaptype *map;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
|
|
|
set = CONTROL_JoyAxes;
|
|
|
|
map = CONTROL_JoyAxesMap;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (map[axis].analogmap)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case analog_turning: info->dyaw += set[axis].analog; break;
|
|
|
|
case analog_strafing: info->dx += set[axis].analog; break;
|
|
|
|
case analog_lookingupanddown: info->dpitch += set[axis].analog; break;
|
|
|
|
case analog_elevation: info->dy += set[axis].analog; break;
|
|
|
|
case analog_rolling: info->droll += set[axis].analog; break;
|
|
|
|
case analog_moving: info->dz += set[axis].analog; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 21:24:54 +00:00
|
|
|
static void CONTROL_PollDevices(ControlInfo *info)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
memset(info, 0, sizeof(ControlInfo));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-03-22 09:25:51 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
CONTROL_Android_PollDevices(info);
|
|
|
|
#endif
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_MouseEnabled)
|
2019-08-11 20:52:50 +00:00
|
|
|
CONTROL_GetMouseDelta(info);
|
2008-08-24 04:55:57 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_JoystickEnabled)
|
|
|
|
{
|
2012-11-17 16:48:11 +00:00
|
|
|
Bmemcpy(CONTROL_LastJoyAxes, CONTROL_JoyAxes, sizeof(CONTROL_JoyAxes));
|
|
|
|
memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes));
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
for (int i=joystick.numAxes-1; i>=0; i--)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
CONTROL_JoyAxes[i].analog = joystick.pAxis[i];
|
2012-11-17 16:47:53 +00:00
|
|
|
|
2019-08-14 05:25:22 +00:00
|
|
|
if (CONTROL_DigitizeAxis(i, controldevice_joystick))
|
|
|
|
CONTROL_LastSeenInput = LastSeenInput::Joystick;
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_ScaleAxis(i, controldevice_joystick);
|
|
|
|
LIMITCONTROL(&CONTROL_JoyAxes[i].analog);
|
|
|
|
CONTROL_ApplyAxis(i, info, controldevice_joystick);
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CONTROL_GetDeviceButtons();
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 05:25:22 +00:00
|
|
|
static int CONTROL_HandleAxisFunction(int32_t *p1, controlaxistype *axes, controlaxismaptype *axismap, int numAxes)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
int axis = numAxes - 1;
|
2019-08-14 05:25:22 +00:00
|
|
|
int retval = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!axes[axis].digital)
|
|
|
|
continue;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
int const j = (axes[axis].digital < 0) ? axismap[axis].minmap : axismap[axis].maxmap;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
if (j != AXISUNDEFINED)
|
2019-08-14 05:25:22 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
p1[j] = 1;
|
2019-08-14 05:25:22 +00:00
|
|
|
retval = 1;
|
|
|
|
}
|
2008-08-24 06:06:04 +00:00
|
|
|
}
|
2018-11-18 18:08:53 +00:00
|
|
|
while (axis--);
|
2019-08-14 05:25:22 +00:00
|
|
|
|
|
|
|
return retval;
|
2018-11-18 18:08:53 +00:00
|
|
|
}
|
2008-08-24 04:55:57 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
static void CONTROL_AxisFunctionState(int32_t *p1)
|
|
|
|
{
|
|
|
|
if (CONTROL_NumJoyAxes)
|
2019-08-14 05:25:22 +00:00
|
|
|
{
|
|
|
|
if (CONTROL_HandleAxisFunction(p1, CONTROL_JoyAxes, CONTROL_JoyAxesMap, CONTROL_NumJoyAxes))
|
|
|
|
CONTROL_LastSeenInput = LastSeenInput::Joystick;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-06 23:06:34 +00:00
|
|
|
static void CONTROL_ButtonFunctionState(int32_t *p1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-08-24 09:01:17 +00:00
|
|
|
if (CONTROL_NumMouseButtons)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
int i = CONTROL_NumMouseButtons-1, j;
|
2008-08-24 09:01:17 +00:00
|
|
|
|
|
|
|
do
|
2008-06-30 19:06:05 +00:00
|
|
|
{
|
2017-07-05 05:42:54 +00:00
|
|
|
if (!CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr)
|
2008-08-24 09:01:17 +00:00
|
|
|
{
|
|
|
|
j = CONTROL_MouseButtonMapping[i].doubleclicked;
|
|
|
|
if (j != KEYUNDEFINED)
|
|
|
|
p1[j] |= CONTROL_MouseButtonClickedState[i];
|
2008-06-30 19:06:05 +00:00
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
j = CONTROL_MouseButtonMapping[i].singleclicked;
|
|
|
|
if (j != KEYUNDEFINED)
|
|
|
|
p1[j] |= CONTROL_MouseButtonState[i];
|
|
|
|
}
|
2008-08-24 06:17:09 +00:00
|
|
|
|
2012-11-17 16:47:47 +00:00
|
|
|
if (!CONTROL_BindsEnabled)
|
2008-08-24 09:01:17 +00:00
|
|
|
continue;
|
2008-08-24 06:17:09 +00:00
|
|
|
|
2017-07-05 05:42:54 +00:00
|
|
|
if (CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr && CONTROL_MouseButtonState[i])
|
2008-08-24 09:01:17 +00:00
|
|
|
{
|
2017-07-05 05:42:54 +00:00
|
|
|
if (CONTROL_KeyBinds[MAXBOUNDKEYS + i].repeat || (CONTROL_KeyBinds[MAXBOUNDKEYS + i].laststate == 0))
|
|
|
|
OSD_Dispatch(CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr);
|
2008-08-24 09:01:17 +00:00
|
|
|
}
|
2017-07-05 05:42:54 +00:00
|
|
|
CONTROL_KeyBinds[MAXBOUNDKEYS + i].laststate = CONTROL_MouseButtonState[i];
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2008-08-24 23:24:14 +00:00
|
|
|
while (i--);
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
if (CONTROL_NumJoyButtons)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
int i=CONTROL_NumJoyButtons-1, j;
|
2019-08-14 05:25:22 +00:00
|
|
|
int retval = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
j = CONTROL_JoyButtonMapping[i].doubleclicked;
|
|
|
|
if (j != KEYUNDEFINED)
|
2019-08-14 05:25:22 +00:00
|
|
|
{
|
|
|
|
auto const state = CONTROL_JoyButtonClickedState[i];
|
|
|
|
p1[j] |= state;
|
|
|
|
retval |= state;
|
|
|
|
}
|
2008-08-24 09:01:17 +00:00
|
|
|
|
|
|
|
j = CONTROL_JoyButtonMapping[i].singleclicked;
|
|
|
|
if (j != KEYUNDEFINED)
|
2019-08-14 05:25:22 +00:00
|
|
|
{
|
|
|
|
auto const state = CONTROL_JoyButtonState[i];
|
|
|
|
p1[j] |= state;
|
|
|
|
retval |= state;
|
|
|
|
}
|
2008-08-24 09:01:17 +00:00
|
|
|
}
|
2008-08-24 23:24:14 +00:00
|
|
|
while (i--);
|
2019-08-14 05:25:22 +00:00
|
|
|
|
|
|
|
if (retval)
|
|
|
|
CONTROL_LastSeenInput = LastSeenInput::Joystick;
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
void CONTROL_ClearButton(int whichbutton)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2016-02-13 21:06:28 +00:00
|
|
|
if (CONTROL_CheckRange(whichbutton)) return;
|
2014-04-15 19:02:48 +00:00
|
|
|
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
CONTROL_Android_ClearButton(whichbutton);
|
2016-02-13 21:06:28 +00:00
|
|
|
#endif
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
BUTTONCLEAR(whichbutton);
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Flags[whichbutton].cleared = TRUE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 20:06:27 +00:00
|
|
|
void CONTROL_ClearAllButtons(void)
|
|
|
|
{
|
|
|
|
CONTROL_ButtonHeldState = 0;
|
|
|
|
CONTROL_ButtonState = 0;
|
|
|
|
|
|
|
|
for (auto & c : CONTROL_Flags)
|
|
|
|
c.cleared = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-08-13 09:15:58 +00:00
|
|
|
int32_t CONTROL_GetGameControllerDigitalAxisPos(int32_t axis)
|
|
|
|
{
|
|
|
|
if (!joystick.isGameController)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CONTROL_JoyAxes[axis].digital > 0 && !CONTROL_JoyAxes[axis].digitalClearedP;
|
|
|
|
}
|
|
|
|
int32_t CONTROL_GetGameControllerDigitalAxisNeg(int32_t axis)
|
|
|
|
{
|
|
|
|
if (!joystick.isGameController)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CONTROL_JoyAxes[axis].digital < 0 && !CONTROL_JoyAxes[axis].digitalClearedN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_ClearGameControllerDigitalAxisPos(int32_t axis)
|
|
|
|
{
|
|
|
|
if (!joystick.isGameController)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CONTROL_JoyAxes[axis].digitalClearedP = 1;
|
|
|
|
}
|
|
|
|
void CONTROL_ClearGameControllerDigitalAxisNeg(int32_t axis)
|
|
|
|
{
|
|
|
|
if (!joystick.isGameController)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CONTROL_JoyAxes[axis].digitalClearedN = 1;
|
|
|
|
}
|
|
|
|
|
2010-05-07 20:45:40 +00:00
|
|
|
void CONTROL_ProcessBinds(void)
|
2008-06-29 10:40:37 +00:00
|
|
|
{
|
2012-11-17 16:47:47 +00:00
|
|
|
if (!CONTROL_BindsEnabled)
|
2009-06-09 06:19:58 +00:00
|
|
|
return;
|
2008-08-24 09:01:17 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
int i = MAXBOUNDKEYS-1;
|
|
|
|
|
2010-05-07 20:45:40 +00:00
|
|
|
do
|
2008-06-29 10:40:37 +00:00
|
|
|
{
|
2012-11-17 16:47:58 +00:00
|
|
|
if (CONTROL_KeyBinds[i].cmdstr)
|
2008-06-29 10:40:37 +00:00
|
|
|
{
|
2019-08-14 05:25:22 +00:00
|
|
|
auto const keyPressed = KB_KeyPressed(i);
|
|
|
|
|
|
|
|
if (keyPressed && (CONTROL_KeyBinds[i].repeat || (CONTROL_KeyBinds[i].laststate == 0)))
|
|
|
|
{
|
|
|
|
CONTROL_LastSeenInput = LastSeenInput::Keyboard;
|
2012-11-17 16:47:58 +00:00
|
|
|
OSD_Dispatch(CONTROL_KeyBinds[i].cmdstr);
|
2019-08-14 05:25:22 +00:00
|
|
|
}
|
2012-11-06 23:06:44 +00:00
|
|
|
|
2019-08-14 05:25:22 +00:00
|
|
|
CONTROL_KeyBinds[i].laststate = keyPressed;
|
2008-06-29 10:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-07 20:45:40 +00:00
|
|
|
while (i--);
|
2008-06-29 10:40:37 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 21:24:54 +00:00
|
|
|
static void CONTROL_GetFunctionInput(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
CONTROL_ButtonFunctionState(CONTROL_ButtonFlags);
|
|
|
|
CONTROL_AxisFunctionState(CONTROL_ButtonFlags);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
CONTROL_ButtonHeldState = CONTROL_ButtonState;
|
|
|
|
CONTROL_ButtonState = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
int i = CONTROL_NUM_FLAGS-1;
|
|
|
|
|
2010-05-07 20:45:40 +00:00
|
|
|
do
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
CONTROL_SetFlag(i, /*CONTROL_KeyboardFunctionPressed(i) | */CONTROL_ButtonFlags[i]);
|
2008-08-24 04:55:57 +00:00
|
|
|
|
2010-05-07 20:45:40 +00:00
|
|
|
if (CONTROL_Flags[i].cleared == FALSE) BUTTONSET(i, CONTROL_Flags[i].active);
|
|
|
|
else if (CONTROL_Flags[i].active == FALSE) CONTROL_Flags[i].cleared = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2010-05-07 20:45:40 +00:00
|
|
|
while (i--);
|
2008-08-24 04:55:57 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
memset(CONTROL_ButtonFlags, 0, sizeof(CONTROL_ButtonFlags));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-06-03 16:11:22 +00:00
|
|
|
void CONTROL_GetInput(ControlInfo *info)
|
|
|
|
{
|
2014-04-15 19:02:48 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
CONTROL_Android_PollDevices(info);
|
2018-11-18 18:08:53 +00:00
|
|
|
#endif
|
2012-06-03 16:11:22 +00:00
|
|
|
CONTROL_PollDevices(info);
|
|
|
|
CONTROL_GetFunctionInput();
|
2013-12-20 07:24:09 +00:00
|
|
|
inputchecked = 1;
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 03:03:52 +00:00
|
|
|
static void CONTROL_ResetJoystickValues()
|
|
|
|
{
|
|
|
|
CONTROL_NumJoyAxes = min(MAXJOYAXES, joystick.numAxes);
|
|
|
|
CONTROL_NumJoyButtons = min(MAXJOYBUTTONS, joystick.numButtons + 4 * (joystick.numHats > 0));
|
|
|
|
CONTROL_JoystickEnabled = CONTROL_JoyPresent = !!((inputdevices & 4) >> 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_ScanForControllers()
|
|
|
|
{
|
|
|
|
joyScanDevices();
|
|
|
|
CONTROL_ResetJoystickValues();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-03-22 10:23:57 +00:00
|
|
|
UNREFERENCED_PARAMETER(which);
|
2008-03-21 04:01:38 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
if (CONTROL_Started) return false;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
ExtGetTime = TimeFunction ? TimeFunction : CONTROL_GetTime;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
// what the fuck???
|
|
|
|
CONTROL_DoubleClickSpeed = (ticspersecond * 57) / 100;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
|
|
|
if (CONTROL_DoubleClickSpeed <= 0)
|
|
|
|
CONTROL_DoubleClickSpeed = 1;
|
|
|
|
|
2019-08-14 15:28:59 +00:00
|
|
|
if (initinput())
|
2018-11-18 18:08:53 +00:00
|
|
|
return true;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
|
|
|
KB_Startup();
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
CONTROL_NumMouseButtons = MAXMOUSEBUTTONS;
|
|
|
|
CONTROL_MousePresent = Mouse_Init();
|
|
|
|
CONTROL_MouseEnabled = CONTROL_MousePresent;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2019-08-14 03:03:52 +00:00
|
|
|
CONTROL_ResetJoystickValues();
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2012-05-01 12:38:43 +00:00
|
|
|
#ifdef GEKKO
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_MousePresent)
|
|
|
|
initprintf("CONTROL_Startup: Mouse Present\n");
|
2018-11-18 18:08:53 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_JoyPresent)
|
|
|
|
initprintf("CONTROL_Startup: Joystick Present\n");
|
2012-02-11 11:52:33 +00:00
|
|
|
#endif
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
CONTROL_ButtonState = 0;
|
|
|
|
CONTROL_ButtonHeldState = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
for (auto & CONTROL_Flag : CONTROL_Flags)
|
|
|
|
CONTROL_Flag.used = FALSE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Started = TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
return false;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_Shutdown(void)
|
|
|
|
{
|
2012-11-18 15:44:18 +00:00
|
|
|
if (!CONTROL_Started)
|
|
|
|
return;
|
2012-11-17 16:47:58 +00:00
|
|
|
|
2012-11-18 15:44:18 +00:00
|
|
|
CONTROL_ClearAllBinds();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
MOUSE_Shutdown();
|
|
|
|
uninitinput();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Started = FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|