mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 22:22:54 +02:00
Merge pull request #9667 from huffman/fix/entity-scripts-not-loading
Fix entity scripts not loading in certain cases
This commit is contained in:
commit
2e245e9cba
3 changed files with 11 additions and 8 deletions
|
@ -938,17 +938,19 @@ void EntityTreeRenderer::addEntityToScene(EntityItemPointer entity) {
|
||||||
|
|
||||||
|
|
||||||
void EntityTreeRenderer::entityScriptChanging(const EntityItemID& entityID, const bool reload) {
|
void EntityTreeRenderer::entityScriptChanging(const EntityItemID& entityID, const bool reload) {
|
||||||
if (_tree && !_shuttingDown) {
|
checkAndCallPreload(entityID, reload, true);
|
||||||
_entitiesScriptEngine->unloadEntityScript(entityID);
|
|
||||||
checkAndCallPreload(entityID, reload);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID, const bool reload) {
|
void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID, const bool reload, const bool unloadFirst) {
|
||||||
if (_tree && !_shuttingDown) {
|
if (_tree && !_shuttingDown) {
|
||||||
EntityItemPointer entity = getTree()->findEntityByEntityItemID(entityID);
|
EntityItemPointer entity = getTree()->findEntityByEntityItemID(entityID);
|
||||||
if (entity && entity->shouldPreloadScript() && _entitiesScriptEngine) {
|
bool shouldLoad = entity && entity->shouldPreloadScript() && _entitiesScriptEngine;
|
||||||
QString scriptUrl = entity->getScript();
|
QString scriptUrl = entity->getScript();
|
||||||
|
if ((unloadFirst && shouldLoad) || scriptUrl.isEmpty()) {
|
||||||
|
_entitiesScriptEngine->unloadEntityScript(entityID);
|
||||||
|
entity->scriptHasUnloaded();
|
||||||
|
}
|
||||||
|
if (shouldLoad && !scriptUrl.isEmpty()) {
|
||||||
scriptUrl = ResourceManager::normalizeURL(scriptUrl);
|
scriptUrl = ResourceManager::normalizeURL(scriptUrl);
|
||||||
ScriptEngine::loadEntityScript(_entitiesScriptEngine, entityID, scriptUrl, reload);
|
ScriptEngine::loadEntityScript(_entitiesScriptEngine, entityID, scriptUrl, reload);
|
||||||
entity->scriptHasPreloaded();
|
entity->scriptHasPreloaded();
|
||||||
|
|
|
@ -148,7 +148,7 @@ private:
|
||||||
bool layerZoneAndHasSkybox(const std::shared_ptr<ZoneEntityItem>& zone);
|
bool layerZoneAndHasSkybox(const std::shared_ptr<ZoneEntityItem>& zone);
|
||||||
bool applySkyboxAndHasAmbient();
|
bool applySkyboxAndHasAmbient();
|
||||||
|
|
||||||
void checkAndCallPreload(const EntityItemID& entityID, const bool reload = false);
|
void checkAndCallPreload(const EntityItemID& entityID, const bool reload = false, const bool unloadFirst = false);
|
||||||
|
|
||||||
QList<ModelPointer> _releasedModels;
|
QList<ModelPointer> _releasedModels;
|
||||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||||
|
|
|
@ -446,6 +446,7 @@ public:
|
||||||
bool shouldPreloadScript() const { return !_script.isEmpty() &&
|
bool shouldPreloadScript() const { return !_script.isEmpty() &&
|
||||||
((_loadedScript != _script) || (_loadedScriptTimestamp != _scriptTimestamp)); }
|
((_loadedScript != _script) || (_loadedScriptTimestamp != _scriptTimestamp)); }
|
||||||
void scriptHasPreloaded() { _loadedScript = _script; _loadedScriptTimestamp = _scriptTimestamp; }
|
void scriptHasPreloaded() { _loadedScript = _script; _loadedScriptTimestamp = _scriptTimestamp; }
|
||||||
|
void scriptHasUnloaded() { _loadedScript = ""; _loadedScriptTimestamp = 0; }
|
||||||
|
|
||||||
bool getClientOnly() const { return _clientOnly; }
|
bool getClientOnly() const { return _clientOnly; }
|
||||||
void setClientOnly(bool clientOnly) { _clientOnly = clientOnly; }
|
void setClientOnly(bool clientOnly) { _clientOnly = clientOnly; }
|
||||||
|
|
Loading…
Reference in a new issue