More control/input cleanup

git-svn-id: https://svn.eduke32.com/eduke32@7181 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-11-18 18:08:53 +00:00
parent a4182305d0
commit 5164ab4a25
11 changed files with 143 additions and 210 deletions

View file

@ -234,12 +234,12 @@ static FORCE_INLINE void keyBufferInsert(char code)
void keyFlushChars(void); void keyFlushChars(void);
int32_t mouseInit(void); void mouseInit(void);
void mouseUninit(void); void mouseUninit(void);
int32_t mouseReadAbs(vec2_t *pResult, vec2_t const *pInput); int32_t mouseReadAbs(vec2_t *pResult, vec2_t const *pInput);
void mouseGrabInput(bool grab); void mouseGrabInput(bool grab);
void mouseLockToWindow(char a); void mouseLockToWindow(char a);
void mouseReadButtons(int32_t *pResult); int32_t mouseReadButtons(void);
void mouseReadPos(int32_t *x, int32_t *y); void mouseReadPos(int32_t *x, int32_t *y);
void joyReadButtons(int32_t *pResult); void joyReadButtons(int32_t *pResult);

View file

@ -121,9 +121,9 @@ int32_t mouseReadAbs(vec2_t * const pResult, vec2_t const * const pInput)
return 1; return 1;
} }
void mouseReadButtons(int32_t *pResult) int32_t mouseReadButtons(void)
{ {
*pResult = (!g_mouseEnabled || !appactive || !g_mouseInsideWindow || (osd && osd->flags & OSD_CAPTURE)) ? 0 : g_mouseBits; return (!g_mouseEnabled || !appactive || !g_mouseInsideWindow || (osd && osd->flags & OSD_CAPTURE)) ? 0 : g_mouseBits;
} }
controllerinput_t joystick; controllerinput_t joystick;

View file

@ -11531,7 +11531,7 @@ void rotatepoint(vec2_t const pivot, vec2_t p, int16_t daang, vec2_t *p2)
void mouseGetValues(int32_t *mousx, int32_t *mousy, int32_t *bstatus) void mouseGetValues(int32_t *mousx, int32_t *mousy, int32_t *bstatus)
{ {
mouseReadPos(mousx, mousy); mouseReadPos(mousx, mousy);
mouseReadButtons(bstatus); *bstatus = mouseReadButtons();
} }

View file

@ -279,11 +279,10 @@ void RI_PollDevices(BOOL loop)
} }
} }
int32_t mouseInit(void) void mouseInit(void)
{ {
if (g_mouseEnabled) return 0; if (!g_mouseEnabled)
mouseGrabInput(g_mouseEnabled = g_mouseLockedToWindow); mouseGrabInput(g_mouseEnabled = g_mouseLockedToWindow);
return 0;
} }
void mouseUninit(void) void mouseUninit(void)

View file

@ -898,11 +898,9 @@ const char *joyGetName(int32_t what, int32_t num)
// //
// initmouse() -- init mouse input // initmouse() -- init mouse input
// //
int32_t mouseInit(void) void mouseInit(void)
{ {
g_mouseEnabled=g_mouseLockedToWindow; mouseGrabInput(g_mouseEnabled = g_mouseLockedToWindow); // FIXME - SA
mouseGrabInput(g_mouseLockedToWindow); // FIXME - SA
return 0;
} }
// //

View file

@ -10899,7 +10899,7 @@ void ExtCheckKeys(void)
} }
lastbstatus = bstatus; lastbstatus = bstatus;
mouseReadButtons(&bstatus); bstatus = mouseReadButtons();
Keys2d3d(); Keys2d3d();

View file

