From 550b9a98b1c6dedb33645cb6ee4fa8c40b0fc37e Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 12 Feb 2016 14:45:55 -0800 Subject: [PATCH] fix error in preload logic --- libraries/entities/src/EntityItem.h | 27 ++++++++------------ libraries/entities/src/EntityTree.cpp | 3 --- libraries/entities/src/EntityTreeElement.cpp | 7 ++--- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index da10886b97..aee5508811 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -404,18 +404,12 @@ public: virtual void loader() {} // called indirectly when urls for geometry are updated - /// Has the entity been added to an entity tree? This is useful in some state decisions - /// for example whether or not to send out a scriptChanging signal. - void markAsAddedToTree() { _isAddedToTree = true; } - bool isAddedToTree() const { return _isAddedToTree; } - /// Should the external entity script mechanism call a preload for this entity. /// Due to the asyncronous nature of signals for add entity and script changing /// it's possible for two similar signals to cross paths. This method allows the /// entity to definitively state if the preload signal should be sent. - bool shouldPreloadScript() const { return !_script.isEmpty() && - _loadedScript != _script && _loadedScriptTimestamp != _scriptTimestamp; } - + bool shouldPreloadScript() const { return !_script.isEmpty() && + _loadedScript != _script && _loadedScriptTimestamp != _scriptTimestamp; } void scriptHasPreloaded() { _loadedScript = _script; _loadedScriptTimestamp = _scriptTimestamp; } protected: @@ -458,8 +452,15 @@ protected: float _restitution; float _friction; float _lifetime; - QString _script; - quint64 _scriptTimestamp; + + QString _script; /// the value of the script property + QString _loadedScript; /// the value of _script when the last preload signal was sent + quint64 _scriptTimestamp{ ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP }; /// the script loaded property used for forced reload + + /// the value of _scriptTimestamp when the last preload signal was sent + // NOTE: on construction we want this to be different from _scriptTimestamp so we intentionally bump it + quint64 _loadedScriptTimestamp{ ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP + 1 }; + QString _collisionSoundURL; glm::vec3 _registrationPoint; float _angularDamping; @@ -520,12 +521,6 @@ protected: mutable QHash _previouslyDeletedActions; QUuid _sourceUUID; /// the server node UUID we came from - - bool _isAddedToTree { false }; /// this is false until the entity has been added to an entity tree - - QString _loadedScript; /// the value of _script when the last preload signal was sent - quint64 _loadedScriptTimestamp { 0 }; /// the value of _scriptTimestamp when the last preload signal was sent - }; #endif // hifi_EntityItem_h diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index fc463b6f21..4c3412edd3 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -92,9 +92,6 @@ void EntityTree::postAddEntity(EntityItemPointer entity) { // find and hook up any entities with this entity as a (previously) missing parent fixupMissingParents(); - - // indicate that the entity has been added to the tree - entity->markAsAddedToTree(); } bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode) { diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 0b10994a58..4abbe3c3fa 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -927,11 +927,8 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int bool reload = entityScriptTimestampBefore != entityScriptTimestampAfter; // If the script value has changed on us, or it's timestamp has changed to force - // a reload then we want to send out a script changing signal... UNLESS this is the - // first time we've read the entity information, in which case, the entity has - // not yet been added to the tree, and we want to wait for the addEntity. In other - // words it's not a "change" in the script, if it's a first time load. - if (entityItem->isAddedToTree() && (entityScriptBefore != entityScriptAfter || reload)) { + // a reload then we want to send out a script changing signal... + if (entityScriptBefore != entityScriptAfter || reload) { _myTree->emitEntityScriptChanging(entityItemID, reload); // the entity script has changed }