mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:48:09 +02:00
Merge pull request #13980 from birarda/bug/parented-traited-entities
revert avatar entity XORing, perform avatar entity cleanup in handleRemovedAvatar
This commit is contained in:
commit
d5456eda6c
9 changed files with 32 additions and 78 deletions
|
@ -443,6 +443,11 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar
|
||||||
avatar->die();
|
avatar->die();
|
||||||
queuePhysicsChange(avatar);
|
queuePhysicsChange(avatar);
|
||||||
|
|
||||||
|
// remove this avatar's entities from the tree now, if we wait (as we did previously) for this Avatar's destructor
|
||||||
|
// it might not fire until after we create a new instance for the same remote avatar, which creates a race
|
||||||
|
// on the creation of entities for that avatar instance and the deletion of entities for this instance
|
||||||
|
avatar->removeAvatarEntitiesFromTree();
|
||||||
|
|
||||||
if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble) {
|
if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble) {
|
||||||
emit DependencyManager::get<UsersScriptingInterface>()->enteredIgnoreRadius();
|
emit DependencyManager::get<UsersScriptingInterface>()->enteredIgnoreRadius();
|
||||||
} else if (removalReason == KillAvatarReason::AvatarDisconnected) {
|
} else if (removalReason == KillAvatarReason::AvatarDisconnected) {
|
||||||
|
|
|
@ -131,16 +131,6 @@ Avatar::Avatar(QThread* thread) :
|
||||||
}
|
}
|
||||||
|
|
||||||
Avatar::~Avatar() {
|
Avatar::~Avatar() {
|
||||||
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
|
||||||
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
|
||||||
if (entityTree) {
|
|
||||||
entityTree->withWriteLock([&] {
|
|
||||||
AvatarEntityMap avatarEntities = getAvatarEntityData();
|
|
||||||
for (auto entityID : avatarEntities.keys()) {
|
|
||||||
entityTree->deleteEntity(entityID, true, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
if (geometryCache) {
|
if (geometryCache) {
|
||||||
geometryCache->releaseID(_nameRectGeometryID);
|
geometryCache->releaseID(_nameRectGeometryID);
|
||||||
|
@ -385,6 +375,19 @@ void Avatar::updateAvatarEntities() {
|
||||||
setAvatarEntityDataChanged(false);
|
setAvatarEntityDataChanged(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Avatar::removeAvatarEntitiesFromTree() {
|
||||||
|
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
||||||
|
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
||||||
|
if (entityTree) {
|
||||||
|
entityTree->withWriteLock([&] {
|
||||||
|
AvatarEntityMap avatarEntities = getAvatarEntityData();
|
||||||
|
for (auto entityID : avatarEntities.keys()) {
|
||||||
|
entityTree->deleteEntity(entityID, true, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Avatar::relayJointDataToChildren() {
|
void Avatar::relayJointDataToChildren() {
|
||||||
forEachChild([&](SpatiallyNestablePointer child) {
|
forEachChild([&](SpatiallyNestablePointer child) {
|
||||||
if (child->getNestableType() == NestableType::Entity) {
|
if (child->getNestableType() == NestableType::Entity) {
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void updateAvatarEntities();
|
void updateAvatarEntities();
|
||||||
|
void removeAvatarEntitiesFromTree();
|
||||||
void simulate(float deltaTime, bool inView);
|
void simulate(float deltaTime, bool inView);
|
||||||
virtual void simulateAttachments(float deltaTime);
|
virtual void simulateAttachments(float deltaTime);
|
||||||
|
|
||||||
|
|
|
@ -1861,9 +1861,7 @@ qint64 AvatarData::packTrait(AvatarTraits::TraitType traitType, ExtendedIODevice
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 AvatarData::packTraitInstance(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID traitInstanceID,
|
qint64 AvatarData::packTraitInstance(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID traitInstanceID,
|
||||||
ExtendedIODevice& destination, AvatarTraits::TraitVersion traitVersion,
|
ExtendedIODevice& destination, AvatarTraits::TraitVersion traitVersion) {
|
||||||
AvatarTraits::TraitInstanceID wireInstanceID) {
|
|
||||||
|
|
||||||
qint64 bytesWritten = 0;
|
qint64 bytesWritten = 0;
|
||||||
|
|
||||||
bytesWritten += destination.writePrimitive(traitType);
|
bytesWritten += destination.writePrimitive(traitType);
|
||||||
|
@ -1872,11 +1870,7 @@ qint64 AvatarData::packTraitInstance(AvatarTraits::TraitType traitType, AvatarTr
|
||||||
bytesWritten += destination.writePrimitive(traitVersion);
|
bytesWritten += destination.writePrimitive(traitVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wireInstanceID.isNull()) {
|
bytesWritten += destination.write(traitInstanceID.toRfc4122());
|
||||||
bytesWritten += destination.write(wireInstanceID.toRfc4122());
|
|
||||||
} else {
|
|
||||||
bytesWritten += destination.write(traitInstanceID.toRfc4122());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (traitType == AvatarTraits::AvatarEntity) {
|
if (traitType == AvatarTraits::AvatarEntity) {
|
||||||
// grab a read lock on the avatar entities and check for entity data for the given ID
|
// grab a read lock on the avatar entities and check for entity data for the given ID
|
||||||
|
|
|
@ -962,8 +962,7 @@ public:
|
||||||
qint64 packTrait(AvatarTraits::TraitType traitType, ExtendedIODevice& destination,
|
qint64 packTrait(AvatarTraits::TraitType traitType, ExtendedIODevice& destination,
|
||||||
AvatarTraits::TraitVersion traitVersion = AvatarTraits::NULL_TRAIT_VERSION);
|
AvatarTraits::TraitVersion traitVersion = AvatarTraits::NULL_TRAIT_VERSION);
|
||||||
qint64 packTraitInstance(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID instanceID,
|
qint64 packTraitInstance(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID instanceID,
|
||||||
ExtendedIODevice& destination, AvatarTraits::TraitVersion traitVersion = AvatarTraits::NULL_TRAIT_VERSION,
|
ExtendedIODevice& destination, AvatarTraits::TraitVersion traitVersion = AvatarTraits::NULL_TRAIT_VERSION);
|
||||||
AvatarTraits::TraitInstanceID wireInstanceID = AvatarTraits::TraitInstanceID());
|
|
||||||
|
|
||||||
void prepareResetTraitInstances();
|
void prepareResetTraitInstances();
|
||||||
|
|
||||||
|
@ -1193,9 +1192,6 @@ public:
|
||||||
void setReplicaIndex(int replicaIndex) { _replicaIndex = replicaIndex; }
|
void setReplicaIndex(int replicaIndex) { _replicaIndex = replicaIndex; }
|
||||||
int getReplicaIndex() { return _replicaIndex; }
|
int getReplicaIndex() { return _replicaIndex; }
|
||||||
|
|
||||||
const AvatarTraits::TraitInstanceID getTraitInstanceXORID() const { return _traitInstanceXORID; }
|
|
||||||
void cycleTraitInstanceXORID() { _traitInstanceXORID = QUuid::createUuid(); }
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
|
@ -1502,8 +1498,6 @@ private:
|
||||||
// privatize the copy constructor and assignment operator so they cannot be called
|
// privatize the copy constructor and assignment operator so they cannot be called
|
||||||
AvatarData(const AvatarData&);
|
AvatarData(const AvatarData&);
|
||||||
AvatarData& operator= (const AvatarData&);
|
AvatarData& operator= (const AvatarData&);
|
||||||
|
|
||||||
AvatarTraits::TraitInstanceID _traitInstanceXORID { QUuid::createUuid() };
|
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(AvatarData*)
|
Q_DECLARE_METATYPE(AvatarData*)
|
||||||
|
|
||||||
|
|
|
@ -86,8 +86,7 @@ void AvatarReplicas::processDeletedTraitInstance(const QUuid& parentID, AvatarTr
|
||||||
if (_replicasMap.find(parentID) != _replicasMap.end()) {
|
if (_replicasMap.find(parentID) != _replicasMap.end()) {
|
||||||
auto &replicas = _replicasMap[parentID];
|
auto &replicas = _replicasMap[parentID];
|
||||||
for (auto avatar : replicas) {
|
for (auto avatar : replicas) {
|
||||||
avatar->processDeletedTraitInstance(traitType,
|
avatar->processDeletedTraitInstance(traitType, instanceID);
|
||||||
AvatarTraits::xoredInstanceID(instanceID, avatar->getTraitInstanceXORID()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,9 +95,7 @@ void AvatarReplicas::processTraitInstance(const QUuid& parentID, AvatarTraits::T
|
||||||
if (_replicasMap.find(parentID) != _replicasMap.end()) {
|
if (_replicasMap.find(parentID) != _replicasMap.end()) {
|
||||||
auto &replicas = _replicasMap[parentID];
|
auto &replicas = _replicasMap[parentID];
|
||||||
for (auto avatar : replicas) {
|
for (auto avatar : replicas) {
|
||||||
avatar->processTraitInstance(traitType,
|
avatar->processTraitInstance(traitType, instanceID, traitBinaryData);
|
||||||
AvatarTraits::xoredInstanceID(instanceID, avatar->getTraitInstanceXORID()),
|
|
||||||
traitBinaryData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,28 +343,16 @@ void AvatarHashMap::processBulkAvatarTraits(QSharedPointer<ReceivedMessage> mess
|
||||||
AvatarTraits::TraitInstanceID traitInstanceID =
|
AvatarTraits::TraitInstanceID traitInstanceID =
|
||||||
QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||||
|
|
||||||
// XOR the incoming trait instance ID with this avatar object's personal XOR ID
|
|
||||||
|
|
||||||
// this ensures that we have separate entity instances in the local tree
|
|
||||||
// if we briefly end up with two Avatar objects for this node
|
|
||||||
|
|
||||||
// (which can occur if the shared pointer for the
|
|
||||||
// previous instance of an avatar hasn't yet gone out of scope before the
|
|
||||||
// new instance is created)
|
|
||||||
|
|
||||||
auto xoredInstanceID = AvatarTraits::xoredInstanceID(traitInstanceID, avatar->getTraitInstanceXORID());
|
|
||||||
|
|
||||||
message->readPrimitive(&traitBinarySize);
|
message->readPrimitive(&traitBinarySize);
|
||||||
|
|
||||||
auto& processedInstanceVersion = lastProcessedVersions.getInstanceValueRef(traitType, traitInstanceID);
|
auto& processedInstanceVersion = lastProcessedVersions.getInstanceValueRef(traitType, traitInstanceID);
|
||||||
if (packetTraitVersion > processedInstanceVersion) {
|
if (packetTraitVersion > processedInstanceVersion) {
|
||||||
// in order to handle re-connections to the avatar mixer when the other
|
|
||||||
if (traitBinarySize == AvatarTraits::DELETED_TRAIT_SIZE) {
|
if (traitBinarySize == AvatarTraits::DELETED_TRAIT_SIZE) {
|
||||||
avatar->processDeletedTraitInstance(traitType, xoredInstanceID);
|
avatar->processDeletedTraitInstance(traitType, traitInstanceID);
|
||||||
_replicas.processDeletedTraitInstance(avatarID, traitType, traitInstanceID);
|
_replicas.processDeletedTraitInstance(avatarID, traitType, traitInstanceID);
|
||||||
} else {
|
} else {
|
||||||
auto traitData = message->read(traitBinarySize);
|
auto traitData = message->read(traitBinarySize);
|
||||||
avatar->processTraitInstance(traitType, xoredInstanceID, traitData);
|
avatar->processTraitInstance(traitType, traitInstanceID, traitData);
|
||||||
_replicas.processTraitInstance(avatarID, traitType, traitInstanceID, traitData);
|
_replicas.processTraitInstance(avatarID, traitType, traitInstanceID, traitData);
|
||||||
}
|
}
|
||||||
processedInstanceVersion = packetTraitVersion;
|
processedInstanceVersion = packetTraitVersion;
|
||||||
|
|
|
@ -41,8 +41,7 @@ namespace AvatarTraits {
|
||||||
const TraitWireSize DELETED_TRAIT_SIZE = -1;
|
const TraitWireSize DELETED_TRAIT_SIZE = -1;
|
||||||
|
|
||||||
inline qint64 packInstancedTraitDelete(TraitType traitType, TraitInstanceID instanceID, ExtendedIODevice& destination,
|
inline qint64 packInstancedTraitDelete(TraitType traitType, TraitInstanceID instanceID, ExtendedIODevice& destination,
|
||||||
TraitVersion traitVersion = NULL_TRAIT_VERSION,
|
TraitVersion traitVersion = NULL_TRAIT_VERSION) {
|
||||||
TraitInstanceID xoredInstanceID = TraitInstanceID()) {
|
|
||||||
qint64 bytesWritten = 0;
|
qint64 bytesWritten = 0;
|
||||||
|
|
||||||
bytesWritten += destination.writePrimitive(traitType);
|
bytesWritten += destination.writePrimitive(traitType);
|
||||||
|
@ -51,28 +50,12 @@ namespace AvatarTraits {
|
||||||
bytesWritten += destination.writePrimitive(traitVersion);
|
bytesWritten += destination.writePrimitive(traitVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xoredInstanceID.isNull()) {
|
bytesWritten += destination.write(instanceID.toRfc4122());
|
||||||
bytesWritten += destination.write(instanceID.toRfc4122());
|
|
||||||
} else {
|
|
||||||
bytesWritten += destination.write(xoredInstanceID.toRfc4122());
|
|
||||||
}
|
|
||||||
|
|
||||||
bytesWritten += destination.writePrimitive(DELETED_TRAIT_SIZE);
|
bytesWritten += destination.writePrimitive(DELETED_TRAIT_SIZE);
|
||||||
|
|
||||||
return bytesWritten;
|
return bytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline TraitInstanceID xoredInstanceID(TraitInstanceID localInstanceID, TraitInstanceID xorKeyID) {
|
|
||||||
QByteArray xoredInstanceID { NUM_BYTES_RFC4122_UUID, 0 };
|
|
||||||
auto xorKeyIDBytes = xorKeyID.toRfc4122();
|
|
||||||
auto localInstanceIDBytes = localInstanceID.toRfc4122();
|
|
||||||
|
|
||||||
for (auto i = 0; i < localInstanceIDBytes.size(); ++i) {
|
|
||||||
xoredInstanceID[i] = localInstanceIDBytes[i] ^ xorKeyIDBytes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return QUuid::fromRfc4122(xoredInstanceID);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AvatarTraits_h
|
#endif // hifi_AvatarTraits_h
|
||||||
|
|
|
@ -43,9 +43,6 @@ void ClientTraitsHandler::resetForNewMixer() {
|
||||||
|
|
||||||
// pre-fill the instanced statuses that we will need to send next frame
|
// pre-fill the instanced statuses that we will need to send next frame
|
||||||
_owningAvatar->prepareResetTraitInstances();
|
_owningAvatar->prepareResetTraitInstances();
|
||||||
|
|
||||||
// reset the trait XOR ID since we're resetting for a new avatar mixer
|
|
||||||
_owningAvatar->cycleTraitInstanceXORID();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientTraitsHandler::sendChangedTraitsToMixer() {
|
void ClientTraitsHandler::sendChangedTraitsToMixer() {
|
||||||
|
@ -96,19 +93,11 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() {
|
||||||
|| instanceIDValuePair.value == Updated) {
|
|| instanceIDValuePair.value == Updated) {
|
||||||
// this is a changed trait we need to send or we haven't send out trait information yet
|
// this is a changed trait we need to send or we haven't send out trait information yet
|
||||||
// ask the owning avatar to pack it
|
// ask the owning avatar to pack it
|
||||||
|
_owningAvatar->packTraitInstance(instancedIt->traitType, instanceIDValuePair.id, *traitsPacketList);
|
||||||
// since this is going to the mixer, use the XORed instance ID (to anonymize trait instance IDs
|
|
||||||
// that would typically persist across sessions)
|
|
||||||
_owningAvatar->packTraitInstance(instancedIt->traitType, instanceIDValuePair.id, *traitsPacketList,
|
|
||||||
AvatarTraits::NULL_TRAIT_VERSION,
|
|
||||||
AvatarTraits::xoredInstanceID(instanceIDValuePair.id,
|
|
||||||
_owningAvatar->getTraitInstanceXORID()));
|
|
||||||
} else if (!_shouldPerformInitialSend && instanceIDValuePair.value == Deleted) {
|
} else if (!_shouldPerformInitialSend && instanceIDValuePair.value == Deleted) {
|
||||||
// pack delete for this trait instance
|
// pack delete for this trait instance
|
||||||
AvatarTraits::packInstancedTraitDelete(instancedIt->traitType, instanceIDValuePair.id,
|
AvatarTraits::packInstancedTraitDelete(instancedIt->traitType, instanceIDValuePair.id,
|
||||||
*traitsPacketList, AvatarTraits::NULL_TRAIT_VERSION,
|
*traitsPacketList);
|
||||||
AvatarTraits::xoredInstanceID(instanceIDValuePair.id,
|
|
||||||
_owningAvatar->getTraitInstanceXORID()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,9 @@ public:
|
||||||
|
|
||||||
void markTraitUpdated(AvatarTraits::TraitType updatedTrait)
|
void markTraitUpdated(AvatarTraits::TraitType updatedTrait)
|
||||||
{ _traitStatuses[updatedTrait] = Updated; _hasChangedTraits = true; }
|
{ _traitStatuses[updatedTrait] = Updated; _hasChangedTraits = true; }
|
||||||
void markInstancedTraitUpdated(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID updatedInstanceID)
|
void markInstancedTraitUpdated(AvatarTraits::TraitType traitType, QUuid updatedInstanceID)
|
||||||
{ _traitStatuses.instanceInsert(traitType, updatedInstanceID, Updated); _hasChangedTraits = true; }
|
{ _traitStatuses.instanceInsert(traitType, updatedInstanceID, Updated); _hasChangedTraits = true; }
|
||||||
void markInstancedTraitDeleted(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID deleteInstanceID)
|
void markInstancedTraitDeleted(AvatarTraits::TraitType traitType, QUuid deleteInstanceID)
|
||||||
{ _traitStatuses.instanceInsert(traitType, deleteInstanceID, Deleted); _hasChangedTraits = true; }
|
{ _traitStatuses.instanceInsert(traitType, deleteInstanceID, Deleted); _hasChangedTraits = true; }
|
||||||
|
|
||||||
void resetForNewMixer();
|
void resetForNewMixer();
|
||||||
|
|
Loading…
Reference in a new issue