mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 05:04:44 +02:00
Renamed ThreadSafeValue to ThreadSafeValueCache
Also bug fixes where I was incorrectly swapping left and right hands.
This commit is contained in:
parent
e7f3f549a5
commit
17e6a04aa8
3 changed files with 31 additions and 27 deletions
|
@ -1130,22 +1130,22 @@ void Avatar::rebuildCollisionShape() {
|
|||
|
||||
// thread-safe
|
||||
glm::vec3 Avatar::getLeftPalmPosition() {
|
||||
return _leftPalmPosition.get();
|
||||
return _leftPalmPositionCache.get();
|
||||
}
|
||||
|
||||
// thread-safe
|
||||
glm::quat Avatar::getLeftPalmRotation() {
|
||||
return _leftPalmRotation.get();
|
||||
return _leftPalmRotationCache.get();
|
||||
}
|
||||
|
||||
// thread-safe
|
||||
glm::vec3 Avatar::getRightPalmPosition() {
|
||||
return _rightPalmPosition.get();
|
||||
return _rightPalmPositionCache.get();
|
||||
}
|
||||
|
||||
// thread-safe
|
||||
glm::quat Avatar::getRightPalmRotation() {
|
||||
return _rightPalmRotation.get();
|
||||
return _rightPalmRotationCache.get();
|
||||
}
|
||||
|
||||
void Avatar::setPosition(const glm::vec3& position) {
|
||||
|
@ -1163,7 +1163,7 @@ void Avatar::updatePalms() {
|
|||
// get palm rotations
|
||||
glm::quat leftPalmRotation, rightPalmRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftPalmRotation);
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), rightPalmRotation);
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightPalmRotation);
|
||||
|
||||
// get palm positions
|
||||
glm::vec3 leftPalmPosition, rightPalmPosition;
|
||||
|
@ -1172,21 +1172,21 @@ void Avatar::updatePalms() {
|
|||
leftPalmPosition += HAND_TO_PALM_OFFSET * glm::inverse(leftPalmRotation);
|
||||
rightPalmPosition += HAND_TO_PALM_OFFSET * glm::inverse(rightPalmRotation);
|
||||
|
||||
// update thread-safe values
|
||||
_leftPalmRotation.update([&](glm::quat& value, bool hasPending, const glm::quat& pendingValue) {
|
||||
// update thread-safe cache values
|
||||
_leftPalmRotationCache.update([&](glm::quat& value, bool hasPending, const glm::quat& pendingValue) {
|
||||
value = leftPalmRotation;
|
||||
return false;
|
||||
});
|
||||
_rightPalmRotation.update([&](glm::quat& value, bool hasPending, const glm::quat& pendingValue) {
|
||||
_rightPalmRotationCache.update([&](glm::quat& value, bool hasPending, const glm::quat& pendingValue) {
|
||||
value = rightPalmRotation;
|
||||
return false;
|
||||
});
|
||||
_leftPalmPosition.update([&](glm::vec3& value, bool hasPending, const glm::vec3& pendingValue) {
|
||||
value = rightPalmPosition;
|
||||
return false;
|
||||
});
|
||||
_rightPalmPosition.update([&](glm::vec3& value, bool hasPending, const glm::vec3& pendingValue) {
|
||||
_leftPalmPositionCache.update([&](glm::vec3& value, bool hasPending, const glm::vec3& pendingValue) {
|
||||
value = leftPalmPosition;
|
||||
return false;
|
||||
});
|
||||
_rightPalmPositionCache.update([&](glm::vec3& value, bool hasPending, const glm::vec3& pendingValue) {
|
||||
value = rightPalmPosition;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "SkeletonModel.h"
|
||||
#include "world.h"
|
||||
#include "Rig.h"
|
||||
#include <ThreadSafeValue.h>
|
||||
#include <ThreadSafeValueCache.h>
|
||||
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const AvatarSharedPointer& avatar);
|
||||
|
@ -230,10 +230,10 @@ protected:
|
|||
|
||||
render::ItemID _renderItemID;
|
||||
|
||||
ThreadSafeValue<glm::vec3> _leftPalmPosition { glm::vec3() };
|
||||
ThreadSafeValue<glm::quat> _leftPalmRotation { glm::quat() };
|
||||
ThreadSafeValue<glm::vec3> _rightPalmPosition { glm::vec3() };
|
||||
ThreadSafeValue<glm::quat> _rightPalmRotation { glm::quat() };
|
||||
ThreadSafeValueCache<glm::vec3> _leftPalmPositionCache { glm::vec3() };
|
||||
ThreadSafeValueCache<glm::quat> _leftPalmRotationCache { glm::quat() };
|
||||
ThreadSafeValueCache<glm::vec3> _rightPalmPositionCache { glm::vec3() };
|
||||
ThreadSafeValueCache<glm::quat> _rightPalmRotationCache { glm::quat() };
|
||||
|
||||
private:
|
||||
bool _initialized;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// ThreadSafeValue.h
|
||||
// ThreadSafeValueCache.h
|
||||
// interface/src/avatar
|
||||
//
|
||||
// Copyright 2012 High Fidelity, Inc.
|
||||
|
@ -8,15 +8,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_ThreadSafeValue_h
|
||||
#define hifi_ThreadSafeValue_h
|
||||
#ifndef hifi_ThreadSafeValueCache_h
|
||||
#define hifi_ThreadSafeValueCache_h
|
||||
|
||||
#include <mutex>
|
||||
|
||||
template <typename T>
|
||||
class ThreadSafeValue {
|
||||
class ThreadSafeValueCache {
|
||||
public:
|
||||
ThreadSafeValue(const T& v) : _value { v }, _pending { v }, _hasPending { false } {}
|
||||
ThreadSafeValueCache(const T& v) : _value { v }, _pending { v }, _hasPending { false } {}
|
||||
|
||||
template <typename F>
|
||||
void update(const F& callback) {
|
||||
|
@ -26,7 +26,11 @@ public:
|
|||
|
||||
T get() const {
|
||||
std::lock_guard<std::mutex> guard(_mutex);
|
||||
return _value;
|
||||
if (_hasPending) {
|
||||
return _pending;
|
||||
} else {
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
|
||||
void set(const T& v) {
|
||||
|
@ -42,8 +46,8 @@ private:
|
|||
bool _hasPending;
|
||||
|
||||
// no copies
|
||||
ThreadSafeValue(const ThreadSafeValue&) = delete;
|
||||
ThreadSafeValue& operator=(const ThreadSafeValue&) = delete;
|
||||
ThreadSafeValueCache(const ThreadSafeValueCache&) = delete;
|
||||
ThreadSafeValueCache& operator=(const ThreadSafeValueCache&) = delete;
|
||||
};
|
||||
|
||||
#endif // #define hifi_ThreadSafeValue_h
|
||||
#endif // #define hifi_ThreadSafeValueCache_h
|
Loading…
Reference in a new issue