mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 00:13:29 +02:00
switch to low-entity-server traffic hold
This commit is contained in:
parent
c884f466bc
commit
1d8db13f41
2 changed files with 95 additions and 36 deletions
|
@ -21,7 +21,8 @@ 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
|
||||||
|
@ -39,39 +40,41 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
bool gotLock = false;
|
bool gotLock = false;
|
||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 offset;
|
std::shared_ptr<Avatar> holdingAvatar = nullptr;
|
||||||
|
|
||||||
gotLock = withTryReadLock([&]{
|
gotLock = withTryReadLock([&]{
|
||||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
|
||||||
glm::vec3 palmPosition;
|
AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID);
|
||||||
glm::quat palmRotation;
|
holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData);
|
||||||
if (_hand == "right") {
|
|
||||||
palmPosition = myAvatar->getRightPalmPosition();
|
|
||||||
palmRotation = myAvatar->getRightPalmRotation();
|
|
||||||
} else {
|
|
||||||
palmPosition = myAvatar->getLeftPalmPosition();
|
|
||||||
palmRotation = myAvatar->getLeftPalmRotation();
|
|
||||||
}
|
|
||||||
|
|
||||||
rotation = palmRotation * _relativeRotation;
|
if (holdingAvatar) {
|
||||||
offset = rotation * _relativePosition;
|
glm::vec3 offset;
|
||||||
position = palmPosition + offset;
|
glm::vec3 palmPosition;
|
||||||
|
glm::quat palmRotation;
|
||||||
|
if (_hand == "right") {
|
||||||
|
palmPosition = holdingAvatar->getRightPalmPosition();
|
||||||
|
palmRotation = holdingAvatar->getRightPalmRotation();
|
||||||
|
} else {
|
||||||
|
palmPosition = holdingAvatar->getLeftPalmPosition();
|
||||||
|
palmRotation = holdingAvatar->getLeftPalmRotation();
|
||||||
|
}
|
||||||
|
|
||||||
|
rotation = palmRotation * _relativeRotation;
|
||||||
|
offset = rotation * _relativePosition;
|
||||||
|
position = palmPosition + offset;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (gotLock) {
|
if (holdingAvatar) {
|
||||||
gotLock = withTryWriteLock([&]{
|
if (gotLock) {
|
||||||
_positionalTarget = position;
|
gotLock = withTryWriteLock([&]{
|
||||||
_rotationalTarget = rotation;
|
_positionalTarget = position;
|
||||||
_positionalTargetSet = true;
|
_rotationalTarget = rotation;
|
||||||
_rotationalTargetSet = true;
|
});
|
||||||
auto ownerEntity = _ownerEntity.lock();
|
}
|
||||||
if (ownerEntity) {
|
if (gotLock) {
|
||||||
ownerEntity->setActionDataDirty(true);
|
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
if (gotLock) {
|
|
||||||
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,10 +118,11 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
||||||
holderID = myAvatar->getSessionUUID();
|
holderID = myAvatar->getSessionUUID();
|
||||||
|
|
||||||
if (somethingChanged ||
|
if (somethingChanged ||
|
||||||
relativePosition != _relativePosition ||
|
relativePosition != _relativePosition
|
||||||
relativeRotation != _relativeRotation ||
|
|| relativeRotation != _relativeRotation
|
||||||
timeScale != _linearTimeScale ||
|
|| timeScale != _linearTimeScale
|
||||||
hand != _hand) {
|
|| hand != _hand
|
||||||
|
|| holderID != _holderID) {
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -131,6 +135,7 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
||||||
_linearTimeScale = glm::max(MIN_TIMESCALE, timeScale);
|
_linearTimeScale = glm::max(MIN_TIMESCALE, timeScale);
|
||||||
_angularTimeScale = _linearTimeScale;
|
_angularTimeScale = _linearTimeScale;
|
||||||
_hand = hand;
|
_hand = hand;
|
||||||
|
_holderID = holderID;
|
||||||
_active = true;
|
_active = true;
|
||||||
|
|
||||||
auto ownerEntity = _ownerEntity.lock();
|
auto ownerEntity = _ownerEntity.lock();
|
||||||
|
@ -147,6 +152,7 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
||||||
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;
|
||||||
|
@ -156,9 +162,61 @@ QVariantMap AvatarActionHold::getArguments() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray AvatarActionHold::serialize() const {
|
QByteArray AvatarActionHold::serialize() const {
|
||||||
return ObjectActionSpring::serialize();
|
QByteArray serializedActionArguments;
|
||||||
|
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) {
|
||||||
assert(false);
|
QDataStream dataStream(serializedArguments);
|
||||||
|
|
||||||
|
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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
QByteArray serialize() const;
|
QByteArray serialize() const;
|
||||||
virtual void deserialize(QByteArray serializedArguments);
|
virtual void deserialize(QByteArray serializedArguments);
|
||||||
|
|
||||||
virtual bool shouldSuppressLocationEdits() { return false; }
|
virtual bool shouldSuppressLocationEdits() { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const uint16_t holdVersion;
|
static const uint16_t holdVersion;
|
||||||
|
@ -38,6 +38,7 @@ private:
|
||||||
glm::vec3 _relativePosition;
|
glm::vec3 _relativePosition;
|
||||||
glm::quat _relativeRotation;
|
glm::quat _relativeRotation;
|
||||||
QString _hand;
|
QString _hand;
|
||||||
|
QUuid _holderID;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AvatarActionHold_h
|
#endif // hifi_AvatarActionHold_h
|
||||||
|
|
Loading…
Reference in a new issue