From 7231116e43c1da7bd9f15717a8166d60e5ca6be1 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 18 Dec 2018 12:39:33 -0800 Subject: [PATCH] fix zone with invalid script not loading --- .../src/EntityTreeRenderer.cpp | 52 +++++++------------ .../src/EntityTreeRenderer.h | 18 +------ 2 files changed, 22 insertions(+), 48 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 980ff8834c..49d95ed536 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -61,8 +61,7 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf _lastPointerEventValid(false), _viewState(viewState), _scriptingServices(scriptingServices), - _displayModelBounds(false), - _layeredZones(this) + _displayModelBounds(false) { setMouseRayPickResultOperator([](unsigned int rayPickID) { RayToEntityIntersectionResult entityResult; @@ -516,41 +515,36 @@ bool EntityTreeRenderer::findBestZoneAndMaybeContainingEntities(QVectorgetScript().isEmpty(); // only consider entities that are zones or have scripts, all other entities can - // be ignored because they can have events fired on them. + // be ignored because they can't have events fired on them. // FIXME - this could be optimized further by determining if the script is loaded // and if it has either an enterEntity or leaveEntity method // // also, don't flag a scripted entity as containing the avatar until the script is loaded, // so that the script is awake in time to receive the "entityEntity" call (even if the entity is a zone). - if ((!hasScript && isZone) || - (hasScript && entity->isScriptPreloadFinished())) { - // now check to see if the point contains our entity, this can be expensive if - // the entity has a collision hull - if (entity->contains(_avatarPosition)) { + bool contains = false; + bool scriptHasLoaded = hasScript && entity->isScriptPreloadFinished(); + if (isZone || scriptHasLoaded) { + contains = entity->contains(_avatarPosition); + } + + if (contains) { + // if this entity is a zone and visible, add it to our layered zones + if (isZone && entity->getVisible() && renderableForEntity(entity)) { + _layeredZones.insert(std::dynamic_pointer_cast(entity)); + } + + if ((!hasScript && isZone) || scriptHasLoaded) { if (entitiesContainingAvatar) { *entitiesContainingAvatar << entity->getEntityItemID(); } - - // if this entity is a zone and visible, determine if it is the bestZone - if (isZone && entity->getVisible() && renderableForEntity(entity)) { - auto zone = std::dynamic_pointer_cast(entity); - _layeredZones.insert(zone); - } - } } } + } // check if our layered zones have changed - if (_layeredZones.empty()) { - if (oldLayeredZones.empty()) { - return; - } - } else if (!oldLayeredZones.empty()) { - if (_layeredZones.contains(oldLayeredZones)) { - return; - } + if ((_layeredZones.empty() && oldLayeredZones.empty()) || (!oldLayeredZones.empty() && _layeredZones.contains(oldLayeredZones))) { + return; } - _layeredZones.apply(); applyLayeredZones(); @@ -653,8 +647,8 @@ bool EntityTreeRenderer::applyLayeredZones() { } else { qCWarning(entitiesrenderer) << "EntityTreeRenderer::applyLayeredZones(), Unexpected null scene, possibly during application shutdown"; } - - return true; + + return true; } void EntityTreeRenderer::processEraseMessage(ReceivedMessage& message, const SharedNodePointer& sourceNode) { @@ -1151,18 +1145,12 @@ std::pair EntityTreeRenderer:: return { it, success }; } -void EntityTreeRenderer::LayeredZones::apply() { - assert(_entityTreeRenderer); -} - void EntityTreeRenderer::LayeredZones::update(std::shared_ptr zone) { - assert(_entityTreeRenderer); bool isVisible = zone->isVisible(); if (empty() && isVisible) { // there are no zones: set this one insert(zone); - apply(); return; } else { LayeredZone zoneLayer(zone); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 4ba1a0060b..4cc2b07cc5 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -205,42 +205,28 @@ private: class LayeredZones : public std::set { public: - LayeredZones(EntityTreeRenderer* parent) : _entityTreeRenderer(parent) {} + LayeredZones() {}; LayeredZones(LayeredZones&& other); // avoid accidental misconstruction - LayeredZones() = delete; LayeredZones(const LayeredZones&) = delete; LayeredZones& operator=(const LayeredZones&) = delete; LayeredZones& operator=(LayeredZones&&) = delete; void clear(); std::pair insert(const LayeredZone& layer); - - void apply(); void update(std::shared_ptr zone); - bool contains(const LayeredZones& other); std::shared_ptr getZone() { return empty() ? nullptr : begin()->zone; } private: - void applyPartial(iterator layer); - std::map _map; - iterator _skyboxLayer{ end() }; - EntityTreeRenderer* _entityTreeRenderer; + iterator _skyboxLayer { end() }; }; LayeredZones _layeredZones; - QString _zoneUserData; - NetworkTexturePointer _ambientTexture; - NetworkTexturePointer _skyboxTexture; - QString _ambientTextureURL; - QString _skyboxTextureURL; float _avgRenderableUpdateCost { 0.0f }; - bool _pendingAmbientTexture { false }; - bool _pendingSkyboxTexture { false }; uint64_t _lastZoneCheck { 0 }; const uint64_t ZONE_CHECK_INTERVAL = USECS_PER_MSEC * 100; // ~10hz