removed _deviceCounts, cache joystick available inputs, added deadzone to gamepad thumbsticks

This commit is contained in:
SamGondelman 2016-06-07 17:12:24 -07:00
parent 545dda0a98
commit 2c1d20bd1a
5 changed files with 54 additions and 67 deletions

View file

@ -1,14 +1,14 @@
{
"name": "XBox to Standard",
"channels": [
{ "from": "GamePad.LY", "to": "Standard.LY" },
{ "from": "GamePad.LX", "to": "Standard.LX" },
{ "from": "GamePad.LY", "filters": { "type": "deadZone", "min": 0.05 }, "to": "Standard.LY" },
{ "from": "GamePad.LX", "filters": { "type": "deadZone", "min": 0.05 }, "to": "Standard.LX" },
{ "from": "GamePad.LT", "to": "Standard.LT" },
{ "from": "GamePad.LB", "to": "Standard.LB" },
{ "from": "GamePad.LS", "to": "Standard.LS" },
{ "from": "GamePad.RY", "to": "Standard.RY" },
{ "from": "GamePad.RX", "to": "Standard.RX" },
{ "from": "GamePad.RY", "filters": { "type": "deadZone", "min": 0.05 }, "to": "Standard.RY" },
{ "from": "GamePad.RX", "filters": { "type": "deadZone", "min": 0.05 }, "to": "Standard.RX" },
{ "from": "GamePad.RT", "to": "Standard.RT" },
{ "from": "GamePad.RB", "to": "Standard.RB" },
{ "from": "GamePad.RS", "to": "Standard.RS" },

View file

@ -62,14 +62,6 @@ namespace controller {
UserInputMapper::~UserInputMapper() {
}
int UserInputMapper::recordDeviceOfType(const QString& deviceName) {
if (!_deviceCounts.contains(deviceName)) {
_deviceCounts[deviceName] = 0;
}
_deviceCounts[deviceName] += 1;
return _deviceCounts[deviceName];
}
void UserInputMapper::registerDevice(InputDevice::Pointer device) {
Locker locker(_lock);
if (device->_deviceID == Input::INVALID_DEVICE) {
@ -77,8 +69,6 @@ void UserInputMapper::registerDevice(InputDevice::Pointer device) {
}
const auto& deviceID = device->_deviceID;
recordDeviceOfType(device->getName());
qCDebug(controllers) << "Registered input device <" << device->getName() << "> deviceID = " << deviceID;
for (const auto& inputMapping : device->getAvailableInputs()) {
@ -126,10 +116,6 @@ void UserInputMapper::removeDevice(int deviceID) {
auto device = proxyEntry->second;
qCDebug(controllers) << "Unregistering input device <" << device->getName() << "> deviceID = " << deviceID;
if (_deviceCounts.contains(device->getName())) {
_deviceCounts[device->getName()] -= 1;
}
unloadMappings(device->getDefaultMappingConfigs());
auto mappingsEntry = _mappingsByDevice.find(deviceID);

View file

@ -141,9 +141,6 @@ namespace controller {
std::vector<Pose> _poseStates = std::vector<Pose>(toInt(Action::NUM_ACTIONS));
std::vector<float> _lastStandardStates = std::vector<float>();
int recordDeviceOfType(const QString& deviceName);
QHash<const QString, int> _deviceCounts;
static float getValue(const EndpointPointer& endpoint, bool peek = false);
static Pose getPose(const EndpointPointer& endpoint, bool peek = false);

View file

@ -64,7 +64,8 @@ void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {
controller::Input::NamedVector Joystick::getAvailableInputs() const {
using namespace controller;
const Input::NamedVector availableInputs{
if (_availableInputs.length() == 0) {
_availableInputs = {
makePair(A, "A"),
makePair(B, "B"),
makePair(X, "X"),
@ -110,7 +111,8 @@ controller::Input::NamedVector Joystick::getAvailableInputs() const {
makePair(DL, "Left"),
makePair(DR, "Right"),
};
return availableInputs;
}
return _availableInputs;
}
QString Joystick::getDefaultMappingConfig() const {

View file

@ -53,6 +53,8 @@ private:
SDL_GameController* _sdlGameController;
SDL_Joystick* _sdlJoystick;
SDL_JoystickID _instanceId;
mutable controller::Input::NamedVector _availableInputs;
};
#endif // hifi_Joystick_h