mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 17:28:13 +02:00
don't block main thread for a script load
This commit is contained in:
parent
36f716cd61
commit
d7f168999d
4 changed files with 40 additions and 23 deletions
|
@ -4013,26 +4013,23 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser
|
||||||
return _scriptEnginesHash[scriptURLString];
|
return _scriptEnginesHash[scriptURLString];
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptEngine* scriptEngine;
|
ScriptEngine* scriptEngine = new ScriptEngine(NO_SCRIPT, "", &_controllerScriptingInterface);
|
||||||
if (scriptFilename.isNull()) {
|
|
||||||
scriptEngine = new ScriptEngine(NO_SCRIPT, "", &_controllerScriptingInterface);
|
|
||||||
} else {
|
|
||||||
// start the script on a new thread...
|
|
||||||
scriptEngine = new ScriptEngine(scriptUrl, &_controllerScriptingInterface);
|
|
||||||
|
|
||||||
if (!scriptEngine->hasScript()) {
|
|
||||||
qDebug() << "Application::loadScript(), script failed to load...";
|
|
||||||
QMessageBox::warning(getWindow(), "Error Loading Script", scriptURLString + " failed to load.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
_scriptEnginesHash.insertMulti(scriptURLString, scriptEngine);
|
|
||||||
_runningScriptsWidget->setRunningScripts(getRunningScripts());
|
|
||||||
UserActivityLogger::getInstance().loadedScript(scriptURLString);
|
|
||||||
}
|
|
||||||
scriptEngine->setUserLoaded(isUserLoaded);
|
scriptEngine->setUserLoaded(isUserLoaded);
|
||||||
|
|
||||||
registerScriptEngineWithApplicationServices(scriptEngine);
|
if (scriptFilename.isNull()) {
|
||||||
|
// this had better be the script editor (we should de-couple so somebody who thinks they are loading a script
|
||||||
|
// doesn't just get an empty script engine)
|
||||||
|
|
||||||
|
// we can complete setup now since there isn't a script we have to load
|
||||||
|
registerScriptEngineWithApplicationServices(scriptEngine);
|
||||||
|
} else {
|
||||||
|
// connect to the appropriate signals of this script engine
|
||||||
|
connect(scriptEngine, &ScriptEngine::scriptLoaded, this, &Application::handleScriptEngineLoaded);
|
||||||
|
connect(scriptEngine, &ScriptEngine::scriptLoaded, this, &Application::handleScriptLoadError);
|
||||||
|
|
||||||
|
// get the script engine object to load the script at the designated script URL
|
||||||
|
scriptEngine->loadURL(scriptUrl);
|
||||||
|
}
|
||||||
|
|
||||||
// restore the main window's active state
|
// restore the main window's active state
|
||||||
if (activateMainWindow && !loadScriptFromEditor) {
|
if (activateMainWindow && !loadScriptFromEditor) {
|
||||||
|
@ -4043,6 +4040,22 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser
|
||||||
return scriptEngine;
|
return scriptEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::handleScriptEngineLoaded(const QUrl& scriptURL) {
|
||||||
|
ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
||||||
|
|
||||||
|
_scriptEnginesHash.insertMulti(scriptURL.toString(), scriptEngine);
|
||||||
|
_runningScriptsWidget->setRunningScripts(getRunningScripts());
|
||||||
|
UserActivityLogger::getInstance().loadedScript(scriptURL.toString());
|
||||||
|
|
||||||
|
// register our application services and set it off on its own thread
|
||||||
|
registerScriptEngineWithApplicationServices(scriptEngine);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::handleScriptLoadError(const QUrl& scriptURL) {
|
||||||
|
qDebug() << "Application::loadScript(), script failed to load...";
|
||||||
|
QMessageBox::warning(getWindow(), "Error Loading Script", scriptURL.toString() + " failed to load.");
|
||||||
|
}
|
||||||
|
|
||||||
void Application::scriptFinished(const QString& scriptName) {
|
void Application::scriptFinished(const QString& scriptName) {
|
||||||
const QString& scriptURLString = QUrl(scriptName).toString();
|
const QString& scriptURLString = QUrl(scriptName).toString();
|
||||||
QHash<QString, ScriptEngine*>::iterator it = _scriptEnginesHash.find(scriptURLString);
|
QHash<QString, ScriptEngine*>::iterator it = _scriptEnginesHash.find(scriptURLString);
|
||||||
|
|
|
@ -393,6 +393,9 @@ private slots:
|
||||||
void timer();
|
void timer();
|
||||||
void idle();
|
void idle();
|
||||||
void aboutToQuit();
|
void aboutToQuit();
|
||||||
|
|
||||||
|
void handleScriptEngineLoaded(const QUrl& scriptURL);
|
||||||
|
void handleScriptLoadError(const QUrl& scriptURL);
|
||||||
|
|
||||||
void connectedToDomain(const QString& hostname);
|
void connectedToDomain(const QString& hostname);
|
||||||
|
|
||||||
|
|
|
@ -177,10 +177,10 @@ void ScriptEngine::loadURL(const QUrl& scriptURL) {
|
||||||
qDebug() << "Loading file:" << fileName;
|
qDebug() << "Loading file:" << fileName;
|
||||||
QTextStream in(&scriptFile);
|
QTextStream in(&scriptFile);
|
||||||
_scriptContents = in.readAll();
|
_scriptContents = in.readAll();
|
||||||
emit scriptLoaded();
|
emit scriptLoaded(url);
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "ERROR Loading file:" << fileName;
|
qDebug() << "ERROR Loading file:" << fileName;
|
||||||
emit errorLoadingScript();
|
emit errorLoadingScript(url);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||||
|
@ -195,9 +195,10 @@ void ScriptEngine::handleScriptDownload() {
|
||||||
|
|
||||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||||
_scriptContents = reply->readAll();
|
_scriptContents = reply->readAll();
|
||||||
|
emit scriptLoaded(reply->url());
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "ERROR Loading file:" << reply->url().toString();
|
qDebug() << "ERROR Loading file:" << reply->url().toString();
|
||||||
emit errorLoadingScript();
|
emit errorLoadingScript(reply->url());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,8 @@ public slots:
|
||||||
void nodeKilled(SharedNodePointer node);
|
void nodeKilled(SharedNodePointer node);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void scriptLoaded();
|
void scriptLoaded(const QUrl& scriptURL);
|
||||||
void errorLoadingScript();
|
void errorLoadingScript(const QUrl& scriptURL);
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
void scriptEnding();
|
void scriptEnding();
|
||||||
void finished(const QString& fileNameString);
|
void finished(const QString& fileNameString);
|
||||||
|
|
Loading…
Reference in a new issue