Skip to content

Commit

Permalink
Controller DeadZone prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
HumanGamer committed Mar 5, 2024
1 parent aceb999 commit 9a88c54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
15 changes: 11 additions & 4 deletions engine/source/platformWin32/winDirectInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ bool DInputManager::smMouseEnabled = false;
bool DInputManager::smJoystickEnabled = false;
bool DInputManager::smXInputEnabled = false;
int DInputManager::smAnalogRange = 0;
F32 DInputManager::smDeadZoneL = XINPUT_DEADZONE_DEFAULT;
F32 DInputManager::smDeadZoneR = XINPUT_DEADZONE_DEFAULT;

// Type definitions:
typedef HRESULT(WINAPI* FN_DirectInputCreate)(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID* ppvOut, LPUNKNOWN punkOuter);
Expand All @@ -44,6 +46,8 @@ void DInputManager::init()
Con::addVariable("pref::Input::MouseEnabled", TypeBool, &smMouseEnabled);
Con::addVariable("pref::Input::JoystickEnabled", TypeBool, &smJoystickEnabled);
Con::addVariable("pref::Input::AnalogRange", TypeS32, &smAnalogRange);
Con::addVariable("pref::Input::DeadZoneL", TypeF32, &smDeadZoneL);
Con::addVariable("pref::Input::DeadZoneR", TypeF32, &smDeadZoneR);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -959,6 +963,9 @@ inline void DInputManager::fireXInputButtonEvent(int controllerID, bool forceFir
// This function does all of the dirty work associated with reporting the state of all 4 XInput controllers -- jason_cahill
void DInputManager::processXInput(void)
{
F32 deadZoneL = smDeadZoneL * FLOAT(0x7FFF);
F32 deadZoneR = smDeadZoneR * FLOAT(0x7FFF);

if (mfnXInputGetState)
{
for (int i = 0; i < 4; i++)
Expand All @@ -970,15 +977,15 @@ void DInputManager::processXInput(void)
if (mXInputDeadZoneOn)
{
// Zero value if thumbsticks are within the dead zone
if ((mXInputStateNew[i].state.Gamepad.sThumbLX < XINPUT_DEADZONE && mXInputStateNew[i].state.Gamepad.sThumbLX > -XINPUT_DEADZONE) &&
(mXInputStateNew[i].state.Gamepad.sThumbLY < XINPUT_DEADZONE && mXInputStateNew[i].state.Gamepad.sThumbLY > -XINPUT_DEADZONE))
if ((mXInputStateNew[i].state.Gamepad.sThumbLX < deadZoneL && mXInputStateNew[i].state.Gamepad.sThumbLX > -deadZoneL) &&
(mXInputStateNew[i].state.Gamepad.sThumbLY < deadZoneL && mXInputStateNew[i].state.Gamepad.sThumbLY > -deadZoneL))
{
mXInputStateNew[i].state.Gamepad.sThumbLX = 0;
mXInputStateNew[i].state.Gamepad.sThumbLY = 0;
}

if ((mXInputStateNew[i].state.Gamepad.sThumbRX < XINPUT_DEADZONE && mXInputStateNew[i].state.Gamepad.sThumbRX > -XINPUT_DEADZONE) &&
(mXInputStateNew[i].state.Gamepad.sThumbRY < XINPUT_DEADZONE && mXInputStateNew[i].state.Gamepad.sThumbRY > -XINPUT_DEADZONE))
if ((mXInputStateNew[i].state.Gamepad.sThumbRX < deadZoneR && mXInputStateNew[i].state.Gamepad.sThumbRX > -deadZoneR) &&
(mXInputStateNew[i].state.Gamepad.sThumbRY < deadZoneR && mXInputStateNew[i].state.Gamepad.sThumbRY > -deadZoneR))
{
mXInputStateNew[i].state.Gamepad.sThumbRX = 0;
mXInputStateNew[i].state.Gamepad.sThumbRY = 0;
Expand Down
5 changes: 4 additions & 1 deletion engine/source/platformWin32/winDirectInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ struct InputEvent;
typedef DWORD(WINAPI* FN_XInputGetState)(DWORD dwUserIndex, XINPUT_STATE* pState);
typedef DWORD(WINAPI* FN_XInputSetState)(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration);
#define XINPUT_MAX_CONTROLLERS 4 // XInput handles up to 4 controllers
#define XINPUT_DEADZONE ( 0.24f * FLOAT(0x7FFF) ) // Default to 24% of the +/- 32767 range. This is a reasonable default value but can be altered if needed.
//#define XINPUT_DEADZONE ( 0.24f * FLOAT(0x7FFF) ) // Default to 24% of the +/- 32767 range. This is a reasonable default value but can be altered if needed.
#define XINPUT_DEADZONE_DEFAULT (0.24f)
struct XINPUT_CONTROLLER_STATE
{
XINPUT_STATE state;
Expand Down Expand Up @@ -59,6 +60,8 @@ class DInputManager : public InputManager
static bool smJoystickEnabled;
static bool smXInputEnabled;
static int smAnalogRange;
static F32 smDeadZoneL;
static F32 smDeadZoneR;

bool mKeyboardActive;
bool mMouseActive;
Expand Down
2 changes: 2 additions & 0 deletions game/marble/client/defaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
$pref::Input::CameraAccelSpeed = 0.05;
$pref::Input::CameraSensitivityHorizontal = 0.7;
$pref::Input::CameraSensitivityVertical = 0.8;
$pref::Input::DeadZoneL = 0.24;
$pref::Input::DeadZoneR = 0.24;
$pref::sceneLighting::cacheSize = 20000;
$pref::sceneLighting::purgeMethod = "lastCreated";
$pref::sceneLighting::cacheLighting = 1;
Expand Down

0 comments on commit 9a88c54

Please sign in to comment.