diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index 02a348df37..b2daabbd6c 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -216,12 +216,6 @@ void EntityScriptServer::resetEntitiesScriptEngine() { auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor); newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue); - -// newEngine->setEmitScriptUpdatesFunction([this]() { -// SharedNodePointer entityServerNode = DependencyManager::get()->soloNodeOfType(NodeType::EntityServer); -// return !entityServerNode || isPhysicsEnabled(); -// }); - newEngine->registerGlobalObject("AvatarList", DependencyManager::get().data()); newEngine->registerGlobalObject("SoundCache", DependencyManager::get().data()); @@ -287,14 +281,16 @@ void EntityScriptServer::entityServerScriptChanging(const EntityItemID& entityID } void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, const bool reload) { - if (_entityViewer.getTree() && !_shuttingDown) { + if (_entityViewer.getTree() && !_shuttingDown && _entitiesScriptEngine) { + EntityItemPointer entity = _entityViewer.getTree()->findEntityByEntityItemID(entityID); - if (entity && entity->shouldPreloadServerScript() && _entitiesScriptEngine) { + EntityScriptDetails details; + bool notRunning = !_entitiesScriptEngine->getEntityScriptDetails(entityID, details); + if (entity && (reload || notRunning || details.scriptText != entity->getServerScripts())) { QString scriptUrl = entity->getServerScripts(); scriptUrl = ResourceManager::normalizeURL(scriptUrl); qDebug() << "Loading entity server script" << scriptUrl << "for" << entityID; ScriptEngine::loadEntityScript(_entitiesScriptEngine, entityID, scriptUrl, reload); - entity->serverScriptHasPreloaded(); } } } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index d4b62e74de..cb696dd91d 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -444,9 +444,6 @@ public: ((_loadedScript != _script) || (_loadedScriptTimestamp != _scriptTimestamp)); } void scriptHasPreloaded() { _loadedScript = _script; _loadedScriptTimestamp = _scriptTimestamp; } - bool shouldPreloadServerScript() const { return !_serverScripts.isEmpty() && ((_loadedServerScripts != _serverScripts)); } - void serverScriptHasPreloaded() { _loadedServerScripts = _serverScripts; } - bool getClientOnly() const { return _clientOnly; } void setClientOnly(bool clientOnly) { _clientOnly = clientOnly; } // if this entity is client-only, which avatar is it associated with? @@ -519,7 +516,6 @@ protected: 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; - QString _loadedServerScripts; /// 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 diff --git a/libraries/networking/src/EntityScriptClient.h b/libraries/networking/src/EntityScriptClient.h index f32d78a6dd..d331b8ca31 100644 --- a/libraries/networking/src/EntityScriptClient.h +++ b/libraries/networking/src/EntityScriptClient.h @@ -73,4 +73,4 @@ private: void forceFailureOfPendingRequests(SharedNodePointer node); }; -#endif \ No newline at end of file +#endif