Merge pull request #7101 from ZappoMan/fixDoublePreload

fix error in preload logic
This commit is contained in:
Eric Levin 2016-02-12 15:35:59 -08:00
commit 921674b952
3 changed files with 17 additions and 24 deletions

View file

@ -404,18 +404,16 @@ 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; }
///
/// We only want to preload if:
/// there is some script, and either the script value or the scriptTimestamp
/// value have changed since our last preload
bool shouldPreloadScript() const { return !_script.isEmpty() &&
((_loadedScript != _script) || (_loadedScriptTimestamp != _scriptTimestamp)); }
void scriptHasPreloaded() { _loadedScript = _script; _loadedScriptTimestamp = _scriptTimestamp; }
protected:
@ -458,8 +456,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 +525,6 @@ protected:
mutable QHash<QUuid, quint64> _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

View file

@ -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) {

View file

@ -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
}