Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 5 files). Show all
Unified · Split
| @@ -94,8 +94,45 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 93 unmodified lines | ||
| 94 | 94 | _isUserLoaded(false), |
| 95 | 95 | _arrayBufferClass(new ArrayBufferClass(this)) |
| 96 | 96 | { |
| 97 | + _allKnownScriptEngines.insert(this); | |
| 97 | 98 | } |
| 98 | 99 | |
| 100 | +ScriptEngine::~ScriptEngine() { | |
| 101 | + qDebug() << "[" << QThread::currentThread() << "]" << "ScriptEngine::~ScriptEngine() " << getFilename(); | |
| 102 | + _allKnownScriptEngines.remove(this); | |
| 103 | +} | |
| 104 | + | |
| 105 | +QSet<ScriptEngine*> ScriptEngine::_allKnownScriptEngines; | |
| 106 | + | |
| 107 | +void ScriptEngine::gracefullyStopAllScripts() { | |
| 108 | + qDebug() << "[" << QThread::currentThread() << "]" << "ScriptEngine::gracefullyStopAllScripts() ----------- START ------------------"; | |
| 109 | + foreach(ScriptEngine* scriptEngine, _allKnownScriptEngines) { | |
| 110 | + if (scriptEngine->isRunning()) { | |
| 111 | + qDebug() << "scriptEngine still alive:" << scriptEngine->getFilename() << "[" << scriptEngine << "]"; | |
| 112 | + | |
| 113 | + QEventLoop loop; | |
| 114 | + QObject::connect(scriptEngine, &ScriptEngine::doneRunning, &loop, &QEventLoop::quit); | |
| 115 | + | |
| 116 | + scriptEngine->stop(); | |
| 117 | + | |
| 118 | + qDebug() << "waiting on script to stop... "; | |
| 119 | + loop.exec(); | |
| 120 | + qDebug() << "done waiting... "; | |
| 121 | + } | |
| 122 | + } | |
| 123 | + qDebug() << "[" << QThread::currentThread() << "]" << "ScriptEngine::gracefullyStopAllScripts() ----------- DONE ------------------"; | |
| 124 | +} | |
| 125 | + | |
| 126 | +QString ScriptEngine::getFilename() const { | |
| 127 | + QStringList fileNameParts = _fileNameString.split("/"); | |
| 128 | + QString lastPart; | |
| 129 | + if (!fileNameParts.isEmpty()) { | |
| 130 | + lastPart = fileNameParts.last(); | |
| 131 | + } | |
| 132 | + return lastPart; | |
| 133 | +} | |
| 134 | + | |
| 135 | + | |
| 99 | 136 | void ScriptEngine::setIsAvatar(bool isAvatar) { |
| 100 | 137 | _isAvatar = isAvatar; |
| 101 | 138 | |
| @@ -364,16 +401,18 @@ void ScriptEngine::run() { · 262 unmodified lines | ||
| 364 | 401 | } |
| 365 | 402 | |
| 366 | 403 | if (_isFinished) { |
| 404 | + qDebug() << "ScriptEngine::run()... while() about to break " << getFilename(); | |
| 367 | 405 | break; |
| 368 | 406 | } |
| 369 | 407 | |
| 370 | 408 | QCoreApplication::processEvents(); |
| 371 | 409 | |
| 372 | 410 | if (_isFinished) { |
| 411 | + qDebug() << "ScriptEngine::run()... while() about to break " << getFilename(); | |
| 373 | 412 | break; |
| 374 | 413 | } |
| 375 | 414 | |
| 376 | − if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { | |
| 415 | + if (!_isFinished && _entityScriptingInterface.getEntityPacketSender()->serversExist()) { | |
| 377 | 416 | // release the queue of edit entity messages. |
| 378 | 417 | _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); |
| 379 | 418 | |
| @@ -383,7 +422,7 @@ void ScriptEngine::run() { · 3 unmodified lines | ||
| 383 | 422 | } |
| 384 | 423 | } |
| 385 | 424 | |
| 386 | − if (_isAvatar && _avatarData) { | |
| 425 | + if (!_isFinished && _isAvatar && _avatarData) { | |
| 387 | 426 | |
| 388 | 427 | const int SCRIPT_AUDIO_BUFFER_SAMPLES = floor(((SCRIPT_DATA_CALLBACK_USECS * AudioConstants::SAMPLE_RATE) |
| 389 | 428 | / (1000 * 1000)) + 0.5); |
| @@ -493,9 +532,13 @@ void ScriptEngine::run() { · 103 unmodified lines | ||
| 493 | 532 | clearExceptions(); |
| 494 | 533 | } |
| 495 | 534 | |
| 496 | − emit update(deltaTime); | |
| 535 | + if (!_isFinished) { | |
| 536 | + //qDebug() << "ScriptEngine::run()... about to emit update() _scriptName:" << _scriptName << "_fileNameString:" << _fileNameString << "_isFinished:" << _isFinished; | |
| 537 | + emit update(deltaTime); | |
| 538 | + } | |
| 497 | 539 | lastUpdate = now; |
| 498 | 540 | } |
| 541 | + qDebug() << "ScriptEngine::run()... about to emit scriptEnding() " << getFilename(); | |
| 499 | 542 | emit scriptEnding(); |
| 500 | 543 | |
| 501 | 544 | // kill the avatar identity timer |
| @@ -513,16 +556,25 @@ void ScriptEngine::run() { · 11 unmodified lines | ||
| 513 | 556 | |
| 514 | 557 | // If we were on a thread, then wait till it's done |
| 515 | 558 | if (thread()) { |
| 559 | + qDebug() << "ScriptEngine::run()... about to call thread()->quit() " << getFilename(); | |
| 516 | 560 | thread()->quit(); |
| 517 | 561 | } |
| 518 | 562 | |
| 563 | + qDebug() << "ScriptEngine::run()... about to emit finished() " << getFilename(); | |
| 519 | 564 | emit finished(_fileNameString); |
| 520 | 565 | |
| 521 | 566 | _isRunning = false; |
| 567 | + | |
| 568 | + qDebug() << "ScriptEngine::run()... about to emit runningStateChanged() " << getFilename(); | |
| 522 | 569 | emit runningStateChanged(); |
| 570 | + | |
| 571 | + qDebug() << "ScriptEngine::run()... about to emit doneRunning() " << getFilename(); | |
| 572 | + emit doneRunning(); | |
| 573 | + qDebug() << "ScriptEngine::run()... DONE WITH run()... " << getFilename(); | |
| 523 | 574 | } |
| 524 | 575 | |
| 525 | 576 | void ScriptEngine::stop() { |
| 577 | + qDebug() << "ScriptEngine::stop()... " << getFilename(); | |
| 526 | 578 | _isFinished = true; |
| 527 | 579 | emit runningStateChanged(); |
| 528 | 580 | } |