Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 3 files). Show all
Unified · Split
| @@ -81,7 +81,7 @@ void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputCon · 80 unmodified lines | ||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, |
| 84 | − AbstractControllerScriptingInterface* controllerScriptingInterface) : | |
| 84 | + AbstractControllerScriptingInterface* controllerScriptingInterface, bool wantSignals) : | |
| 85 | 85 | |
| 86 | 86 | _scriptContents(scriptContents), |
| 87 | 87 | _isFinished(false), |
| @@ -95,6 +95,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 7 unmodified lines | ||
| 95 | 95 | _avatarSound(NULL), |
| 96 | 96 | _numAvatarSoundSentBytes(0), |
| 97 | 97 | _controllerScriptingInterface(controllerScriptingInterface), |
| 98 | + _wantSignals(wantSignals), | |
| 98 | 99 | _avatarData(NULL), |
| 99 | 100 | _scriptName(), |
| 100 | 101 | _fileNameString(fileNameString), |
| @@ -299,10 +300,14 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 198 unmodified lines | ||
| 299 | 300 | qCDebug(scriptengine) << "ScriptEngine loading file:" << _fileNameString; |
| 300 | 301 | QTextStream in(&scriptFile); |
| 301 | 302 | _scriptContents = in.readAll(); |
| 302 | − emit scriptLoaded(_fileNameString); | |
| 303 | + if (_wantSignals) { | |
| 304 | + emit scriptLoaded(_fileNameString); | |
| 305 | + } | |
| 303 | 306 | } else { |
| 304 | 307 | qCDebug(scriptengine) << "ERROR Loading file:" << _fileNameString << "line:" << __LINE__; |
| 305 | − emit errorLoadingScript(_fileNameString); | |
| 308 | + if (_wantSignals) { | |
| 309 | + emit errorLoadingScript(_fileNameString); | |
| 310 | + } | |
| 306 | 311 | } |
| 307 | 312 | } else { |
| 308 | 313 | bool isPending; |
| @@ -314,12 +319,16 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 5 unmodified lines | ||
| 314 | 319 | |
| 315 | 320 | void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) { |
| 316 | 321 | _scriptContents = scriptContents; |
| 317 | − emit scriptLoaded(_fileNameString); | |
| 322 | + if (_wantSignals) { | |
| 323 | + emit scriptLoaded(_fileNameString); | |
| 324 | + } | |
| 318 | 325 | } |
| 319 | 326 | |
| 320 | 327 | void ScriptEngine::errorInLoadingScript(const QUrl& url) { |
| 321 | 328 | qCDebug(scriptengine) << "ERROR Loading file:" << url.toString() << "line:" << __LINE__; |
| 322 | − emit errorLoadingScript(_fileNameString); // ?? | |
| 329 | + if (_wantSignals) { | |
| 330 | + emit errorLoadingScript(_fileNameString); // ?? | |
| 331 | + } | |
| 323 | 332 | } |
| 324 | 333 | |
| 325 | 334 | void ScriptEngine::init() { |
| @@ -524,7 +533,9 @@ void ScriptEngine::evaluate() { · 198 unmodified lines | ||
| 524 | 533 | if (hasUncaughtException()) { |
| 525 | 534 | int line = uncaughtExceptionLineNumber(); |
| 526 | 535 | 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 | + } | |
| 528 | 539 | clearExceptions(); |
| 529 | 540 | } |
| 530 | 541 | } |
| @@ -541,7 +552,9 @@ QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileN · 10 unmodified lines | ||
| 541 | 552 | qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << " : " << fileName << ") line" << line << ": " << result.toString(); |
| 542 | 553 | } |
| 543 | 554 | _evaluatesPending--; |
| 544 | − emit evaluationFinished(result, hasUncaughtException()); | |
| 555 | + if (_wantSignals) { | |
| 556 | + emit evaluationFinished(result, hasUncaughtException()); | |
| 557 | + } | |
| 545 | 558 | clearExceptions(); |
| 546 | 559 | return result; |
| 547 | 560 | } |
| @@ -567,7 +580,9 @@ void ScriptEngine::run() { · 19 unmodified lines | ||
| 567 | 580 | } |
| 568 | 581 | _isRunning = true; |
| 569 | 582 | _isFinished = false; |
| 570 | − emit runningStateChanged(); | |
| 583 | + if (_wantSignals) { | |
| 584 | + emit runningStateChanged(); | |
| 585 | + } | |
| 571 | 586 | |
| 572 | 587 | QScriptValue result = evaluate(_scriptContents); |
| 573 | 588 | |
| @@ -714,19 +729,25 @@ void ScriptEngine::run() { · 140 unmodified lines | ||
| 714 | 729 | if (hasUncaughtException()) { |
| 715 | 730 | int line = uncaughtExceptionLineNumber(); |
| 716 | 731 | 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 | + } | |
| 718 | 735 | clearExceptions(); |
| 719 | 736 | } |
| 720 | 737 | |
| 721 | 738 | if (!_isFinished) { |
| 722 | − emit update(deltaTime); | |
| 739 | + if (_wantSignals) { | |
| 740 | + emit update(deltaTime); | |
| 741 | + } | |
| 723 | 742 | } |
| 724 | 743 | lastUpdate = now; |
| 725 | 744 | |
| 726 | 745 | } |
| 727 | 746 | |
| 728 | 747 | stopAllTimers(); // make sure all our timers are stopped if the script is ending |
| 729 | − emit scriptEnding(); | |
| 748 | + if (_wantSignals) { | |
| 749 | + emit scriptEnding(); | |
| 750 | + } | |
| 730 | 751 | |
| 731 | 752 | // kill the avatar identity timer |
| 732 | 753 | delete _avatarIdentityTimer; |
| @@ -747,12 +768,15 @@ void ScriptEngine::run() { · 14 unmodified lines | ||
| 747 | 768 | } |
| 748 | 769 | } |
| 749 | 770 | |
| 750 | − emit finished(_fileNameString); | |
| 771 | + if (_wantSignals) { | |
| 772 | + emit finished(_fileNameString); | |
| 773 | + } | |
| 751 | 774 | |
| 752 | 775 | _isRunning = false; |
| 753 | − emit runningStateChanged(); | |
| 754 | − | |
| 755 | − emit doneRunning(); | |
| 776 | + if (_wantSignals) { | |
| 777 | + emit runningStateChanged(); | |
| 778 | + emit doneRunning(); | |
| 779 | + } | |
| 756 | 780 | |
| 757 | 781 | _doneRunningThisScript = true; |
| 758 | 782 | } |
| @@ -771,7 +795,9 @@ void ScriptEngine::stopAllTimers() { · 12 unmodified lines | ||
| 771 | 795 | void ScriptEngine::stop() { |
| 772 | 796 | if (!_isFinished) { |
| 773 | 797 | _isFinished = true; |
| 774 | − emit runningStateChanged(); | |
| 798 | + if (_wantSignals) { | |
| 799 | + emit runningStateChanged(); | |
| 800 | + } | |
| 775 | 801 | } |
| 776 | 802 | } |
| 777 | 803 | |
| @@ -859,7 +885,9 @@ QUrl ScriptEngine::resolvePath(const QString& include) const { · 81 unmodified lines | ||
| 859 | 885 | } |
| 860 | 886 | |
| 861 | 887 | void ScriptEngine::print(const QString& message) { |
| 862 | − emit printedMessage(message); | |
| 888 | + if (_wantSignals) { | |
| 889 | + emit printedMessage(message); | |
| 890 | + } | |
| 863 | 891 | } |
| 864 | 892 | |
| 865 | 893 | // 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 | ||
| 943 | 971 | if (_isReloading) { |
| 944 | 972 | auto scriptCache = DependencyManager::get<ScriptCache>(); |
| 945 | 973 | scriptCache->deleteScript(url.toString()); |
| 946 | − emit reloadScript(url.toString(), false); | |
| 974 | + if (_wantSignals) { | |
| 975 | + emit reloadScript(url.toString(), false); | |
| 976 | + } | |
| 947 | 977 | } else { |
| 948 | − emit loadScript(url.toString(), false); | |
| 978 | + if (_wantSignals) { | |
| 979 | + emit loadScript(url.toString(), false); | |
| 980 | + } | |
| 949 | 981 | } |
| 950 | 982 | } |
| 951 | 983 | |