@ -140,10 +140,8 @@ void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN])
void CONFIG_SetDefaults(void) void CONFIG_SetDefaults(void)
{ {
// JBF 20031211
int32_t i;
ud.config.scripthandle = -1; ud.config.scripthandle = -1;
#ifdef __ANDROID__ #ifdef __ANDROID__
droidinput.forward_sens = 5.f; droidinput.forward_sens = 5.f;
droidinput.gameControlsAlpha = 0.5; droidinput.gameControlsAlpha = 0.5;
@ -194,15 +192,9 @@ void CONFIG_SetDefaults(void)
#if defined GEKKO || defined __OPENDINGUX__ #if defined GEKKO || defined __OPENDINGUX__
ud.config.NumVoices = 32; ud.config.NumVoices = 32;
ud.camera_time = 11;
#else #else
ud.config.NumVoices = 64; ud.config.NumVoices = 64;
#endif
#if defined GEKKO || defined __OPENDINGUX__
ud.camera_time = 11;
#elif defined(__ANDROID__)
ud.camera_time = 7;
#else
ud.camera_time = 4; ud.camera_time = 4;
#endif #endif
@ -316,7 +308,7 @@ void CONFIG_SetDefaults(void)
CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY; CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
for (i=0; i<MAXMOUSEBUTTONS; i++) for (int i=0; i<MAXMOUSEBUTTONS; i++)
{ {
ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]); ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse); CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
@ -325,7 +317,7 @@ void CONFIG_SetDefaults(void)
CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse); CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
} }
for (i=0; i<MAXMOUSEAXES; i++) for (int i=0; i<MAXMOUSEAXES; i++)
{ {
ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE; ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE;
CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse); CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
@ -339,7 +331,7 @@ void CONFIG_SetDefaults(void)
CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse); CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
} }
for (i=0; i<MAXJOYBUTTONSANDHATS; i++) for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
{ {
ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]); ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]); ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
@ -347,7 +339,7 @@ void CONFIG_SetDefaults(void)
CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick); CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
} }
for (i=0; i<MAXJOYAXES; i++) for (int i=0; i<MAXJOYAXES; i++)
{ {
ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE; ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD; ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;

View file

@ -866,9 +866,14 @@ static int osdcmd_name(osdcmdptr_t parm)
static int osdcmd_button(osdcmdptr_t parm) static int osdcmd_button(osdcmdptr_t parm)
{ {
char const *p = parm->name+9; // skip "gamefunc_" static char const s_gamefunc_[] = "gamefunc_";
int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1;
char const *p = parm->name + strlen_gamefunc_;
// if (g_player[myconnectindex].ps->gm == MODE_GAME) // only trigger these if in game // if (g_player[myconnectindex].ps->gm == MODE_GAME) // only trigger these if in game
CONTROL_OSDInput[CONFIG_FunctionNameToNum(p)] = 1; // FIXME CONTROL_ButtonFlags[CONFIG_FunctionNameToNum(p)] = 1; // FIXME
return OSDCMD_OK; return OSDCMD_OK;
} }

View file

@ -51,12 +51,9 @@ extern "C" {
#define BUTTON(x) ((CONTROL_ButtonState >> ((uint64_t)(x))) & 1) #define BUTTON(x) ((CONTROL_ButtonState >> ((uint64_t)(x))) & 1)
#define BUTTONHELD(x) ((CONTROL_ButtonHeldState >> ((uint64_t)(x))) & 1) #define BUTTONHELD(x) ((CONTROL_ButtonHeldState >> ((uint64_t)(x))) & 1)
#define BUTTONJUSTPRESSED(x) \ #define BUTTONJUSTPRESSED(x) (BUTTON(x) && !BUTTONHELD(x))
( BUTTON( x ) && !BUTTONHELD( x ) ) #define BUTTONRELEASED(x) (!BUTTON(x) && BUTTONHELD(x))
#define BUTTONRELEASED(x) \ #define BUTTONSTATECHANGED(x) (BUTTON(x) != BUTTONHELD(x))
( !BUTTON( x ) && BUTTONHELD( x ) )
#define BUTTONSTATECHANGED(x) \
( BUTTON( x ) != BUTTONHELD( x ) )
//*************************************************************************** //***************************************************************************
@ -134,11 +131,12 @@ typedef enum
// //
//*************************************************************************** //***************************************************************************
extern int32_t CONTROL_Started; extern bool CONTROL_Started;
extern int32_t CONTROL_MousePresent; extern bool CONTROL_MousePresent;
extern int32_t CONTROL_JoyPresent; extern bool CONTROL_JoyPresent;
extern int32_t CONTROL_MouseEnabled; extern bool CONTROL_MouseEnabled;
extern int32_t CONTROL_JoystickEnabled; extern bool CONTROL_JoystickEnabled;
extern uint64_t CONTROL_ButtonState; extern uint64_t CONTROL_ButtonState;
extern uint64_t CONTROL_ButtonHeldState; extern uint64_t CONTROL_ButtonHeldState;
@ -156,14 +154,11 @@ int CONTROL_FlagActive( int which );
void CONTROL_ClearAssignments( void ); void CONTROL_ClearAssignments( void );
// void CONTROL_GetFunctionInput( void ); // void CONTROL_GetFunctionInput( void );
void CONTROL_GetInput( ControlInfo *info ); void CONTROL_GetInput( ControlInfo *info );
void CONTROL_ClearButton( int32_t whichbutton ); void CONTROL_ClearButton( int whichbutton );
extern float CONTROL_MouseSensitivity; extern float CONTROL_MouseSensitivity;
int32_t CONTROL_Startup(controltype which, int32_t ( *TimeFunction )( void ), int32_t ticspersecond); bool CONTROL_Startup(controltype which, int32_t ( *TimeFunction )( void ), int32_t ticspersecond);
void CONTROL_Shutdown( void ); void CONTROL_Shutdown( void );
void CONTROL_SetDoubleClickDelay(int32_t delay);
int32_t CONTROL_GetDoubleClickDelay(void);
void CONTROL_MapAnalogAxis(int whichaxis, int whichanalog, controldevice device); void CONTROL_MapAnalogAxis(int whichaxis, int whichanalog, controldevice device);
void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t direction, controldevice device); 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); void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldevice device);
@ -178,16 +173,18 @@ void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldev
#define MAXBOUNDKEYS MAXKEYBOARDSCAN #define MAXBOUNDKEYS MAXKEYBOARDSCAN
#define MAXMOUSEBUTTONS 10 #define MAXMOUSEBUTTONS 10
typedef struct binding { typedef struct
const char *key; // always set to const char * {
char *cmdstr; // alloc'd const char *key;
char *cmdstr;
char repeat; char repeat;
char laststate; char laststate;
} keybind; }
consolekeybind_t;
// Direct use DEPRECATED: // Direct use DEPRECATED:
extern keybind CONTROL_KeyBinds[MAXBOUNDKEYS+MAXMOUSEBUTTONS]; extern consolekeybind_t CONTROL_KeyBinds[MAXBOUNDKEYS+MAXMOUSEBUTTONS];
extern int32_t CONTROL_BindsEnabled; extern bool CONTROL_BindsEnabled;
void CONTROL_ClearAllBinds(void); void CONTROL_ClearAllBinds(void);
void CONTROL_BindKey(int i, char const * cmd, int repeat, char const * keyname); void CONTROL_BindKey(int i, char const * cmd, int repeat, char const * keyname);
@ -195,9 +192,10 @@ void CONTROL_BindMouse(int i, char const * cmd, int repeat, char const * keyname
void CONTROL_FreeKeyBind(int i); void CONTROL_FreeKeyBind(int i);
void CONTROL_FreeMouseBind(int i); void CONTROL_FreeMouseBind(int i);
static inline int32_t CONTROL_KeyIsBound(int32_t i) static inline int CONTROL_KeyIsBound(int const key)
{ {
return (CONTROL_KeyBinds[i].cmdstr && CONTROL_KeyBinds[i].key); auto &bind = CONTROL_KeyBinds[key];
return bind.cmdstr && bind.key;
} }
void CONTROL_ProcessBinds(void); void CONTROL_ProcessBinds(void);
@ -205,8 +203,8 @@ void CONTROL_ProcessBinds(void);
//////////////////// ////////////////////
#define CONTROL_NUM_FLAGS 64 #define CONTROL_NUM_FLAGS 64
extern int32_t CONTROL_OSDInput[CONTROL_NUM_FLAGS]; extern int32_t CONTROL_ButtonFlags[CONTROL_NUM_FLAGS];
extern int32_t CONTROL_SmoothMouse; extern bool CONTROL_SmoothMouse;
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -46,29 +46,16 @@ extern "C" {
#include "baselayer.h" #include "baselayer.h"
static inline int32_t Mouse_Init(void) static inline bool Mouse_Init(void)
{ {
mouseInit(); mouseInit();
return ((inputdevices & 2) == 2); return ((inputdevices & 2) == 2);
} }
static inline void MOUSE_Shutdown(void) { mouseUninit(); } static inline void MOUSE_Shutdown(void) { mouseUninit(); }
static inline int32_t MOUSE_GetButtons(void) { return mouseReadButtons(); }
#if 0 static inline void MOUSE_ClearButton(int32_t b) { g_mouseBits &= ~b; }
static inline void MOUSE_ShowCursor(void) {} static inline void MOUSE_ClearAllButtons(void) { g_mouseBits = 0; }
static inline void MOUSE_HideCursor(void) {}
#endif
static inline int32_t MOUSE_GetButtons(void)
{
int32_t buttons;
mouseReadButtons(&buttons);
return buttons;
}
#define MOUSE_ClearButton(b) (g_mouseBits &= ~b)
#define MOUSE_ClearAllButtons() g_mouseBits = 0
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -22,10 +22,12 @@
#include "android.h" #include "android.h"
#endif #endif
int32_t CONTROL_JoyPresent = FALSE; bool CONTROL_Started = false;
int32_t CONTROL_JoystickEnabled = FALSE; bool CONTROL_JoyPresent = false;
int32_t CONTROL_MousePresent = FALSE; bool CONTROL_JoystickEnabled = false;
int32_t CONTROL_MouseEnabled = FALSE; bool CONTROL_MousePresent = false;
bool CONTROL_MouseEnabled = false;
uint64_t CONTROL_ButtonState = 0; uint64_t CONTROL_ButtonState = 0;
uint64_t CONTROL_ButtonHeldState = 0; uint64_t CONTROL_ButtonHeldState = 0;
@ -52,7 +54,6 @@ static controlaxistype CONTROL_LastJoyAxes[MAXJOYAXES];
static int32_t CONTROL_MouseAxesScale[MAXMOUSEAXES]; static int32_t CONTROL_MouseAxesScale[MAXMOUSEAXES];
static int32_t CONTROL_JoyAxesScale[MAXJOYAXES]; static int32_t CONTROL_JoyAxesScale[MAXJOYAXES];
#ifndef __ANDROID__
static int32_t CONTROL_MouseButtonState[MAXMOUSEBUTTONS]; static int32_t CONTROL_MouseButtonState[MAXMOUSEBUTTONS];
static int32_t CONTROL_MouseButtonClickedTime[MAXMOUSEBUTTONS]; static int32_t CONTROL_MouseButtonClickedTime[MAXMOUSEBUTTONS];
static int32_t CONTROL_MouseButtonClickedState[MAXMOUSEBUTTONS]; static int32_t CONTROL_MouseButtonClickedState[MAXMOUSEBUTTONS];
@ -64,27 +65,24 @@ static int32_t CONTROL_JoyButtonClickedTime[MAXJOYBUTTONS];
static int32_t CONTROL_JoyButtonClickedState[MAXJOYBUTTONS]; static int32_t CONTROL_JoyButtonClickedState[MAXJOYBUTTONS];
static int32_t CONTROL_JoyButtonClicked[MAXJOYBUTTONS]; static int32_t CONTROL_JoyButtonClicked[MAXJOYBUTTONS];
static uint8_t CONTROL_JoyButtonClickedCount[MAXJOYBUTTONS]; static uint8_t CONTROL_JoyButtonClickedCount[MAXJOYBUTTONS];
#endif
static int32_t(*ExtGetTime)(void); static int32_t(*ExtGetTime)(void);
int32_t CONTROL_Started = FALSE;
//static int32_t ticrate; //static int32_t ticrate;
static int32_t CONTROL_DoubleClickSpeed; static uint8_t CONTROL_DoubleClickSpeed;
int32_t CONTROL_OSDInput[CONTROL_NUM_FLAGS]; int32_t CONTROL_ButtonFlags[CONTROL_NUM_FLAGS];
keybind CONTROL_KeyBinds[MAXBOUNDKEYS + MAXMOUSEBUTTONS]; consolekeybind_t CONTROL_KeyBinds[MAXBOUNDKEYS + MAXMOUSEBUTTONS];
int32_t CONTROL_BindsEnabled = 0; bool CONTROL_BindsEnabled = 0;
int32_t CONTROL_SmoothMouse = 0; bool CONTROL_SmoothMouse = 0;
#define CONTROL_CheckRange(which) ((unsigned)which >= (unsigned)CONTROL_NUM_FLAGS) #define CONTROL_CheckRange(which) ((unsigned)which >= (unsigned)CONTROL_NUM_FLAGS)
#define BIND(x, s, r, k) do { Bfree(x.cmdstr); x.cmdstr = s; x.repeat = r; x.key = k; } while (0) #define BIND(x, s, r, k) do { Bfree(x.cmdstr); x.cmdstr = s; x.repeat = r; x.key = k; } while (0)
void CONTROL_ClearAllBinds(void) void CONTROL_ClearAllBinds(void)
{ {
int32_t i; for (int i=0; i<MAXBOUNDKEYS; i++)
for (i=0; i<MAXBOUNDKEYS; i++)
CONTROL_FreeKeyBind(i); CONTROL_FreeKeyBind(i);
for (i=0; i<MAXMOUSEBUTTONS; i++) for (int i=0; i<MAXMOUSEBUTTONS; i++)
CONTROL_FreeMouseBind(i); CONTROL_FreeMouseBind(i);
} }
@ -108,7 +106,6 @@ void CONTROL_FreeMouseBind(int i)
BIND(CONTROL_KeyBinds[MAXBOUNDKEYS + i], NULL, 0, NULL); BIND(CONTROL_KeyBinds[MAXBOUNDKEYS + i], NULL, 0, NULL);
} }
#ifndef __ANDROID__
static void CONTROL_GetMouseDelta(void) static void CONTROL_GetMouseDelta(void)
{ {
vec2_t input; vec2_t input;
@ -126,7 +123,6 @@ static void CONTROL_GetMouseDelta(void)
CONTROL_MouseAxes[0].analog = Blrintf(finput.x * 4.f * CONTROL_MouseSensitivity); CONTROL_MouseAxes[0].analog = Blrintf(finput.x * 4.f * CONTROL_MouseSensitivity);
CONTROL_MouseAxes[1].analog = Blrintf(finput.y * 8.f * CONTROL_MouseSensitivity); CONTROL_MouseAxes[1].analog = Blrintf(finput.y * 8.f * CONTROL_MouseSensitivity);
} }
#endif
static int32_t CONTROL_GetTime(void) static int32_t CONTROL_GetTime(void)
{ {
@ -135,8 +131,7 @@ static int32_t CONTROL_GetTime(void)
return t; return t;
} }
#ifndef __ANDROID__ static void CONTROL_SetFlag(int which, int active)
static void CONTROL_SetFlag(int32_t which, int32_t active)
{ {
if (CONTROL_CheckRange(which)) return; if (CONTROL_CheckRange(which)) return;
@ -152,7 +147,6 @@ static void CONTROL_SetFlag(int32_t which, int32_t active)
flags.active = (flags.active ? FALSE : TRUE); flags.active = (flags.active ? FALSE : TRUE);
} }
} }
#endif
#if 0 #if 0
int32_t CONTROL_KeyboardFunctionPressed(int32_t which) int32_t CONTROL_KeyboardFunctionPressed(int32_t which)
@ -193,10 +187,10 @@ void CONTROL_DefineFlag(int which, int toggle)
controlflags &flags = CONTROL_Flags[which]; controlflags &flags = CONTROL_Flags[which];
flags.active = FALSE; flags.active = FALSE;
flags.used = TRUE;
flags.toggle = toggle;
flags.buttonheld = FALSE; flags.buttonheld = FALSE;
flags.cleared = 0; flags.cleared = 0;
flags.toggle = toggle;
flags.used = TRUE;
} }
int CONTROL_FlagActive(int which) int CONTROL_FlagActive(int which)
@ -426,24 +420,23 @@ void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t di
void CONTROL_ClearAssignments(void) void CONTROL_ClearAssignments(void)
{ {
int32_t i; memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes));
memset(CONTROL_JoyAxesMap, AXISUNDEFINED, sizeof(CONTROL_JoyAxesMap));
memset(CONTROL_MouseButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_MouseButtonMapping));
memset(CONTROL_JoyButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_JoyButtonMapping)); memset(CONTROL_JoyButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_JoyButtonMapping));
// memset(CONTROL_KeyMapping, KEYUNDEFINED, sizeof(CONTROL_KeyMapping)); // memset(CONTROL_KeyMapping, KEYUNDEFINED, sizeof(CONTROL_KeyMapping));
memset(CONTROL_MouseAxesMap, AXISUNDEFINED, sizeof(CONTROL_MouseAxesMap));
memset(CONTROL_JoyAxesMap, AXISUNDEFINED, sizeof(CONTROL_JoyAxesMap));
memset(CONTROL_MouseAxes, 0, sizeof(CONTROL_MouseAxes));
memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes));
memset(CONTROL_LastMouseAxes, 0, sizeof(CONTROL_LastMouseAxes));
memset(CONTROL_LastJoyAxes, 0, sizeof(CONTROL_LastJoyAxes)); memset(CONTROL_LastJoyAxes, 0, sizeof(CONTROL_LastJoyAxes));
for (i=0; i<MAXMOUSEAXES; i++) memset(CONTROL_LastMouseAxes, 0, sizeof(CONTROL_LastMouseAxes));
CONTROL_MouseAxesScale[i] = NORMALAXISSCALE; memset(CONTROL_MouseAxes, 0, sizeof(CONTROL_MouseAxes));
for (i=0; i<MAXJOYAXES; i++) memset(CONTROL_MouseAxesMap, AXISUNDEFINED, sizeof(CONTROL_MouseAxesMap));
CONTROL_JoyAxesScale[i] = NORMALAXISSCALE; memset(CONTROL_MouseButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_MouseButtonMapping));
for (int & i : CONTROL_MouseAxesScale)
i = NORMALAXISSCALE;
for (int & i : CONTROL_JoyAxesScale)
i = NORMALAXISSCALE;
} }
#ifndef __ANDROID__
static void DoGetDeviceButtons( static void DoGetDeviceButtons(
int32_t buttons, int32_t tm, int32_t buttons, int32_t tm,
int32_t NumButtons, int32_t NumButtons,
@ -458,7 +451,7 @@ static void DoGetDeviceButtons(
for (; i>=0; i--) for (; i>=0; i--)
{ {
int32_t bs = (buttons >> i) & 1; int const bs = (buttons >> i) & 1;
DeviceButtonState[i] = bs; DeviceButtonState[i] = bs;
ButtonClickedState[i] = FALSE; ButtonClickedState[i] = FALSE;
@ -498,7 +491,7 @@ static void DoGetDeviceButtons(
static void CONTROL_GetDeviceButtons(void) static void CONTROL_GetDeviceButtons(void)
{ {
int32_t t = ExtGetTime(); int32_t const t = ExtGetTime();
if (CONTROL_MouseEnabled) if (CONTROL_MouseEnabled)
{ {
@ -527,7 +520,7 @@ static void CONTROL_GetDeviceButtons(void)
} }
} }
static void CONTROL_DigitizeAxis(int32_t axis, controldevice device) static void CONTROL_DigitizeAxis(int axis, controldevice device)
{ {
controlaxistype *set, *lastset; controlaxistype *set, *lastset;
@ -558,7 +551,7 @@ static void CONTROL_DigitizeAxis(int32_t axis, controldevice device)
} }
} }
static void CONTROL_ScaleAxis(int32_t axis, controldevice device) static void CONTROL_ScaleAxis(int axis, controldevice device)
{ {
controlaxistype *set; controlaxistype *set;
int32_t *scale; int32_t *scale;
@ -581,7 +574,7 @@ static void CONTROL_ScaleAxis(int32_t axis, controldevice device)
set[axis].analog = mulscale16(set[axis].analog, scale[axis]); set[axis].analog = mulscale16(set[axis].analog, scale[axis]);
} }
static void CONTROL_ApplyAxis(int32_t axis, ControlInfo *info, controldevice device) static void CONTROL_ApplyAxis(int axis, ControlInfo *info, controldevice device)
{ {
controlaxistype *set; controlaxistype *set;
controlaxismaptype *map; controlaxismaptype *map;
@ -623,13 +616,11 @@ static void CONTROL_PollDevices(ControlInfo *info)
if (CONTROL_MouseEnabled) if (CONTROL_MouseEnabled)
{ {
int32_t i = MAXMOUSEAXES-1;
Bmemcpy(CONTROL_LastMouseAxes, CONTROL_MouseAxes, sizeof(CONTROL_MouseAxes)); Bmemcpy(CONTROL_LastMouseAxes, CONTROL_MouseAxes, sizeof(CONTROL_MouseAxes));
memset(CONTROL_MouseAxes, 0, sizeof(CONTROL_MouseAxes)); memset(CONTROL_MouseAxes, 0, sizeof(CONTROL_MouseAxes));
CONTROL_GetMouseDelta(); CONTROL_GetMouseDelta();
for (; i>=0; i--) for (int i=MAXMOUSEAXES-1; i>=0; i--)
{ {
CONTROL_DigitizeAxis(i, controldevice_mouse); CONTROL_DigitizeAxis(i, controldevice_mouse);
CONTROL_ScaleAxis(i, controldevice_mouse); CONTROL_ScaleAxis(i, controldevice_mouse);
@ -640,12 +631,10 @@ static void CONTROL_PollDevices(ControlInfo *info)
if (CONTROL_JoystickEnabled) if (CONTROL_JoystickEnabled)
{ {
int32_t i = joystick.numAxes-1;
Bmemcpy(CONTROL_LastJoyAxes, CONTROL_JoyAxes, sizeof(CONTROL_JoyAxes)); Bmemcpy(CONTROL_LastJoyAxes, CONTROL_JoyAxes, sizeof(CONTROL_JoyAxes));
memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes)); memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes));
for (; i>=0; i--) for (int i=joystick.numAxes-1; i>=0; i--)
{ {
CONTROL_JoyAxes[i].analog = joystick.pAxis[i]; CONTROL_JoyAxes[i].analog = joystick.pAxis[i];
@ -659,52 +648,37 @@ static void CONTROL_PollDevices(ControlInfo *info)
CONTROL_GetDeviceButtons(); CONTROL_GetDeviceButtons();
} }
static void CONTROL_HandleAxisFunction(int32_t *p1, controlaxistype *axes, controlaxismaptype *axismap, int numAxes)
{
int axis = numAxes - 1;
do
{
if (!axes[axis].digital)
continue;
int const j = (axes[axis].digital < 0) ? axismap[axis].minmap : axismap[axis].maxmap;
if (j != AXISUNDEFINED)
p1[j] = 1;
}
while (axis--);
}
static void CONTROL_AxisFunctionState(int32_t *p1) static void CONTROL_AxisFunctionState(int32_t *p1)
{ {
if (CONTROL_NumMouseAxes) if (CONTROL_NumMouseAxes)
{ CONTROL_HandleAxisFunction(p1, CONTROL_MouseAxes, CONTROL_MouseAxesMap, CONTROL_NumMouseAxes);
int32_t j, i = CONTROL_NumMouseAxes-1;
do
{
if (!CONTROL_MouseAxes[i].digital) continue;
if (CONTROL_MouseAxes[i].digital < 0)
j = CONTROL_MouseAxesMap[i].minmap;
else
j = CONTROL_MouseAxesMap[i].maxmap;
if (j != AXISUNDEFINED)
p1[j] = 1;
}
while (i--);
}
if (CONTROL_NumJoyAxes) if (CONTROL_NumJoyAxes)
{ CONTROL_HandleAxisFunction(p1, CONTROL_JoyAxes, CONTROL_JoyAxesMap, CONTROL_NumJoyAxes);
int32_t j, i = CONTROL_NumJoyAxes-1;
do
{
if (!CONTROL_JoyAxes[i].digital) continue;
if (CONTROL_JoyAxes[i].digital < 0)
j = CONTROL_JoyAxesMap[i].minmap;
else
j = CONTROL_JoyAxesMap[i].maxmap;
if (j != AXISUNDEFINED)
p1[j] = 1;
}
while (i--);
}
} }
static void CONTROL_ButtonFunctionState(int32_t *p1) static void CONTROL_ButtonFunctionState(int32_t *p1)
{ {
if (CONTROL_NumMouseButtons) if (CONTROL_NumMouseButtons)
{ {
int32_t i = CONTROL_NumMouseButtons-1, j; int i = CONTROL_NumMouseButtons-1, j;
do do
{ {
@ -734,7 +708,7 @@ static void CONTROL_ButtonFunctionState(int32_t *p1)
if (CONTROL_NumJoyButtons) if (CONTROL_NumJoyButtons)
{ {
int32_t i=CONTROL_NumJoyButtons-1, j; int i=CONTROL_NumJoyButtons-1, j;
do do
{ {
@ -749,9 +723,8 @@ static void CONTROL_ButtonFunctionState(int32_t *p1)
while (i--); while (i--);
} }
} }
#endif
void CONTROL_ClearButton(int32_t whichbutton) void CONTROL_ClearButton(int whichbutton)
{ {
if (CONTROL_CheckRange(whichbutton)) return; if (CONTROL_CheckRange(whichbutton)) return;
@ -765,11 +738,11 @@ void CONTROL_ClearButton(int32_t whichbutton)
void CONTROL_ProcessBinds(void) void CONTROL_ProcessBinds(void)
{ {
int32_t i=MAXBOUNDKEYS-1;
if (!CONTROL_BindsEnabled) if (!CONTROL_BindsEnabled)
return; return;
int i = MAXBOUNDKEYS-1;
do do
{ {
if (CONTROL_KeyBinds[i].cmdstr) if (CONTROL_KeyBinds[i].cmdstr)
@ -783,89 +756,70 @@ void CONTROL_ProcessBinds(void)
while (i--); while (i--);
} }
#ifndef __ANDROID__
static void CONTROL_GetFunctionInput(void) static void CONTROL_GetFunctionInput(void)
{ {
int32_t periphs[CONTROL_NUM_FLAGS]; CONTROL_ButtonFunctionState(CONTROL_ButtonFlags);
int32_t i = CONTROL_NUM_FLAGS-1; CONTROL_AxisFunctionState(CONTROL_ButtonFlags);
memset(periphs, 0, sizeof(periphs));
CONTROL_ButtonFunctionState(periphs);
CONTROL_AxisFunctionState(periphs);
CONTROL_ButtonHeldState = CONTROL_ButtonState; CONTROL_ButtonHeldState = CONTROL_ButtonState;
CONTROL_ButtonState = 0; CONTROL_ButtonState = 0;
int i = CONTROL_NUM_FLAGS-1;
do do
{ {
CONTROL_SetFlag(i, /*CONTROL_KeyboardFunctionPressed(i) | */periphs[i] | CONTROL_OSDInput[i]); CONTROL_SetFlag(i, /*CONTROL_KeyboardFunctionPressed(i) | */CONTROL_ButtonFlags[i]);
if (CONTROL_Flags[i].cleared == FALSE) BUTTONSET(i, CONTROL_Flags[i].active); if (CONTROL_Flags[i].cleared == FALSE) BUTTONSET(i, CONTROL_Flags[i].active);
else if (CONTROL_Flags[i].active == FALSE) CONTROL_Flags[i].cleared = 0; else if (CONTROL_Flags[i].active == FALSE) CONTROL_Flags[i].cleared = 0;
} }
while (i--); while (i--);
memset(CONTROL_OSDInput, 0, sizeof(CONTROL_OSDInput)); memset(CONTROL_ButtonFlags, 0, sizeof(CONTROL_ButtonFlags));
} }
#endif
void CONTROL_GetInput(ControlInfo *info) void CONTROL_GetInput(ControlInfo *info)
{ {
#ifdef __ANDROID__ #ifdef __ANDROID__
CONTROL_Android_PollDevices(info); CONTROL_Android_PollDevices(info);
#else #endif
CONTROL_PollDevices(info); CONTROL_PollDevices(info);
CONTROL_GetFunctionInput(); CONTROL_GetFunctionInput();
inputchecked = 1; inputchecked = 1;
#endif
} }
int32_t CONTROL_Startup(controltype which, int32_t(*TimeFunction)(void), int32_t ticspersecond) bool CONTROL_Startup(controltype which, int32_t(*TimeFunction)(void), int32_t ticspersecond)
{ {
int32_t i;
UNREFERENCED_PARAMETER(which); UNREFERENCED_PARAMETER(which);
if (CONTROL_Started) return FALSE; if (CONTROL_Started) return false;
if (TimeFunction) ExtGetTime = TimeFunction; ExtGetTime = TimeFunction ? TimeFunction : CONTROL_GetTime;
else ExtGetTime = CONTROL_GetTime;
// ticrate = ticspersecond;
// what the fuck???
CONTROL_DoubleClickSpeed = (ticspersecond * 57) / 100; CONTROL_DoubleClickSpeed = (ticspersecond * 57) / 100;
if (CONTROL_DoubleClickSpeed <= 0) if (CONTROL_DoubleClickSpeed <= 0)
CONTROL_DoubleClickSpeed = 1; CONTROL_DoubleClickSpeed = 1;
if (initinput()) return TRUE; if (initinput())
return true;
CONTROL_MousePresent = CONTROL_MouseEnabled = FALSE;
CONTROL_JoyPresent = CONTROL_JoystickEnabled = FALSE;
CONTROL_NumMouseButtons = CONTROL_NumJoyButtons = 0;
CONTROL_NumMouseAxes = CONTROL_NumJoyAxes = 0;
KB_Startup(); KB_Startup();
//switch (which) {
// case controltype_keyboard:
// break;
// case controltype_keyboardandmouse:
CONTROL_NumMouseAxes = MAXMOUSEAXES; CONTROL_NumMouseAxes = MAXMOUSEAXES;
CONTROL_NumMouseButtons = MAXMOUSEBUTTONS; CONTROL_NumMouseButtons = MAXMOUSEBUTTONS;
CONTROL_MousePresent = Mouse_Init(); CONTROL_MousePresent = Mouse_Init();
CONTROL_MouseEnabled = CONTROL_MousePresent; CONTROL_MouseEnabled = CONTROL_MousePresent;
// break;
// case controltype_keyboardandjoystick:
CONTROL_NumJoyAxes = min(MAXJOYAXES, joystick.numAxes); CONTROL_NumJoyAxes = min(MAXJOYAXES, joystick.numAxes);
CONTROL_NumJoyButtons = min(MAXJOYBUTTONS, joystick.numButtons + 4 * (joystick.numHats > 0)); CONTROL_NumJoyButtons = min(MAXJOYBUTTONS, joystick.numButtons + 4 * (joystick.numHats > 0));
CONTROL_JoystickEnabled = CONTROL_JoyPresent = (inputdevices&4)>>2; CONTROL_JoystickEnabled = CONTROL_JoyPresent = !!((inputdevices & 4) >> 2);
// break;
//}
#ifdef GEKKO #ifdef GEKKO
if (CONTROL_MousePresent) if (CONTROL_MousePresent)
initprintf("CONTROL_Startup: Mouse Present\n"); initprintf("CONTROL_Startup: Mouse Present\n");
if (CONTROL_JoyPresent) if (CONTROL_JoyPresent)
initprintf("CONTROL_Startup: Joystick Present\n"); initprintf("CONTROL_Startup: Joystick Present\n");
#endif #endif
@ -873,12 +827,12 @@ int32_t CONTROL_Startup(controltype which, int32_t(*TimeFunction)(void), int32_t
CONTROL_ButtonState = 0; CONTROL_ButtonState = 0;
CONTROL_ButtonHeldState = 0; CONTROL_ButtonHeldState = 0;
for (i=0; i<CONTROL_NUM_FLAGS; i++) for (auto & CONTROL_Flag : CONTROL_Flags)
CONTROL_Flags[i].used = FALSE; CONTROL_Flag.used = FALSE;
CONTROL_Started = TRUE; CONTROL_Started = TRUE;
return FALSE; return false;
} }
void CONTROL_Shutdown(void) void CONTROL_Shutdown(void)