History

Remove deferred script loading logic

Clement committed 7 years ago

Commit 77232611 parent 2dcfea52 files · +0 −118Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+0−115
@@ -2061,68 +2061,6 @@ bool ScriptEngine::hasEntityScriptDetails(const EntityItemID& entityID) const { · 2060 unmodified lines
2061 return _entityScripts.contains(entityID);2061 return _entityScripts.contains(entityID);
2062}2062}
2063 2063
2064const static EntityItemID BAD_SCRIPT_UUID_PLACEHOLDER { "{20170224-dead-face-0000-cee000021114}" };
2065
2066void ScriptEngine::processDeferredEntityLoads(const QString& entityScript, const EntityItemID& leaderID) {
2067 QList<DeferredLoadEntity> retryLoads;
2068 QMutableListIterator<DeferredLoadEntity> i(_deferredEntityLoads);
2069 while (i.hasNext()) {
2070 auto retry = i.next();
2071 if (retry.entityScript == entityScript) {
2072 retryLoads << retry;
2073 i.remove();
2074 }
2075 }
2076 foreach(DeferredLoadEntity retry, retryLoads) {
2077 // check whether entity was since been deleted
2078
2079 EntityScriptDetails details;
2080 if (!getEntityScriptDetails(retry.entityID, details)) {
2081 qCDebug(scriptengine) << "processDeferredEntityLoads -- entity details gone (entity deleted?)"
2082 << retry.entityID;
2083 continue;
2084 }
2085
2086 // check whether entity has since been unloaded or otherwise errored-out
2087 if (details.status != EntityScriptStatus::PENDING) {
2088 qCDebug(scriptengine) << "processDeferredEntityLoads -- entity status no longer PENDING; "
2089 << retry.entityID << details.status;
2090 continue;
2091 }
2092
2093 // propagate leader's failure reasons to the pending entity
2094 EntityScriptDetails leaderDetails;
2095 {
2096 QWriteLocker locker { &_entityScriptsLock };
2097 leaderDetails = _entityScripts[leaderID];
2098 }
2099 if (leaderDetails.status != EntityScriptStatus::RUNNING) {
2100 qCDebug(scriptengine) << QString("... pending load of %1 cancelled (leader: %2 status: %3)")
2101 .arg(retry.entityID.toString()).arg(leaderID.toString()).arg(leaderDetails.status);
2102
2103 auto extraDetail = QString("\n(propagated from %1)").arg(leaderID.toString());
2104 if (leaderDetails.status == EntityScriptStatus::ERROR_LOADING_SCRIPT ||
2105 leaderDetails.status == EntityScriptStatus::ERROR_RUNNING_SCRIPT) {
2106 // propagate same error so User doesn't have to hunt down stampede's leader
2107 updateEntityScriptStatus(retry.entityID, leaderDetails.status, leaderDetails.errorInfo + extraDetail);
2108 } else {
2109 // the leader Entity somehow ended up in some other state (rapid-fire delete or unload could cause)
2110 updateEntityScriptStatus(retry.entityID, EntityScriptStatus::ERROR_LOADING_SCRIPT,
2111 "A previous Entity failed to load using this script URL; reload to try again." + extraDetail);
2112 }
2113 continue;
2114 }
2115
2116 if (_occupiedScriptURLs.contains(retry.entityScript)) {
2117 qCWarning(scriptengine) << "--- SHOULD NOT HAPPEN -- recursive call into processDeferredEntityLoads" << retry.entityScript;
2118 continue;
2119 }
2120
2121 // if we made it here then the leading entity was successful so proceed with normal load
2122 loadEntityScript(retry.entityID, retry.entityScript, false);
2123 }
2124}
2125
2126void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) {2064void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) {
2127 if (QThread::currentThread() != thread()) {2065 if (QThread::currentThread() != thread()) {
2128 QMetaObject::invokeMethod(this, "loadEntityScript",2066 QMetaObject::invokeMethod(this, "loadEntityScript",
@@ -2147,40 +2085,6 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 18 unmodified lines
2147 updateEntityScriptStatus(entityID, EntityScriptStatus::PENDING, "...pending...");2085 updateEntityScriptStatus(entityID, EntityScriptStatus::PENDING, "...pending...");
2148 }2086 }
2149 2087
2150 // This "occupied" approach allows multiple Entities to boot from the same script URL while still taking
2151 // full advantage of cacheable require modules. This only affects Entities literally coming in back-to-back
2152 // before the first one has time to finish loading.
2153 if (_occupiedScriptURLs.contains(entityScript)) {
2154 auto currentEntityID = _occupiedScriptURLs[entityScript];
2155 if (currentEntityID == BAD_SCRIPT_UUID_PLACEHOLDER) {
2156 if (forceRedownload) {
2157 // script was previously marked unusable, but we're reloading so reset it
2158 _occupiedScriptURLs.remove(entityScript);
2159 } else {
2160 // since not reloading, assume that the exact same input would produce the exact same output again
2161 // note: this state gets reset with "reload all scripts," leaving/returning to a Domain, clear cache, etc.
2162#ifdef DEBUG_ENTITY_STATES
2163 qCDebug(scriptengine) << QString("loadEntityScript.cancelled entity: %1 (previous script failure)")
2164 .arg(entityID.toString());
2165#endif
2166 updateEntityScriptStatus(entityID, EntityScriptStatus::ERROR_LOADING_SCRIPT,
2167 "A previous Entity failed to load using this script URL; reload to try again.");
2168 return;
2169 }
2170 } else {
2171 // another entity is busy loading from this script URL so wait for them to finish
2172#ifdef DEBUG_ENTITY_STATES
2173 qCDebug(scriptengine) << QString("loadEntityScript.deferring[%0] entity: %1 (waiting on %2 )")
2174 .arg(_deferredEntityLoads.size()).arg(entityID.toString()).arg(currentEntityID.toString());
2175#endif
2176 _deferredEntityLoads.push_back({ entityID, entityScript });
2177 return;
2178 }
2179 }
2180
2181 // the scriptURL slot is available; flag as in-use
2182 _occupiedScriptURLs[entityScript] = entityID;
2183
2184#ifdef DEBUG_ENTITY_STATES2088#ifdef DEBUG_ENTITY_STATES
2185 {2089 {
2186 EntityScriptDetails details;2090 EntityScriptDetails details;
@@ -2223,10 +2127,6 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 36 unmodified lines
2223 qCDebug(scriptengine) << "loadEntityScript.contentAvailable -- aborting";2127 qCDebug(scriptengine) << "loadEntityScript.contentAvailable -- aborting";
2224#endif2128#endif
2225 }2129 }
2226 // recheck whether us since may have been set to BAD_SCRIPT_UUID_PLACEHOLDER in entityScriptContentAvailable
2227 if (_occupiedScriptURLs.contains(entityScript) && _occupiedScriptURLs[entityScript] == entityID) {
2228 _occupiedScriptURLs.remove(entityScript);
2229 }
2230 });2130 });
2231 }, forceRedownload);2131 }, forceRedownload);
2232}2132}
@@ -2301,13 +2201,6 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 68 unmodified lines
2301 newDetails.errorInfo = errorInfo;2201 newDetails.errorInfo = errorInfo;
2302 newDetails.status = status;2202 newDetails.status = status;
2303 setEntityScriptDetails(entityID, newDetails);2203 setEntityScriptDetails(entityID, newDetails);
2304
2305#ifdef DEBUG_ENTITY_STATES
2306 qCDebug(scriptengine) << "entityScriptContentAvailable -- flagging as BAD_SCRIPT_UUID_PLACEHOLDER";
2307#endif
2308 // flag the original entityScript as unusuable
2309 _occupiedScriptURLs[entityScript] = BAD_SCRIPT_UUID_PLACEHOLDER;
2310 processDeferredEntityLoads(entityScript, entityID);
2311 };2204 };
2312 2205
2313 // NETWORK / FILESYSTEM ERRORS2206 // NETWORK / FILESYSTEM ERRORS
@@ -2441,9 +2334,6 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 127 unmodified lines
2441 callEntityScriptMethod(entityID, "preload");2334 callEntityScriptMethod(entityID, "preload");
2442 2335
2443 emit entityScriptPreloadFinished(entityID);2336 emit entityScriptPreloadFinished(entityID);
2444
2445 _occupiedScriptURLs.remove(entityScript);
2446 processDeferredEntityLoads(entityScript, entityID);
2447}2337}
2448 2338
2449/**jsdoc2339/**jsdoc
@@ -2499,10 +2389,6 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID, bool shouldR · 49 unmodified lines
2499 }2389 }
2500 2390
2501 stopAllTimersForEntityScript(entityID);2391 stopAllTimersForEntityScript(entityID);
2502 {
2503 // FIXME: shouldn't have to do this here, but currently something seems to be firing unloads moments after firing initial load requests
2504 processDeferredEntityLoads(scriptText, entityID);
2505 }
2506 }2392 }
2507}2393}
2508 2394
@@ -2532,7 +2418,6 @@ void ScriptEngine::unloadAllEntityScripts() { · 23 unmodified lines
2532 _entityScripts.clear();2418 _entityScripts.clear();
2533 }2419 }
2534 emit entityScriptDetailsUpdated();2420 emit entityScriptDetailsUpdated();
2535 _occupiedScriptURLs.clear();
2536 2421
2537#ifdef DEBUG_ENGINE_STATE2422#ifdef DEBUG_ENGINE_STATE
2538 _debugDump(2423 _debugDump(

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t