History

Merge branch 'master' into loginInitiative2

Wayne Chen committed 7 years ago

Commit 9deb15b2 parents 527f8a2 f98f07054 files · +698 −446Browse files

Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 54 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngines.cpp+16−23
@@ -191,7 +191,6 @@ void ScriptEngines::shutdownScripting() { · 190 unmodified lines
191 191
192 // Gracefully stop the engine's scripting thread192 // 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't195 // 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 accessing196 // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing
@@ -375,13 +374,10 @@ QStringList ScriptEngines::getRunningScripts() { · 177 unmodified lines
375}374}
376 375
377void ScriptEngines::stopAllScripts(bool restart) {376void ScriptEngines::stopAllScripts(bool restart) {
378 QVector<QString> toReload;
379 QReadLocker lock(&_scriptEnginesHashLock);377 QReadLocker lock(&_scriptEnginesHashLock);
380 378
381 if (_isReloading) {379 if (_isReloading) {
382 return;380 return;
383 } else {
384 _isReloading = true;
385 }381 }
386 382
387 for (QHash<QUrl, ScriptEnginePointer>::const_iterator it = _scriptEnginesHash.constBegin();383 for (QHash<QUrl, ScriptEnginePointer>::const_iterator it = _scriptEnginesHash.constBegin();
@@ -394,29 +390,27 @@ void ScriptEngines::stopAllScripts(bool restart) { · 6 unmodified lines
394 390
395 // queue user scripts if restarting391 // queue user scripts if restarting
396 if (restart && scriptEngine->isUserLoaded()) {392 if (restart && scriptEngine->isUserLoaded()) {
397 toReload << it.key().toString();393 _isReloading = true;
394 bool lastScript = (it == _scriptEnginesHash.constEnd() - 1);
395 ScriptEngine::Type type = scriptEngine->getType();
396
397 connect(scriptEngine.data(), &ScriptEngine::finished, this, [this, type, lastScript] (QString scriptName) {
398 reloadScript(scriptName, true)->setType(type);
399
400 if (lastScript) {
401 _isReloading = false;
402 }
403 });
398 }404 }
399 405
400 // stop all scripts406 // stop all scripts
401 scriptEngine->stop();407 scriptEngine->stop();
402 removeScriptEngine(scriptEngine);
403 }408 }
404 // wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before409
405 // triggering reload of any Client scripts / Entity scripts410 if (restart) {
406 QTimer::singleShot(1000, this, [=]() {411 qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading";
407 for(const auto &scriptName : toReload) {412 emit scriptsReloading();
408 auto scriptEngine = getScriptEngine(scriptName);413 }
409 if (scriptEngine && !scriptEngine->isFinished()) {
410 scriptEngine->waitTillDoneRunning();
411 }
412 reloadScript(scriptName);
413 }
414 if (restart) {
415 qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading";
416 emit scriptsReloading();
417 }
418 _isReloading = false;
419 });
420}414}
421 415
422bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {416bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
@@ -444,7 +438,6 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { · 21 unmodified lines
444 }438 }
445 }439 }
446 scriptEngine->stop();440 scriptEngine->stop();
447 removeScriptEngine(scriptEngine);
448 stoppedScript = true;441 stoppedScript = true;
449 }442 }
450 }443 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t