History

new --scripts switch overrides default scripts location

David Kelly committed 9 years ago

Commit ff5b37c1 parent 34edd958 files · +81 −45Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+20−20
@@ -172,7 +172,7 @@ ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const · 171 unmodified lines
172172 emit unhandledException(exception);
173173 }
174174 }, Qt::DirectConnection);
175−
175+
176176 setProcessEventsInterval(MSECS_PER_SECOND);
177177 if (isEntityServerScript()) {
178178 qCDebug(scriptengine) << "isEntityServerScript() -- limiting maxRetries to 1";
@@ -281,7 +281,7 @@ void ScriptEngine::runDebuggable() { · 102 unmodified lines
281281 scriptDebugMenu = nullptr;
282282 }
283283 }
284− disconnect(timer);
284+ disconnect(timer);
285285 });
286286
287287 connect(timer, &QTimer::timeout, [this, timer] {
@@ -340,7 +340,7 @@ void ScriptEngine::runInThread() { · 52 unmodified lines
340340 QThread* workerThread = new QThread();
341341 workerThread->setObjectName(QString("js:") + getFilename().replace("about:",""));
342342 moveToThread(workerThread);
343−
343+
344344 // NOTE: If you connect any essential signals for proper shutdown or cleanup of
345345 // the script engine, make sure to add code to "reconnect" them to the
346346 // disconnectNonEssentialSignals() method
@@ -1047,26 +1047,26 @@ void ScriptEngine::run() { · 700 unmodified lines
10471047 auto beforeSleep = clock::now();
10481048
10491049 // Throttle to SCRIPT_FPS
1050− // We'd like to try to keep the script at a solid SCRIPT_FPS update rate. And so we will
1050+ // We'd like to try to keep the script at a solid SCRIPT_FPS update rate. And so we will
10511051 // calculate a sleepUntil to be the time from our start time until the original target
1052− // sleepUntil for this frame. This approach will allow us to "catch up" in the event
1053− // that some of our script udpates/frames take a little bit longer than the target average
1052+ // sleepUntil for this frame. This approach will allow us to "catch up" in the event
1053+ // that some of our script udpates/frames take a little bit longer than the target average
10541054 // to execute.
10551055 // NOTE: if we go to variable SCRIPT_FPS, then we will need to reconsider this approach
10561056 const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(USECS_PER_SECOND / SCRIPT_FPS + 1);
10571057 clock::time_point targetSleepUntil(startTime + (thisFrame++ * TARGET_SCRIPT_FRAME_DURATION));
10581058
1059− // However, if our sleepUntil is not at least our average update and timer execution time
1060− // into the future it means our script is taking too long in its updates, and we want to
1061− // punish the script a little bit. So we will force the sleepUntil to be at least our
1059+ // However, if our sleepUntil is not at least our average update and timer execution time
1060+ // into the future it means our script is taking too long in its updates, and we want to
1061+ // punish the script a little bit. So we will force the sleepUntil to be at least our
10621062 // averageUpdate + averageTimerPerFrame time into the future.
10631063 auto averageUpdate = totalUpdates / thisFrame;
10641064 auto averageTimerPerFrame = _totalTimerExecution / thisFrame;
10651065 auto averageTimerAndUpdate = averageUpdate + averageTimerPerFrame;
10661066 auto sleepUntil = std::max(targetSleepUntil, beforeSleep + averageTimerAndUpdate);
10671067
1068− // We don't want to actually sleep for too long, because it causes our scripts to hang
1069− // on shutdown and stop... so we want to loop and sleep until we've spent our time in
1068+ // We don't want to actually sleep for too long, because it causes our scripts to hang
1069+ // on shutdown and stop... so we want to loop and sleep until we've spent our time in
10701070 // purgatory, constantly checking to see if our script was asked to end
10711071 bool processedEvents = false;
10721072 while (!_isFinished && clock::now() < sleepUntil) {
@@ -1399,7 +1399,7 @@ QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& re · 326 unmodified lines
13991399 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
14001400 return QString();
14011401 }
1402− QUrl defaultScriptsLoc = defaultScriptsLocation();
1402+ QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation();
14031403 QUrl url(moduleId);
14041404
14051405 auto displayId = moduleId;
@@ -1465,7 +1465,7 @@ QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& re · 59 unmodified lines
14651465 canonical.setPath(file.canonicalFilePath());
14661466 }
14671467
1468− bool disallowOutsideFiles = !defaultScriptsLocation().isParentOf(canonical) && !currentSandboxURL.isLocalFile();
1468+ bool disallowOutsideFiles = !PathUtils::defaultScriptsLocation().isParentOf(canonical) && !currentSandboxURL.isLocalFile();
14691469 if (disallowOutsideFiles && !PathUtils::isDescendantOf(canonical, currentSandboxURL)) {
14701470 return throwResolveError(makeError(message.arg(
14711471 QString("path '%1' outside of origin script '%2' '%3'")
@@ -1750,7 +1750,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 278 unmodified lines
17501750 return;
17511751 }
17521752 if (DependencyManager::get<ScriptEngines>()->isStopped()) {
1753− scriptWarningMessage("Script.include() while shutting down is ignored... includeFiles:"
1753+ scriptWarningMessage("Script.include() while shutting down is ignored... includeFiles:"
17541754 + includeFiles.join(",") + "parent script:" + getFilename());
17551755 return; // bail early
17561756 }
@@ -1762,7 +1762,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 5 unmodified lines
17621762 bool isStandardLibrary = false;
17631763 if (file.startsWith("/~/")) {
17641764 thisURL = expandScriptUrl(QUrl::fromLocalFile(expandScriptPath(file)));
1765− QUrl defaultScriptsLoc = defaultScriptsLocation();
1765+ QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation();
17661766 if (!defaultScriptsLoc.isParentOf(thisURL)) {
17671767 scriptWarningMessage("Script.include() -- skipping" + file + "-- outside of standard libraries");
17681768 continue;
@@ -1774,7 +1774,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 5 unmodified lines
17741774
17751775 bool disallowOutsideFiles = thisURL.isLocalFile() && !isStandardLibrary && !currentSandboxURL.isLocalFile();
17761776 if (disallowOutsideFiles && !PathUtils::isDescendantOf(thisURL, currentSandboxURL)) {
1777− scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString()
1777+ scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString()
17781778 + "outside of original entity script" + currentSandboxURL.toString());
17791779 } else {
17801780 // We could also check here for CORS, but we don't yet.
@@ -1844,7 +1844,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 63 unmodified lines
18441844
18451845 void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
18461846 if (DependencyManager::get<ScriptEngines>()->isStopped()) {
1847− scriptWarningMessage("Script.include() while shutting down is ignored... includeFile:"
1847+ scriptWarningMessage("Script.include() while shutting down is ignored... includeFile:"
18481848 + includeFile + "parent script:" + getFilename());
18491849 return; // bail early
18501850 }
@@ -1862,12 +1862,12 @@ void ScriptEngine::load(const QString& loadFile) { · 11 unmodified lines
18621862 return;
18631863 }
18641864 if (DependencyManager::get<ScriptEngines>()->isStopped()) {
1865− scriptWarningMessage("Script.load() while shutting down is ignored... loadFile:"
1865+ scriptWarningMessage("Script.load() while shutting down is ignored... loadFile:"
18661866 + loadFile + "parent script:" + getFilename());
18671867 return; // bail early
18681868 }
18691869 if (!currentEntityIdentifier.isInvalidID()) {
1870− scriptWarningMessage("Script.load() from entity script is ignored... loadFile:"
1870+ scriptWarningMessage("Script.load() from entity script is ignored... loadFile:"
18711871 + loadFile + "parent script:" + getFilename() + "entity: " + currentEntityIdentifier.toString());
18721872 return; // bail early
18731873 }
@@ -2548,7 +2548,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 674 unmodified lines
25482548 qCDebug(scriptengine) << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] "
25492549 "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision";
25502550 #endif
2551−
2551+
25522552 if (HIFI_AUTOREFRESH_FILE_SCRIPTS) {
25532553 refreshFileScript(entityID);
25542554 }