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
172 emit unhandledException(exception);172 emit unhandledException(exception);
173 }173 }
174 }, Qt::DirectConnection);174 }, Qt::DirectConnection);
175 175
176 setProcessEventsInterval(MSECS_PER_SECOND);176 setProcessEventsInterval(MSECS_PER_SECOND);
177 if (isEntityServerScript()) {177 if (isEntityServerScript()) {
178 qCDebug(scriptengine) << "isEntityServerScript() -- limiting maxRetries to 1";178 qCDebug(scriptengine) << "isEntityServerScript() -- limiting maxRetries to 1";
@@ -281,7 +281,7 @@ void ScriptEngine::runDebuggable() { · 102 unmodified lines
281 scriptDebugMenu = nullptr;281 scriptDebugMenu = nullptr;
282 }282 }
283 }283 }
284 disconnect(timer); 284 disconnect(timer);
285 });285 });
286 286
287 connect(timer, &QTimer::timeout, [this, timer] {287 connect(timer, &QTimer::timeout, [this, timer] {
@@ -340,7 +340,7 @@ void ScriptEngine::runInThread() { · 52 unmodified lines
340 QThread* workerThread = new QThread();340 QThread* workerThread = new QThread();
341 workerThread->setObjectName(QString("js:") + getFilename().replace("about:",""));341 workerThread->setObjectName(QString("js:") + getFilename().replace("about:",""));
342 moveToThread(workerThread);342 moveToThread(workerThread);
343 343
344 // NOTE: If you connect any essential signals for proper shutdown or cleanup of344 // NOTE: If you connect any essential signals for proper shutdown or cleanup of
345 // the script engine, make sure to add code to "reconnect" them to the345 // the script engine, make sure to add code to "reconnect" them to the
346 // disconnectNonEssentialSignals() method346 // disconnectNonEssentialSignals() method
@@ -1047,26 +1047,26 @@ void ScriptEngine::run() { · 700 unmodified lines
1047 auto beforeSleep = clock::now();1047 auto beforeSleep = clock::now();
1048 1048
1049 // Throttle to SCRIPT_FPS1049 // 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
1051 // calculate a sleepUntil to be the time from our start time until the original target1051 // 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 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 1053 // that some of our script udpates/frames take a little bit longer than the target average
1054 // to execute.1054 // to execute.
1055 // NOTE: if we go to variable SCRIPT_FPS, then we will need to reconsider this approach1055 // NOTE: if we go to variable SCRIPT_FPS, then we will need to reconsider this approach
1056 const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(USECS_PER_SECOND / SCRIPT_FPS + 1);1056 const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(USECS_PER_SECOND / SCRIPT_FPS + 1);
1057 clock::time_point targetSleepUntil(startTime + (thisFrame++ * TARGET_SCRIPT_FRAME_DURATION));1057 clock::time_point targetSleepUntil(startTime + (thisFrame++ * TARGET_SCRIPT_FRAME_DURATION));
1058 1058
1059 // However, if our sleepUntil is not at least our average update and timer execution time 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 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 1061 // punish the script a little bit. So we will force the sleepUntil to be at least our
1062 // averageUpdate + averageTimerPerFrame time into the future.1062 // averageUpdate + averageTimerPerFrame time into the future.
1063 auto averageUpdate = totalUpdates / thisFrame;1063 auto averageUpdate = totalUpdates / thisFrame;
1064 auto averageTimerPerFrame = _totalTimerExecution / thisFrame;1064 auto averageTimerPerFrame = _totalTimerExecution / thisFrame;
1065 auto averageTimerAndUpdate = averageUpdate + averageTimerPerFrame;1065 auto averageTimerAndUpdate = averageUpdate + averageTimerPerFrame;
1066 auto sleepUntil = std::max(targetSleepUntil, beforeSleep + averageTimerAndUpdate);1066 auto sleepUntil = std::max(targetSleepUntil, beforeSleep + averageTimerAndUpdate);
1067 1067
1068 // We don't want to actually sleep for too long, because it causes our scripts to hang 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 1069 // on shutdown and stop... so we want to loop and sleep until we've spent our time in
1070 // purgatory, constantly checking to see if our script was asked to end1070 // purgatory, constantly checking to see if our script was asked to end
1071 bool processedEvents = false;1071 bool processedEvents = false;
1072 while (!_isFinished && clock::now() < sleepUntil) {1072 while (!_isFinished && clock::now() < sleepUntil) {
@@ -1399,7 +1399,7 @@ QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& re · 326 unmodified lines
1399 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {1399 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
1400 return QString();1400 return QString();
1401 }1401 }
1402 QUrl defaultScriptsLoc = defaultScriptsLocation();1402 QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation();
1403 QUrl url(moduleId);1403 QUrl url(moduleId);
1404 1404
1405 auto displayId = moduleId;1405 auto displayId = moduleId;
@@ -1465,7 +1465,7 @@ QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& re · 59 unmodified lines
1465 canonical.setPath(file.canonicalFilePath());1465 canonical.setPath(file.canonicalFilePath());
1466 }1466 }
1467 1467
1468 bool disallowOutsideFiles = !defaultScriptsLocation().isParentOf(canonical) && !currentSandboxURL.isLocalFile();1468 bool disallowOutsideFiles = !PathUtils::defaultScriptsLocation().isParentOf(canonical) && !currentSandboxURL.isLocalFile();
1469 if (disallowOutsideFiles && !PathUtils::isDescendantOf(canonical, currentSandboxURL)) {1469 if (disallowOutsideFiles && !PathUtils::isDescendantOf(canonical, currentSandboxURL)) {
1470 return throwResolveError(makeError(message.arg(1470 return throwResolveError(makeError(message.arg(
1471 QString("path '%1' outside of origin script '%2' '%3'")1471 QString("path '%1' outside of origin script '%2' '%3'")
@@ -1750,7 +1750,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 278 unmodified lines
1750 return;1750 return;
1751 }1751 }
1752 if (DependencyManager::get<ScriptEngines>()->isStopped()) {1752 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:"
1754 + includeFiles.join(",") + "parent script:" + getFilename());1754 + includeFiles.join(",") + "parent script:" + getFilename());
1755 return; // bail early1755 return; // bail early
1756 }1756 }
@@ -1762,7 +1762,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 5 unmodified lines
1762 bool isStandardLibrary = false;1762 bool isStandardLibrary = false;
1763 if (file.startsWith("/~/")) {1763 if (file.startsWith("/~/")) {
1764 thisURL = expandScriptUrl(QUrl::fromLocalFile(expandScriptPath(file)));1764 thisURL = expandScriptUrl(QUrl::fromLocalFile(expandScriptPath(file)));
1765 QUrl defaultScriptsLoc = defaultScriptsLocation();1765 QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation();
1766 if (!defaultScriptsLoc.isParentOf(thisURL)) {1766 if (!defaultScriptsLoc.isParentOf(thisURL)) {
1767 scriptWarningMessage("Script.include() -- skipping" + file + "-- outside of standard libraries");1767 scriptWarningMessage("Script.include() -- skipping" + file + "-- outside of standard libraries");
1768 continue;1768 continue;
@@ -1774,7 +1774,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 5 unmodified lines
1774 1774
1775 bool disallowOutsideFiles = thisURL.isLocalFile() && !isStandardLibrary && !currentSandboxURL.isLocalFile();1775 bool disallowOutsideFiles = thisURL.isLocalFile() && !isStandardLibrary && !currentSandboxURL.isLocalFile();
1776 if (disallowOutsideFiles && !PathUtils::isDescendantOf(thisURL, currentSandboxURL)) {1776 if (disallowOutsideFiles && !PathUtils::isDescendantOf(thisURL, currentSandboxURL)) {
1777 scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString() 1777 scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString()
1778 + "outside of original entity script" + currentSandboxURL.toString());1778 + "outside of original entity script" + currentSandboxURL.toString());
1779 } else {1779 } else {
1780 // We could also check here for CORS, but we don't yet.1780 // 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
1844 1844
1845void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {1845void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
1846 if (DependencyManager::get<ScriptEngines>()->isStopped()) {1846 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:"
1848 + includeFile + "parent script:" + getFilename());1848 + includeFile + "parent script:" + getFilename());
1849 return; // bail early1849 return; // bail early
1850 }1850 }
@@ -1862,12 +1862,12 @@ void ScriptEngine::load(const QString& loadFile) { · 11 unmodified lines
1862 return;1862 return;
1863 }1863 }
1864 if (DependencyManager::get<ScriptEngines>()->isStopped()) {1864 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:"
1866 + loadFile + "parent script:" + getFilename());1866 + loadFile + "parent script:" + getFilename());
1867 return; // bail early1867 return; // bail early
1868 }1868 }
1869 if (!currentEntityIdentifier.isInvalidID()) {1869 if (!currentEntityIdentifier.isInvalidID()) {
1870 scriptWarningMessage("Script.load() from entity script is ignored... loadFile:" 1870 scriptWarningMessage("Script.load() from entity script is ignored... loadFile:"
1871 + loadFile + "parent script:" + getFilename() + "entity: " + currentEntityIdentifier.toString());1871 + loadFile + "parent script:" + getFilename() + "entity: " + currentEntityIdentifier.toString());
1872 return; // bail early1872 return; // bail early
1873 }1873 }
@@ -2548,7 +2548,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 674 unmodified lines
2548 qCDebug(scriptengine) << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] "2548 qCDebug(scriptengine) << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] "
2549 "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision";2549 "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision";
2550#endif2550#endif
2551 2551
2552 if (HIFI_AUTOREFRESH_FILE_SCRIPTS) {2552 if (HIFI_AUTOREFRESH_FILE_SCRIPTS) {
2553 refreshFileScript(entityID);2553 refreshFileScript(entityID);
2554 }2554 }