From 6edc817bf26c66347db23940d50704098202299b Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 18 Sep 2015 11:35:50 -0700 Subject: [PATCH] move the best zone logic out of EntityTreeRenderer::render() --- .../src/EntityTreeRenderer.cpp | 85 +++++++------------ .../src/EntityTreeRenderer.h | 2 +- 2 files changed, 33 insertions(+), 54 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index ebdf0f0339..4d42b79092 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -165,12 +165,41 @@ void EntityTreeRenderer::checkEnterLeaveEntities() { _tree->withReadLock([&] { std::static_pointer_cast(_tree)->findEntities(avatarPosition, radius, foundEntities); + // Whenever you're in an intersection between zones, we will always choose the smallest zone. + _bestZone = NULL; // NOTE: Is this what we want? + _bestZoneVolume = std::numeric_limits::max(); + // create a list of entities that actually contain the avatar's position foreach(EntityItemPointer entity, foundEntities) { if (entity->contains(avatarPosition)) { entitiesContainingAvatar << entity->getEntityItemID(); + + // if this entity is a zone, use this time to determine the bestZone + if (entity->getType() == EntityTypes::Zone) { + float entityVolumeEstimate = entity->getVolumeEstimate(); + if (entityVolumeEstimate < _bestZoneVolume) { + _bestZoneVolume = entityVolumeEstimate; + _bestZone = std::dynamic_pointer_cast(entity); + } else if (entityVolumeEstimate == _bestZoneVolume) { + if (!_bestZone) { + _bestZoneVolume = entityVolumeEstimate; + _bestZone = std::dynamic_pointer_cast(entity); + } else { + // in the case of the volume being equal, we will use the + // EntityItemID to deterministically pick one entity over the other + if (entity->getEntityItemID() < _bestZone->getEntityItemID()) { + _bestZoneVolume = entityVolumeEstimate; + _bestZone = std::dynamic_pointer_cast(entity); + } + } + } + + } } } + + applyZonePropertiesToScene(_bestZone); + }); // Note: at this point we don't need to worry about the tree being locked, because we only deal with @@ -306,23 +335,9 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr_renderer = this; - _tree->withReadLock([&] { - // Whenever you're in an intersection between zones, we will always choose the smallest zone. - _bestZone = NULL; // NOTE: Is this what we want? - _bestZoneVolume = std::numeric_limits::max(); - - // FIX ME: right now the renderOperation does the following: - // 1) determining the best zone (not really rendering) - // 2) render the debug cell details - // we should clean this up - _tree->recurseTreeWithOperation(renderOperation, renderArgs); - - applyZonePropertiesToScene(_bestZone); - }); - } + // FIXME - currently the EntityItem rendering code still depends on knowing about the EntityTreeRenderer + // because it uses it as a model loading service. We don't actually do anything in rendering other than this. + renderArgs->_renderer = this; deleteReleasedModels(); // seems like as good as any other place to do some memory cleanup } @@ -370,42 +385,6 @@ const FBXGeometry* EntityTreeRenderer::getCollisionGeometryForEntity(EntityItemP return result; } -void EntityTreeRenderer::renderElement(OctreeElementPointer element, RenderArgs* args) { - // actually render it here... - // we need to iterate the actual entityItems of the element - EntityTreeElementPointer entityTreeElement = std::static_pointer_cast(element); - - bool isShadowMode = args->_renderMode == RenderArgs::SHADOW_RENDER_MODE; - - entityTreeElement->forEachEntity([&](EntityItemPointer entityItem) { - if (entityItem->isVisible()) { - // NOTE: Zone Entities are a special case we handle here... - if (entityItem->getType() == EntityTypes::Zone) { - if (entityItem->contains(_viewState->getAvatarPosition())) { - float entityVolumeEstimate = entityItem->getVolumeEstimate(); - if (entityVolumeEstimate < _bestZoneVolume) { - _bestZoneVolume = entityVolumeEstimate; - _bestZone = std::dynamic_pointer_cast(entityItem); - } else if (entityVolumeEstimate == _bestZoneVolume) { - if (!_bestZone) { - _bestZoneVolume = entityVolumeEstimate; - _bestZone = std::dynamic_pointer_cast(entityItem); - } else { - // in the case of the volume being equal, we will use the - // EntityItemID to deterministically pick one entity over the other - if (entityItem->getEntityItemID() < _bestZone->getEntityItemID()) { - _bestZoneVolume = entityVolumeEstimate; - _bestZone = std::dynamic_pointer_cast(entityItem); - } - } - } - } - } - } - }); - -} - float EntityTreeRenderer::getSizeScale() const { return _viewState->getSizeScale(); } diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 2691c3c66f..1664920a1d 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -40,7 +40,7 @@ public: virtual char getMyNodeType() const { return NodeType::EntityServer; } virtual PacketType getMyQueryMessageType() const { return PacketType::EntityQuery; } virtual PacketType getExpectedPacketType() const { return PacketType::EntityData; } - virtual void renderElement(OctreeElementPointer element, RenderArgs* args); + virtual void renderElement(OctreeElementPointer element, RenderArgs* args) { } virtual float getSizeScale() const; virtual int getBoundaryLevelAdjust() const; virtual void setTree(OctreePointer newTree);