Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 1 file). Show all
Unified · Split
| @@ -191,7 +191,6 @@ void ScriptEngines::shutdownScripting() { · 190 unmodified lines | |||
| 191 | 191 | ||
| 192 | // Gracefully stop the engine's scripting thread | 192 | // Gracefully stop the engine's scripting thread |
| 193 | scriptEngine->stop(); | 193 | scriptEngine->stop(); |
| 194 | removeScriptEngine(scriptEngine); | ||
| 195 | 194 | ||
| 196 | // We need to wait for the engine to be done running before we proceed, because we don't | 195 | // We need to wait for the engine to be done running before we proceed, because we don't |
| 197 | // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing | 196 | // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing |
| @@ -370,13 +369,10 @@ QStringList ScriptEngines::getRunningScripts() { · 172 unmodified lines | |||
| 370 | } | 369 | } |
| 371 | 370 | ||
| 372 | void ScriptEngines::stopAllScripts(bool restart) { | 371 | void ScriptEngines::stopAllScripts(bool restart) { |
| 373 | QVector<QString> toReload; | ||
| 374 | QReadLocker lock(&_scriptEnginesHashLock); | 372 | QReadLocker lock(&_scriptEnginesHashLock); |
| 375 | 373 | ||
| 376 | if (_isReloading) { | 374 | if (_isReloading) { |
| 377 | return; | 375 | return; |
| 378 | } else { | ||
| 379 | _isReloading = true; | ||
| 380 | } | 376 | } |
| 381 | 377 | ||
| 382 | for (QHash<QUrl, ScriptEnginePointer>::const_iterator it = _scriptEnginesHash.constBegin(); | 378 | for (QHash<QUrl, ScriptEnginePointer>::const_iterator it = _scriptEnginesHash.constBegin(); |
| @@ -389,29 +385,27 @@ void ScriptEngines::stopAllScripts(bool restart) { · 6 unmodified lines | |||
| 389 | 385 | ||
| 390 | // queue user scripts if restarting | 386 | // queue user scripts if restarting |
| 391 | if (restart && scriptEngine->isUserLoaded()) { | 387 | if (restart && scriptEngine->isUserLoaded()) { |
| 392 | toReload << it.key().toString(); | 388 | _isReloading = true; |
| 389 | bool lastScript = (it == _scriptEnginesHash.constEnd() - 1); | ||
| 390 | ScriptEngine::Type type = scriptEngine->getType(); | ||
| 391 | |||
| 392 | connect(scriptEngine.data(), &ScriptEngine::finished, this, [this, type, lastScript] (QString scriptName) { | ||
| 393 | reloadScript(scriptName, true)->setType(type); | ||
| 394 | |||
| 395 | if (lastScript) { | ||
| 396 | _isReloading = false; | ||
| 397 | } | ||
| 398 | }); | ||
| 393 | } | 399 | } |
| 394 | 400 | ||
| 395 | // stop all scripts | 401 | // stop all scripts |
| 396 | scriptEngine->stop(); | 402 | scriptEngine->stop(); |
| 397 | removeScriptEngine(scriptEngine); | ||
| 398 | } | 403 | } |
| 399 | // wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before | 404 | |
| 400 | // triggering reload of any Client scripts / Entity scripts | 405 | if (restart) { |
| 401 | QTimer::singleShot(1000, this, [=]() { | 406 | qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading"; |
| 402 | for(const auto &scriptName : toReload) { | 407 | emit scriptsReloading(); |
| 403 | auto scriptEngine = getScriptEngine(scriptName); | 408 | } |
| 404 | if (scriptEngine && !scriptEngine->isFinished()) { | ||
| 405 | scriptEngine->waitTillDoneRunning(); | ||
| 406 | } | ||
| 407 | reloadScript(scriptName); | ||
| 408 | } | ||
| 409 | if (restart) { | ||
| 410 | qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading"; | ||
| 411 | emit scriptsReloading(); | ||
| 412 | } | ||
| 413 | _isReloading = false; | ||
| 414 | }); | ||
| 415 | } | 409 | } |
| 416 | 410 | ||
| 417 | bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { | 411 | bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { |
| @@ -439,7 +433,6 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { · 21 unmodified lines | |||
| 439 | } | 433 | } |
| 440 | } | 434 | } |
| 441 | scriptEngine->stop(); | 435 | scriptEngine->stop(); |
| 442 | removeScriptEngine(scriptEngine); | ||
| 443 | stoppedScript = true; | 436 | stoppedScript = true; |
| 444 | } | 437 | } |
| 445 | } | 438 | } |