mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 00:17:25 +02:00
clean up code, change try-locks to locks
This commit is contained in:
parent
d3c57821c0
commit
8bfbb69316
2 changed files with 31 additions and 59 deletions
|
@ -33,6 +33,19 @@ AvatarActionHold::~AvatarActionHold() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 AvatarActionHold::getAvatarRigidBodyPosition() {
|
||||||
|
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
|
MyCharacterController* controller = myAvatar ? myAvatar->getCharacterController() : nullptr;
|
||||||
|
if (!controller) {
|
||||||
|
qDebug() << "AvatarActionHold::getAvatarRigidBodyPosition failed to get character controller";
|
||||||
|
return glm::vec3(0.0f);
|
||||||
|
}
|
||||||
|
glm::vec3 avatarRigidBodyPosition;
|
||||||
|
glm::quat avatarRigidBodyRotation;
|
||||||
|
controller->getRigidBodyLocation(avatarRigidBodyPosition, avatarRigidBodyRotation);
|
||||||
|
return avatarRigidBodyPosition;
|
||||||
|
}
|
||||||
|
|
||||||
void AvatarActionHold::prepareForPhysicsSimulation() {
|
void AvatarActionHold::prepareForPhysicsSimulation() {
|
||||||
auto avatarManager = DependencyManager::get<AvatarManager>();
|
auto avatarManager = DependencyManager::get<AvatarManager>();
|
||||||
auto holdingAvatar = std::static_pointer_cast<Avatar>(avatarManager->getAvatarBySessionID(_holderID));
|
auto holdingAvatar = std::static_pointer_cast<Avatar>(avatarManager->getAvatarBySessionID(_holderID));
|
||||||
|
@ -41,45 +54,14 @@ void AvatarActionHold::prepareForPhysicsSimulation() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
withTryReadLock([&]{
|
withReadLock([&]{
|
||||||
bool isRightHand = (_hand == "right");
|
|
||||||
|
|
||||||
if (_ignoreIK && holdingAvatar->isMyAvatar()) {
|
if (_ignoreIK && holdingAvatar->isMyAvatar()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (holdingAvatar->isMyAvatar()) {
|
if (holdingAvatar->isMyAvatar()) {
|
||||||
glm::vec3 palmPosition { Vectors::ZERO };
|
glm::vec3 palmPosition = (_hand == "right") ?
|
||||||
glm::quat palmRotation { Quaternions::IDENTITY };
|
holdingAvatar->getRightPalmPosition() : holdingAvatar->getLeftPalmPosition();
|
||||||
if (isRightHand) {
|
_palmOffsetFromRigidBody = palmPosition - getAvatarRigidBodyPosition();
|
||||||
palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getPosition();
|
|
||||||
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getRotation();
|
|
||||||
} else {
|
|
||||||
palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition();
|
|
||||||
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation();
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX dup code
|
|
||||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
|
||||||
MyCharacterController* controller = myAvatar ? myAvatar->getCharacterController() : nullptr;
|
|
||||||
if (!controller) {
|
|
||||||
qDebug() << "AvatarActionHold::prepareForPhysicsSimulation failed to get character controller";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
glm::vec3 avatarRigidBodyPosition;
|
|
||||||
glm::quat avatarRigidBodyRotation;
|
|
||||||
controller->getRigidBodyLocation(avatarRigidBodyPosition, avatarRigidBodyRotation);
|
|
||||||
|
|
||||||
|
|
||||||
if (isRightHand) {
|
|
||||||
palmPosition = holdingAvatar->getRightPalmPosition();
|
|
||||||
palmRotation = holdingAvatar->getRightPalmRotation();
|
|
||||||
} else {
|
|
||||||
palmPosition = holdingAvatar->getLeftPalmPosition();
|
|
||||||
palmRotation = holdingAvatar->getLeftPalmRotation();
|
|
||||||
}
|
|
||||||
|
|
||||||
_palmOffsetFromRigidBody = palmPosition - avatarRigidBodyPosition;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -92,7 +74,7 @@ std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::ve
|
||||||
return holdingAvatar;
|
return holdingAvatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
withTryReadLock([&]{
|
withReadLock([&]{
|
||||||
bool isRightHand = (_hand == "right");
|
bool isRightHand = (_hand == "right");
|
||||||
glm::vec3 palmPosition { Vectors::ZERO };
|
glm::vec3 palmPosition { Vectors::ZERO };
|
||||||
glm::quat palmRotation { Quaternions::IDENTITY };
|
glm::quat palmRotation { Quaternions::IDENTITY };
|
||||||
|
@ -108,21 +90,12 @@ std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::ve
|
||||||
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation();
|
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation();
|
||||||
}
|
}
|
||||||
} else if (holdingAvatar->isMyAvatar()) {
|
} else if (holdingAvatar->isMyAvatar()) {
|
||||||
// XXX dup code
|
palmPosition = getAvatarRigidBodyPosition() + _palmOffsetFromRigidBody;
|
||||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
if (isRightHand) {
|
||||||
MyCharacterController* controller = myAvatar ? myAvatar->getCharacterController() : nullptr;
|
palmRotation = holdingAvatar->getRightPalmRotation();
|
||||||
if (!controller) {
|
} else {
|
||||||
qDebug() << "AvatarActionHold::prepareForPhysicsSimulation failed to get character controller";
|
palmRotation = holdingAvatar->getLeftPalmRotation();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
glm::vec3 avatarRigidBodyPosition;
|
|
||||||
glm::quat avatarRigidBodyRotation;
|
|
||||||
controller->getRigidBodyLocation(avatarRigidBodyPosition, avatarRigidBodyRotation);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
palmPosition = avatarRigidBodyPosition + _palmOffsetFromRigidBody;
|
|
||||||
palmRotation = holdingAvatar->getRightPalmRotation(); // XXX
|
|
||||||
} else {
|
} else {
|
||||||
if (isRightHand) {
|
if (isRightHand) {
|
||||||
palmPosition = holdingAvatar->getRightPalmPosition();
|
palmPosition = holdingAvatar->getRightPalmPosition();
|
||||||
|
@ -171,21 +144,19 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
if (valid && holdCount > 0) {
|
if (valid && holdCount > 0) {
|
||||||
position /= holdCount;
|
position /= holdCount;
|
||||||
|
|
||||||
bool gotLock = withTryWriteLock([&]{
|
withWriteLock([&]{
|
||||||
_positionalTarget = position;
|
_positionalTarget = position;
|
||||||
_rotationalTarget = rotation;
|
_rotationalTarget = rotation;
|
||||||
_positionalTargetSet = true;
|
_positionalTargetSet = true;
|
||||||
_rotationalTargetSet = true;
|
_rotationalTargetSet = true;
|
||||||
_active = true;
|
_active = true;
|
||||||
});
|
});
|
||||||
if (gotLock) {
|
if (_kinematic) {
|
||||||
if (_kinematic) {
|
doKinematicUpdate(deltaTimeStep);
|
||||||
doKinematicUpdate(deltaTimeStep);
|
} else {
|
||||||
} else {
|
activateBody();
|
||||||
activateBody();
|
forceBodyNonStatic();
|
||||||
forceBodyNonStatic();
|
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
||||||
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
|
|
||||||
virtual bool shouldSuppressLocationEdits() override { return _active && !_ownerEntity.expired(); }
|
virtual bool shouldSuppressLocationEdits() override { return _active && !_ownerEntity.expired(); }
|
||||||
|
|
||||||
|
glm::vec3 getAvatarRigidBodyPosition();
|
||||||
std::shared_ptr<Avatar> getTarget(glm::quat& rotation, glm::vec3& position);
|
std::shared_ptr<Avatar> getTarget(glm::quat& rotation, glm::vec3& position);
|
||||||
|
|
||||||
virtual void prepareForPhysicsSimulation() override;
|
virtual void prepareForPhysicsSimulation() override;
|
||||||
|
|
Loading…
Reference in a new issue