diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index a72f24e651..abb9544892 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -26,7 +26,7 @@ namespace controller { class VirtualEndpoint : public Endpoint { public: - VirtualEndpoint(const UserInputMapper::Input& id = UserInputMapper::Input(-1)) + VirtualEndpoint(const UserInputMapper::Input& id = UserInputMapper::Input::INVALID_INPUT) : Endpoint(id) { } @@ -41,7 +41,7 @@ namespace controller { class JSEndpoint : public Endpoint { public: JSEndpoint(const QJSValue& callable) - : Endpoint(UserInputMapper::Input(-1)), _callable(callable) {} + : Endpoint(UserInputMapper::Input::INVALID_INPUT), _callable(callable) {} virtual float value() { float result = (float)_callable.call().toNumber();; @@ -59,7 +59,7 @@ namespace controller { class ScriptEndpoint : public Endpoint { public: ScriptEndpoint(const QScriptValue& callable) - : Endpoint(UserInputMapper::Input(-1)), _callable(callable) { + : Endpoint(UserInputMapper::Input::INVALID_INPUT), _callable(callable) { } virtual float value() { @@ -78,7 +78,7 @@ namespace controller { class CompositeEndpoint : public Endpoint, Endpoint::Pair { public: CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second) - : Endpoint(UserInputMapper::Input(-1)), Pair(first, second) { } + : Endpoint(UserInputMapper::Input(UserInputMapper::Input::INVALID_INPUT)), Pair(first, second) { } virtual float value() { float result = first->value() * -1.0 + second->value(); @@ -96,7 +96,7 @@ namespace controller { class ActionEndpoint : public Endpoint { public: - ActionEndpoint(const UserInputMapper::Input& id = UserInputMapper::Input(-1)) + ActionEndpoint(const UserInputMapper::Input& id = UserInputMapper::Input::INVALID_INPUT) : Endpoint(id) { } @@ -156,9 +156,7 @@ namespace controller { QString cleanActionName = QString(actionName).remove(ScriptingInterface::SANITIZE_NAME_EXPRESSION); _actions.insert(cleanActionName, actionInput.getID()); - // Create the endpoints - // FIXME action endpoints need to accumulate values, and have them cleared at each frame - // _endpoints[actionInput] = std::make_shared(); + // Create the action endpoints _endpoints[actionInput] = std::make_shared(actionInput); } diff --git a/libraries/controllers/src/controllers/UserInputMapper.cpp b/libraries/controllers/src/controllers/UserInputMapper.cpp index daa7c78640..0d0ae7d85f 100755 --- a/libraries/controllers/src/controllers/UserInputMapper.cpp +++ b/libraries/controllers/src/controllers/UserInputMapper.cpp @@ -19,6 +19,7 @@ const uint16_t UserInputMapper::Input::INVALID_DEVICE = INVALID_INPUT.getDevice( const uint16_t UserInputMapper::Input::INVALID_CHANNEL = INVALID_INPUT.getChannel(); const uint16_t UserInputMapper::Input::INVALID_TYPE = (uint16_t)INVALID_INPUT.getType(); const uint16_t UserInputMapper::Input::ACTIONS_DEVICE = INVALID_DEVICE - (uint16)1; +const uint16_t UserInputMapper::Input::STANDARD_DEVICE = 0; // Default contruct allocate the poutput size with the current hardcoded action channels UserInputMapper::UserInputMapper() { @@ -38,6 +39,13 @@ bool UserInputMapper::registerDevice(uint16 deviceID, const DeviceProxy::Pointer return true; } +bool UserInputMapper::registerStandardDevice(const DeviceProxy::Pointer& device) { + device->_name = "Standard"; // Just to make sure + _registeredDevices[getStandardDeviceID()] = device; + return true; +} + + UserInputMapper::DeviceProxy::Pointer UserInputMapper::getDeviceProxy(const Input& input) { auto device = _registeredDevices.find(input.getDevice()); if (device != _registeredDevices.end()) { @@ -69,10 +77,6 @@ void UserInputMapper::resetDevice(uint16 deviceID) { } int UserInputMapper::findDevice(QString name) const { - if (_standardDevice && (_standardDevice->getName() == name)) { - return getStandardDeviceID(); - } - for (auto device : _registeredDevices) { if (device.second->_name.split(" (")[0] == name) { return device.first; diff --git a/libraries/controllers/src/controllers/UserInputMapper.h b/libraries/controllers/src/controllers/UserInputMapper.h index 7e0832b55a..8b466d79c9 100644 --- a/libraries/controllers/src/controllers/UserInputMapper.h +++ b/libraries/controllers/src/controllers/UserInputMapper.h @@ -86,6 +86,7 @@ public: static const uint16 INVALID_CHANNEL; static const uint16 INVALID_TYPE; static const uint16 ACTIONS_DEVICE; + static const uint16 STANDARD_DEVICE; }; @@ -138,7 +139,7 @@ public: uint16 getFreeDeviceID() { return _nextFreeDeviceID++; } bool registerDevice(uint16 deviceID, const DeviceProxy::Pointer& device); - bool registerStandardDevice(const DeviceProxy::Pointer& device) { _standardDevice = device; _registeredDevices[getStandardDeviceID()] = device; return true; } + bool registerStandardDevice(const DeviceProxy::Pointer& device); DeviceProxy::Pointer getDeviceProxy(const Input& input); QString getDeviceName(uint16 deviceID); QVector getAvailableInputs(uint16 deviceID) { return _registeredDevices[deviceID]->getAvailabeInputs(); } @@ -275,8 +276,8 @@ public: typedef std::map DevicesMap; DevicesMap getDevices() { return _registeredDevices; } - uint16 getStandardDeviceID() const { return _standardDeviceID; } - DeviceProxy::Pointer getStandardDevice() { return _standardDevice; } + uint16 getStandardDeviceID() const { return Input::STANDARD_DEVICE; } + DeviceProxy::Pointer getStandardDevice() { return _registeredDevices[getStandardDeviceID()]; } signals: void actionEvent(int action, float state); @@ -284,12 +285,10 @@ signals: protected: void registerStandardDevice(); - uint16 _standardDeviceID = 0; - DeviceProxy::Pointer _standardDevice; StandardControllerPointer _standardController; DevicesMap _registeredDevices; - uint16 _nextFreeDeviceID = 1; + uint16 _nextFreeDeviceID = Input::STANDARD_DEVICE + 1; typedef std::map InputToMoModifiersMap; InputToMoModifiersMap _inputToModifiersMap;