mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-22 15:00:19 +02:00
Merge pull request #399 from HifiExperiments/controller
Fix various crashes/issues in controller scripting API
This commit is contained in:
commit
2ecbf49176
2 changed files with 33 additions and 4 deletions
|
@ -312,8 +312,11 @@ void UserInputMapper::update(float deltaTime) {
|
||||||
Input::NamedVector UserInputMapper::getAvailableInputs(uint16 deviceID) const {
|
Input::NamedVector UserInputMapper::getAvailableInputs(uint16 deviceID) const {
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
auto iterator = _registeredDevices.find(deviceID);
|
auto iterator = _registeredDevices.find(deviceID);
|
||||||
|
if (iterator != _registeredDevices.end()) {
|
||||||
return iterator->second->getAvailableInputs();
|
return iterator->second->getAvailableInputs();
|
||||||
}
|
}
|
||||||
|
return Input::NamedVector();
|
||||||
|
}
|
||||||
|
|
||||||
QVector<Action> UserInputMapper::getAllActions() const {
|
QVector<Action> UserInputMapper::getAllActions() const {
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
|
@ -366,7 +369,7 @@ bool UserInputMapper::triggerHapticPulse(float strength, float duration, control
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
bool toReturn = false;
|
bool toReturn = false;
|
||||||
for (const auto& device : _registeredDevices) {
|
for (const auto& device : _registeredDevices) {
|
||||||
toReturn = toReturn || device.second->triggerHapticPulse(strength, duration, hand);
|
toReturn = device.second->triggerHapticPulse(strength, duration, hand) || toReturn;
|
||||||
}
|
}
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
@ -1237,16 +1240,42 @@ void UserInputMapper::disableMapping(const Mapping::Pointer& mapping) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInputMapper::setActionState(Action action, float value, bool valid) {
|
void UserInputMapper::setActionState(Action action, float value, bool valid) {
|
||||||
|
Locker locker(_lock);
|
||||||
_actionStates[toInt(action)] = value;
|
_actionStates[toInt(action)] = value;
|
||||||
_actionStatesValid[toInt(action)] = valid;
|
_actionStatesValid[toInt(action)] = valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInputMapper::deltaActionState(Action action, float delta, bool valid) {
|
void UserInputMapper::deltaActionState(Action action, float delta, bool valid) {
|
||||||
|
Locker locker(_lock);
|
||||||
_actionStates[toInt(action)] += delta;
|
_actionStates[toInt(action)] += delta;
|
||||||
bool wasValid = _actionStatesValid[toInt(action)];
|
bool wasValid = _actionStatesValid[toInt(action)];
|
||||||
_actionStatesValid[toInt(action)] = wasValid & valid;
|
_actionStatesValid[toInt(action)] = wasValid & valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float UserInputMapper::getActionState(Action action) const {
|
||||||
|
Locker locker(_lock);
|
||||||
|
|
||||||
|
int index = toInt(action);
|
||||||
|
if (index >= 0 && index < _actionStates.size()) {
|
||||||
|
return _actionStates[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
qCDebug(controllers) << "UserInputMapper::getActionState invalid action:" << index;
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UserInputMapper::getActionStateValid(Action action) const {
|
||||||
|
Locker locker(_lock);
|
||||||
|
|
||||||
|
int index = toInt(action);
|
||||||
|
if (index >= 0 && index < _actionStatesValid.size()) {
|
||||||
|
return _actionStatesValid[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
qCDebug(controllers) << "UserInputMapper::getActionStateValid invalid action:" << index;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,8 @@ namespace controller {
|
||||||
QVector<Action> getAllActions() const;
|
QVector<Action> getAllActions() const;
|
||||||
QString getActionName(Action action) const;
|
QString getActionName(Action action) const;
|
||||||
QString getStandardPoseName(uint16_t pose);
|
QString getStandardPoseName(uint16_t pose);
|
||||||
float getActionState(Action action) const { return _actionStates[toInt(action)]; }
|
float getActionState(Action action) const;
|
||||||
bool getActionStateValid(Action action) const { return _actionStatesValid[toInt(action)]; }
|
bool getActionStateValid(Action action) const;
|
||||||
Pose getPoseState(Action action) const;
|
Pose getPoseState(Action action) const;
|
||||||
int findAction(const QString& actionName) const;
|
int findAction(const QString& actionName) const;
|
||||||
QVector<QString> getActionNames() const;
|
QVector<QString> getActionNames() const;
|
||||||
|
|
Loading…
Reference in a new issue