mirror of
https://github.com/overte-org/overte.git
synced 2025-07-29 21:59:06 +02:00
update AvatarEntity trait when parentID changes
This commit is contained in:
parent
840f3a3a2e
commit
9d11e44b4b
6 changed files with 21 additions and 23 deletions
|
@ -1570,7 +1570,7 @@ void MyAvatar::handleChangedAvatarEntityData() {
|
||||||
entityTree->withWriteLock([&] {
|
entityTree->withWriteLock([&] {
|
||||||
EntityItemPointer entity = entityTree->addEntity(id, properties);
|
EntityItemPointer entity = entityTree->addEntity(id, properties);
|
||||||
if (entity) {
|
if (entity) {
|
||||||
packetSender->queueEditEntityMessage(PacketType::EntityAdd, entityTree, id, properties);
|
packetSender->queueEditAvatarEntityMessage(entityTree, id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -3451,10 +3451,10 @@ float MyAvatar::getGravity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::setSessionUUID(const QUuid& sessionUUID) {
|
void MyAvatar::setSessionUUID(const QUuid& sessionUUID) {
|
||||||
QUuid oldID = getSessionUUID();
|
QUuid oldSessionID = getSessionUUID();
|
||||||
Avatar::setSessionUUID(sessionUUID);
|
Avatar::setSessionUUID(sessionUUID);
|
||||||
QUuid id = getSessionUUID();
|
QUuid newSessionID = getSessionUUID();
|
||||||
if (id != oldID) {
|
if (newSessionID != oldSessionID) {
|
||||||
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
||||||
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
||||||
if (entityTree) {
|
if (entityTree) {
|
||||||
|
@ -3462,15 +3462,20 @@ void MyAvatar::setSessionUUID(const QUuid& sessionUUID) {
|
||||||
_avatarEntitiesLock.withReadLock([&] {
|
_avatarEntitiesLock.withReadLock([&] {
|
||||||
avatarEntityIDs = _packedAvatarEntityData.keys();
|
avatarEntityIDs = _packedAvatarEntityData.keys();
|
||||||
});
|
});
|
||||||
|
EntityEditPacketSender* packetSender = qApp->getEntityEditPacketSender();
|
||||||
entityTree->withWriteLock([&] {
|
entityTree->withWriteLock([&] {
|
||||||
for (const auto& entityID : avatarEntityIDs) {
|
for (const auto& entityID : avatarEntityIDs) {
|
||||||
auto entity = entityTree->findEntityByID(entityID);
|
auto entity = entityTree->findEntityByID(entityID);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
entity->setOwningAvatarID(id);
|
entity->setOwningAvatarID(newSessionID);
|
||||||
if (entity->getParentID() == oldID) {
|
// NOTE: each attached AvatarEntity should already have the correct updated parentID
|
||||||
entity->setParentID(id);
|
// via magic in SpatiallyNestable, but when an AvatarEntity IS parented to MyAvatar
|
||||||
|
// we need to update the "packedAvatarEntityData" we send to the avatar-mixer
|
||||||
|
// so that others will get the updated state.
|
||||||
|
if (entity->getParentID() == newSessionID) {
|
||||||
|
packetSender->queueEditAvatarEntityMessage(entityTree, entityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -5523,14 +5528,14 @@ void MyAvatar::initFlowFromFST() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::sendPacket(const QUuid& entityID, const EntityItemProperties& properties) const {
|
void MyAvatar::sendPacket(const QUuid& entityID) const {
|
||||||
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
||||||
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
||||||
if (entityTree) {
|
if (entityTree) {
|
||||||
entityTree->withWriteLock([&] {
|
entityTree->withWriteLock([&] {
|
||||||
// force an update packet
|
// force an update packet
|
||||||
EntityEditPacketSender* packetSender = qApp->getEntityEditPacketSender();
|
EntityEditPacketSender* packetSender = qApp->getEntityEditPacketSender();
|
||||||
packetSender->queueEditEntityMessage(PacketType::EntityEdit, entityTree, entityID, properties);
|
packetSender->queueEditAvatarEntityMessage(entityTree, entityID);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1918,7 +1918,7 @@ private:
|
||||||
bool didTeleport();
|
bool didTeleport();
|
||||||
bool getIsAway() const { return _isAway; }
|
bool getIsAway() const { return _isAway; }
|
||||||
void setAway(bool value);
|
void setAway(bool value);
|
||||||
void sendPacket(const QUuid& entityID, const EntityItemProperties& properties) const override;
|
void sendPacket(const QUuid& entityID) const override;
|
||||||
|
|
||||||
std::mutex _pinnedJointsMutex;
|
std::mutex _pinnedJointsMutex;
|
||||||
std::vector<int> _pinnedJoints;
|
std::vector<int> _pinnedJoints;
|
||||||
|
|
|
@ -376,7 +376,7 @@ bool Avatar::applyGrabChanges() {
|
||||||
const EntityItemPointer& entity = std::dynamic_pointer_cast<EntityItem>(target);
|
const EntityItemPointer& entity = std::dynamic_pointer_cast<EntityItem>(target);
|
||||||
if (entity && entity->getEntityHostType() == entity::HostType::AVATAR && entity->getSimulationOwner().getID() == getID()) {
|
if (entity && entity->getEntityHostType() == entity::HostType::AVATAR && entity->getSimulationOwner().getID() == getID()) {
|
||||||
EntityItemProperties properties = entity->getProperties();
|
EntityItemProperties properties = entity->getProperties();
|
||||||
sendPacket(entity->getID(), properties);
|
sendPacket(entity->getID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -605,7 +605,7 @@ protected:
|
||||||
|
|
||||||
// protected methods...
|
// protected methods...
|
||||||
bool isLookingAtMe(AvatarSharedPointer avatar) const;
|
bool isLookingAtMe(AvatarSharedPointer avatar) const;
|
||||||
virtual void sendPacket(const QUuid& entityID, const EntityItemProperties& properties) const { }
|
virtual void sendPacket(const QUuid& entityID) const { }
|
||||||
bool applyGrabChanges();
|
bool applyGrabChanges();
|
||||||
void relayJointDataToChildren();
|
void relayJointDataToChildren();
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,7 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, QByte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityEditPacketSender::queueEditAvatarEntityMessage(EntityTreePointer entityTree,
|
void EntityEditPacketSender::queueEditAvatarEntityMessage(EntityTreePointer entityTree, EntityItemID entityItemID) {
|
||||||
EntityItemID entityItemID,
|
|
||||||
const EntityItemProperties& properties) {
|
|
||||||
assert(_myAvatar);
|
assert(_myAvatar);
|
||||||
if (!entityTree) {
|
if (!entityTree) {
|
||||||
qCDebug(entities) << "EntityEditPacketSender::queueEditAvatarEntityMessage null entityTree.";
|
qCDebug(entities) << "EntityEditPacketSender::queueEditAvatarEntityMessage null entityTree.";
|
||||||
|
@ -54,11 +52,6 @@ void EntityEditPacketSender::queueEditAvatarEntityMessage(EntityTreePointer enti
|
||||||
}
|
}
|
||||||
entity->setLastBroadcast(usecTimestampNow());
|
entity->setLastBroadcast(usecTimestampNow());
|
||||||
|
|
||||||
// serialize ALL properties in an "AvatarEntity" packet
|
|
||||||
// rather than just the ones being edited.
|
|
||||||
EntityItemProperties entityProperties = entity->getProperties();
|
|
||||||
entityProperties.merge(properties);
|
|
||||||
|
|
||||||
OctreePacketData packetData(false, AvatarTraits::MAXIMUM_TRAIT_SIZE);
|
OctreePacketData packetData(false, AvatarTraits::MAXIMUM_TRAIT_SIZE);
|
||||||
EncodeBitstreamParams params;
|
EncodeBitstreamParams params;
|
||||||
EntityTreeElementExtraEncodeDataPointer extra { nullptr };
|
EntityTreeElementExtraEncodeDataPointer extra { nullptr };
|
||||||
|
@ -82,7 +75,7 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type,
|
||||||
qCWarning(entities) << "Suppressing entity edit message: cannot send avatar entity edit with no myAvatar";
|
qCWarning(entities) << "Suppressing entity edit message: cannot send avatar entity edit with no myAvatar";
|
||||||
} else if (properties.getOwningAvatarID() == _myAvatar->getID()) {
|
} else if (properties.getOwningAvatarID() == _myAvatar->getID()) {
|
||||||
// this is an avatar-based entity --> update our avatar-data rather than sending to the entity-server
|
// this is an avatar-based entity --> update our avatar-data rather than sending to the entity-server
|
||||||
queueEditAvatarEntityMessage(entityTree, entityItemID, properties);
|
queueEditAvatarEntityMessage(entityTree, entityItemID);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(entities) << "Suppressing entity edit message: cannot send avatar entity edit for another avatar";
|
qCWarning(entities) << "Suppressing entity edit message: cannot send avatar entity edit for another avatar";
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,8 @@ public slots:
|
||||||
void processEntityEditNackPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode);
|
void processEntityEditNackPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void queueEditAvatarEntityMessage(EntityTreePointer entityTree,
|
friend class MyAvatar;
|
||||||
EntityItemID entityItemID, const EntityItemProperties& properties);
|
void queueEditAvatarEntityMessage(EntityTreePointer entityTree, EntityItemID entityItemID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex _mutex;
|
std::mutex _mutex;
|
||||||
|
|
Loading…
Reference in a new issue