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
191191
192192 // Gracefully stop the engine's scripting thread
193193 scriptEngine->stop();
194− removeScriptEngine(scriptEngine);
195194
196195 // We need to wait for the engine to be done running before we proceed, because we don't
197196 // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing
@@ -375,13 +374,10 @@ QStringList ScriptEngines::getRunningScripts() { · 177 unmodified lines
375374 }
376375
377376 void ScriptEngines::stopAllScripts(bool restart) {
378− QVector<QString> toReload;
379377 QReadLocker lock(&_scriptEnginesHashLock);
380378
381379 if (_isReloading) {
382380 return;
383− } else {
384− _isReloading = true;
385381 }
386382
387383 for (QHash<QUrl, ScriptEnginePointer>::const_iterator it = _scriptEnginesHash.constBegin();
@@ -394,29 +390,27 @@ void ScriptEngines::stopAllScripts(bool restart) { · 6 unmodified lines
394390
395391 // queue user scripts if restarting
396392 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+ });
398404 }
399405
400406 // stop all scripts
401407 scriptEngine->stop();
402− removeScriptEngine(scriptEngine);
403408 }
404− // wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before
405− // triggering reload of any Client scripts / Entity scripts
406− QTimer::singleShot(1000, this, [=]() {
407− for(const auto &scriptName : toReload) {
408− auto scriptEngine = getScriptEngine(scriptName);
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− });
409+
410+ if (restart) {
411+ qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading";
412+ emit scriptsReloading();
413+ }
420414 }
421415
422416 bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
@@ -444,7 +438,6 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { · 21 unmodified lines
444438 }
445439 }
446440 scriptEngine->stop();
447− removeScriptEngine(scriptEngine);
448441 stoppedScript = true;
449442 }
450443 }

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