Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all
Unified · Split
| @@ -42,12 +42,6 @@ · 41 unmodified lines | |||
| 42 | #include "MIDIEvent.h" | 42 | #include "MIDIEvent.h" |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | #ifdef WANT_DEBUG_SCRIPT_ENDING | ||
| 46 | #define DEBUG_SCRIPT_ENDING(X) X | ||
| 47 | #else | ||
| 48 | #define DEBUG_SCRIPT_ENDING(x) | ||
| 49 | #endif | ||
| 50 | |||
| 51 | EntityScriptingInterface ScriptEngine::_entityScriptingInterface; | 45 | EntityScriptingInterface ScriptEngine::_entityScriptingInterface; |
| 52 | 46 | ||
| 53 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ | 47 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ |
| @@ -107,7 +101,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 53 unmodified lines | |||
| 107 | } | 101 | } |
| 108 | 102 | ||
| 109 | ScriptEngine::~ScriptEngine() { | 103 | ScriptEngine::~ScriptEngine() { |
| 110 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::~ScriptEngine() ------- BEGIN ------- script:" << getFilename();) | ||
| 111 | // If we're not already in the middle of stopping all scripts, then we should remove ourselves | 104 | // If we're not already in the middle of stopping all scripts, then we should remove ourselves |
| 112 | // from the list of running scripts. We don't do this if we're in the process of stopping all scripts | 105 | // from the list of running scripts. We don't do this if we're in the process of stopping all scripts |
| 113 | // because that method removes scripts from its list as it iterates them | 106 | // because that method removes scripts from its list as it iterates them |
| @@ -116,7 +109,6 @@ ScriptEngine::~ScriptEngine() { · 2 unmodified lines | |||
| 116 | _allKnownScriptEngines.remove(this); | 109 | _allKnownScriptEngines.remove(this); |
| 117 | _allScriptsMutex.unlock(); | 110 | _allScriptsMutex.unlock(); |
| 118 | } | 111 | } |
| 119 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::~ScriptEngine() ------- END ------- script:" << getFilename();) | ||
| 120 | } | 112 | } |
| 121 | 113 | ||
| 122 | QSet<ScriptEngine*> ScriptEngine::_allKnownScriptEngines; | 114 | QSet<ScriptEngine*> ScriptEngine::_allKnownScriptEngines; |
| @@ -136,8 +128,6 @@ void ScriptEngine::stopAllScripts(QObject* application) { · 13 unmodified lines | |||
| 136 | 128 | ||
| 137 | QString scriptName = scriptEngine->getFilename(); | 129 | QString scriptName = scriptEngine->getFilename(); |
| 138 | 130 | ||
| 139 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() considering:" << scriptName << "isRunning():" << scriptEngine->isRunning() << "evaluatePending():" << scriptEngine->evaluatePending();) | ||
| 140 | |||
| 141 | // NOTE: typically all script engines are running. But there's at least one known exception to this, the | 131 | // NOTE: typically all script engines are running. But there's at least one known exception to this, the |
| 142 | // "entities sandbox" which is only used to evaluate entities scripts to test their validity before using | 132 | // "entities sandbox" which is only used to evaluate entities scripts to test their validity before using |
| 143 | // them. We don't need to stop scripts that aren't running. | 133 | // them. We don't need to stop scripts that aren't running. |
| @@ -149,18 +139,14 @@ void ScriptEngine::stopAllScripts(QObject* application) { · 5 unmodified lines | |||
| 149 | while (scriptEngine->evaluatePending()) { | 139 | while (scriptEngine->evaluatePending()) { |
| 150 | QEventLoop loop; | 140 | QEventLoop loop; |
| 151 | QObject::connect(scriptEngine, &ScriptEngine::evaluationFinished, &loop, &QEventLoop::quit); | 141 | QObject::connect(scriptEngine, &ScriptEngine::evaluationFinished, &loop, &QEventLoop::quit); |
| 152 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() while(evaluatePending()) STARTING loop.exec() script:" << scriptName;) | ||
| 153 | loop.exec(); | 142 | loop.exec(); |
| 154 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() while(evaluatePending()) AFTER loop.exec() script:" << scriptName;) | ||
| 155 | } | 143 | } |
| 156 | } | 144 | } |
| 157 | 145 | ||
| 158 | scriptEngine->disconnect(application); | 146 | scriptEngine->disconnect(application); |
| 159 | scriptEngine->stop(); | 147 | scriptEngine->stop(); |
| 160 | 148 | ||
| 161 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() -- WAITING for waitTillDoneRunning() script:" << scriptName;) | ||
| 162 | scriptEngine->waitTillDoneRunning(); | 149 | scriptEngine->waitTillDoneRunning(); |
| 163 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stopAllScripts() -- AFTER waitTillDoneRunning() script:" << scriptName;) | ||
| 164 | i.remove(); | 150 | i.remove(); |
| 165 | } else { | 151 | } else { |
| 166 | qDebug() << "ScriptEngine::stopAllScripts() " << scriptName << " - will be freed on it's own."; | 152 | qDebug() << "ScriptEngine::stopAllScripts() " << scriptName << " - will be freed on it's own."; |
| @@ -175,10 +161,8 @@ void ScriptEngine::stopAllScripts(QObject* application) { · 8 unmodified lines | |||
| 175 | 161 | ||
| 176 | void ScriptEngine::waitTillDoneRunning() { | 162 | void ScriptEngine::waitTillDoneRunning() { |
| 177 | QString scriptName = getFilename(); | 163 | QString scriptName = getFilename(); |
| 178 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() ------- BEGIN ------- script:" << scriptName;) | ||
| 179 | 164 | ||
| 180 | if (_isRunning) { | 165 | if (_isRunning) { |
| 181 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() SETTING _doneRunningThisScript = false ################################### line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 182 | _doneRunningThisScript = false; | 166 | _doneRunningThisScript = false; |
| 183 | _isWaitingForDoneRunning = true; | 167 | _isWaitingForDoneRunning = true; |
| 184 | 168 | ||
| @@ -191,31 +175,18 @@ void ScriptEngine::waitTillDoneRunning() { · 6 unmodified lines | |||
| 191 | // and run a QEventLoop??? | 175 | // and run a QEventLoop??? |
| 192 | QEventLoop loop; | 176 | QEventLoop loop; |
| 193 | QObject::connect(this, &ScriptEngine::doneRunning, &loop, &QEventLoop::quit); | 177 | QObject::connect(this, &ScriptEngine::doneRunning, &loop, &QEventLoop::quit); |
| 194 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() STARTING loop.exec() script:" << scriptName;) | ||
| 195 | DEBUG_SCRIPT_ENDING(qDebug() << " _doneRunningThisScript:" << _doneRunningThisScript;) | ||
| 196 | DEBUG_SCRIPT_ENDING(qDebug() << " _isRunning:" << _isRunning;) | ||
| 197 | DEBUG_SCRIPT_ENDING(qDebug() << " _isWaitingForDoneRunning:" << _isWaitingForDoneRunning;) | ||
| 198 | DEBUG_SCRIPT_ENDING(qDebug() << " _isFinished:" << _isFinished;) | ||
| 199 | DEBUG_SCRIPT_ENDING(qDebug() << " _isInitialized:" << _isInitialized;) | ||
| 200 | DEBUG_SCRIPT_ENDING(qDebug() << " _evaluatesPending:" << _evaluatesPending;) | ||
| 201 | loop.exec(); | 178 | loop.exec(); |
| 202 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() AFTER loop.exec() script:" << scriptName;) | ||
| 203 | 179 | ||
| 204 | // process events | 180 | // process events |
| 205 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() STARTING QCoreApplication::processEvents() script:" << scriptName;) | ||
| 206 | QCoreApplication::processEvents(); | 181 | QCoreApplication::processEvents(); |
| 207 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() AFTER QCoreApplication::processEvents() script:" << scriptName;) | ||
| 208 | 182 | ||
| 209 | if (_doneRunningThisScript) { | 183 | if (_doneRunningThisScript) { |
| 210 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() _doneRunningThisScript after processEvents... breaking!!! script:" << scriptName;) | ||
| 211 | break; | 184 | break; |
| 212 | } | 185 | } |
| 213 | } | 186 | } |
| 214 | 187 | ||
| 215 | _isWaitingForDoneRunning = false; | 188 | _isWaitingForDoneRunning = false; |
| 216 | } | 189 | } |
| 217 | |||
| 218 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::waitTillDoneRunning() ------- DONE ------- script:" << scriptName;) | ||
| 219 | } | 190 | } |
| 220 | 191 | ||
| 221 | QString ScriptEngine::getFilename() const { | 192 | QString ScriptEngine::getFilename() const { |
| @@ -428,25 +399,20 @@ void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::Func · 206 unmodified lines | |||
| 428 | 399 | ||
| 429 | void ScriptEngine::evaluate() { | 400 | void ScriptEngine::evaluate() { |
| 430 | if (_stoppingAllScripts) { | 401 | if (_stoppingAllScripts) { |
| 431 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate() while shutting down is ignored...";) | ||
| 432 | DEBUG_SCRIPT_ENDING(qDebug() << " parent script:" << getFilename() << "[" << this << "]";) | ||
| 433 | return; // bail early | 402 | return; // bail early |
| 434 | } | 403 | } |
| 435 | 404 | ||
| 436 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate() -- BEGIN script:" << getFilename() << "[" << this << "]";) | ||
| 437 | if (!_isInitialized) { | 405 | if (!_isInitialized) { |
| 438 | init(); | 406 | init(); |
| 439 | } | 407 | } |
| 440 | 408 | ||
| 441 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate() -- about to call own evaluate(program) script:" << getFilename() << "[" << this << "]";) | ||
| 442 | QScriptValue result = evaluate(_scriptContents); | 409 | QScriptValue result = evaluate(_scriptContents); |
| 443 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate() -- AFTER own evaluate(program) script:" << getFilename() << "[" << this << "]";) | ||
| 444 | 410 | ||
| 445 | // TODO: why do we check this twice? It seems like the call to clearExcpetions() in the lower level evaluate call | 411 | // TODO: why do we check this twice? It seems like the call to clearExcpetions() in the lower level evaluate call |
| 446 | // will cause this code to never actually run... | 412 | // will cause this code to never actually run... |
| 447 | if (hasUncaughtException()) { | 413 | if (hasUncaughtException()) { |
| 448 | int line = uncaughtExceptionLineNumber(); | 414 | int line = uncaughtExceptionLineNumber(); |
| 449 | DEBUG_SCRIPT_ENDING(qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();) | 415 | qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString(); |
| 450 | emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString()); | 416 | emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString()); |
| 451 | clearExceptions(); | 417 | clearExceptions(); |
| 452 | } | 418 | } |
| @@ -454,29 +420,18 @@ void ScriptEngine::evaluate() { · 1 unmodified line | |||
| 454 | 420 | ||
| 455 | QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileName, int lineNumber) { | 421 | QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileName, int lineNumber) { |
| 456 | if (_stoppingAllScripts) { | 422 | if (_stoppingAllScripts) { |
| 457 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) while shutting down is ignored...";) | ||
| 458 | DEBUG_SCRIPT_ENDING(qDebug() << " parent script:" << getFilename() << "[" << this << "]";) | ||
| 459 | return QScriptValue(); // bail early | 423 | return QScriptValue(); // bail early |
| 460 | } | 424 | } |
| 461 | 425 | ||
| 462 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- BEGIN script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";) | ||
| 463 | _evaluatesPending++; | 426 | _evaluatesPending++; |
| 464 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- after _evaluatesPending++ script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";) | ||
| 465 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- BEFORE QScriptEngine::evaluate() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";) | ||
| 466 | QScriptValue result = QScriptEngine::evaluate(program, fileName, lineNumber); | 427 | QScriptValue result = QScriptEngine::evaluate(program, fileName, lineNumber); |
| 467 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- AFTER QScriptEngine::evaluate() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";) | ||
| 468 | if (hasUncaughtException()) { | 428 | if (hasUncaughtException()) { |
| 469 | int line = uncaughtExceptionLineNumber(); | 429 | int line = uncaughtExceptionLineNumber(); |
| 470 | qDebug() << "Uncaught exception at (" << _fileNameString << " : " << fileName << ") line" << line << ": " << result.toString(); | 430 | qDebug() << "Uncaught exception at (" << _fileNameString << " : " << fileName << ") line" << line << ": " << result.toString(); |
| 471 | } | 431 | } |
| 472 | _evaluatesPending--; | 432 | _evaluatesPending--; |
| 473 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- after _evaluatesPending-- script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";) | ||
| 474 | |||
| 475 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- ABOUT TO emit evaluationFinished() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";) | ||
| 476 | emit evaluationFinished(result, hasUncaughtException()); | 433 | emit evaluationFinished(result, hasUncaughtException()); |
| 477 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- AFTER emit evaluationFinished() script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";) | ||
| 478 | clearExceptions(); | 434 | clearExceptions(); |
| 479 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::evaluate(program) -- DONE script:" << getFilename() << "_evaluatesPending:" << _evaluatesPending << "[" << this << "]";) | ||
| 480 | return result; | 435 | return result; |
| 481 | } | 436 | } |
| 482 | 437 | ||
| @@ -496,18 +451,14 @@ void ScriptEngine::run() { · 13 unmodified lines | |||
| 496 | // TODO: can we add a short circuit for _stoppingAllScripts here? What does it mean to not start running if | 451 | // TODO: can we add a short circuit for _stoppingAllScripts here? What does it mean to not start running if |
| 497 | // we're in the process of stopping? | 452 | // we're in the process of stopping? |
| 498 | 453 | ||
| 499 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 500 | if (!_isInitialized) { | 454 | if (!_isInitialized) { |
| 501 | init(); | 455 | init(); |
| 502 | } | 456 | } |
| 503 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 504 | _isRunning = true; | 457 | _isRunning = true; |
| 505 | _isFinished = false; | 458 | _isFinished = false; |
| 506 | emit runningStateChanged(); | 459 | emit runningStateChanged(); |
| 507 | 460 | ||
| 508 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 509 | QScriptValue result = evaluate(_scriptContents); | 461 | QScriptValue result = evaluate(_scriptContents); |
| 510 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 511 | 462 | ||
| 512 | QElapsedTimer startTime; | 463 | QElapsedTimer startTime; |
| 513 | startTime.start(); | 464 | startTime.start(); |
| @@ -518,35 +469,19 @@ void ScriptEngine::run() { · 4 unmodified lines | |||
| 518 | 469 | ||
| 519 | qint64 lastUpdate = usecTimestampNow(); | 470 | qint64 lastUpdate = usecTimestampNow(); |
| 520 | 471 | ||
| 521 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 522 | |||
| 523 | while (!_isFinished) { | 472 | while (!_isFinished) { |
| 524 | if (_isWaitingForDoneRunning) { | ||
| 525 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 526 | } | ||
| 527 | |||
| 528 | int usecToSleep = (thisFrame++ * SCRIPT_DATA_CALLBACK_USECS) - startTime.nsecsElapsed() / 1000; // nsec to usec | 473 | int usecToSleep = (thisFrame++ * SCRIPT_DATA_CALLBACK_USECS) - startTime.nsecsElapsed() / 1000; // nsec to usec |
| 529 | if (usecToSleep > 0) { | 474 | if (usecToSleep > 0) { |
| 530 | usleep(usecToSleep); | 475 | usleep(usecToSleep); |
| 531 | } | 476 | } |
| 532 | 477 | ||
| 533 | if (_isFinished) { | 478 | if (_isFinished) { |
| 534 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 535 | break; | 479 | break; |
| 536 | } | 480 | } |
| 537 | 481 | ||
| 538 | if (_isWaitingForDoneRunning) { | ||
| 539 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 540 | } | ||
| 541 | |||
| 542 | QCoreApplication::processEvents(); | 482 | QCoreApplication::processEvents(); |
| 543 | 483 | ||
| 544 | if (_isWaitingForDoneRunning) { | ||
| 545 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 546 | } | ||
| 547 | |||
| 548 | if (_isFinished) { | 484 | if (_isFinished) { |
| 549 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 550 | break; | 485 | break; |
| 551 | } | 486 | } |
| 552 | 487 | ||
| @@ -675,37 +610,14 @@ void ScriptEngine::run() { · 122 unmodified lines | |||
| 675 | } | 610 | } |
| 676 | lastUpdate = now; | 611 | lastUpdate = now; |
| 677 | 612 | ||
| 678 | if (_isWaitingForDoneRunning) { | ||
| 679 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 680 | } | ||
| 681 | |||
| 682 | } | ||
| 683 | |||
| 684 | if (_isWaitingForDoneRunning) { | ||
| 685 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 686 | } | 613 | } |
| 687 | 614 | ||
| 688 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 689 | |||
| 690 | stopAllTimers(); // make sure all our timers are stopped if the script is ending | 615 | stopAllTimers(); // make sure all our timers are stopped if the script is ending |
| 691 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename();) | ||
| 692 | |||
| 693 | if (_isWaitingForDoneRunning) { | ||
| 694 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 695 | } | ||
| 696 | |||
| 697 | emit scriptEnding(); | 616 | emit scriptEnding(); |
| 698 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 699 | 617 | ||
| 700 | // kill the avatar identity timer | 618 | // kill the avatar identity timer |
| 701 | delete _avatarIdentityTimer; | 619 | delete _avatarIdentityTimer; |
| 702 | 620 | ||
| 703 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 704 | |||
| 705 | if (_isWaitingForDoneRunning) { | ||
| 706 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 707 | } | ||
| 708 | |||
| 709 | if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { | 621 | if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { |
| 710 | // release the queue of edit entity messages. | 622 | // release the queue of edit entity messages. |
| 711 | _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); | 623 | _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); |
| @@ -716,44 +628,19 @@ void ScriptEngine::run() { · 4 unmodified lines | |||
| 716 | } | 628 | } |
| 717 | } | 629 | } |
| 718 | 630 | ||
| 719 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 720 | |||
| 721 | // If we were on a thread, then wait till it's done | 631 | // If we were on a thread, then wait till it's done |
| 722 | if (thread()) { | 632 | if (thread()) { |
| 723 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 724 | thread()->quit(); | 633 | thread()->quit(); |
| 725 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 726 | } | ||
| 727 | |||
| 728 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 729 | |||
| 730 | if (_isWaitingForDoneRunning) { | ||
| 731 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 732 | } | 634 | } |
| 733 | 635 | ||
| 734 | emit finished(_fileNameString); | 636 | emit finished(_fileNameString); |
| 735 | 637 | ||
| 736 | if (_isWaitingForDoneRunning) { | ||
| 737 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 738 | } | ||
| 739 | |||
| 740 | _isRunning = false; | 638 | _isRunning = false; |
| 741 | emit runningStateChanged(); | 639 | emit runningStateChanged(); |
| 742 | 640 | ||
| 743 | DEBUG_SCRIPT_ENDING(qDebug() << "ABOUT TO emit doneRunning() script:" << getFilename() << "[" << this << "]";) | ||
| 744 | emit doneRunning(); | 641 | emit doneRunning(); |
| 745 | DEBUG_SCRIPT_ENDING(qDebug() << "AFTER emit doneRunning() script:" << getFilename() << "[" << this << "]";) | ||
| 746 | 642 | ||
| 747 | if (_isWaitingForDoneRunning) { | ||
| 748 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 749 | } | ||
| 750 | |||
| 751 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() SETTING _doneRunningThisScript = true ################################### line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 752 | _doneRunningThisScript = true; | 643 | _doneRunningThisScript = true; |
| 753 | |||
| 754 | if (_isWaitingForDoneRunning) { | ||
| 755 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::run() ** _isWaitingForDoneRunning == true ** line:" << __LINE__ << " script:" << getFilename() << "[" << this << "]";) | ||
| 756 | } | ||
| 757 | } | 644 | } |
| 758 | 645 | ||
| 759 | // NOTE: This is private because it must be called on the same thread that created the timers, which is why | 646 | // NOTE: This is private because it must be called on the same thread that created the timers, which is why |
| @@ -768,10 +655,8 @@ void ScriptEngine::stopAllTimers() { · 8 unmodified lines | |||
| 768 | } | 655 | } |
| 769 | 656 | ||
| 770 | void ScriptEngine::stop() { | 657 | void ScriptEngine::stop() { |
| 771 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stop() -- START -- line:" << __LINE__ << " script:" << getFilename();) | ||
| 772 | _isFinished = true; | 658 | _isFinished = true; |
| 773 | emit runningStateChanged(); | 659 | emit runningStateChanged(); |
| 774 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::stop() -- DONE -- line:" << __LINE__ << " script:" << getFilename();) | ||
| 775 | } | 660 | } |
| 776 | 661 | ||
| 777 | void ScriptEngine::timerFired() { | 662 | void ScriptEngine::timerFired() { |
| @@ -887,9 +772,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 109 unmodified lines | |||
| 887 | if (contents.isNull()) { | 772 | if (contents.isNull()) { |
| 888 | qDebug() << "Error loading file: " << url; | 773 | qDebug() << "Error loading file: " << url; |
| 889 | } else { | 774 | } else { |
| 890 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::include() BEFORE evaluate() line:" << __LINE__ << " parent script:" << getFilename() << "[" << this << "]" << " url:" << url << "_evaluatesPending:" << _evaluatesPending;) | ||
| 891 | QScriptValue result = evaluate(contents, url.toString()); | 775 | QScriptValue result = evaluate(contents, url.toString()); |
| 892 | DEBUG_SCRIPT_ENDING(qDebug() << "ScriptEngine::include() AFTER evaluate() line:" << __LINE__ << " parent script:" << getFilename() << "[" << this << "]" << " url:" << url << "_evaluatesPending:" << _evaluatesPending;) | ||
| 893 | } | 776 | } |
| 894 | } | 777 | } |
| 895 | 778 | ||