mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 17:03:11 +02:00
reload qml with scripts
This commit is contained in:
parent
3c82a489fa
commit
aeaae4ccc8
4 changed files with 16 additions and 12 deletions
|
@ -545,6 +545,10 @@ QObject* OffscreenQmlSurface::load(const QUrl& qmlSource, std::function<void(QQm
|
|||
return finishQmlLoad(f);
|
||||
}
|
||||
|
||||
void OffscreenQmlSurface::clearCache() {
|
||||
getRootContext()->engine()->clearComponentCache();
|
||||
}
|
||||
|
||||
void OffscreenQmlSurface::requestUpdate() {
|
||||
_polish = true;
|
||||
_render = true;
|
||||
|
|
|
@ -40,10 +40,12 @@ public:
|
|||
virtual void create(QOpenGLContext* context);
|
||||
void resize(const QSize& size, bool forceResize = false);
|
||||
QSize size() const;
|
||||
|
||||
Q_INVOKABLE QObject* load(const QUrl& qmlSource, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
||||
Q_INVOKABLE QObject* load(const QString& qmlSourceFile, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}) {
|
||||
return load(QUrl(qmlSourceFile), f);
|
||||
}
|
||||
void clearCache();
|
||||
|
||||
Q_INVOKABLE void executeOnUiThread(std::function<void()> function, bool blocking = false);
|
||||
Q_INVOKABLE QVariant returnFromUiThread(std::function<QVariant()> function);
|
||||
|
|
|
@ -17,3 +17,5 @@ if (NOT ANDROID)
|
|||
endif ()
|
||||
|
||||
link_hifi_libraries(shared networking octree gpu ui procedural model model-networking recording avatars fbx entities controllers animation audio physics)
|
||||
# ui includes gl, but link_hifi_libraries does not use transitive includes, so gl must be explicit
|
||||
include_hifi_library_headers(gl)
|
|
@ -16,6 +16,8 @@
|
|||
#include <UserActivityLogger.h>
|
||||
#include <PathUtils.h>
|
||||
|
||||
#include <OffscreenUi.h>
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
#include "ScriptEngineLogging.h"
|
||||
|
||||
|
@ -367,28 +369,21 @@ QStringList ScriptEngines::getRunningScripts() {
|
|||
|
||||
void ScriptEngines::stopAllScripts(bool restart) {
|
||||
QReadLocker lock(&_scriptEnginesHashLock);
|
||||
if (restart) {
|
||||
// Delete all running scripts from cache so that they are re-downloaded when they are restarted
|
||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||
for (QHash<QUrl, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
|
||||
it != _scriptEnginesHash.constEnd(); it++) {
|
||||
if (!it.value()->isFinished()) {
|
||||
scriptCache->deleteScript(it.key());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stop and possibly restart all currently running scripts
|
||||
for (QHash<QUrl, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
|
||||
it != _scriptEnginesHash.constEnd(); it++) {
|
||||
// skip already stopped scripts
|
||||
if (it.value()->isFinished() || it.value()->isStopping()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// queue user scripts if restarting
|
||||
if (restart && it.value()->isUserLoaded()) {
|
||||
connect(it.value(), &ScriptEngine::finished, this, [this](QString scriptName, ScriptEngine* engine) {
|
||||
reloadScript(scriptName);
|
||||
});
|
||||
}
|
||||
|
||||
// stop all scripts
|
||||
it.value()->stop(true);
|
||||
qCDebug(scriptengine) << "stopping script..." << it.key();
|
||||
}
|
||||
|
@ -431,6 +426,7 @@ void ScriptEngines::setScriptsLocation(const QString& scriptsLocation) {
|
|||
|
||||
void ScriptEngines::reloadAllScripts() {
|
||||
DependencyManager::get<ScriptCache>()->clearCache();
|
||||
DependencyManager::get<OffscreenUi>()->clearCache();
|
||||
emit scriptsReloading();
|
||||
stopAllScripts(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue