From a465aa20ff5bb2b6a9b3ac396137fd74ab65c34d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 17 Dec 2014 11:41:42 -0800 Subject: [PATCH] more Application and Menu dependency removal --- .../entities/RenderableLightEntityItem.cpp | 33 ++++++++----------- .../entities/RenderableModelEntityItem.cpp | 24 +++----------- .../src/entities/RenderableModelEntityItem.h | 1 + .../entities/src/EntityScriptingInterface.cpp | 10 ++---- libraries/entities/src/EntityTree.cpp | 1 - libraries/entities/src/EntityTree.h | 3 -- libraries/entities/src/LightEntityItem.cpp | 1 + libraries/entities/src/LightEntityItem.h | 5 +++ 8 files changed, 29 insertions(+), 49 deletions(-) diff --git a/interface/src/entities/RenderableLightEntityItem.cpp b/interface/src/entities/RenderableLightEntityItem.cpp index be64fe7520..9097956c88 100644 --- a/interface/src/entities/RenderableLightEntityItem.cpp +++ b/interface/src/entities/RenderableLightEntityItem.cpp @@ -16,8 +16,6 @@ #include #include -#include "Application.h" -#include "Menu.h" #include "RenderableLightEntityItem.h" EntityItem* RenderableLightEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { @@ -55,17 +53,13 @@ void RenderableLightEntityItem::render(RenderArgs* args) { float exponent = getExponent(); float cutoff = glm::radians(getCutoff()); - bool disableLights = Menu::getInstance()->isOptionChecked(MenuOption::DisableLightEntities); - - if (!disableLights) { - if (_isSpotlight) { - DependencyManager::get()->addSpotLight(position, largestDiameter / 2.0f, - ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation, - direction, exponent, cutoff); - } else { - DependencyManager::get()->addPointLight(position, largestDiameter / 2.0f, - ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation); - } + if (_isSpotlight) { + DependencyManager::get()->addSpotLight(position, largestDiameter / 2.0f, + ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation, + direction, exponent, cutoff); + } else { + DependencyManager::get()->addPointLight(position, largestDiameter / 2.0f, + ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation); } #ifdef WANT_DEBUG @@ -88,10 +82,11 @@ void RenderableLightEntityItem::render(RenderArgs* args) { bool RenderableLightEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const { - - // TODO: this isn't really correct because we don't know if we actually live in the main tree of the applications's - // EntityTreeRenderer. But we probably do. Technically we could be on the clipboard and someone might be trying to - // use the ray intersection API there. Anyway... if you ever try to do ray intersection testing off of trees other - // than the main tree of the main entity renderer, then you'll need to fix this mechanism. - return Application::getInstance()->getEntities()->getTree()->getLightsArePickable(); + + // TODO: consider if this is really what we want to do. We've made it so that "lights are pickable" is a global state + // this is probably reasonable since there's typically only one tree you'd be picking on at a time. Technically we could + // be on the clipboard and someone might be trying to use the ray intersection API there. Anyway... if you ever try to + // do ray intersection testing off of trees other than the main tree of the main entity renderer, then we'll need to + // fix this mechanism. + return _lightsArePickable; } diff --git a/interface/src/entities/RenderableModelEntityItem.cpp b/interface/src/entities/RenderableModelEntityItem.cpp index c998570a27..3e5118d203 100644 --- a/interface/src/entities/RenderableModelEntityItem.cpp +++ b/interface/src/entities/RenderableModelEntityItem.cpp @@ -13,10 +13,13 @@ #include +#include + #include +#include #include -#include "Menu.h" +#include "EntityTreeRenderer.h" #include "RenderableModelEntityItem.h" EntityItem* RenderableModelEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { @@ -159,28 +162,11 @@ void RenderableModelEntityItem::render(RenderArgs* args) { _needsInitialSimulation = false; } - // TODO: should we allow entityItems to have alpha on their models? - Model::RenderMode modelRenderMode = args->_renderMode == RenderArgs::SHADOW_RENDER_MODE - ? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; - if (_model->isActive()) { // TODO: this is the majority of model render time. And rendering of a cube model vs the basic Box render // is significantly more expensive. Is there a way to call this that doesn't cost us as much? PerformanceTimer perfTimer("model->render"); - bool dontRenderAsScene = Menu::getInstance()->isOptionChecked(MenuOption::DontRenderEntitiesAsScene); - bool displayModelTriangles = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelTriangles); - bool rendered = false; - if (displayModelTriangles) { - rendered = _model->renderTriangleProxies(); - } - - if (!rendered) { - if (dontRenderAsScene) { - _model->render(alpha, modelRenderMode, args); - } else { - _model->renderInScene(alpha, args); - } - } + _model->renderInScene(alpha, args); } else { // if we couldn't get a model, then just draw a cube glColor3ub(getColor()[RED_INDEX],getColor()[GREEN_INDEX],getColor()[BLUE_INDEX]); diff --git a/interface/src/entities/RenderableModelEntityItem.h b/interface/src/entities/RenderableModelEntityItem.h index 9e66e4ef40..6f61a1b9db 100644 --- a/interface/src/entities/RenderableModelEntityItem.h +++ b/interface/src/entities/RenderableModelEntityItem.h @@ -18,6 +18,7 @@ #include class Model; +class EntityTreeRenderer; class RenderableModelEntityItem : public ModelEntityItem { public: diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 26870ad9bb..6226012052 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -11,6 +11,7 @@ #include "EntityScriptingInterface.h" #include "EntityTree.h" +#include "LightEntityItem.h" #include "ModelEntityItem.h" EntityScriptingInterface::EntityScriptingInterface() : @@ -226,16 +227,11 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke } void EntityScriptingInterface::setLightsArePickable(bool value) { - if (_entityTree) { - _entityTree->setLightsArePickable(value); - } + LightEntityItem::setLightsArePickable(value); } bool EntityScriptingInterface::getLightsArePickable() const { - if (_entityTree) { - return _entityTree->getLightsArePickable(); - } - return false; + return LightEntityItem::getLightsArePickable(); } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 17178ccbed..fb8e4345f4 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -22,7 +22,6 @@ EntityTree::EntityTree(bool shouldReaverage) : Octree(shouldReaverage), _fbxService(NULL), - _lightsArePickable(true), _simulation(NULL) { _rootElement = createNewElement(); diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 9a0fb43ecb..cfd08c3b5c 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -150,8 +150,6 @@ public: void emitEntityScriptChanging(const EntityItemID& entityItemID); - bool getLightsArePickable() const { return _lightsArePickable; } - void setLightsArePickable(bool value) { _lightsArePickable = value; } void setSimulation(EntitySimulation* simulation); signals: @@ -180,7 +178,6 @@ private: QHash _entityToElementMap; - bool _lightsArePickable; EntitySimulation* _simulation; }; diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index a24fe58c2a..44b83bc94e 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -18,6 +18,7 @@ #include "EntityTreeElement.h" #include "LightEntityItem.h" +bool LightEntityItem::_lightsArePickable = false; EntityItem* LightEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return new LightEntityItem(entityID, properties); diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index eb9a2ed051..6ebb85beda 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -99,6 +99,9 @@ public: void setCutoff(float value) { _cutoff = value; } virtual const Shape& getCollisionShapeInMeters() const { return _emptyShape; } + + static bool getLightsArePickable() { return _lightsArePickable; } + static void setLightsArePickable(bool value) { _lightsArePickable = value; } protected: virtual void recalculateCollisionShape() { /* nothing to do */ } @@ -116,6 +119,8 @@ protected: // used for collision detection SphereShape _emptyShape; + + static bool _lightsArePickable; }; #endif // hifi_LightEntityItem_h