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