History

Merge branch 'master' of https://github.com/highfidelity/hifi into brown

samcake committed 9 years ago

Commit b7b520a2 parents c24e254 f1fe4ed99 files · +1609 −821Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+22−24
@@ -24,6 +24,8 @@ · 23 unmodified lines
2424
2525 #include <QtWidgets/QMainWindow>
2626 #include <QtWidgets/QApplication>
27+#include <QtWidgets/QMenuBar>
28+#include <QtWidgets/QMenu>
2729
2830 #include <QtNetwork/QNetworkRequest>
2931 #include <QtNetwork/QNetworkReply>
@@ -48,7 +50,6 @@ · 18 unmodified lines
4850 #include <ScriptAvatarData.h>
4951 #include <udt/PacketHeaders.h>
5052 #include <UUID.h>
51−#include <ui/Menu.h>
5253
5354 #include <controllers/ScriptingInterface.h>
5455 #include <AnimationObject.h>
@@ -70,7 +71,6 @@ · 15 unmodified lines
7071 #include "WebSocketClass.h"
7172 #include "RecordingScriptingInterface.h"
7273 #include "ScriptEngines.h"
73−#include "TabletScriptingInterface.h"
7474 #include "ModelScriptingInterface.h"
7575
7676
@@ -172,7 +172,7 @@ ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const · 95 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
@@ -697,8 +697,6 @@ void ScriptEngine::init() { · 350 unmodified lines
697697 // constants
698698 globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE)));
699699
700− registerGlobalObject("Tablet", DependencyManager::get<TabletScriptingInterface>().data());
701− qScriptRegisterMetaType(this, tabletToScriptValue, tabletFromScriptValue);
702700 registerGlobalObject("Assets", &_assetScriptingInterface);
703701 registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data());
704702
@@ -1047,26 +1045,26 @@ void ScriptEngine::run() { · 342 unmodified lines
10471045 auto beforeSleep = clock::now();
10481046
10491047 // 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
10511049 // 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
10541052 // to execute.
10551053 // NOTE: if we go to variable SCRIPT_FPS, then we will need to reconsider this approach
10561054 const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(USECS_PER_SECOND / SCRIPT_FPS + 1);
10571055 clock::time_point targetSleepUntil(startTime + (thisFrame++ * TARGET_SCRIPT_FRAME_DURATION));
10581056
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
10621060 // averageUpdate + averageTimerPerFrame time into the future.
10631061 auto averageUpdate = totalUpdates / thisFrame;
10641062 auto averageTimerPerFrame = _totalTimerExecution / thisFrame;
10651063 auto averageTimerAndUpdate = averageUpdate + averageTimerPerFrame;
10661064 auto sleepUntil = std::max(targetSleepUntil, beforeSleep + averageTimerAndUpdate);
10671065
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
10701068 // purgatory, constantly checking to see if our script was asked to end
10711069 bool processedEvents = false;
10721070 while (!_isFinished && clock::now() < sleepUntil) {
@@ -1414,7 +1412,7 @@ QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& re · 341 unmodified lines
14141412 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
14151413 return QString();
14161414 }
1417− QUrl defaultScriptsLoc = defaultScriptsLocation();
1415+ QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation();
14181416 QUrl url(moduleId);
14191417
14201418 auto displayId = moduleId;
@@ -1480,7 +1478,7 @@ QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& re · 59 unmodified lines
14801478 canonical.setPath(file.canonicalFilePath());
14811479 }
14821480
1483− bool disallowOutsideFiles = !defaultScriptsLocation().isParentOf(canonical) && !currentSandboxURL.isLocalFile();
1481+ bool disallowOutsideFiles = !PathUtils::defaultScriptsLocation().isParentOf(canonical) && !currentSandboxURL.isLocalFile();
14841482 if (disallowOutsideFiles && !PathUtils::isDescendantOf(canonical, currentSandboxURL)) {
14851483 return throwResolveError(makeError(message.arg(
14861484 QString("path '%1' outside of origin script '%2' '%3'")
@@ -1765,7 +1763,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 278 unmodified lines
17651763 return;
17661764 }
17671765 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:"
17691767 + includeFiles.join(",") + "parent script:" + getFilename());
17701768 return; // bail early
17711769 }
@@ -1777,7 +1775,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 5 unmodified lines
17771775 bool isStandardLibrary = false;
17781776 if (file.startsWith("/~/")) {
17791777 thisURL = expandScriptUrl(QUrl::fromLocalFile(expandScriptPath(file)));
1780− QUrl defaultScriptsLoc = defaultScriptsLocation();
1778+ QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation();
17811779 if (!defaultScriptsLoc.isParentOf(thisURL)) {
17821780 scriptWarningMessage("Script.include() -- skipping" + file + "-- outside of standard libraries");
17831781 continue;
@@ -1789,7 +1787,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 5 unmodified lines
17891787
17901788 bool disallowOutsideFiles = thisURL.isLocalFile() && !isStandardLibrary && !currentSandboxURL.isLocalFile();
17911789 if (disallowOutsideFiles && !PathUtils::isDescendantOf(thisURL, currentSandboxURL)) {
1792− scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString()
1790+ scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString()
17931791 + "outside of original entity script" + currentSandboxURL.toString());
17941792 } else {
17951793 // 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
18591857
18601858 void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
18611859 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:"
18631861 + includeFile + "parent script:" + getFilename());
18641862 return; // bail early
18651863 }
@@ -1877,12 +1875,12 @@ void ScriptEngine::load(const QString& loadFile) { · 11 unmodified lines
18771875 return;
18781876 }
18791877 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:"
18811879 + loadFile + "parent script:" + getFilename());
18821880 return; // bail early
18831881 }
18841882 if (!currentEntityIdentifier.isInvalidID()) {
1885− scriptWarningMessage("Script.load() from entity script is ignored... loadFile:"
1883+ scriptWarningMessage("Script.load() from entity script is ignored... loadFile:"
18861884 + loadFile + "parent script:" + getFilename() + "entity: " + currentEntityIdentifier.toString());
18871885 return; // bail early
18881886 }
@@ -2563,7 +2561,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 674 unmodified lines
25632561 qCDebug(scriptengine) << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] "
25642562 "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision";
25652563 #endif
2566−
2564+
25672565 if (HIFI_AUTOREFRESH_FILE_SCRIPTS) {
25682566 refreshFileScript(entityID);
25692567 }