mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
ControllerInterface: Input detection improvements.
This commit is contained in:
@ -259,7 +259,7 @@ std::string Joystick::Hat::GetName() const
|
||||
|
||||
ControlState Joystick::Axis::GetState() const
|
||||
{
|
||||
return std::max(0.0, ControlState(m_axis - m_base) / m_range);
|
||||
return ControlState(m_axis - m_base) / m_range;
|
||||
}
|
||||
|
||||
ControlState Joystick::Button::GetState() const
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "InputCommon/ControllerInterface/Device.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@ -68,6 +69,11 @@ Device::Output* Device::FindOutput(const std::string& name) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ControlState Device::FullAnalogSurface::GetState() const
|
||||
{
|
||||
return (1 + std::max(0.0, m_high.GetState()) - std::max(0.0, m_low.GetState())) / 2;
|
||||
}
|
||||
|
||||
//
|
||||
// DeviceQualifier :: ToString
|
||||
//
|
||||
@ -214,5 +220,5 @@ bool DeviceContainer::HasConnectedDevice(const DeviceQualifier& qualifier) const
|
||||
const auto device = FindDevice(qualifier);
|
||||
return device != nullptr && device->IsValid();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Core
|
||||
} // namespace ciface
|
||||
|
@ -55,9 +55,22 @@ public:
|
||||
class Input : public Control
|
||||
{
|
||||
public:
|
||||
// things like absolute axes/ absolute mouse position will override this
|
||||
// Things like absolute axes/ absolute mouse position should override this to prevent
|
||||
// undesirable behavior in our mapping logic.
|
||||
virtual bool IsDetectable() { return true; }
|
||||
|
||||
// Implementations should return a value from 0.0 to 1.0 across their normal range.
|
||||
// One input should be provided for each "direction". (e.g. 2 for each axis)
|
||||
// If possible, negative values may be returned in situations where an opposing input is
|
||||
// activated. (e.g. When an underlying axis, X, is currently negative, "Axis X-", will return a
|
||||
// positive value and "Axis X+" may return a negative value.)
|
||||
// Doing so is solely to allow our input detection logic to better detect false positives.
|
||||
// This is necessary when making use of "FullAnalogSurface" as multiple inputs will be seen
|
||||
// increasing from 0.0 to 1.0 as a user tries to map just one. The negative values provide a
|
||||
// view of the underlying axis. (Negative values are clamped off before they reach
|
||||
// expression-parser or controller-emu)
|
||||
virtual ControlState GetState() const = 0;
|
||||
|
||||
Input* ToInput() override { return this; }
|
||||
};
|
||||
|
||||
@ -96,11 +109,7 @@ protected:
|
||||
{
|
||||
public:
|
||||
FullAnalogSurface(Input* low, Input* high) : m_low(*low), m_high(*high) {}
|
||||
ControlState GetState() const override
|
||||
{
|
||||
return (1 + m_high.GetState() - m_low.GetState()) / 2;
|
||||
}
|
||||
|
||||
ControlState GetState() const override;
|
||||
std::string GetName() const override { return m_low.GetName() + *m_high.GetName().rbegin(); }
|
||||
|
||||
private:
|
||||
|
@ -228,7 +228,7 @@ ControlState Device::Trigger::GetState() const
|
||||
|
||||
ControlState Device::Axis::GetState() const
|
||||
{
|
||||
return std::max(0.0, ControlState(m_axis) / m_range);
|
||||
return ControlState(m_axis) / m_range;
|
||||
}
|
||||
|
||||
void Device::Motor::SetState(ControlState state)
|
||||
@ -236,5 +236,5 @@ void Device::Motor::SetState(ControlState state)
|
||||
m_motor = (WORD)(state * m_range);
|
||||
m_parent->UpdateMotors();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace XInput
|
||||
} // namespace ciface
|
||||
|
@ -343,7 +343,7 @@ ControlState evdevDevice::Axis::GetState() const
|
||||
int value = 0;
|
||||
libevdev_fetch_event_value(m_dev, EV_ABS, m_code, &value);
|
||||
|
||||
return std::max(0.0, ControlState(value - m_base) / m_range);
|
||||
return ControlState(value - m_base) / m_range;
|
||||
}
|
||||
|
||||
evdevDevice::Effect::Effect(int fd) : m_fd(fd)
|
||||
|
Reference in New Issue
Block a user