From ec384d7dbbf5097789810c93963030698ab6b1f8 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 7 Dec 2018 11:30:53 -0800 Subject: [PATCH] more correct reload AvatarEntityData from settings --- interface/src/Application.cpp | 3 +- interface/src/avatar/MyAvatar.cpp | 46 ++++++++++++++++--------------- interface/src/avatar/MyAvatar.h | 2 ++ 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 134c375b56..0fbe9fba94 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6783,7 +6783,8 @@ void Application::clearDomainOctreeDetails() { DependencyManager::get()->clearUnusedResources(); DependencyManager::get()->clearUnusedResources(); - getMyAvatar()->setAvatarEntityDataChanged(true); + // we just deleted all of MyAvatar's AvatarEntities so we flag it to reload from settings + getMyAvatar()->rememberToReloadOfAvatarEntityDataFromSettings(); } void Application::domainURLChanged(QUrl domainURL) { diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 4a1fc1b740..ce70d40c74 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1443,8 +1443,10 @@ void MyAvatar::updateAvatarEntity(const QUuid& entityID, const EntityItemPropert // TODO? handle this case? return; } + // TODO: remember this entity and its properties, so we can save to settings } else { // TODO: propagate changes to entity + // TODO: and remember these changes so we can save to settings } } @@ -1474,7 +1476,7 @@ void MyAvatar::updateAvatarEntities() { // - ClientTraitsHandler::sendChangedTraitsToMixer sends the entity bytes to the mixer which relays them to other interfaces // - AvatarHashMap::processBulkAvatarTraits on other interfaces calls avatar->processTraitInstace // - AvatarData::processTraitInstance calls updateAvatarEntity, which sets _avatarEntityDataChanged = true - // - (My)Avatar::simulate notices _avatarEntityDataChanged and here we are... + // - (My)Avatar::simulate calls updateAvatarEntities every frame and here we are... // AVATAR ENTITY DELETE FLOW // - EntityScriptingInterface::deleteEntity calls _myAvatar->clearAvatarEntity() for deleted avatar entities @@ -1483,28 +1485,26 @@ void MyAvatar::updateAvatarEntities() { // - AvatarHashMap::processBulkAvatarTraits on other interfaces calls avatar->processDeletedTraitInstace // - AvatarData::processDeletedTraitInstance calls clearAvatarEntity // - AvatarData::clearAvatarEntity sets _avatarEntityDataChanged = true and adds the ID to the detached list - // - Avatar::simulate notices _avatarEntityDataChanged and here we are... + // - Avatar::simulate calls updateAvatarEntities every frame and here we are... - if (!_avatarEntityDataChanged) { - return; + if (_reloadAvatarEntityDataFromSettings) { + + if (getID().isNull() || + getID() == AVATAR_SELF_ID || + DependencyManager::get()->getSessionUUID() == QUuid()) { + // wait until MyAvatar and this Node gets an ID before doing this. Otherwise, various things go wrong -- + // things get their parent fixed up from AVATAR_SELF_ID to a null uuid which means "no parent". + return; + } + + auto treeRenderer = DependencyManager::get(); + EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr; + if (!entityTree) { + return; + } + + loadAvatarEntityDataFromSettings(); } - - if (getID().isNull() || - getID() == AVATAR_SELF_ID || - DependencyManager::get()->getSessionUUID() == QUuid()) { - // wait until MyAvatar and this Node gets an ID before doing this. Otherwise, various things go wrong -- - // things get their parent fixed up from AVATAR_SELF_ID to a null uuid which means "no parent". - return; - } - - auto treeRenderer = DependencyManager::get(); - EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr; - if (!entityTree) { - return; - } - - loadAvatarEntityDataFromSettings(); - setAvatarEntityDataChanged(false); } @@ -1547,6 +1547,7 @@ void MyAvatar::loadAvatarEntityDataFromSettings() { _avatarEntityData.clear(); }); + _reloadAvatarEntityDataFromSettings = false; int numEntities = _avatarEntityCountSetting.get(0); if (numEntities == 0) { return; @@ -1588,7 +1589,7 @@ void MyAvatar::loadAvatarEntityDataFromSettings() { // use the entity to build the data payload OctreeElement::AppendState appendState = entity->appendEntityData(&packetData, params, extra); if (appendState == OctreeElement::COMPLETED) { - // only remember an AvatarEntity that successfully loads + // only remember an AvatarEntity that successfully loads and can be packed QByteArray tempArray = QByteArray::fromRawData((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize()); storeAvatarEntityDataPayload(entityID, tempArray); _avatarEntitiesAsPropertiesStrings[entityID] = _avatarEntityDataSettings[i].get(); @@ -2089,6 +2090,7 @@ void MyAvatar::removeWearableAvatarEntities() { } QVariantList MyAvatar::getAvatarEntitiesVariant() { + // NOTE: this method is NOT efficient QVariantList avatarEntitiesData; QScriptEngine scriptEngine; auto treeRenderer = DependencyManager::get(); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index b343f9bf79..a6df4de7bf 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1188,6 +1188,7 @@ public: glm::vec3 getNextPosition() { return _goToPending ? _goToPosition : getWorldPosition(); } void updateAvatarEntities() override; + void rememberToReloadOfAvatarEntityDataFromSettings() { _reloadAvatarEntityDataFromSettings = true; } /**jsdoc * Create a new grab. @@ -1927,6 +1928,7 @@ private: bool _haveReceivedHeightLimitsFromDomain { false }; int _disableHandTouchCount { 0 }; bool _skeletonModelLoaded { false }; + bool _reloadAvatarEntityDataFromSettings { true }; Setting::Handle _dominantHandSetting; Setting::Handle _headPitchSetting;