From f1b4f79ad9040dda1774ab54d9a7fd18c6a75e75 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 25 Jan 2017 11:28:02 -0800 Subject: [PATCH 1/2] a simple hack to accept newer server scripts --- libraries/entities/src/EntityItem.cpp | 17 +++++++++++++++++ libraries/entities/src/EntityItem.h | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 0b2e7fd5ca..8b2763fec8 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -780,7 +780,24 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_LIFETIME, float, updateLifetime); READ_ENTITY_PROPERTY(PROP_SCRIPT, QString, setScript); READ_ENTITY_PROPERTY(PROP_SCRIPT_TIMESTAMP, quint64, setScriptTimestamp); + + bool previousOverwriteLocalDataValue = overwriteLocalData; + + if (!overwriteLocalData) { + // We've decided not to read the data in this update because we have a newer local state of the entity. + // In order to work around a bug stopping server script changes from being received by an entity script server + // running a script that continously updates an entity, we force the overwriting of the server scripts + // if we believe this update might have a newer version than the one we have locally. + + if (_lastEditedFromRemote > _serverScriptsChangedTimestamp) { + overwriteLocalData = true; + } + } + READ_ENTITY_PROPERTY(PROP_SERVER_SCRIPTS, QString, setServerScripts); + + overwriteLocalData = previousOverwriteLocalDataValue; + READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, glm::vec3, updateRegistrationPoint); READ_ENTITY_PROPERTY(PROP_ANGULAR_DAMPING, float, updateAngularDamping); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 2fb91d0d77..718a399a39 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -261,7 +261,8 @@ public: void setScriptTimestamp(const quint64 value) { _scriptTimestamp = value; } QString getServerScripts() const { return _serverScripts; } - void setServerScripts(const QString& serverScripts) { _serverScripts = serverScripts; } + void setServerScripts(const QString& serverScripts) + { _serverScripts = serverScripts; _serverScriptsChangedTimestamp = usecTimestampNow(); } const QString& getCollisionSoundURL() const { return _collisionSoundURL; } void setCollisionSoundURL(const QString& value); @@ -515,7 +516,9 @@ protected: 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 + QString _serverScripts; + quint64 _serverScriptsChangedTimestamp; /// keep track of time when _serverScripts property was last changed /// 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 From 304618f51dc877103f552c1e8503517b7870f354 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 25 Jan 2017 12:39:21 -0800 Subject: [PATCH 2/2] cleanup comment and scoping for server script URL changes --- libraries/entities/src/EntityItem.cpp | 21 ++++++++------------- libraries/entities/src/EntityItem.h | 3 ++- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 8b2763fec8..28d07672a0 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -781,23 +781,18 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_SCRIPT, QString, setScript); READ_ENTITY_PROPERTY(PROP_SCRIPT_TIMESTAMP, quint64, setScriptTimestamp); - bool previousOverwriteLocalDataValue = overwriteLocalData; + { + // We use this scope to work around an issue stopping server script changes + // from being received by an entity script server running a script that continously updates an entity. - if (!overwriteLocalData) { - // We've decided not to read the data in this update because we have a newer local state of the entity. - // In order to work around a bug stopping server script changes from being received by an entity script server - // running a script that continously updates an entity, we force the overwriting of the server scripts - // if we believe this update might have a newer version than the one we have locally. + // Basically, we'll allow recent changes to the server scripts even if there are local changes to other properties + // that have been made more recently. - if (_lastEditedFromRemote > _serverScriptsChangedTimestamp) { - overwriteLocalData = true; - } + bool overwriteLocalData = !ignoreServerPacket || (lastEditedFromBufferAdjusted > _serverScriptsChangedTimestamp); + + READ_ENTITY_PROPERTY(PROP_SERVER_SCRIPTS, QString, setServerScripts); } - READ_ENTITY_PROPERTY(PROP_SERVER_SCRIPTS, QString, setServerScripts); - - overwriteLocalData = previousOverwriteLocalDataValue; - READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, glm::vec3, updateRegistrationPoint); READ_ENTITY_PROPERTY(PROP_ANGULAR_DAMPING, float, updateAngularDamping); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 718a399a39..b0389cf99f 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -518,7 +518,8 @@ protected: quint64 _scriptTimestamp{ ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP }; /// the script loaded property used for forced reload QString _serverScripts; - quint64 _serverScriptsChangedTimestamp; /// keep track of time when _serverScripts property was last changed + /// keep track of time when _serverScripts property was last changed + quint64 _serverScriptsChangedTimestamp { ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP }; /// 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