From 5f6978a517d5b46c727b4a1421db8604b8640909 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 26 May 2015 09:41:51 -0700 Subject: [PATCH] sam's CR feedback, more use of share_ptr<> --- .../src/EntityTreeRenderer.cpp | 24 +++++++++---------- .../src/EntityTreeRenderer.h | 5 ++-- libraries/entities/src/EntityItem.cpp | 3 --- libraries/entities/src/EntityTypes.h | 1 - 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index a4e62bdb06..e635a8a52e 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -394,7 +394,7 @@ void EntityTreeRenderer::leaveAllEntities() { } } -void EntityTreeRenderer::applyZonePropertiesToScene(const ZoneEntityItem* zone) { +void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr zone) { QSharedPointer scene = DependencyManager::get(); if (zone) { if (!_hasPreviousZone) { @@ -498,7 +498,7 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, _tree->lockForRead(); // Whenever you're in an intersection between zones, we will always choose the smallest zone. - _bestZone = NULL; + _bestZone = NULL; // NOTE: Is this what we want? _bestZoneVolume = std::numeric_limits::max(); _tree->recurseTreeWithOperation(renderOperation, &args); @@ -538,8 +538,8 @@ const FBXGeometry* EntityTreeRenderer::getGeometryForEntity(EntityItemPointer en const FBXGeometry* result = NULL; if (entityItem->getType() == EntityTypes::Model) { - const RenderableModelEntityItem* constModelEntityItem = dynamic_cast(entityItem.get()); - RenderableModelEntityItem* modelEntityItem = const_cast(constModelEntityItem); + std::shared_ptr modelEntityItem = + std::dynamic_pointer_cast(entityItem); assert(modelEntityItem); // we need this!!! Model* model = modelEntityItem->getModel(this); if (model) { @@ -552,8 +552,8 @@ const FBXGeometry* EntityTreeRenderer::getGeometryForEntity(EntityItemPointer en const Model* EntityTreeRenderer::getModelForEntityItem(EntityItemPointer entityItem) { const Model* result = NULL; if (entityItem->getType() == EntityTypes::Model) { - const RenderableModelEntityItem* constModelEntityItem = dynamic_cast(entityItem.get()); - RenderableModelEntityItem* modelEntityItem = const_cast(constModelEntityItem); + std::shared_ptr modelEntityItem = + std::dynamic_pointer_cast(entityItem); result = modelEntityItem->getModel(this); } return result; @@ -563,9 +563,9 @@ const FBXGeometry* EntityTreeRenderer::getCollisionGeometryForEntity(EntityItemP const FBXGeometry* result = NULL; if (entityItem->getType() == EntityTypes::Model) { - const RenderableModelEntityItem* constModelEntityItem = dynamic_cast(entityItem.get()); - if (constModelEntityItem->hasCompoundShapeURL()) { - RenderableModelEntityItem* modelEntityItem = const_cast(constModelEntityItem); + std::shared_ptr modelEntityItem = + std::dynamic_pointer_cast(entityItem); + if (modelEntityItem->hasCompoundShapeURL()) { Model* model = modelEntityItem->getModel(this); if (model) { const QSharedPointer collisionNetworkGeometry = model->getCollisionGeometry(); @@ -680,17 +680,17 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) float entityVolumeEstimate = entityItem->getVolumeEstimate(); if (entityVolumeEstimate < _bestZoneVolume) { _bestZoneVolume = entityVolumeEstimate; - _bestZone = dynamic_cast(entityItem.get()); + _bestZone = std::dynamic_pointer_cast(entityItem); } else if (entityVolumeEstimate == _bestZoneVolume) { if (!_bestZone) { _bestZoneVolume = entityVolumeEstimate; - _bestZone = dynamic_cast(entityItem.get()); + _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 = dynamic_cast(entityItem.get()); + _bestZone = std::dynamic_pointer_cast(entityItem); } } } diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 25fa7359ff..733550621c 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -125,7 +125,7 @@ protected: virtual Octree* createTree() { return new EntityTree(true); } private: - void applyZonePropertiesToScene(const ZoneEntityItem* zone); + void applyZonePropertiesToScene(std::shared_ptr zone); void renderElementProxy(EntityTreeElement* entityTreeElement, RenderArgs* args); void checkAndCallPreload(const EntityItemID& entityID); void checkAndCallUnload(const EntityItemID& entityID); @@ -174,7 +174,8 @@ private: QMultiMap _waitingOnPreload; bool _hasPreviousZone = false; - const ZoneEntityItem* _bestZone; + std::shared_ptr _bestZone; + float _bestZoneVolume; glm::vec3 _previousKeyLightColor; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 427c5e7f87..6ad2bed291 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -87,9 +87,6 @@ EntityItem::~EntityItem() { assert(!_simulated); assert(!_element); assert(!_physicsInfo); - - qDebug() << "EntityItem::~EntityItem()"; - debugDump(); } EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const { diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index 7839137f3d..524e5b6e82 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -21,7 +21,6 @@ class EntityItem; typedef std::shared_ptr EntityItemPointer; -//typedef EntityItem* EntityItemPointer; inline uint qHash(const EntityItemPointer& a, uint seed) { return qHash(a.get(), seed);