From df99c314aa9ffeede5a4040e69c3d762ec23facc Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 31 Mar 2015 12:44:44 -0700 Subject: [PATCH] fix issue with preload not being called on import --- .../entities-renderer/src/EntityTreeRenderer.cpp | 9 ++++++--- libraries/entities-renderer/src/EntityTreeRenderer.h | 1 + libraries/entities/src/EntityTree.cpp | 12 +++++++++++- libraries/entities/src/EntityTree.h | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 058e02b507..95ca30a90f 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -101,7 +101,7 @@ void EntityTreeRenderer::init() { _lastAvatarPosition = _viewState->getAvatarPosition() + glm::vec3((float)TREE_SCALE); connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity); - connect(entityTree, &EntityTree::addingEntity, this, &EntityTreeRenderer::checkAndCallPreload); + connect(entityTree, &EntityTree::addingEntity, this, &EntityTreeRenderer::addingEntity); connect(entityTree, &EntityTree::entityScriptChanging, this, &EntityTreeRenderer::entitySciptChanging); connect(entityTree, &EntityTree::changingEntityID, this, &EntityTreeRenderer::changingEntityID); } @@ -193,7 +193,7 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity, bool isPre // can accomplish all we need to here with just the script "text" and the ID. EntityItemID entityID = entity->getEntityItemID(); QString entityScript = entity->getScript(); - + if (_entityScripts.contains(entityID)) { EntityScriptDetails details = _entityScripts[entityID]; @@ -217,7 +217,6 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity, bool isPre if (isPending && isPreload && isURL) { _waitingOnPreload.insert(url, entityID); - } auto scriptCache = DependencyManager::get(); @@ -941,6 +940,10 @@ void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) { _entityScripts.remove(entityID); } +void EntityTreeRenderer::addingEntity(const EntityItemID& entityID) { + checkAndCallPreload(entityID); +} + void EntityTreeRenderer::entitySciptChanging(const EntityItemID& entityID) { if (_tree && !_shuttingDown) { checkAndCallUnload(entityID); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 12d5f6e166..e8d70c9df9 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -105,6 +105,7 @@ signals: void leaveEntity(const EntityItemID& entityItemID); public slots: + void addingEntity(const EntityItemID& entityID); void deletingEntity(const EntityItemID& entityID); void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID); void entitySciptChanging(const EntityItemID& entityID); diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 266aa2bdce..cb5d43693d 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -404,7 +404,8 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) { EntityItem* foundEntity = NULL; EntityItemID creatorTokenVersion = searchEntityID.convertToCreatorTokenVersion(); EntityItemID knownIDVersion = searchEntityID.convertToKnownIDVersion(); - + + _changedEntityIDs[creatorTokenVersion] = knownIDVersion; // First look for and find the "viewed version" of this entity... it's possible we got // the known ID version sent to us between us creating our local version, and getting this @@ -592,6 +593,9 @@ EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) / EntityTreeElement* containingElement = getContainingElement(entityID); if (containingElement) { foundEntity = containingElement->getEntityWithEntityItemID(entityID); + if (!foundEntity && _changedEntityIDs.contains(entityID)) { + foundEntity = containingElement->getEntityWithEntityItemID(_changedEntityIDs[entityID]); + } } return foundEntity; } @@ -958,6 +962,12 @@ EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& entityIt creatorTokenOnly.isKnownID = false; element = _entityToElementMap.value(creatorTokenOnly); } + + // If we still didn't find the entity, but the ID was in our changed entityIDs, search for the new ID version + if (!element && _changedEntityIDs.contains(entityItemID)) { + element = getContainingElement(_changedEntityIDs[entityItemID]); + } + return element; } diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 29fecc88b4..c49cfb2600 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -195,6 +195,7 @@ private: EntityItemFBXService* _fbxService; QHash _entityToElementMap; + QHash _changedEntityIDs; EntitySimulation* _simulation;