mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:37:58 +02:00
add reload all support for entity scripts
This commit is contained in:
parent
009633f281
commit
7840f122dc
7 changed files with 30 additions and 3 deletions
|
@ -4347,6 +4347,8 @@ void Application::stopScript(const QString &scriptName, bool restart) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::reloadAllScripts() {
|
void Application::reloadAllScripts() {
|
||||||
|
DependencyManager::get<ScriptCache>()->clearCache();
|
||||||
|
getEntities()->reloadEntityScripts();
|
||||||
stopAllScripts(true);
|
stopAllScripts(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,15 @@ void EntityTreeRenderer::clear() {
|
||||||
OctreeRenderer::clear();
|
OctreeRenderer::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityTreeRenderer::reloadEntityScripts() {
|
||||||
|
_entitiesScriptEngine->unloadAllEntityScripts();
|
||||||
|
foreach(auto entity, _entitiesInScene) {
|
||||||
|
if (!entity->getScript().isEmpty()) {
|
||||||
|
_entitiesScriptEngine->loadEntityScript(entity->getEntityItemID(), entity->getScript(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EntityTreeRenderer::init() {
|
void EntityTreeRenderer::init() {
|
||||||
OctreeRenderer::init();
|
OctreeRenderer::init();
|
||||||
EntityTreePointer entityTree = std::static_pointer_cast<EntityTree>(_tree);
|
EntityTreePointer entityTree = std::static_pointer_cast<EntityTree>(_tree);
|
||||||
|
@ -769,6 +778,7 @@ void EntityTreeRenderer::addEntityToScene(EntityItemPointer entity) {
|
||||||
|
|
||||||
|
|
||||||
void EntityTreeRenderer::entitySciptChanging(const EntityItemID& entityID, const bool reload) {
|
void EntityTreeRenderer::entitySciptChanging(const EntityItemID& entityID, const bool reload) {
|
||||||
|
qDebug() << "entitySciptChanging() entityID:" << entityID << "reload:" << reload;
|
||||||
if (_tree && !_shuttingDown) {
|
if (_tree && !_shuttingDown) {
|
||||||
_entitiesScriptEngine->unloadEntityScript(entityID);
|
_entitiesScriptEngine->unloadEntityScript(entityID);
|
||||||
checkAndCallPreload(entityID, reload);
|
checkAndCallPreload(entityID, reload);
|
||||||
|
|
|
@ -62,6 +62,10 @@ public:
|
||||||
/// clears the tree
|
/// clears the tree
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
|
/// reloads the entity scripts, calling unload and preload
|
||||||
|
void reloadEntityScripts();
|
||||||
|
|
||||||
|
|
||||||
/// if a renderable entity item needs a model, we will allocate it for them
|
/// if a renderable entity item needs a model, we will allocate it for them
|
||||||
Q_INVOKABLE Model* allocateModel(const QString& url, const QString& collisionUrl);
|
Q_INVOKABLE Model* allocateModel(const QString& url, const QString& collisionUrl);
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,11 @@ ScriptCache::ScriptCache(QObject* parent) {
|
||||||
// nothing to do here...
|
// nothing to do here...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptCache::clearCache() {
|
||||||
|
_scriptCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString ScriptCache::getScript(const QUrl& unnormalizedURL, ScriptUser* scriptUser, bool& isPending, bool reload) {
|
QString ScriptCache::getScript(const QUrl& unnormalizedURL, ScriptUser* scriptUser, bool& isPending, bool reload) {
|
||||||
QUrl url = ResourceManager::normalizeURL(unnormalizedURL);
|
QUrl url = ResourceManager::normalizeURL(unnormalizedURL);
|
||||||
QString scriptContents;
|
QString scriptContents;
|
||||||
|
@ -95,6 +100,8 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qCDebug(scriptengine) << "ScriptCache::getScriptContents() scriptOrURL:" << scriptOrURL << " forceDownload:" << forceDownload << " on thread[" << QThread::currentThread() << "] expected thread[" << thread() << "]";
|
||||||
|
|
||||||
if (_scriptCache.contains(url) && !forceDownload) {
|
if (_scriptCache.contains(url) && !forceDownload) {
|
||||||
qCDebug(scriptengine) << "Found script in cache:" << url.toString();
|
qCDebug(scriptengine) << "Found script in cache:" << url.toString();
|
||||||
#if 1 // def THREAD_DEBUGGING
|
#if 1 // def THREAD_DEBUGGING
|
||||||
|
|
|
@ -28,6 +28,7 @@ class ScriptCache : public QObject, public Dependency {
|
||||||
SINGLETON_DEPENDENCY
|
SINGLETON_DEPENDENCY
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void clearCache();
|
||||||
void getScriptContents(const QString& scriptOrURL, contentAvailableCallback contentAvailable, bool forceDownload = false);
|
void getScriptContents(const QString& scriptOrURL, contentAvailableCallback contentAvailable, bool forceDownload = false);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -909,6 +909,9 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString&
|
||||||
#ifdef THREAD_DEBUGGING
|
#ifdef THREAD_DEBUGGING
|
||||||
qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() scriptOrURL:" << entityScript << "forceDownload:" << forceRedownload << "on thread[" << QThread::currentThread() << "] expected thread[" << thread() << "]";
|
||||||
|
|
||||||
DependencyManager::get<ScriptCache>()->getScriptContents(entityScript, [=](const QString& scriptOrURL, const QString& contents, bool isURL, bool success) {
|
DependencyManager::get<ScriptCache>()->getScriptContents(entityScript, [=](const QString& scriptOrURL, const QString& contents, bool isURL, bool success) {
|
||||||
#ifdef THREAD_DEBUGGING
|
#ifdef THREAD_DEBUGGING
|
||||||
qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
||||||
|
|
Loading…
Reference in a new issue