Merged https://github.com/ZDoom/gzdoom/pull/1894 (Individual Joystick Toggles)

This commit is contained in:
Major Cooke 2023-01-21 11:10:18 -06:00
parent 0a2fc5651c
commit b5a95b47c1
10 changed files with 174 additions and 7 deletions

View file

@ -120,6 +120,11 @@ bool M_LoadJoystickConfig(IJoystickConfig *joy)
{ {
return false; return false;
} }
value = GameConfig->GetValueForKey("Enabled");
if (value != NULL)
{
joy->SetEnabled((bool)atoi(value));
}
value = GameConfig->GetValueForKey("Sensitivity"); value = GameConfig->GetValueForKey("Sensitivity");
if (value != NULL) if (value != NULL)
{ {
@ -176,6 +181,10 @@ void M_SaveJoystickConfig(IJoystickConfig *joy)
if (GameConfig != NULL && M_SetJoystickConfigSection(joy, true, GameConfig)) if (GameConfig != NULL && M_SetJoystickConfigSection(joy, true, GameConfig))
{ {
GameConfig->ClearCurrentSection(); GameConfig->ClearCurrentSection();
if (!joy->GetEnabled())
{
GameConfig->SetValueForKey("Enabled", "0");
}
if (!joy->IsSensitivityDefault()) if (!joy->IsSensitivityDefault())
{ {
mysnprintf(value, countof(value), "%g", joy->GetSensitivity()); mysnprintf(value, countof(value), "%g", joy->GetSensitivity());

View file

@ -36,6 +36,9 @@ struct NOVTABLE IJoystickConfig
virtual void SetAxisMap(int axis, EJoyAxis gameaxis) = 0; virtual void SetAxisMap(int axis, EJoyAxis gameaxis) = 0;
virtual void SetAxisScale(int axis, float scale) = 0; virtual void SetAxisScale(int axis, float scale) = 0;
virtual bool GetEnabled() = 0;
virtual void SetEnabled(bool enabled) = 0;
// Used by the saver to not save properties that are at their defaults. // Used by the saver to not save properties that are at their defaults.
virtual bool IsSensitivityDefault() = 0; virtual bool IsSensitivityDefault() = 0;
virtual bool IsAxisDeadZoneDefault(int axis) = 0; virtual bool IsAxisDeadZoneDefault(int axis) = 0;

View file

@ -119,6 +119,20 @@ DEFINE_ACTION_FUNCTION(IJoystickConfig, GetNumAxes)
ACTION_RETURN_INT(self->GetNumAxes()); ACTION_RETURN_INT(self->GetNumAxes());
} }
DEFINE_ACTION_FUNCTION(IJoystickConfig, GetEnabled)
{
PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig);
ACTION_RETURN_BOOL(self->GetEnabled());
}
DEFINE_ACTION_FUNCTION(IJoystickConfig, SetEnabled)
{
PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig);
PARAM_BOOL(enabled);
self->SetEnabled(enabled);
return 0;
}
void UpdateJoystickMenu(IJoystickConfig *selected) void UpdateJoystickMenu(IJoystickConfig *selected)
{ {

View file

@ -104,6 +104,9 @@ public:
virtual bool IsAxisMapDefault(int axis); virtual bool IsAxisMapDefault(int axis);
virtual bool IsAxisScaleDefault(int axis); virtual bool IsAxisScaleDefault(int axis);
virtual bool GetEnabled();
virtual void SetEnabled(bool enabled);
virtual void SetDefaultConfig(); virtual void SetDefaultConfig();
virtual FString GetIdentifier(); virtual FString GetIdentifier();
@ -165,6 +168,7 @@ private:
TArray<DigitalButton> m_buttons; TArray<DigitalButton> m_buttons;
TArray<DigitalButton> m_POVs; TArray<DigitalButton> m_POVs;
bool m_enabled;
bool m_useAxesPolling; bool m_useAxesPolling;
io_object_t m_notification; io_object_t m_notification;
@ -279,6 +283,7 @@ IOKitJoystick::IOKitJoystick(const io_object_t device)
: m_interface(CreateDeviceInterface(device)) : m_interface(CreateDeviceInterface(device))
, m_queue(CreateDeviceQueue(m_interface)) , m_queue(CreateDeviceQueue(m_interface))
, m_sensitivity(DEFAULT_SENSITIVITY) , m_sensitivity(DEFAULT_SENSITIVITY)
, m_enabled(true)
, m_useAxesPolling(true) , m_useAxesPolling(true)
, m_notification(0) , m_notification(0)
{ {
@ -430,6 +435,17 @@ bool IOKitJoystick::IsAxisScaleDefault(int axis)
: true; : true;
} }
bool IOKitJoystick::GetEnabled()
{
return m_enabled;
}
void IOKitJoystick::SetEnabled(bool enabled)
{
m_enabled = enabled;
}
#undef IS_AXIS_VALID #undef IS_AXIS_VALID
void IOKitJoystick::SetDefaultConfig() void IOKitJoystick::SetDefaultConfig()
@ -547,7 +563,7 @@ void IOKitJoystick::Update()
if (kIOReturnSuccess == eventResult) if (kIOReturnSuccess == eventResult)
{ {
if (use_joystick) if (use_joystick && m_enabled)
{ {
ProcessAxis(event) || ProcessButton(event) || ProcessPOV(event); ProcessAxis(event) || ProcessButton(event) || ProcessPOV(event);
} }
@ -557,7 +573,7 @@ void IOKitJoystick::Update()
Printf(TEXTCOLOR_RED "IOHIDQueueInterface::getNextEvent() failed with code 0x%08X\n", eventResult); Printf(TEXTCOLOR_RED "IOHIDQueueInterface::getNextEvent() failed with code 0x%08X\n", eventResult);
} }
ProcessAxes(); if(m_enabled) ProcessAxes();
} }

View file

@ -44,7 +44,7 @@
class SDLInputJoystick: public IJoystickConfig class SDLInputJoystick: public IJoystickConfig
{ {
public: public:
SDLInputJoystick(int DeviceIndex) : DeviceIndex(DeviceIndex), Multiplier(1.0f) SDLInputJoystick(int DeviceIndex) : DeviceIndex(DeviceIndex), Multiplier(1.0f) , Enabled(true)
{ {
Device = SDL_JoystickOpen(DeviceIndex); Device = SDL_JoystickOpen(DeviceIndex);
if(Device != NULL) if(Device != NULL)
@ -154,6 +154,17 @@ public:
Axes.Push(info); Axes.Push(info);
} }
} }
bool GetEnabled()
{
return Enabled;
}
void SetEnabled(bool enabled)
{
Enabled = enabled;
}
FString GetIdentifier() FString GetIdentifier()
{ {
char id[16]; char id[16];
@ -248,9 +259,12 @@ protected:
SDL_Joystick *Device; SDL_Joystick *Device;
float Multiplier; float Multiplier;
bool Enabled;
TArray<AxisInfo> Axes; TArray<AxisInfo> Axes;
int NumAxes; int NumAxes;
int NumHats; int NumHats;
friend class SDLInputJoystickManager;
}; };
const EJoyAxis SDLInputJoystick::DefaultAxes[5] = {JOYAXIS_Side, JOYAXIS_Forward, JOYAXIS_Pitch, JOYAXIS_Yaw, JOYAXIS_Up}; const EJoyAxis SDLInputJoystick::DefaultAxes[5] = {JOYAXIS_Side, JOYAXIS_Forward, JOYAXIS_Pitch, JOYAXIS_Yaw, JOYAXIS_Up};
@ -291,7 +305,7 @@ public:
void ProcessInput() const void ProcessInput() const
{ {
for(unsigned int i = 0;i < Joysticks.Size();++i) for(unsigned int i = 0;i < Joysticks.Size();++i)
Joysticks[i]->ProcessInput(); if(Joysticks[i]->Enabled) Joysticks[i]->ProcessInput();
} }
protected: protected:
TArray<SDLInputJoystick *> Joysticks; TArray<SDLInputJoystick *> Joysticks;

View file

@ -180,6 +180,9 @@ public:
bool IsAxisMapDefault(int axis); bool IsAxisMapDefault(int axis);
bool IsAxisScaleDefault(int axis); bool IsAxisScaleDefault(int axis);
bool GetEnabled();
void SetEnabled(bool enabled);
void SetDefaultConfig(); void SetDefaultConfig();
FString GetIdentifier(); FString GetIdentifier();
@ -219,6 +222,8 @@ protected:
DIOBJECTDATAFORMAT *Objects; DIOBJECTDATAFORMAT *Objects;
DIDATAFORMAT DataFormat; DIDATAFORMAT DataFormat;
bool Enabled;
static BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef); static BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef);
void OrderAxes(); void OrderAxes();
bool ReorderAxisPair(const GUID &x, const GUID &y, int pos); bool ReorderAxisPair(const GUID &x, const GUID &y, int pos);
@ -297,6 +302,7 @@ FDInputJoystick::FDInputJoystick(const GUID *instance, FString &name)
Instance = *instance; Instance = *instance;
Name = name; Name = name;
Marked = false; Marked = false;
Enabled = true;
} }
//=========================================================================== //===========================================================================
@ -410,7 +416,7 @@ void FDInputJoystick::ProcessInput()
{ {
hr = Device->Acquire(); hr = Device->Acquire();
} }
if (FAILED(hr)) if (FAILED(hr) || !Enabled)
{ {
return; return;
} }
@ -984,6 +990,28 @@ bool FDInputJoystick::IsAxisScaleDefault(int axis)
return true; return true;
} }
//===========================================================================
//
// FDInputJoystick :: GetEnabled
//
//===========================================================================
bool FDInputJoystick::GetEnabled()
{
return Enabled;
}
//===========================================================================
//
// FDInputJoystick :: SetEnabled
//
//===========================================================================
void FDInputJoystick::SetEnabled(bool enabled)
{
Enabled = enabled;
}
//=========================================================================== //===========================================================================
// //
// FDInputJoystick :: IsAxisMapDefault // FDInputJoystick :: IsAxisMapDefault

