From b4362aa6a995537fac64669cf45117ae7bc3893f Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Tue, 13 Aug 2019 09:15:49 +0000 Subject: [PATCH] Implement controller defaults git-svn-id: https://svn.eduke32.com/eduke32@7968 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/src/sdlayer.cpp | 8 +- source/duke3d/src/_functio.h | 21 +--- source/duke3d/src/config.cpp | 213 +++++++++++++++++++++++++++++++++ source/duke3d/src/config.h | 4 + source/duke3d/src/gamedefs.h | 2 +- source/duke3d/src/input.cpp | 201 +++++++++++++++++-------------- source/duke3d/src/menus.cpp | 41 +++++-- source/mact/include/_control.h | 4 +- source/mact/include/control.h | 32 +++++ source/mact/include/joystick.h | 2 + source/mact/src/joystick.cpp | 16 +++ 11 files changed, 415 insertions(+), 129 deletions(-) diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index b1ba830e5..caccbab70 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -111,7 +111,7 @@ static SDL_Surface *loadappicon(void); static mutex_t m_initprintf; // Joystick dead and saturation zones -uint16_t *joydead, *joysatur; +uint16_t joydead[9], joysatur[9]; #ifdef _WIN32 # if SDL_MAJOR_VERSION != 1 @@ -918,9 +918,6 @@ int32_t initinput(void) joystick.pAxis = (int32_t *)Xcalloc(joystick.numAxes, sizeof(int32_t)); - joydead = (uint16_t *)Xcalloc(joystick.numAxes, sizeof(uint16_t)); - joysatur = (uint16_t *)Xcalloc(joystick.numAxes, sizeof(uint16_t)); - return 0; } } @@ -948,9 +945,6 @@ int32_t initinput(void) for (i = 0; i < joystick.numHats; i++) joystick.pHat[i] = -1; // centre - joydead = (uint16_t *)Xcalloc(joystick.numAxes, sizeof(uint16_t)); - joysatur = (uint16_t *)Xcalloc(joystick.numAxes, sizeof(uint16_t)); - return 0; } } diff --git a/source/duke3d/src/_functio.h b/source/duke3d/src/_functio.h index 42e5420bb..830f44ed0 100644 --- a/source/duke3d/src/_functio.h +++ b/source/duke3d/src/_functio.h @@ -279,7 +279,7 @@ static const char * mousedigitaldefaults[MAXMOUSEDIGITAL] = { }; -#if defined(GEKKO) +#if defined GEKKO static const char * joystickdefaults[MAXJOYBUTTONSANDHATS] = { "Open", // A @@ -331,25 +331,6 @@ static const char * joystickanalogdefaults[MAXJOYAXES] = }; -static const char * joystickdigitaldefaults[MAXJOYDIGITAL] = - { - }; -#else -static const char * joystickdefaults[MAXJOYBUTTONSANDHATS] = - { - }; - - -static const char * joystickclickeddefaults[MAXJOYBUTTONSANDHATS] = - { - }; - - -static const char * joystickanalogdefaults[MAXJOYAXES] = - { - }; - - static const char * joystickdigitaldefaults[MAXJOYDIGITAL] = { }; diff --git a/source/duke3d/src/config.cpp b/source/duke3d/src/config.cpp index 1aaa4a750..9eda6715e 100644 --- a/source/duke3d/src/config.cpp +++ b/source/duke3d/src/config.cpp @@ -96,6 +96,34 @@ static char const * CONFIG_AnalogNumToName(int32_t func) } +static void CONFIG_SetJoystickButtonFunction(int i, int j, int function) +{ + ud.config.JoystickFunctions[i][j] = function; + CONTROL_MapButton(function, i, j, controldevice_joystick); +} +static void CONFIG_SetJoystickAnalogAxisScale(int i, int scale) +{ + ud.config.JoystickAnalogueScale[i] = scale; + CONTROL_SetAnalogAxisScale(i, scale, controldevice_joystick); +} +static void CONFIG_SetJoystickAnalogAxisDeadSaturate(int i, int dead, int saturate) +{ + ud.config.JoystickAnalogueDead[i] = dead; + ud.config.JoystickAnalogueSaturate[i] = saturate; + joySetDeadZone(i, dead, saturate); +} +static void CONFIG_SetJoystickDigitalAxisFunction(int i, int j, int function) +{ + ud.config.JoystickDigitalFunctions[i][j] = function; + CONTROL_MapDigitalAxis(i, function, j, controldevice_joystick); +} +static void CONFIG_SetJoystickAnalogAxisFunction(int i, int function) +{ + ud.config.JoystickAnalogueAxes[i] = function; + CONTROL_MapAnalogAxis(i, function, controldevice_joystick); +} + + void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN], bool lazy/*=false*/) { static char const s_gamefunc_[] = "gamefunc_"; @@ -338,6 +366,9 @@ void CONFIG_SetDefaults(void) CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse); } +#if !defined GEKKO + CONFIG_SetGameControllerDefaultsStandard(); +#else for (int i=0; ii, myconnectindex); } @@ -544,6 +576,187 @@ void CONFIG_SetupJoystick(void) } } +struct GameControllerButtonSetting +{ + GameControllerButton button; + int function; + + void apply() const + { + CONFIG_SetJoystickButtonFunction(button, 0, function); + } +}; +struct GameControllerAnalogAxisSetting +{ + GameControllerAxis axis; + int function; + + void apply() const + { + CONFIG_SetJoystickAnalogAxisFunction(axis, function); + } +}; +struct GameControllerDigitalAxisSetting +{ + GameControllerAxis axis; + int polarity; + int function; + + void apply() const + { + CONFIG_SetJoystickDigitalAxisFunction(axis, polarity, function); + } +}; + +static void CONFIG_SetGameControllerAxesModern() +{ + static GameControllerAnalogAxisSetting const analogAxes[] = + { + { GAMECONTROLLER_AXIS_LEFTX, analog_strafing }, + { GAMECONTROLLER_AXIS_LEFTY, analog_moving }, + { GAMECONTROLLER_AXIS_RIGHTX, analog_turning }, + { GAMECONTROLLER_AXIS_RIGHTY, analog_lookingupanddown }, + }; + + for (auto const & analogAxis : analogAxes) + analogAxis.apply(); +} + +void CONFIG_SetGameControllerDefaultsStandard() +{ + CONFIG_SetGameControllerDefaultsClear(); + CONFIG_SetGameControllerAxesModern(); + + static GameControllerButtonSetting const buttons[] = + { + { GAMECONTROLLER_BUTTON_A, gamefunc_Jump }, + { GAMECONTROLLER_BUTTON_X, gamefunc_Open }, + { GAMECONTROLLER_BUTTON_Y, gamefunc_Quick_Kick }, + { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map }, + { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run }, + { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Crouch }, + { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch }, + { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Jump }, + { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon }, + { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon }, + }; + + static GameControllerButtonSetting const dukebuttons[] = + { + { GAMECONTROLLER_BUTTON_B, gamefunc_Inventory }, + { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left }, + { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right }, + }; + + static GameControllerButtonSetting const furybuttons[] = + { + { GAMECONTROLLER_BUTTON_B, gamefunc_Steroids }, + { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit }, + { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, + }; + + for (auto const & button : buttons) + button.apply(); + + if (FURY) + { + for (auto const & button : furybuttons) + button.apply(); + } + else + { + for (auto const & button : dukebuttons) + button.apply(); + } + + static GameControllerDigitalAxisSetting const digitalAxes[] = + { + { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Alt_Fire }, + { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire }, + }; + + for (auto const & digitalAxis : digitalAxes) + digitalAxis.apply(); +} + +void CONFIG_SetGameControllerDefaultsPro() +{ + CONFIG_SetGameControllerDefaultsClear(); + CONFIG_SetGameControllerAxesModern(); + + static GameControllerButtonSetting const buttons[] = + { + { GAMECONTROLLER_BUTTON_A, gamefunc_Open }, + { GAMECONTROLLER_BUTTON_B, gamefunc_Quick_Kick }, + { GAMECONTROLLER_BUTTON_Y, gamefunc_Third_Person_View }, + { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map }, + { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run }, + { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Crouch }, + { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon }, + { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon }, + }; + + static GameControllerButtonSetting const dukebuttons[] = + { + { GAMECONTROLLER_BUTTON_X, gamefunc_Inventory }, + { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Previous_Weapon }, + { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Next_Weapon }, + { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left }, + { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right }, + }; + + static GameControllerButtonSetting const furybuttons[] = + { + { GAMECONTROLLER_BUTTON_X, gamefunc_Steroids }, + { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch }, + { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Alt_Fire }, + { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit }, + { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, + }; + + for (auto const & button : buttons) + button.apply(); + + if (FURY) + { + for (auto const & button : furybuttons) + button.apply(); + } + else + { + for (auto const & button : dukebuttons) + button.apply(); + } + + static GameControllerDigitalAxisSetting const digitalAxes[] = + { + { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Jump }, + { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire }, + }; + + for (auto const & digitalAxis : digitalAxes) + digitalAxis.apply(); +} + +void CONFIG_SetGameControllerDefaultsClear() +{ + for (int i=0; i