History

Fix scripts not reloading in certain edge cases

Atlante45 committed 9 years ago

Commit 20a82df1 parent bb5c6e44 files · +12 −13Browse files

Showing the changes to assignment-client/src/scripts/EntityScriptServer.cpp (1 of 4 files). Show all

Unified · Split

assignment-client/src/scripts/EntityScriptServer.cpp+4−9
@@ -216,12 +216,6 @@ void EntityScriptServer::resetEntitiesScriptEngine() { · 215 unmodified lines
216 auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor);216 auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor);
217 newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);217 newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
218 218
219
220// newEngine->setEmitScriptUpdatesFunction([this]() {
221// SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer);
222// return !entityServerNode || isPhysicsEnabled();
223// });
224
225 newEngine->registerGlobalObject("AvatarList", DependencyManager::get<AvatarHashMap>().data());219 newEngine->registerGlobalObject("AvatarList", DependencyManager::get<AvatarHashMap>().data());
226 newEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());220 newEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
227 221
@@ -287,14 +281,15 @@ void EntityScriptServer::entityServerScriptChanging(const EntityItemID& entityID · 59 unmodified lines
287}281}
288 282
289void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, const bool reload) {283void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, const bool reload) {
290 if (_entityViewer.getTree() && !_shuttingDown) {284 if (_entityViewer.getTree() && !_shuttingDown && _entitiesScriptEngine) {
285 auto details = _entitiesScriptEngine->getEntityScriptDetails(entityID);
286
291 EntityItemPointer entity = _entityViewer.getTree()->findEntityByEntityItemID(entityID);287 EntityItemPointer entity = _entityViewer.getTree()->findEntityByEntityItemID(entityID);
292 if (entity && entity->shouldPreloadServerScript() && _entitiesScriptEngine) {288 if (entity && (details.scriptText != entity->getServerScripts() || reload)) {
293 QString scriptUrl = entity->getServerScripts();289 QString scriptUrl = entity->getServerScripts();
294 scriptUrl = ResourceManager::normalizeURL(scriptUrl);290 scriptUrl = ResourceManager::normalizeURL(scriptUrl);
295 qDebug() << "Loading entity server script" << scriptUrl << "for" << entityID;291 qDebug() << "Loading entity server script" << scriptUrl << "for" << entityID;
296 ScriptEngine::loadEntityScript(_entitiesScriptEngine, entityID, scriptUrl, reload);292 ScriptEngine::loadEntityScript(_entitiesScriptEngine, entityID, scriptUrl, reload);
297 entity->serverScriptHasPreloaded();
298 }293 }
299 }294 }
300}295}