View file

@ -114,6 +114,9 @@ public:
bool IsAxisMapDefault(int axis); bool IsAxisMapDefault(int axis);
bool IsAxisScaleDefault(int axis); bool IsAxisScaleDefault(int axis);
bool GetEnabled();
void SetEnabled(bool enabled);
void SetDefaultConfig(); void SetDefaultConfig();
FString GetIdentifier(); FString GetIdentifier();
@ -153,6 +156,7 @@ protected:
bool Connected; bool Connected;
bool Marked; bool Marked;
bool Active; bool Active;
bool Enabled;
void Attached(); void Attached();
void Detached(); void Detached();
@ -376,6 +380,7 @@ FRawPS2Controller::FRawPS2Controller(HANDLE handle, EAdapterType type, int seque
ControllerNumber = controller; ControllerNumber = controller;
Sequence = sequence; Sequence = sequence;
DeviceID = devid; DeviceID = devid;
Enabled = true;
// The EMS USB2 controller provides attachment status. The others do not. // The EMS USB2 controller provides attachment status. The others do not.
Connected = (Descriptors[type].ControllerStatus < 0); Connected = (Descriptors[type].ControllerStatus < 0);
@ -849,6 +854,28 @@ bool FRawPS2Controller::IsAxisScaleDefault(int axis)
return true; return true;
} }
//===========================================================================
//
// FRawPS2Controller :: GetEnabled
//
//===========================================================================
bool FRawPS2Controller::GetEnabled()
{
return Enabled;
}
//===========================================================================
//
// FRawPS2Controller :: SetEnabled
//
//===========================================================================
void FRawPS2Controller::SetEnabled(bool enabled)
{
Enabled = enabled;
}
//=========================================================================== //===========================================================================
// //
// FRawPS2Controller :: IsAxisMapDefault // FRawPS2Controller :: IsAxisMapDefault
@ -972,7 +999,7 @@ bool FRawPS2Manager::ProcessRawInput(RAWINPUT *raw, int code)
{ {
if (Devices[i]->Handle == raw->header.hDevice) if (Devices[i]->Handle == raw->header.hDevice)
{ {
if (Devices[i]->ProcessInput(&raw->data.hid, code)) if (Devices[i]->Enabled && Devices[i]->ProcessInput(&raw->data.hid, code))
{ {
return true; return true;
} }

View file

@ -102,6 +102,9 @@ public:
bool IsAxisMapDefault(int axis); bool IsAxisMapDefault(int axis);
bool IsAxisScaleDefault(int axis); bool IsAxisScaleDefault(int axis);
bool GetEnabled();
void SetEnabled(bool enabled);
void SetDefaultConfig(); void SetDefaultConfig();
FString GetIdentifier(); FString GetIdentifier();
@ -138,6 +141,7 @@ protected:
DWORD LastPacketNumber; DWORD LastPacketNumber;
int LastButtons; int LastButtons;
bool Connected; bool Connected;
bool Enabled;
void Attached(); void Attached();
void Detached(); void Detached();
@ -221,6 +225,7 @@ FXInputController::FXInputController(int index)
{ {
Index = index; Index = index;
Connected = false; Connected = false;
Enabled = true;
M_LoadJoystickConfig(this); M_LoadJoystickConfig(this);
} }
@ -269,7 +274,7 @@ void FXInputController::ProcessInput()
{ {
Attached(); Attached();
} }
if (state.dwPacketNumber == LastPacketNumber) if (state.dwPacketNumber == LastPacketNumber || !Enabled)
{ // Nothing has changed since last time. { // Nothing has changed since last time.
return; return;
} }
@ -628,6 +633,28 @@ bool FXInputController::IsAxisScaleDefault(int axis)
return true; return true;
} }
//===========================================================================
//
// FXInputController :: GetEnabled
//
//===========================================================================
bool FXInputController::GetEnabled()
{
return Enabled;
}
//===========================================================================
//
// FXInputController :: SetEnabled
//
//===========================================================================
void FXInputController::SetEnabled(bool enabled)
{
Enabled = enabled;
}
//=========================================================================== //===========================================================================
// //
// FXInputController :: IsAxisMapDefault // FXInputController :: IsAxisMapDefault

View file

@ -220,6 +220,29 @@ class OptionMenuItemInverter : OptionMenuItemOptionBase
// //
//============================================================================= //=============================================================================
class OptionMenuJoyEnable : OptionMenuItemOptionBase
{
JoystickConfig mJoy;
OptionMenuJoyEnable Init(String label, JoystickConfig joy)
{
Super.Init(label,"none","YesNo",null,0);
mJoy = joy;
return self;
}
override int GetSelection()
{
return mJoy.GetEnabled() ? 1 : 0;
}
override void SetSelection(int Selection)
{
mJoy.SetEnabled(Selection);
}
}
class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu
{ {
JoystickConfig mJoy; JoystickConfig mJoy;
@ -259,6 +282,9 @@ class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu
it = new("OptionMenuItemStaticText").Init(joy.GetName(), false); it = new("OptionMenuItemStaticText").Init(joy.GetName(), false);
it = new("OptionMenuItemStaticText").Init("", false); it = new("OptionMenuItemStaticText").Init("", false);
it = new("OptionMenuJoyEnable").Init("$JOYMNU_JOYENABLE", joy);
opt.mItems.Push(it);
it = new("OptionMenuSliderJoySensitivity").Init("$JOYMNU_OVRSENS", 0, 2, 0.1, 3, joy); it = new("OptionMenuSliderJoySensitivity").Init("$JOYMNU_OVRSENS", 0, 2, 0.1, 3, joy);
opt.mItems.Push(it); opt.mItems.Push(it);
it = new("OptionMenuItemStaticText").Init(" ", false); it = new("OptionMenuItemStaticText").Init(" ", false);

View file

@ -84,6 +84,9 @@ struct JoystickConfig native version("2.4")
native int GetNumAxes(); native int GetNumAxes();
native String GetAxisName(int axis); native String GetAxisName(int axis);
native bool GetEnabled();
native void SetEnabled(bool enabled);
} }
class Menu : Object native ui version("2.4") class Menu : Object native ui version("2.4")