History

resolve conflicts on merge with upstream/master

Stephen Birarda committed 11 years ago

Commit cee029f2 parents 7986b61 170725457 files · +855 −682Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+295−295
@@ -58,13 +58,13 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ · 57 unmodified lines
5858 message += context->argument(i).toString();
5959 }
6060 qCDebug(scriptengine) << "script:print()<<" << message;
61−
61+
6262 message = message.replace("\\", "\\\\")
63− .replace("\n", "\\n")
64− .replace("\r", "\\r")
65− .replace("'", "\\'");
63+ .replace("\n", "\\n")
64+ .replace("\r", "\\r")
65+ .replace("'", "\\'");
6666 engine->evaluate("Script.print('" + message + "')");
67−
67+
6868 return QScriptValue();
6969 }
7070
@@ -83,20 +83,51 @@ void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputCon · 12 unmodified lines
8383 out = qobject_cast<AbstractInputController*>(object.toQObject());
8484 }
8585
86−ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString,
87− AbstractControllerScriptingInterface* controllerScriptingInterface, bool wantSignals) :
86+static bool hasCorrectSyntax(const QScriptProgram& program) {
87+ const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());
88+ if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
89+ const auto error = syntaxCheck.errorMessage();
90+ const auto line = QString::number(syntaxCheck.errorLineNumber());
91+ const auto column = QString::number(syntaxCheck.errorColumnNumber());
92+ const auto message = QString("[SyntaxError] %1 in %2:%3(%4)").arg(error, program.fileName(), line, column);
93+ qCWarning(scriptengine) << qPrintable(message);
94+ return false;
95+ }
96+ return true;
97+}
8898
89− _scriptContents(scriptContents),
90− _isFinished(false),
91− _isRunning(false),
92− _isInitialized(false),
93− _timerFunctionMap(),
94− _wantSignals(wantSignals),
95− _controllerScriptingInterface(controllerScriptingInterface),
96− _fileNameString(fileNameString),
97− _isUserLoaded(false),
98− _isReloading(false),
99− _arrayBufferClass(new ArrayBufferClass(this))
99+static bool hadUncauchtExceptions(QScriptEngine& engine, const QString& fileName) {
100+ if (engine.hasUncaughtException()) {
101+ const auto backtrace = engine.uncaughtExceptionBacktrace();
102+ const auto exception = engine.uncaughtException().toString();
103+ const auto line = QString::number(engine.uncaughtExceptionLineNumber());
104+ engine.clearExceptions();
105+
106+ auto message = QString("[UncaughtException] %1 in %2:%3").arg(exception, fileName, line);
107+ if (!backtrace.empty()) {
108+ static const auto lineSeparator = "\n ";
109+ message += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator));
110+ }
111+ qCWarning(scriptengine) << qPrintable(message);
112+ return true;
113+ }
114+ return false;
115+}
116+
117+ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString,
118+ AbstractControllerScriptingInterface* controllerScriptingInterface, bool wantSignals) :
119+
120+_scriptContents(scriptContents),
121+_isFinished(false),
122+_isRunning(false),
123+_isInitialized(false),
124+_timerFunctionMap(),
125+_wantSignals(wantSignals),
126+_controllerScriptingInterface(controllerScriptingInterface),
127+_fileNameString(fileNameString),
128+_isUserLoaded(false),
129+_isReloading(false),
130+_arrayBufferClass(new ArrayBufferClass(this))
100131 {
101132 _allScriptsMutex.lock();
102133 _allKnownScriptEngines.insert(this);
@@ -118,21 +149,21 @@ void ScriptEngine::runInThread() { · 15 unmodified lines
118149 QThread* workerThread = new QThread(); // thread is not owned, so we need to manage the delete
119150 QString scriptEngineName = QString("Script Thread:") + getFilename();
120151 workerThread->setObjectName(scriptEngineName);
121−
152+
122153 // when the worker thread is started, call our engine's run..
123154 connect(workerThread, &QThread::started, this, &ScriptEngine::run);
124−
155+
125156 // tell the thread to stop when the script engine is done
126157 connect(this, &ScriptEngine::doneRunning, workerThread, &QThread::quit);
127−
158+
128159 // when the thread is finished, add thread to the deleteLater queue
129160 connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater);
130−
161+
131162 // when the thread is finished, add scriptEngine to the deleteLater queue
132163 connect(workerThread, &QThread::finished, this, &ScriptEngine::deleteLater);
133−
164+
134165 moveToThread(workerThread);
135−
166+
136167 // Starts an event loop, and emits workerThread->started()
137168 workerThread->start();
138169 }
@@ -145,23 +176,23 @@ bool ScriptEngine::_doneRunningThisScript = false; · 6 unmodified lines
145176 void ScriptEngine::stopAllScripts(QObject* application) {
146177 _allScriptsMutex.lock();
147178 _stoppingAllScripts = true;
148−
179+
149180 QMutableSetIterator<ScriptEngine*> i(_allKnownScriptEngines);
150181 while (i.hasNext()) {
151182 ScriptEngine* scriptEngine = i.next();
152−
183+
153184 QString scriptName = scriptEngine->getFilename();
154−
185+
155186 // NOTE: typically all script engines are running. But there's at least one known exception to this, the
156187 // "entities sandbox" which is only used to evaluate entities scripts to test their validity before using
157188 // them. We don't need to stop scripts that aren't running.
158189 if (scriptEngine->isRunning()) {
159−
190+
160191 // If the script is running, but still evaluating then we need to wait for its evaluation step to
161192 // complete. After that we can handle the stop process appropriately
162193 if (scriptEngine->evaluatePending()) {
163194 while (scriptEngine->evaluatePending()) {
164−
195+
165196 // This event loop allows any started, but not yet finished evaluate() calls to complete
166197 // we need to let these complete so that we can be guaranteed that the script engine isn't
167198 // in a partially setup state, which can confuse our shutdown unwinding.
@@ -170,21 +201,21 @@ void ScriptEngine::stopAllScripts(QObject* application) { · 2 unmodified lines
170201 loop.exec();
171202 }
172203 }
173−
204+
174205 // We disconnect any script engine signals from the application because we don't want to do any
175206 // extra stopScript/loadScript processing that the Application normally does when scripts start
176207 // and stop. We can safely short circuit this because we know we're in the "quitting" process
177208 scriptEngine->disconnect(application);
178−
209+
179210 // Calling stop on the script engine will set it's internal _isFinished state to true, and result
180211 // in the ScriptEngine gracefully ending it's run() method.
181212 scriptEngine->stop();
182−
213+
183214 // We need to wait for the engine to be done running before we proceed, because we don't
184215 // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing
185216 // any application state after we leave this stopAllScripts() method
186217 scriptEngine->waitTillDoneRunning();
187−
218+
188219 // If the script is stopped, we can remove it from our set
189220 i.remove();
190221 }
@@ -197,15 +228,15 @@ void ScriptEngine::stopAllScripts(QObject* application) { · 6 unmodified lines
197228 void ScriptEngine::waitTillDoneRunning() {
198229 // If the script never started running or finished running before we got here, we don't need to wait for it
199230 if (_isRunning) {
200−
231+
201232 _doneRunningThisScript = false; // NOTE: this is static, we serialize our waiting for scripts to finish
202−
233+
203234 // NOTE: waitTillDoneRunning() will be called on the main Application thread, inside of stopAllScripts()
204235 // we want the application thread to continue to process events, because the scripts will likely need to
205236 // marshall messages across to the main thread. For example if they access Settings or Meny in any of their
206237 // shutdown code.
207238 while (!_doneRunningThisScript) {
208−
239+
209240 // process events for the main application thread, allowing invokeMethod calls to pass between threads
210241 QCoreApplication::processEvents();
211242 }
@@ -227,12 +258,12 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 15 unmodified lines
227258 if (_isRunning) {
228259 return;
229260 }
230−
261+
231262 _fileNameString = scriptURL.toString();
232263 _isReloading = reload;
233−
264+
234265 QUrl url(scriptURL);
235−
266+
236267 bool isPending;
237268 auto scriptCache = DependencyManager::get<ScriptCache>();
238269 scriptCache->getScript(url, this, isPending, reload);
@@ -258,12 +289,12 @@ void ScriptEngine::init() { · 19 unmodified lines
258289 if (_isInitialized) {
259290 return; // only initialize once
260291 }
261−
292+
262293 _isInitialized = true;
263294
264295 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
265296 entityScriptingInterface->init();
266−
297+
267298 // register various meta-types
268299 registerMetaTypes(this);
269300 registerMIDIMetaTypes(this);
@@ -272,30 +303,30 @@ void ScriptEngine::init() { · 2 unmodified lines
272303 registerAnimationTypes(this);
273304 registerAvatarTypes(this);
274305 registerAudioMetaTypes(this);
275−
306+
276307 qScriptRegisterMetaType(this, EntityPropertyFlagsToScriptValue, EntityPropertyFlagsFromScriptValue);
277308 qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValueHonorReadOnly);
278309 qScriptRegisterMetaType(this, EntityItemIDtoScriptValue, EntityItemIDfromScriptValue);
279310 qScriptRegisterMetaType(this, RayToEntityIntersectionResultToScriptValue, RayToEntityIntersectionResultFromScriptValue);
280311 qScriptRegisterSequenceMetaType<QVector<QUuid>>(this);
281312 qScriptRegisterSequenceMetaType<QVector<EntityItemID>>(this);
282−
313+
283314 qScriptRegisterSequenceMetaType<QVector<glm::vec2> >(this);
284315 qScriptRegisterSequenceMetaType<QVector<glm::quat> >(this);
285316 qScriptRegisterSequenceMetaType<QVector<QString> >(this);
286−
317+
287318 QScriptValue xmlHttpRequestConstructorValue = newFunction(XMLHttpRequestClass::constructor);
288319 globalObject().setProperty("XMLHttpRequest", xmlHttpRequestConstructorValue);
289−
320+
290321 QScriptValue webSocketConstructorValue = newFunction(WebSocketClass::constructor);
291322 globalObject().setProperty("WebSocket", webSocketConstructorValue);
292−
323+
293324 QScriptValue printConstructorValue = newFunction(debugPrint);
294325 globalObject().setProperty("print", printConstructorValue);
295−
326+
296327 QScriptValue audioEffectOptionsConstructorValue = newFunction(AudioEffectOptions::constructor);
297328 globalObject().setProperty("AudioEffectOptions", audioEffectOptionsConstructorValue);
298−
329+
299330 qScriptRegisterMetaType(this, injectorToScriptValue, injectorFromScriptValue);
300331 qScriptRegisterMetaType(this, inputControllerToScriptValue, inputControllerFromScriptValue);
301332 qScriptRegisterMetaType(this, avatarDataToScriptValue, avatarDataFromScriptValue);
@@ -303,7 +334,7 @@ void ScriptEngine::init() { · 1 unmodified line
303334 qScriptRegisterMetaType(this, webSocketToScriptValue, webSocketFromScriptValue);
304335 qScriptRegisterMetaType(this, qWSCloseCodeToScriptValue, qWSCloseCodeFromScriptValue);
305336 qScriptRegisterMetaType(this, wscReadyStateToScriptValue, wscReadyStateFromScriptValue);
306−
337+
307338 registerGlobalObject("Script", this);
308339 registerGlobalObject("Audio", &AudioScriptingInterface::getInstance());
309340 registerGlobalObject("Controller", _controllerScriptingInterface);
@@ -312,15 +343,15 @@ void ScriptEngine::init() { · 2 unmodified lines
312343 registerGlobalObject("Vec3", &_vec3Library);
313344 registerGlobalObject("Uuid", &_uuidLibrary);
314345 registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
315−
346+
316347 // constants
317348 globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE)));
318−
349+
319350 if (_controllerScriptingInterface) {
320351 _controllerScriptingInterface->registerControllerTypes(this);
321352 }
322−
323−
353+
354+
324355 }
325356
326357 void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
@@ -329,15 +360,15 @@ void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) { · 2 unmodified lines
329360 qDebug() << "*** WARNING *** ScriptEngine::registerValue() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;
330361 #endif
331362 QMetaObject::invokeMethod(this, "registerValue",
332− Q_ARG(const QString&, valueName),
333− Q_ARG(QScriptValue, value));
363+ Q_ARG(const QString&, valueName),
364+ Q_ARG(QScriptValue, value));
334365 return;
335366 }
336−
367+
337368 QStringList pathToValue = valueName.split(".");
338369 int partsToGo = pathToValue.length();
339370 QScriptValue partObject = globalObject();
340−
371+
341372 for (const auto& pathPart : pathToValue) {
342373 partsToGo--;
343374 if (!partObject.property(pathPart).isValid()) {
@@ -356,18 +387,18 @@ void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) { · 12 unmodified lines
356387
357388 void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) {
358389 if (QThread::currentThread() != thread()) {
359− #ifdef THREAD_DEBUGGING
390+#ifdef THREAD_DEBUGGING
360391 qDebug() << "*** WARNING *** ScriptEngine::registerGlobalObject() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;
361− #endif
392+#endif
362393 QMetaObject::invokeMethod(this, "registerGlobalObject",
363− Q_ARG(const QString&, name),
364− Q_ARG(QObject*, object));
394+ Q_ARG(const QString&, name),
395+ Q_ARG(QObject*, object));
365396 return;
366397 }
367− #ifdef THREAD_DEBUGGING
398+#ifdef THREAD_DEBUGGING
368399 qDebug() << "ScriptEngine::registerGlobalObject() called on thread [" << QThread::currentThread() << "] name:" << name;
369− #endif
370−
400+#endif
401+
371402 if (!globalObject().property(name).isValid()) {
372403 if (object) {
373404 QScriptValue value = newQObject(object);
@@ -380,38 +411,38 @@ void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { · 6 unmodified lines
380411
381412 void ScriptEngine::registerFunction(const QString& name, QScriptEngine::FunctionSignature functionSignature, int numArguments) {
382413 if (QThread::currentThread() != thread()) {
383− #ifdef THREAD_DEBUGGING
414+#ifdef THREAD_DEBUGGING
384415 qDebug() << "*** WARNING *** ScriptEngine::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;
385− #endif
416+#endif
386417 QMetaObject::invokeMethod(this, "registerFunction",
387− Q_ARG(const QString&, name),
388− Q_ARG(QScriptEngine::FunctionSignature, functionSignature),
389− Q_ARG(int, numArguments));
418+ Q_ARG(const QString&, name),
419+ Q_ARG(QScriptEngine::FunctionSignature, functionSignature),
420+ Q_ARG(int, numArguments));
390421 return;
391422 }
392− #ifdef THREAD_DEBUGGING
423+#ifdef THREAD_DEBUGGING
393424 qDebug() << "ScriptEngine::registerFunction() called on thread [" << QThread::currentThread() << "] name:" << name;
394− #endif
395−
425+#endif
426+
396427 QScriptValue scriptFun = newFunction(functionSignature, numArguments);
397428 globalObject().setProperty(name, scriptFun);
398429 }
399430
400431 void ScriptEngine::registerFunction(const QString& parent, const QString& name, QScriptEngine::FunctionSignature functionSignature, int numArguments) {
401432 if (QThread::currentThread() != thread()) {
402− #ifdef THREAD_DEBUGGING
433+#ifdef THREAD_DEBUGGING
403434 qDebug() << "*** WARNING *** ScriptEngine::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] parent:" << parent << "name:" << name;
404− #endif
435+#endif
405436 QMetaObject::invokeMethod(this, "registerFunction",
406− Q_ARG(const QString&, name),
407− Q_ARG(QScriptEngine::FunctionSignature, functionSignature),
408− Q_ARG(int, numArguments));
437+ Q_ARG(const QString&, name),
438+ Q_ARG(QScriptEngine::FunctionSignature, functionSignature),
439+ Q_ARG(int, numArguments));
409440 return;
410441 }
411− #ifdef THREAD_DEBUGGING
442+#ifdef THREAD_DEBUGGING
412443 qDebug() << "ScriptEngine::registerFunction() called on thread [" << QThread::currentThread() << "] parent:" << parent << "name:" << name;
413− #endif
414−
444+#endif
445+
415446 QScriptValue object = globalObject().property(parent);
416447 if (object.isValid()) {
417448 QScriptValue scriptFun = newFunction(functionSignature, numArguments);
@@ -420,26 +451,26 @@ void ScriptEngine::registerFunction(const QString& parent, const QString& name, · 2 unmodified lines
420451 }
421452
422453 void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter,
423− QScriptEngine::FunctionSignature setter, const QString& parent) {
454+ QScriptEngine::FunctionSignature setter, const QString& parent) {
424455 if (QThread::currentThread() != thread()) {
425− #ifdef THREAD_DEBUGGING
456+#ifdef THREAD_DEBUGGING
426457 qDebug() << "*** WARNING *** ScriptEngine::registerGetterSetter() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
427− " name:" << name << "parent:" << parent;
428− #endif
458+ " name:" << name << "parent:" << parent;
459+#endif
429460 QMetaObject::invokeMethod(this, "registerGetterSetter",
430− Q_ARG(const QString&, name),
431− Q_ARG(QScriptEngine::FunctionSignature, getter),
432− Q_ARG(QScriptEngine::FunctionSignature, setter),
433− Q_ARG(const QString&, parent));
461+ Q_ARG(const QString&, name),
462+ Q_ARG(QScriptEngine::FunctionSignature, getter),
463+ Q_ARG(QScriptEngine::FunctionSignature, setter),
464+ Q_ARG(const QString&, parent));
434465 return;
435466 }
436− #ifdef THREAD_DEBUGGING
467+#ifdef THREAD_DEBUGGING
437468 qDebug() << "ScriptEngine::registerGetterSetter() called on thread [" << QThread::currentThread() << "] name:" << name << "parent:" << parent;
438− #endif
439−
469+#endif
470+
440471 QScriptValue setterFunction = newFunction(setter, 1);
441472 QScriptValue getterFunction = newFunction(getter);
442−
473+
443474 if (!parent.isNull() && !parent.isEmpty()) {
444475 QScriptValue object = globalObject().property(parent);
445476 if (object.isValid()) {
@@ -455,20 +486,20 @@ void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::Func · 9 unmodified lines
455486 // Unregister the handlers for this eventName and entityID.
456487 void ScriptEngine::removeEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler) {
457488 if (QThread::currentThread() != thread()) {
458− #ifdef THREAD_DEBUGGING
489+#ifdef THREAD_DEBUGGING
459490 qDebug() << "*** WARNING *** ScriptEngine::removeEventHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
460− "entityID:" << entityID << " eventName:" << eventName;
461− #endif
491+ "entityID:" << entityID << " eventName:" << eventName;
492+#endif
462493 QMetaObject::invokeMethod(this, "removeEventHandler",
463− Q_ARG(const EntityItemID&, entityID),
464− Q_ARG(const QString&, eventName),
465− Q_ARG(QScriptValue, handler));
494+ Q_ARG(const EntityItemID&, entityID),
495+ Q_ARG(const QString&, eventName),
496+ Q_ARG(QScriptValue, handler));
466497 return;
467498 }
468− #ifdef THREAD_DEBUGGING
499+#ifdef THREAD_DEBUGGING
469500 qDebug() << "ScriptEngine::removeEventHandler() called on thread [" << QThread::currentThread() << "] entityID:" << entityID << " eventName : " << eventName;
470− #endif
471−
501+#endif
502+
472503 if (!_registeredHandlers.contains(entityID)) {
473504 return;
474505 }
@@ -485,21 +516,21 @@ void ScriptEngine::removeEventHandler(const EntityItemID& entityID, const QStrin · 10 unmodified lines
485516 // Register the handler.
486517 void ScriptEngine::addEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler) {
487518 if (QThread::currentThread() != thread()) {
488− #ifdef THREAD_DEBUGGING
519+#ifdef THREAD_DEBUGGING
489520 qDebug() << "*** WARNING *** ScriptEngine::addEventHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
490− "entityID:" << entityID << " eventName:" << eventName;
491− #endif
492−
521+ "entityID:" << entityID << " eventName:" << eventName;
522+#endif
523+
493524 QMetaObject::invokeMethod(this, "addEventHandler",
494− Q_ARG(const EntityItemID&, entityID),
495− Q_ARG(const QString&, eventName),
496− Q_ARG(QScriptValue, handler));
525+ Q_ARG(const EntityItemID&, entityID),
526+ Q_ARG(const QString&, eventName),
527+ Q_ARG(QScriptValue, handler));
497528 return;
498529 }
499− #ifdef THREAD_DEBUGGING
530+#ifdef THREAD_DEBUGGING
500531 qDebug() << "ScriptEngine::addEventHandler() called on thread [" << QThread::currentThread() << "] entityID:" << entityID << " eventName : " << eventName;
501− #endif
502−
532+#endif
533+
503534 if (_registeredHandlers.count() == 0) { // First time any per-entity handler has been added in this script...
504535 // Connect up ALL the handlers to the global entities object's signals.
505536 // (We could go signal by signal, or even handler by handler, but I don't think the efficiency is worth the complexity.)
@@ -527,25 +558,25 @@ void ScriptEngine::addEventHandler(const EntityItemID& entityID, const QString& · 21 unmodified lines
527558 auto makeCollisionHandler = [this](QString eventName) -> CollisionHandler {
528559 return [this, eventName](const EntityItemID& idA, const EntityItemID& idB, const Collision& collision) {
529560 forwardHandlerCall(idA, eventName, { idA.toScriptValue(this), idB.toScriptValue(this),
530− collisionToScriptValue(this, collision) });
561+ collisionToScriptValue(this, collision) });
531562 };
532563 };
533564
534565 connect(entities.data(), &EntityScriptingInterface::enterEntity, this, makeSingleEntityHandler("enterEntity"));
535566 connect(entities.data(), &EntityScriptingInterface::leaveEntity, this, makeSingleEntityHandler("leaveEntity"));
536−
567+
537568 connect(entities.data(), &EntityScriptingInterface::mousePressOnEntity, this, makeMouseHandler("mousePressOnEntity"));
538569 connect(entities.data(), &EntityScriptingInterface::mouseMoveOnEntity, this, makeMouseHandler("mouseMoveOnEntity"));
539570 connect(entities.data(), &EntityScriptingInterface::mouseReleaseOnEntity, this, makeMouseHandler("mouseReleaseOnEntity"));
540−
571+
541572 connect(entities.data(), &EntityScriptingInterface::clickDownOnEntity, this, makeMouseHandler("clickDownOnEntity"));
542573 connect(entities.data(), &EntityScriptingInterface::holdingClickOnEntity, this, makeMouseHandler("holdingClickOnEntity"));
543574 connect(entities.data(), &EntityScriptingInterface::clickReleaseOnEntity, this, makeMouseHandler("clickReleaseOnEntity"));
544−
575+
545576 connect(entities.data(), &EntityScriptingInterface::hoverEnterEntity, this, makeMouseHandler("hoverEnterEntity"));
546577 connect(entities.data(), &EntityScriptingInterface::hoverOverEntity, this, makeMouseHandler("hoverOverEntity"));
547578 connect(entities.data(), &EntityScriptingInterface::hoverLeaveEntity, this, makeMouseHandler("hoverLeaveEntity"));
548−
579+
549580 connect(entities.data(), &EntityScriptingInterface::collisionWithEntity, this, makeCollisionHandler("collisionWithEntity"));
550581 }
551582 if (!_registeredHandlers.contains(entityID)) {
@@ -560,32 +591,32 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi · 8 unmodified lines
560591 if (_stoppingAllScripts) {
561592 return QScriptValue(); // bail early
562593 }
563−
594+
564595 if (QThread::currentThread() != thread()) {
565596 QScriptValue result;
566− #ifdef THREAD_DEBUGGING
597+#ifdef THREAD_DEBUGGING
567598 qDebug() << "*** WARNING *** ScriptEngine::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
568− "sourceCode:" << sourceCode << " fileName:" << fileName << "lineNumber:" << lineNumber;
569− #endif
599+ "sourceCode:" << sourceCode << " fileName:" << fileName << "lineNumber:" << lineNumber;
600+#endif
570601 QMetaObject::invokeMethod(this, "evaluate", Qt::BlockingQueuedConnection,
571− Q_RETURN_ARG(QScriptValue, result),
572− Q_ARG(const QString&, sourceCode),
573− Q_ARG(const QString&, fileName),
574− Q_ARG(int, lineNumber));
602+ Q_RETURN_ARG(QScriptValue, result),
603+ Q_ARG(const QString&, sourceCode),
604+ Q_ARG(const QString&, fileName),
605+ Q_ARG(int, lineNumber));
575606 return result;
576607 }
577608
578609 // Check syntax
579610 const QScriptProgram program(sourceCode, fileName, lineNumber);
580− if (!checkSyntax(program)) {
611+ if (!hasCorrectSyntax(program)) {
581612 return QScriptValue();
582613 }
583−
614+
584615 ++_evaluatesPending;
585616 const auto result = QScriptEngine::evaluate(program);
586617 --_evaluatesPending;
587618
588− const auto hadUncaughtException = checkExceptions(*this, program.fileName());
619+ const auto hadUncaughtException = hadUncauchtExceptions(*this, program.fileName());
589620 if (_wantSignals) {
590621 emit evaluationFinished(result, hadUncaughtException);
591622 }
@@ -595,7 +626,7 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi · 3 unmodified lines
595626 void ScriptEngine::run() {
596627 // TODO: can we add a short circuit for _stoppingAllScripts here? What does it mean to not start running if
597628 // we're in the process of stopping?
598−
629+
599630 if (!_isInitialized) {
600631 init();
601632 }
@@ -605,69 +636,69 @@ void ScriptEngine::run() { · 3 unmodified lines
605636 if (_wantSignals) {
606637 emit runningStateChanged();
607638 }
608−
639+
609640 QScriptValue result = evaluate(_scriptContents, _fileNameString);
610−
641+
611642 QElapsedTimer startTime;
612643 startTime.start();
613−
644+
614645 int thisFrame = 0;
615−
646+
616647 auto nodeList = DependencyManager::get<NodeList>();
617648 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
618−
649+
619650 qint64 lastUpdate = usecTimestampNow();
620−
651+
621652 while (!_isFinished) {
622653 int usecToSleep = (thisFrame++ * SCRIPT_DATA_CALLBACK_USECS) - startTime.nsecsElapsed() / 1000; // nsec to usec
623654 if (usecToSleep > 0) {
624655 usleep(usecToSleep);
625656 }
626−
657+
627658 if (_isFinished) {
628659 break;
629660 }
630−
661+
631662 QCoreApplication::processEvents();
632−
663+
633664 if (_isFinished) {
634665 break;
635666 }
636−
667+
637668 if (!_isFinished && entityScriptingInterface->getEntityPacketSender()->serversExist()) {
638669 // release the queue of edit entity messages.
639670 entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages();
640−
671+
641672 // since we're in non-threaded mode, call process so that the packets are sent
642673 if (!entityScriptingInterface->getEntityPacketSender()->isThreaded()) {
643674 entityScriptingInterface->getEntityPacketSender()->process();
644675 }
645676 }
646−
677+
647678 qint64 now = usecTimestampNow();
648679 float deltaTime = (float) (now - lastUpdate) / (float) USECS_PER_SECOND;
649−
680+
650681 if (!_isFinished) {
651682 if (_wantSignals) {
652683 emit update(deltaTime);
653684 }
654685 }
655686 lastUpdate = now;
656−
657− if (!checkExceptions(*this, _fileNameString)) {
687+
688+ if (hadUncauchtExceptions(*this, _fileNameString)) {
658689 stop();
659690 }
660691 }
661−
692+
662693 stopAllTimers(); // make sure all our timers are stopped if the script is ending
663694 if (_wantSignals) {
664695 emit scriptEnding();
665696 }
666−
697+
667698 if (entityScriptingInterface->getEntityPacketSender()->serversExist()) {
668699 // release the queue of edit entity messages.
669700 entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages();
670−
701+
671702 // since we're in non-threaded mode, call process so that the packets are sent
672703 if (!entityScriptingInterface->getEntityPacketSender()->isThreaded()) {
673704 // wait here till the edit packet sender is completely done sending
@@ -679,17 +710,17 @@ void ScriptEngine::run() { · 5 unmodified lines
679710 // FIXME - do we need to have a similar "wait here" loop for non-threaded packet senders?
680711 }
681712 }
682−
713+
683714 if (_wantSignals) {
684715 emit finished(_fileNameString);
685716 }
686−
717+
687718 _isRunning = false;
688719 if (_wantSignals) {
689720 emit runningStateChanged();
690721 emit doneRunning();
691722 }
692−
723+
693724 _doneRunningThisScript = true;
694725 }
695726
@@ -716,13 +747,13 @@ void ScriptEngine::stop() { · 20 unmodified lines
716747 void ScriptEngine::timerFired() {
717748 QTimer* callingTimer = reinterpret_cast<QTimer*>(sender());
718749 QScriptValue timerFunction = _timerFunctionMap.value(callingTimer);
719−
750+
720751 if (!callingTimer->isActive()) {
721752 // this timer is done, we can kill it
722753 _timerFunctionMap.remove(callingTimer);
723754 delete callingTimer;
724755 }
725−
756+
726757 // call the associated JS function, if it exists
727758 if (timerFunction.isValid()) {
728759 timerFunction.call();
@@ -733,14 +764,14 @@ QObject* ScriptEngine::setupTimerWithInterval(const QScriptValue& function, int · 4 unmodified lines
733764 // create the timer, add it to the map, and start it
734765 QTimer* newTimer = new QTimer(this);
735766 newTimer->setSingleShot(isSingleShot);
736−
767+
737768 connect(newTimer, &QTimer::timeout, this, &ScriptEngine::timerFired);
738−
769+
739770 // make sure the timer stops when the script does
740771 connect(this, &ScriptEngine::scriptEnding, newTimer, &QTimer::stop);
741−
772+
742773 _timerFunctionMap.insert(newTimer, function);
743−
774+
744775 newTimer->start(intervalMS);
745776 return newTimer;
746777 }
@@ -750,7 +781,7 @@ QObject* ScriptEngine::setInterval(const QScriptValue& function, int intervalMS) · 3 unmodified lines
750781 qCDebug(scriptengine) << "Script.setInterval() while shutting down is ignored... parent script:" << getFilename();
751782 return NULL; // bail early
752783 }
753−
784+
754785 return setupTimerWithInterval(function, intervalMS, false);
755786 }
756787
@@ -759,7 +790,7 @@ QObject* ScriptEngine::setTimeout(const QScriptValue& function, int timeoutMS) { · 2 unmodified lines
759790 qCDebug(scriptengine) << "Script.setTimeout() while shutting down is ignored... parent script:" << getFilename();
760791 return NULL; // bail early
761792 }
762−
793+
763794 return setupTimerWithInterval(function, timeoutMS, true);
764795 }
765796
@@ -777,7 +808,7 @@ QUrl ScriptEngine::resolvePath(const QString& include) const { · 11 unmodified lines
777808 if (!url.scheme().isEmpty()) {
778809 return url;
779810 }
780−
811+
781812 // we apparently weren't a fully qualified url, so, let's assume we're relative
782813 // to the original URL of our script
783814 QUrl parentURL;
@@ -790,7 +821,7 @@ QUrl ScriptEngine::resolvePath(const QString& include) const { · 6 unmodified lines
790821 if (parentURL.scheme().isEmpty()) {
791822 parentURL = QUrl::fromLocalFile(_fileNameString);
792823 }
793−
824+
794825 // at this point we should have a legitimate fully qualified URL for our parent
795826 url = parentURL.resolved(url);
796827 return url;
@@ -809,7 +840,7 @@ void ScriptEngine::print(const QString& message) { · 12 unmodified lines
809840 void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callback) {
810841 if (_stoppingAllScripts) {
811842 qCDebug(scriptengine) << "Script.include() while shutting down is ignored..."
812− << "includeFiles:" << includeFiles << "parent script:" << getFilename();
843+ << "includeFiles:" << includeFiles << "parent script:" << getFilename();
813844 return; // bail early
814845 }
815846 QList<QUrl> urls;
@@ -823,9 +854,9 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 7 unmodified lines
823854 qCDebug(scriptengine) << "Script.include() ignoring previously included url:" << thisURL;
824855 }
825856 }
826−
857+
827858 BatchLoader* loader = new BatchLoader(urls);
828−
859+
829860 auto evaluateScripts = [=](const QMap<QUrl, QString>& data) {
830861 for (QUrl url : urls) {
831862 QString contents = data[url];
@@ -835,21 +866,21 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 3 unmodified lines
835866 QScriptValue result = evaluate(contents, url.toString());
836867 }
837868 }
838−
869+
839870 if (callback.isFunction()) {
840871 QScriptValue(callback).call();
841872 }
842−
873+
843874 loader->deleteLater();
844875 };
845−
876+
846877 connect(loader, &BatchLoader::finished, this, evaluateScripts);
847−
878+
848879 // If we are destroyed before the loader completes, make sure to clean it up
849880 connect(this, &QObject::destroyed, loader, &QObject::deleteLater);
850−
881+
851882 loader->start();
852−
883+
853884 if (!callback.isFunction() && !loader->isFinished()) {
854885 QEventLoop loop;
855886 QObject::connect(loader, &BatchLoader::finished, &loop, &QEventLoop::quit);
@@ -860,10 +891,10 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 4 unmodified lines
860891 void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
861892 if (_stoppingAllScripts) {
862893 qCDebug(scriptengine) << "Script.include() while shutting down is ignored... "
863− << "includeFile:" << includeFile << "parent script:" << getFilename();
894+ << "includeFile:" << includeFile << "parent script:" << getFilename();
864895 return; // bail early
865896 }
866−
897+
867898 QStringList urls;
868899 urls.append(includeFile);
869900 include(urls, callback);
@@ -875,10 +906,10 @@ void ScriptEngine::include(const QString& includeFile, QScriptValue callback) { · 5 unmodified lines
875906 void ScriptEngine::load(const QString& loadFile) {
876907 if (_stoppingAllScripts) {
877908 qCDebug(scriptengine) << "Script.load() while shutting down is ignored... "
878− << "loadFile:" << loadFile << "parent script:" << getFilename();
909+ << "loadFile:" << loadFile << "parent script:" << getFilename();
879910 return; // bail early
880911 }
881−
912+
882913 QUrl url = resolvePath(loadFile);
883914 if (_isReloading) {
884915 auto scriptCache = DependencyManager::get<ScriptCache>();
@@ -893,37 +924,6 @@ void ScriptEngine::load(const QString& loadFile) { · 8 unmodified lines
893924 }
894925 }
895926
896−bool ScriptEngine::checkSyntax(const QScriptProgram& program) {
897− const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());
898− if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
899− const auto error = syntaxCheck.errorMessage();
900− const auto line = QString::number(syntaxCheck.errorLineNumber());
901− const auto column = QString::number(syntaxCheck.errorColumnNumber());
902− const auto message = QString("[SyntaxError] %1 in %2:%3(%4)").arg(error, program.fileName(), line, column);
903− qCWarning(scriptengine) << qPrintable(message);
904− return false;
905− }
906− return true;
907−}
908−
909−bool ScriptEngine::checkExceptions(QScriptEngine& engine, const QString& fileName) {
910− if (engine.hasUncaughtException()) {
911− const auto backtrace = engine.uncaughtExceptionBacktrace();
912− const auto exception = engine.uncaughtException().toString();
913− const auto line = QString::number(engine.uncaughtExceptionLineNumber());
914− engine.clearExceptions();
915−
916− auto message = QString("[UncaughtException] %1 in %2:%3").arg(exception, fileName, line);
917− if (!backtrace.empty()) {
918− static const auto lineSeparator = "\n ";
919− message += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator));
920− }
921− qCWarning(scriptengine) << qPrintable(message);
922− return false;
923− }
924− return true;
925−}
926−
927927 // Look up the handler associated with eventName and entityID. If found, evalute the argGenerator thunk and call the handler with those args
928928 void ScriptEngine::forwardHandlerCall(const EntityItemID& entityID, const QString& eventName, QScriptValueList eventHanderArgs) {
929929 if (QThread::currentThread() != thread()) {
@@ -931,7 +931,7 @@ void ScriptEngine::forwardHandlerCall(const EntityItemID& entityID, const QStrin · 1 unmodified line
931931 assert(false);
932932 return;
933933 }
934−
934+
935935 if (!_registeredHandlers.contains(entityID)) {
936936 return;
937937 }
@@ -951,97 +951,97 @@ void ScriptEngine::forwardHandlerCall(const EntityItemID& entityID, const QStrin · 13 unmodified lines
951951 // for the download
952952 void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) {
953953 if (QThread::currentThread() != thread()) {
954− #ifdef THREAD_DEBUGGING
954+#ifdef THREAD_DEBUGGING
955955 qDebug() << "*** WARNING *** ScriptEngine::loadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
956− "entityID:" << entityID << "entityScript:" << entityScript <<"forceRedownload:" << forceRedownload;
957− #endif
958−
956+ "entityID:" << entityID << "entityScript:" << entityScript <<"forceRedownload:" << forceRedownload;
957+#endif
958+
959959 QMetaObject::invokeMethod(this, "loadEntityScript",
960− Q_ARG(const EntityItemID&, entityID),
961− Q_ARG(const QString&, entityScript),
962− Q_ARG(bool, forceRedownload));
960+ Q_ARG(const EntityItemID&, entityID),
961+ Q_ARG(const QString&, entityScript),
962+ Q_ARG(bool, forceRedownload));
963963 return;
964964 }
965− #ifdef THREAD_DEBUGGING
965+#ifdef THREAD_DEBUGGING
966966 qDebug() << "ScriptEngine::loadEntityScript() called on correct thread [" << thread() << "] "
967− "entityID:" << entityID << "entityScript:" << entityScript << "forceRedownload:" << forceRedownload;
968− #endif
969−
967+ "entityID:" << entityID << "entityScript:" << entityScript << "forceRedownload:" << forceRedownload;
968+#endif
969+
970970 // If we've been called our known entityScripts should not know about us..
971971 assert(!_entityScripts.contains(entityID));
972−
973− #ifdef THREAD_DEBUGGING
972+
973+#ifdef THREAD_DEBUGGING
974974 qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
975− #endif
975+#endif
976976 DependencyManager::get<ScriptCache>()->getScriptContents(entityScript, [=](const QString& scriptOrURL, const QString& contents, bool isURL, bool success) {
977− #ifdef THREAD_DEBUGGING
978− qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
979− #endif
980−
981− this->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success);
982− }, forceRedownload);
977+#ifdef THREAD_DEBUGGING
978+ qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
979+#endif
980+
981+ this->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success);
982+ }, forceRedownload);
983983 }
984984
985985 // since all of these operations can be asynch we will always do the actual work in the response handler
986986 // for the download
987987 void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, const QString& scriptOrURL, const QString& contents, bool isURL, bool success) {
988988 if (QThread::currentThread() != thread()) {
989− #ifdef THREAD_DEBUGGING
989+#ifdef THREAD_DEBUGGING
990990 qDebug() << "*** WARNING *** ScriptEngine::entityScriptContentAvailable() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
991− "entityID:" << entityID << "scriptOrURL:" << scriptOrURL << "contents:" << contents << "isURL:" << isURL << "success:" << success;
992− #endif
993−
991+ "entityID:" << entityID << "scriptOrURL:" << scriptOrURL << "contents:" << contents << "isURL:" << isURL << "success:" << success;
992+#endif
993+
994994 QMetaObject::invokeMethod(this, "entityScriptContentAvailable",
995− Q_ARG(const EntityItemID&, entityID),
996− Q_ARG(const QString&, scriptOrURL),
997− Q_ARG(const QString&, contents),
998− Q_ARG(bool, isURL),
999− Q_ARG(bool, success));
995+ Q_ARG(const EntityItemID&, entityID),
996+ Q_ARG(const QString&, scriptOrURL),
997+ Q_ARG(const QString&, contents),
998+ Q_ARG(bool, isURL),
999+ Q_ARG(bool, success));
10001000 return;
10011001 }
1002−
1003− #ifdef THREAD_DEBUGGING
1002+
1003+#ifdef THREAD_DEBUGGING
10041004 qDebug() << "ScriptEngine::entityScriptContentAvailable() thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
1005− #endif
1006−
1005+#endif
1006+
10071007 auto scriptCache = DependencyManager::get<ScriptCache>();
10081008 bool isFileUrl = isURL && scriptOrURL.startsWith("file://");
10091009 auto fileName = QString("(EntityID:%1, %2)").arg(entityID.toString(), isURL ? scriptOrURL : "EmbededEntityScript");
1010−
1010+
10111011 QScriptProgram program(contents, fileName);
1012− if (!checkSyntax(program)) {
1012+ if (!hasCorrectSyntax(program)) {
10131013 if (!isFileUrl) {
10141014 scriptCache->addScriptToBadScriptList(scriptOrURL);
10151015 }
10161016 return; // done processing script
10171017 }
1018−
1018+
10191019 if (isURL) {
10201020 setParentURL(scriptOrURL);
10211021 }
1022−
1022+
10231023 QScriptEngine sandbox;
10241024 QScriptValue testConstructor = sandbox.evaluate(program);
1025− if (!checkExceptions(sandbox, program.fileName())) {
1025+ if (hadUncauchtExceptions(sandbox, program.fileName())) {
10261026 return;
10271027 }
10281028
10291029 if (!testConstructor.isFunction()) {
10301030 qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID << "\n"
1031− " NOT CONSTRUCTOR\n"
1032− " SCRIPT:" << scriptOrURL;
1031+ " NOT CONSTRUCTOR\n"
1032+ " SCRIPT:" << scriptOrURL;
10331033 if (!isFileUrl) {
10341034 scriptCache->addScriptToBadScriptList(scriptOrURL);
10351035 }
10361036 return; // done processing script
10371037 }
1038−
1038+
10391039 int64_t lastModified = 0;
10401040 if (isFileUrl) {
10411041 QString file = QUrl(scriptOrURL).toLocalFile();
10421042 lastModified = (quint64)QFileInfo(file).lastModified().toMSecsSinceEpoch();
10431043 }
1044−
1044+
10451045 QScriptValue entityScriptConstructor = evaluate(contents, fileName);
10461046 QScriptValue entityScriptObject = entityScriptConstructor.construct();
10471047 EntityScriptDetails newDetails = { scriptOrURL, entityScriptObject, lastModified };
@@ -1049,27 +1049,27 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 1 unmodified line
10491049 if (isURL) {
10501050 setParentURL("");
10511051 }
1052−
1052+
10531053 // if we got this far, then call the preload method
10541054 callEntityScriptMethod(entityID, "preload");
10551055 }
10561056
10571057 void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) {
10581058 if (QThread::currentThread() != thread()) {
1059− #ifdef THREAD_DEBUGGING
1059+#ifdef THREAD_DEBUGGING
10601060 qDebug() << "*** WARNING *** ScriptEngine::unloadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
1061− "entityID:" << entityID;
1062− #endif
1063−
1061+ "entityID:" << entityID;
1062+#endif
1063+
10641064 QMetaObject::invokeMethod(this, "unloadEntityScript",
1065− Q_ARG(const EntityItemID&, entityID));
1065+ Q_ARG(const EntityItemID&, entityID));
10661066 return;
10671067 }
1068− #ifdef THREAD_DEBUGGING
1068+#ifdef THREAD_DEBUGGING
10691069 qDebug() << "ScriptEngine::unloadEntityScript() called on correct thread [" << thread() << "] "
1070− "entityID:" << entityID;
1071− #endif
1072−
1070+ "entityID:" << entityID;
1071+#endif
1072+
10731073 if (_entityScripts.contains(entityID)) {
10741074 callEntityScriptMethod(entityID, "unload");
10751075 _entityScripts.remove(entityID);
@@ -1081,7 +1081,7 @@ void ScriptEngine::unloadAllEntityScripts() { · 5 unmodified lines
10811081 #ifdef THREAD_DEBUGGING
10821082 qDebug() << "*** WARNING *** ScriptEngine::unloadAllEntityScripts() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]";
10831083 #endif
1084−
1084+
10851085 QMetaObject::invokeMethod(this, "unloadAllEntityScripts");
10861086 return;
10871087 }
@@ -1098,13 +1098,13 @@ void ScriptEngine::refreshFileScript(const EntityItemID& entityID) { · 10 unmodified lines
10981098 if (!_entityScripts.contains(entityID)) {
10991099 return;
11001100 }
1101−
1101+
11021102 static bool recurseGuard = false;
11031103 if (recurseGuard) {
11041104 return;
11051105 }
11061106 recurseGuard = true;
1107−
1107+
11081108 EntityScriptDetails details = _entityScripts[entityID];
11091109 // Check to see if a file based script needs to be reloaded (easier debugging)
11101110 if (details.lastModified > 0) {
@@ -1112,7 +1112,7 @@ void ScriptEngine::refreshFileScript(const EntityItemID& entityID) { · 1 unmodified line
11121112 auto lastModified = QFileInfo(filePath).lastModified().toMSecsSinceEpoch();
11131113 if (lastModified > details.lastModified) {
11141114 qDebug() << "Reloading modified script " << details.scriptText;
1115−
1115+
11161116 QFile file(filePath);
11171117 file.open(QIODevice::ReadOnly);
11181118 QString scriptContents = QTextStream(&file).readAll();
@@ -1131,21 +1131,21 @@ void ScriptEngine::refreshFileScript(const EntityItemID& entityID) { · 12 unmodified lines
11311131
11321132 void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName) {
11331133 if (QThread::currentThread() != thread()) {
1134− #ifdef THREAD_DEBUGGING
1134+#ifdef THREAD_DEBUGGING
11351135 qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
1136− "entityID:" << entityID << "methodName:" << methodName;
1137− #endif
1138−
1136+ "entityID:" << entityID << "methodName:" << methodName;
1137+#endif
1138+
11391139 QMetaObject::invokeMethod(this, "callEntityScriptMethod",
1140− Q_ARG(const EntityItemID&, entityID),
1141− Q_ARG(const QString&, methodName));
1140+ Q_ARG(const EntityItemID&, entityID),
1141+ Q_ARG(const QString&, methodName));
11421142 return;
11431143 }
1144− #ifdef THREAD_DEBUGGING
1144+#ifdef THREAD_DEBUGGING
11451145 qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] "
1146− "entityID:" << entityID << "methodName:" << methodName;
1147− #endif
1148−
1146+ "entityID:" << entityID << "methodName:" << methodName;
1147+#endif
1148+
11491149 refreshFileScript(entityID);
11501150 if (_entityScripts.contains(entityID)) {
11511151 EntityScriptDetails details = _entityScripts[entityID];
@@ -1155,28 +1155,28 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 3 unmodified lines
11551155 args << entityID.toScriptValue(this);
11561156 entityScript.property(methodName).call(entityScript, args);
11571157 }
1158−
1158+
11591159 }
11601160 }
11611161
11621162 void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const MouseEvent& event) {
11631163 if (QThread::currentThread() != thread()) {
1164− #ifdef THREAD_DEBUGGING
1164+#ifdef THREAD_DEBUGGING
11651165 qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
1166− "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent";
1167− #endif
1168−
1166+ "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent";
1167+#endif
1168+
11691169 QMetaObject::invokeMethod(this, "callEntityScriptMethod",
1170− Q_ARG(const EntityItemID&, entityID),
1171− Q_ARG(const QString&, methodName),
1172− Q_ARG(const MouseEvent&, event));
1170+ Q_ARG(const EntityItemID&, entityID),
1171+ Q_ARG(const QString&, methodName),
1172+ Q_ARG(const MouseEvent&, event));
11731173 return;
11741174 }
1175− #ifdef THREAD_DEBUGGING
1175+#ifdef THREAD_DEBUGGING
11761176 qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] "
1177− "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent";
1178− #endif
1179−
1177+ "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent";
1178+#endif
1179+
11801180 refreshFileScript(entityID);
11811181 if (_entityScripts.contains(entityID)) {
11821182 EntityScriptDetails details = _entityScripts[entityID];
@@ -1193,23 +1193,23 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 10 unmodified lines
11931193
11941194 void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const EntityItemID& otherID, const Collision& collision) {
11951195 if (QThread::currentThread() != thread()) {
1196− #ifdef THREAD_DEBUGGING
1196+#ifdef THREAD_DEBUGGING
11971197 qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
1198− "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision";
1199− #endif
1200−
1198+ "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision";
1199+#endif
1200+
12011201 QMetaObject::invokeMethod(this, "callEntityScriptMethod",
1202− Q_ARG(const EntityItemID&, entityID),
1203− Q_ARG(const QString&, methodName),
1204− Q_ARG(const EntityItemID&, otherID),
1205− Q_ARG(const Collision&, collision));
1202+ Q_ARG(const EntityItemID&, entityID),
1203+ Q_ARG(const QString&, methodName),
1204+ Q_ARG(const EntityItemID&, otherID),
1205+ Q_ARG(const Collision&, collision));
12061206 return;
12071207 }
1208− #ifdef THREAD_DEBUGGING
1208+#ifdef THREAD_DEBUGGING
12091209 qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] "
1210− "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision";
1211− #endif
1212−
1210+ "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision";
1211+#endif
1212+
12131213 refreshFileScript(entityID);
12141214 if (_entityScripts.contains(entityID)) {
12151215 EntityScriptDetails details = _entityScripts[entityID];
@@ -1222,4 +1222,4 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 6 unmodified lines
12221222 entityScript.property(methodName).call(entityScript, args);
12231223 }
12241224 }
1225−}
1225+}