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