mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 07:22:25 +02:00
Fixing the review comments and setting the StandardDevice of USerINputMapper in the registeredDevices just like any other, only the ID is special
This commit is contained in:
parent
f0034844e7
commit
0fc04ab297
3 changed files with 19 additions and 18 deletions
|
@ -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<VirtualEndpoint>();
|
||||
// Create the action endpoints
|
||||
_endpoints[actionInput] = std::make_shared<ActionEndpoint>(actionInput);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<InputPair> getAvailableInputs(uint16 deviceID) { return _registeredDevices[deviceID]->getAvailabeInputs(); }
|
||||
|
@ -275,8 +276,8 @@ public:
|
|||
typedef std::map<int, DeviceProxy::Pointer> 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<int, Modifiers> InputToMoModifiersMap;
|
||||
InputToMoModifiersMap _inputToModifiersMap;
|
||||
|
|
Loading…
Reference in a new issue