mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 22:22:54 +02:00
fix up AvatarActionHold
This commit is contained in:
parent
5ebefadda1
commit
9f40c7bf8c
1 changed files with 65 additions and 140 deletions
|
@ -21,8 +21,7 @@ AvatarActionHold::AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntit
|
||||||
ObjectActionSpring(id, ownerEntity),
|
ObjectActionSpring(id, ownerEntity),
|
||||||
_relativePosition(glm::vec3(0.0f)),
|
_relativePosition(glm::vec3(0.0f)),
|
||||||
_relativeRotation(glm::quat()),
|
_relativeRotation(glm::quat()),
|
||||||
_hand("right"),
|
_hand("right")
|
||||||
_holderID(QUuid())
|
|
||||||
{
|
{
|
||||||
_type = ACTION_TYPE_HOLD;
|
_type = ACTION_TYPE_HOLD;
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
|
@ -37,122 +36,100 @@ AvatarActionHold::~AvatarActionHold() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
bool gotLock = false;
|
|
||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
std::shared_ptr<Avatar> holdingAvatar = nullptr;
|
|
||||||
|
|
||||||
gotLock = withTryReadLock([&]{
|
|
||||||
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
|
|
||||||
AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID);
|
|
||||||
holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData);
|
|
||||||
|
|
||||||
if (holdingAvatar) {
|
|
||||||
glm::vec3 offset;
|
glm::vec3 offset;
|
||||||
|
bool gotLock = withTryReadLock([&]{
|
||||||
|
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
glm::vec3 palmPosition;
|
glm::vec3 palmPosition;
|
||||||
glm::quat palmRotation;
|
glm::quat palmRotation;
|
||||||
if (_hand == "right") {
|
if (_hand == "right") {
|
||||||
palmPosition = holdingAvatar->getRightPalmPosition();
|
palmPosition = myAvatar->getRightPalmPosition();
|
||||||
palmRotation = holdingAvatar->getRightPalmRotation();
|
palmRotation = myAvatar->getRightPalmRotation();
|
||||||
} else {
|
} else {
|
||||||
palmPosition = holdingAvatar->getLeftPalmPosition();
|
palmPosition = myAvatar->getLeftPalmPosition();
|
||||||
palmRotation = holdingAvatar->getLeftPalmRotation();
|
palmRotation = myAvatar->getLeftPalmRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
rotation = palmRotation * _relativeRotation;
|
rotation = palmRotation * _relativeRotation;
|
||||||
offset = rotation * _relativePosition;
|
offset = rotation * _relativePosition;
|
||||||
position = palmPosition + offset;
|
position = palmPosition + offset;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (holdingAvatar) {
|
|
||||||
if (gotLock) {
|
if (gotLock) {
|
||||||
gotLock = withTryWriteLock([&]{
|
gotLock = withTryWriteLock([&]{
|
||||||
|
if (_positionalTarget != position || _rotationalTarget != rotation) {
|
||||||
|
auto ownerEntity = _ownerEntity.lock();
|
||||||
|
if (ownerEntity) {
|
||||||
|
ownerEntity->setActionDataDirty(true);
|
||||||
|
}
|
||||||
_positionalTarget = position;
|
_positionalTarget = position;
|
||||||
_rotationalTarget = rotation;
|
_rotationalTarget = rotation;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gotLock) {
|
if (gotLock) {
|
||||||
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
||||||
glm::vec3 relativePosition;
|
if (!ObjectAction::updateArguments(arguments)) {
|
||||||
glm::quat relativeRotation;
|
return false;
|
||||||
float timeScale;
|
}
|
||||||
QString hand;
|
|
||||||
QUuid holderID;
|
|
||||||
bool needUpdate = false;
|
|
||||||
|
|
||||||
bool somethingChanged = ObjectAction::updateArguments(arguments);
|
|
||||||
withReadLock([&]{
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
relativePosition = EntityActionInterface::extractVec3Argument("hold", arguments, "relativePosition", ok, false);
|
glm::vec3 relativePosition =
|
||||||
|
EntityActionInterface::extractVec3Argument("hold", arguments, "relativePosition", ok, false);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
relativePosition = _relativePosition;
|
relativePosition = _relativePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
ok = true;
|
||||||
relativeRotation = EntityActionInterface::extractQuatArgument("hold", arguments, "relativeRotation", ok, false);
|
glm::quat relativeRotation =
|
||||||
|
EntityActionInterface::extractQuatArgument("hold", arguments, "relativeRotation", ok, false);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
relativeRotation = _relativeRotation;
|
relativeRotation = _relativeRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
ok = true;
|
||||||
timeScale = EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false);
|
float timeScale =
|
||||||
|
EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
timeScale = _linearTimeScale;
|
timeScale = _linearTimeScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
ok = true;
|
||||||
hand = EntityActionInterface::extractStringArgument("hold", arguments, "hand", ok, false);
|
QString hand =
|
||||||
|
EntityActionInterface::extractStringArgument("hold", arguments, "hand", ok, false);
|
||||||
if (!ok || !(hand == "left" || hand == "right")) {
|
if (!ok || !(hand == "left" || hand == "right")) {
|
||||||
hand = _hand;
|
hand = _hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
if (relativePosition != _relativePosition
|
||||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
|
||||||
holderID = myAvatar->getSessionUUID();
|
|
||||||
|
|
||||||
if (somethingChanged ||
|
|
||||||
relativePosition != _relativePosition
|
|
||||||
|| relativeRotation != _relativeRotation
|
|| relativeRotation != _relativeRotation
|
||||||
|| timeScale != _linearTimeScale
|
|| timeScale != _linearTimeScale
|
||||||
|| hand != _hand
|
|| hand != _hand) {
|
||||||
|| holderID != _holderID) {
|
|
||||||
needUpdate = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (needUpdate) {
|
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
_relativePosition = relativePosition;
|
_relativePosition = relativePosition;
|
||||||
_relativeRotation = relativeRotation;
|
_relativeRotation = relativeRotation;
|
||||||
const float MIN_TIMESCALE = 0.1f;
|
const float MIN_TIMESCALE = 0.1f;
|
||||||
_linearTimeScale = glm::max(MIN_TIMESCALE, timeScale);
|
_linearTimeScale = glm::min(MIN_TIMESCALE, timeScale);
|
||||||
_angularTimeScale = _linearTimeScale;
|
_angularTimeScale = _linearTimeScale;
|
||||||
_hand = hand;
|
_hand = hand;
|
||||||
_holderID = holderID;
|
|
||||||
_active = true;
|
_active = true;
|
||||||
|
|
||||||
auto ownerEntity = _ownerEntity.lock();
|
|
||||||
if (ownerEntity) {
|
|
||||||
ownerEntity->setActionDataDirty(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
activateBody();
|
activateBody();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantMap AvatarActionHold::getArguments() {
|
QVariantMap AvatarActionHold::getArguments() {
|
||||||
QVariantMap arguments = ObjectAction::getArguments();
|
QVariantMap arguments = ObjectAction::getArguments();
|
||||||
withReadLock([&]{
|
withReadLock([&]{
|
||||||
arguments["holderID"] = _holderID;
|
|
||||||
arguments["relativePosition"] = glmToQMap(_relativePosition);
|
arguments["relativePosition"] = glmToQMap(_relativePosition);
|
||||||
arguments["relativeRotation"] = glmToQMap(_relativeRotation);
|
arguments["relativeRotation"] = glmToQMap(_relativeRotation);
|
||||||
arguments["timeScale"] = _linearTimeScale;
|
arguments["timeScale"] = _linearTimeScale;
|
||||||
|
@ -162,61 +139,9 @@ QVariantMap AvatarActionHold::getArguments() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray AvatarActionHold::serialize() const {
|
QByteArray AvatarActionHold::serialize() const {
|
||||||
QByteArray serializedActionArguments;
|
return ObjectActionSpring::serialize();
|
||||||
QDataStream dataStream(&serializedActionArguments, QIODevice::WriteOnly);
|
|
||||||
|
|
||||||
withReadLock([&]{
|
|
||||||
dataStream << ACTION_TYPE_HOLD;
|
|
||||||
dataStream << getID();
|
|
||||||
dataStream << AvatarActionHold::holdVersion;
|
|
||||||
|
|
||||||
dataStream << _holderID;
|
|
||||||
dataStream << _relativePosition;
|
|
||||||
dataStream << _relativeRotation;
|
|
||||||
dataStream << _linearTimeScale;
|
|
||||||
dataStream << _hand;
|
|
||||||
|
|
||||||
dataStream << _expires;
|
|
||||||
dataStream << _tag;
|
|
||||||
});
|
|
||||||
|
|
||||||
return serializedActionArguments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
||||||
QDataStream dataStream(serializedArguments);
|
assert(false);
|
||||||
|
|
||||||
EntityActionType type;
|
|
||||||
dataStream >> type;
|
|
||||||
assert(type == getType());
|
|
||||||
|
|
||||||
QUuid id;
|
|
||||||
dataStream >> id;
|
|
||||||
assert(id == getID());
|
|
||||||
|
|
||||||
uint16_t serializationVersion;
|
|
||||||
dataStream >> serializationVersion;
|
|
||||||
if (serializationVersion != AvatarActionHold::holdVersion) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
withWriteLock([&]{
|
|
||||||
dataStream >> _holderID;
|
|
||||||
dataStream >> _relativePosition;
|
|
||||||
dataStream >> _relativeRotation;
|
|
||||||
dataStream >> _linearTimeScale;
|
|
||||||
_angularTimeScale = _linearTimeScale;
|
|
||||||
dataStream >> _hand;
|
|
||||||
|
|
||||||
dataStream >> _expires;
|
|
||||||
dataStream >> _tag;
|
|
||||||
|
|
||||||
#if WANT_DEBUG
|
|
||||||
qDebug() << "deserialize AvatarActionHold: " << _holderID
|
|
||||||
<< _relativePosition.x << _relativePosition.y << _relativePosition.z
|
|
||||||
<< _hand << _expires;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_active = true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue