Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 99 files). Show all
Unified · Split
| @@ -24,6 +24,8 @@ · 23 unmodified lines | ||
| 24 | 24 | |
| 25 | 25 | #include <QtWidgets/QMainWindow> |
| 26 | 26 | #include <QtWidgets/QApplication> |
| 27 | +#include <QtWidgets/QMenuBar> | |
| 28 | +#include <QtWidgets/QMenu> | |
| 27 | 29 | |
| 28 | 30 | #include <QtNetwork/QNetworkRequest> |
| 29 | 31 | #include <QtNetwork/QNetworkReply> |
| @@ -48,7 +50,6 @@ · 18 unmodified lines | ||
| 48 | 50 | #include <ScriptAvatarData.h> |
| 49 | 51 | #include <udt/PacketHeaders.h> |
| 50 | 52 | #include <UUID.h> |
| 51 | −#include <ui/Menu.h> | |
| 52 | 53 | |
| 53 | 54 | #include <controllers/ScriptingInterface.h> |
| 54 | 55 | #include <AnimationObject.h> |
| @@ -70,7 +71,6 @@ · 15 unmodified lines | ||
| 70 | 71 | #include "WebSocketClass.h" |
| 71 | 72 | #include "RecordingScriptingInterface.h" |
| 72 | 73 | #include "ScriptEngines.h" |
| 73 | −#include "TabletScriptingInterface.h" | |
| 74 | 74 | #include "ModelScriptingInterface.h" |
| 75 | 75 | |
| 76 | 76 | |
| @@ -172,7 +172,7 @@ ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const · 95 unmodified lines | ||
| 172 | 172 | emit unhandledException(exception); |
| 173 | 173 | } |
| 174 | 174 | }, Qt::DirectConnection); |
| 175 | − | |
| 175 | + | |
| 176 | 176 | setProcessEventsInterval(MSECS_PER_SECOND); |
| 177 | 177 | if (isEntityServerScript()) { |
| 178 | 178 | qCDebug(scriptengine) << "isEntityServerScript() -- limiting maxRetries to 1"; |
| @@ -281,7 +281,7 @@ void ScriptEngine::runDebuggable() { · 102 unmodified lines | ||
| 281 | 281 | scriptDebugMenu = nullptr; |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | − disconnect(timer); | |
| 284 | + disconnect(timer); | |
| 285 | 285 | }); |
| 286 | 286 | |
| 287 | 287 | connect(timer, &QTimer::timeout, [this, timer] { |
| @@ -340,7 +340,7 @@ void ScriptEngine::runInThread() { · 52 unmodified lines | ||
| 340 | 340 | QThread* workerThread = new QThread(); |
| 341 | 341 | workerThread->setObjectName(QString("js:") + getFilename().replace("about:","")); |
| 342 | 342 | moveToThread(workerThread); |
| 343 | − | |
| 343 | + | |
| 344 | 344 | // NOTE: If you connect any essential signals for proper shutdown or cleanup of |
| 345 | 345 | // the script engine, make sure to add code to "reconnect" them to the |
| 346 | 346 | // disconnectNonEssentialSignals() method |
| @@ -697,8 +697,6 @@ void ScriptEngine::init() { · 350 unmodified lines | ||
| 697 | 697 | // constants |
| 698 | 698 | globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE))); |
| 699 | 699 | |
| 700 | − registerGlobalObject("Tablet", DependencyManager::get<TabletScriptingInterface>().data()); | |
| 701 | − qScriptRegisterMetaType(this, tabletToScriptValue, tabletFromScriptValue); | |
| 702 | 700 | registerGlobalObject("Assets", &_assetScriptingInterface); |
| 703 | 701 | registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data()); |
| 704 | 702 | |
| @@ -1047,26 +1045,26 @@ void ScriptEngine::run() { · 342 unmodified lines | ||
| 1047 | 1045 | auto beforeSleep = clock::now(); |
| 1048 | 1046 | |
| 1049 | 1047 | // 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 | |
| 1048 | + // We'd like to try to keep the script at a solid SCRIPT_FPS update rate. And so we will | |
| 1051 | 1049 | // 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 | |
| 1050 | + // sleepUntil for this frame. This approach will allow us to "catch up" in the event | |
| 1051 | + // that some of our script udpates/frames take a little bit longer than the target average | |
| 1054 | 1052 | // to execute. |
| 1055 | 1053 | // NOTE: if we go to variable SCRIPT_FPS, then we will need to reconsider this approach |
| 1056 | 1054 | const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(USECS_PER_SECOND / SCRIPT_FPS + 1); |
| 1057 | 1055 | clock::time_point targetSleepUntil(startTime + (thisFrame++ * TARGET_SCRIPT_FRAME_DURATION)); |
| 1058 | 1056 | |
| 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 | |
| 1057 | + // However, if our sleepUntil is not at least our average update and timer execution time | |
| 1058 | + // into the future it means our script is taking too long in its updates, and we want to | |
| 1059 | + // punish the script a little bit. So we will force the sleepUntil to be at least our | |
| 1062 | 1060 | // averageUpdate + averageTimerPerFrame time into the future. |
| 1063 | 1061 | auto averageUpdate = totalUpdates / thisFrame; |
| 1064 | 1062 | auto averageTimerPerFrame = _totalTimerExecution / thisFrame; |
| 1065 | 1063 | auto averageTimerAndUpdate = averageUpdate + averageTimerPerFrame; |
| 1066 | 1064 | auto sleepUntil = std::max(targetSleepUntil, beforeSleep + averageTimerAndUpdate); |
| 1067 | 1065 | |
| 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 | |
| 1066 | + // We don't want to actually sleep for too long, because it causes our scripts to hang | |
| 1067 | + // on shutdown and stop... so we want to loop and sleep until we've spent our time in | |
| 1070 | 1068 | // purgatory, constantly checking to see if our script was asked to end |
| 1071 | 1069 | bool processedEvents = false; |
| 1072 | 1070 | while (!_isFinished && clock::now() < sleepUntil) { |
| @@ -1414,7 +1412,7 @@ QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& re · 341 unmodified lines | ||
| 1414 | 1412 | if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) { |
| 1415 | 1413 | return QString(); |
| 1416 | 1414 | } |
| 1417 | − QUrl defaultScriptsLoc = defaultScriptsLocation(); | |
| 1415 | + QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation(); | |
| 1418 | 1416 | QUrl url(moduleId); |
| 1419 | 1417 | |
| 1420 | 1418 | auto displayId = moduleId; |
| @@ -1480,7 +1478,7 @@ QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& re · 59 unmodified lines | ||
| 1480 | 1478 | canonical.setPath(file.canonicalFilePath()); |
| 1481 | 1479 | } |
| 1482 | 1480 | |
| 1483 | − bool disallowOutsideFiles = !defaultScriptsLocation().isParentOf(canonical) && !currentSandboxURL.isLocalFile(); | |
| 1481 | + bool disallowOutsideFiles = !PathUtils::defaultScriptsLocation().isParentOf(canonical) && !currentSandboxURL.isLocalFile(); | |
| 1484 | 1482 | if (disallowOutsideFiles && !PathUtils::isDescendantOf(canonical, currentSandboxURL)) { |
| 1485 | 1483 | return throwResolveError(makeError(message.arg( |
| 1486 | 1484 | QString("path '%1' outside of origin script '%2' '%3'") |
| @@ -1765,7 +1763,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 278 unmodified lines | ||
| 1765 | 1763 | return; |
| 1766 | 1764 | } |
| 1767 | 1765 | if (DependencyManager::get<ScriptEngines>()->isStopped()) { |
| 1768 | − scriptWarningMessage("Script.include() while shutting down is ignored... includeFiles:" | |
| 1766 | + scriptWarningMessage("Script.include() while shutting down is ignored... includeFiles:" | |
| 1769 | 1767 | + includeFiles.join(",") + "parent script:" + getFilename()); |
| 1770 | 1768 | return; // bail early |
| 1771 | 1769 | } |
| @@ -1777,7 +1775,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 5 unmodified lines | ||
| 1777 | 1775 | bool isStandardLibrary = false; |
| 1778 | 1776 | if (file.startsWith("/~/")) { |
| 1779 | 1777 | thisURL = expandScriptUrl(QUrl::fromLocalFile(expandScriptPath(file))); |
| 1780 | − QUrl defaultScriptsLoc = defaultScriptsLocation(); | |
| 1778 | + QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation(); | |
| 1781 | 1779 | if (!defaultScriptsLoc.isParentOf(thisURL)) { |
| 1782 | 1780 | scriptWarningMessage("Script.include() -- skipping" + file + "-- outside of standard libraries"); |
| 1783 | 1781 | continue; |
| @@ -1789,7 +1787,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 5 unmodified lines | ||
| 1789 | 1787 | |
| 1790 | 1788 | bool disallowOutsideFiles = thisURL.isLocalFile() && !isStandardLibrary && !currentSandboxURL.isLocalFile(); |
| 1791 | 1789 | if (disallowOutsideFiles && !PathUtils::isDescendantOf(thisURL, currentSandboxURL)) { |
| 1792 | − scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString() | |
| 1790 | + scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString() | |
| 1793 | 1791 | + "outside of original entity script" + currentSandboxURL.toString()); |
| 1794 | 1792 | } else { |
| 1795 | 1793 | // We could also check here for CORS, but we don't yet. |
| @@ -1859,7 +1857,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 63 unmodified lines | ||
| 1859 | 1857 | |
| 1860 | 1858 | void ScriptEngine::include(const QString& includeFile, QScriptValue callback) { |
| 1861 | 1859 | if (DependencyManager::get<ScriptEngines>()->isStopped()) { |
| 1862 | − scriptWarningMessage("Script.include() while shutting down is ignored... includeFile:" | |
| 1860 | + scriptWarningMessage("Script.include() while shutting down is ignored... includeFile:" | |
| 1863 | 1861 | + includeFile + "parent script:" + getFilename()); |
| 1864 | 1862 | return; // bail early |
| 1865 | 1863 | } |
| @@ -1877,12 +1875,12 @@ void ScriptEngine::load(const QString& loadFile) { · 11 unmodified lines | ||
| 1877 | 1875 | return; |
| 1878 | 1876 | } |
| 1879 | 1877 | if (DependencyManager::get<ScriptEngines>()->isStopped()) { |
| 1880 | − scriptWarningMessage("Script.load() while shutting down is ignored... loadFile:" | |
| 1878 | + scriptWarningMessage("Script.load() while shutting down is ignored... loadFile:" | |
| 1881 | 1879 | + loadFile + "parent script:" + getFilename()); |
| 1882 | 1880 | return; // bail early |
| 1883 | 1881 | } |
| 1884 | 1882 | if (!currentEntityIdentifier.isInvalidID()) { |
| 1885 | − scriptWarningMessage("Script.load() from entity script is ignored... loadFile:" | |
| 1883 | + scriptWarningMessage("Script.load() from entity script is ignored... loadFile:" | |
| 1886 | 1884 | + loadFile + "parent script:" + getFilename() + "entity: " + currentEntityIdentifier.toString()); |
| 1887 | 1885 | return; // bail early |
| 1888 | 1886 | } |
| @@ -2563,7 +2561,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 674 unmodified lines | ||
| 2563 | 2561 | qCDebug(scriptengine) << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " |
| 2564 | 2562 | "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision"; |
| 2565 | 2563 | #endif |
| 2566 | − | |
| 2564 | + | |
| 2567 | 2565 | if (HIFI_AUTOREFRESH_FILE_SCRIPTS) { |
| 2568 | 2566 | refreshFileScript(entityID); |
| 2569 | 2567 | } |