History

prevent sending signals in the entities script engine

Brad Hefta-Gaub committed 11 years ago

Commit b9d54121 parent 9ab603e3 files · +56 −22Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+51−19
@@ -81,7 +81,7 @@ void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputCon · 80 unmodified lines
8181 }
8282
8383 ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString,
84− AbstractControllerScriptingInterface* controllerScriptingInterface) :
84+ AbstractControllerScriptingInterface* controllerScriptingInterface, bool wantSignals) :
8585
8686 _scriptContents(scriptContents),
8787 _isFinished(false),
@@ -95,6 +95,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 7 unmodified lines
9595 _avatarSound(NULL),
9696 _numAvatarSoundSentBytes(0),
9797 _controllerScriptingInterface(controllerScriptingInterface),
98+ _wantSignals(wantSignals),
9899 _avatarData(NULL),
99100 _scriptName(),
100101 _fileNameString(fileNameString),
@@ -299,10 +300,14 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 198 unmodified lines
299300 qCDebug(scriptengine) << "ScriptEngine loading file:" << _fileNameString;
300301 QTextStream in(&scriptFile);
301302 _scriptContents = in.readAll();
302− emit scriptLoaded(_fileNameString);
303+ if (_wantSignals) {
304+ emit scriptLoaded(_fileNameString);
305+ }
303306 } else {
304307 qCDebug(scriptengine) << "ERROR Loading file:" << _fileNameString << "line:" << __LINE__;
305− emit errorLoadingScript(_fileNameString);
308+ if (_wantSignals) {
309+ emit errorLoadingScript(_fileNameString);
310+ }
306311 }
307312 } else {
308313 bool isPending;
@@ -314,12 +319,16 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 5 unmodified lines
314319
315320 void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) {
316321 _scriptContents = scriptContents;
317− emit scriptLoaded(_fileNameString);
322+ if (_wantSignals) {
323+ emit scriptLoaded(_fileNameString);
324+ }
318325 }
319326
320327 void ScriptEngine::errorInLoadingScript(const QUrl& url) {
321328 qCDebug(scriptengine) << "ERROR Loading file:" << url.toString() << "line:" << __LINE__;
322− emit errorLoadingScript(_fileNameString); // ??
329+ if (_wantSignals) {
330+ emit errorLoadingScript(_fileNameString); // ??
331+ }
323332 }
324333
325334 void ScriptEngine::init() {
@@ -524,7 +533,9 @@ void ScriptEngine::evaluate() { · 198 unmodified lines
524533 if (hasUncaughtException()) {
525534 int line = uncaughtExceptionLineNumber();
526535 qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
527− emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
536+ if (_wantSignals) {
537+ emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
538+ }
528539 clearExceptions();
529540 }
530541 }
@@ -541,7 +552,9 @@ QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileN · 10 unmodified lines
541552 qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << " : " << fileName << ") line" << line << ": " << result.toString();
542553 }
543554 _evaluatesPending--;
544− emit evaluationFinished(result, hasUncaughtException());
555+ if (_wantSignals) {
556+ emit evaluationFinished(result, hasUncaughtException());
557+ }
545558 clearExceptions();
546559 return result;
547560 }
@@ -567,7 +580,9 @@ void ScriptEngine::run() { · 19 unmodified lines
567580 }
568581 _isRunning = true;
569582 _isFinished = false;
570− emit runningStateChanged();
583+ if (_wantSignals) {
584+ emit runningStateChanged();
585+ }
571586
572587 QScriptValue result = evaluate(_scriptContents);
573588
@@ -714,19 +729,25 @@ void ScriptEngine::run() { · 140 unmodified lines
714729 if (hasUncaughtException()) {
715730 int line = uncaughtExceptionLineNumber();
716731 qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << uncaughtException().toString();
717− emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + uncaughtException().toString());
732+ if (_wantSignals) {
733+ emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + uncaughtException().toString());
734+ }
718735 clearExceptions();
719736 }
720737
721738 if (!_isFinished) {
722− emit update(deltaTime);
739+ if (_wantSignals) {
740+ emit update(deltaTime);
741+ }
723742 }
724743 lastUpdate = now;
725744
726745 }
727746
728747 stopAllTimers(); // make sure all our timers are stopped if the script is ending
729− emit scriptEnding();
748+ if (_wantSignals) {
749+ emit scriptEnding();
750+ }
730751
731752 // kill the avatar identity timer
732753 delete _avatarIdentityTimer;
@@ -747,12 +768,15 @@ void ScriptEngine::run() { · 14 unmodified lines
747768 }
748769 }
749770
750− emit finished(_fileNameString);
771+ if (_wantSignals) {
772+ emit finished(_fileNameString);
773+ }
751774
752775 _isRunning = false;
753− emit runningStateChanged();
754−
755− emit doneRunning();
776+ if (_wantSignals) {
777+ emit runningStateChanged();
778+ emit doneRunning();
779+ }
756780
757781 _doneRunningThisScript = true;
758782 }
@@ -771,7 +795,9 @@ void ScriptEngine::stopAllTimers() { · 12 unmodified lines
771795 void ScriptEngine::stop() {
772796 if (!_isFinished) {
773797 _isFinished = true;
774− emit runningStateChanged();
798+ if (_wantSignals) {
799+ emit runningStateChanged();
800+ }
775801 }
776802 }
777803
@@ -859,7 +885,9 @@ QUrl ScriptEngine::resolvePath(const QString& include) const { · 81 unmodified lines
859885 }
860886
861887 void ScriptEngine::print(const QString& message) {
862− emit printedMessage(message);
888+ if (_wantSignals) {
889+ emit printedMessage(message);
890+ }
863891 }
864892
865893 // If a callback is specified, the included files will be loaded asynchronously and the callback will be called
@@ -943,9 +971,13 @@ void ScriptEngine::load(const QString& loadFile) { · 77 unmodified lines
943971 if (_isReloading) {
944972 auto scriptCache = DependencyManager::get<ScriptCache>();
945973 scriptCache->deleteScript(url.toString());
946− emit reloadScript(url.toString(), false);
974+ if (_wantSignals) {
975+ emit reloadScript(url.toString(), false);
976+ }
947977 } else {
948− emit loadScript(url.toString(), false);
978+ if (_wantSignals) {
979+ emit loadScript(url.toString(), false);
980+ }
949981 }
950982 }
951983