From 5d636e21c64d8789f198bbdaf4cbf325372740cc Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 17 Dec 2014 11:10:45 -0800 Subject: [PATCH] more Application dependency cleanup --- interface/src/Application.cpp | 6 ++--- interface/src/Application.h | 14 ++++++----- interface/src/entities/EntityTreeRenderer.cpp | 23 ++++++++++++------- interface/src/entities/EntityTreeRenderer.h | 8 +++++-- .../src/AbstractViewStateInterface.h | 16 ++++++++----- .../src/AmbientOcclusionEffect.cpp | 3 ++- .../render-utils/src/AmbientOcclusionEffect.h | 7 +++--- .../src/DeferredLightingEffect.cpp | 15 ++++-------- .../render-utils/src/DeferredLightingEffect.h | 6 ++--- libraries/render-utils/src/Model.cpp | 4 +++- libraries/render-utils/src/Model.h | 6 ++--- 11 files changed, 60 insertions(+), 48 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d8c7811b6a..1453cec53b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -155,9 +155,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _voxelImporter(), _importSucceded(false), _sharedVoxelSystem(TREE_SCALE, DEFAULT_MAX_VOXELS_PER_SYSTEM, &_clipboard), - _entities(true, this), + _entities(true, this, this), _entityCollisionSystem(), - _entityClipboardRenderer(false, this), + _entityClipboardRenderer(false, this, this), _entityClipboard(), _wantToKillLocalVoxels(false), _viewFrustum(), @@ -191,7 +191,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _isVSyncOn(true), _aboutToQuit(false) { - Model::setViewStateInterface(this); // The model class will sometimes need to know view state details from us + Model::setAbstractViewStateInterface(this); // The model class will sometimes need to know view state details from us // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); diff --git a/interface/src/Application.h b/interface/src/Application.h index 86683a6608..d192a9abe6 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -32,6 +32,8 @@ #include #include +#include +#include #include #include #include @@ -42,7 +44,6 @@ #include #include #include -#include #include #include "MainWindow.h" @@ -127,7 +128,7 @@ static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS static const QString INFO_HELP_PATH = "html/interface-welcome-allsvg.html"; static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-entities-commands.html"; -class Application : public QApplication, public ViewStateInterface { +class Application : public QApplication, public AbstractViewStateInterface, AbstractScriptingServicesInterface { Q_OBJECT friend class OctreePacketProcessor; @@ -186,6 +187,7 @@ public: GLCanvas* getGLWidget() { return _glWidget; } bool isThrottleRendering() const { return _glWidget->isThrottleRendering(); } MyAvatar* getAvatar() { return _myAvatar; } + const MyAvatar* getAvatar() const { return _myAvatar; } Audio* getAudio() { return &_audio; } Camera* getCamera() { return &_myCamera; } ViewFrustum* getViewFrustum() { return &_viewFrustum; } @@ -248,7 +250,9 @@ public: ToolWindow* getToolWindow() { return _toolWindow ; } - ControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; } + virtual AbstractControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; } + virtual void registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine); + AvatarManager& getAvatarManager() { return _avatarManager; } void resetProfile(const QString& username); @@ -288,6 +292,7 @@ public: virtual float getSizeScale() const; virtual int getBoundaryLevelAdjust() const; virtual PickRay computePickRay(float x, float y); + virtual const glm::vec3& getAvatarPosition() const { return getAvatar()->getPosition(); } NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; } @@ -312,9 +317,6 @@ public: bool isVSyncEditable() const; bool isAboutToQuit() const { return _aboutToQuit; } - - void registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine); - // the isHMDmode is true whenever we use the interface from an HMD and not a standard flat display // rendering of several elements depend on that // TODO: carry that information on the Camera as a setting diff --git a/interface/src/entities/EntityTreeRenderer.cpp b/interface/src/entities/EntityTreeRenderer.cpp index 6684daf7e8..5654b416f1 100644 --- a/interface/src/entities/EntityTreeRenderer.cpp +++ b/interface/src/entities/EntityTreeRenderer.cpp @@ -11,16 +11,21 @@ #include +#include // TODO - we need to get rid of this ASAP + #include +#include #include - + +#include +#include #include +#include #include #include -#include +#include -#include "Application.h" #include "EntityTreeRenderer.h" #include "RenderableBoxEntityItem.h" @@ -30,12 +35,14 @@ #include "RenderableTextEntityItem.h" -EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, ViewStateInterface* viewState) : +EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterface* viewState, + AbstractScriptingServicesInterface* scriptingServices) : OctreeRenderer(), _wantScripts(wantScripts), _entitiesScriptEngine(NULL), _lastMouseEventValid(false), _viewState(viewState), + _scriptingServices(scriptingServices), _displayElementChildProxies(false), _displayModelBounds(false), _displayModelElementProxy(false), @@ -70,13 +77,13 @@ void EntityTreeRenderer::init() { if (_wantScripts) { _entitiesScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities", - Application::getInstance()->getControllerScriptingInterface()); - Application::getInstance()->registerScriptEngineWithApplicationServices(_entitiesScriptEngine); + _scriptingServices->getControllerScriptingInterface()); + _scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine); } // make sure our "last avatar position" is something other than our current position, so that on our // first chance, we'll check for enter/leave entity events. - glm::vec3 avatarPosition = Application::getInstance()->getAvatar()->getPosition(); + glm::vec3 avatarPosition = _viewState->getAvatarPosition(); _lastAvatarPosition = avatarPosition + glm::vec3(1.0f, 1.0f, 1.0f); connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity); @@ -233,7 +240,7 @@ void EntityTreeRenderer::update() { void EntityTreeRenderer::checkEnterLeaveEntities() { if (_tree) { _tree->lockForWrite(); // so that our scripts can do edits if they want - glm::vec3 avatarPosition = Application::getInstance()->getAvatar()->getPosition() / (float) TREE_SCALE; + glm::vec3 avatarPosition = _viewState->getAvatarPosition() / (float) TREE_SCALE; if (avatarPosition != _lastAvatarPosition) { float radius = 1.0f / (float) TREE_SCALE; // for now, assume 1 meter radius diff --git a/interface/src/entities/EntityTreeRenderer.h b/interface/src/entities/EntityTreeRenderer.h index c3bd77aba7..f827685409 100644 --- a/interface/src/entities/EntityTreeRenderer.h +++ b/interface/src/entities/EntityTreeRenderer.h @@ -19,6 +19,8 @@ class Model; class ScriptEngine; +class AbstractViewStateInterface; +class AbstractScriptingServicesInterface; class EntityScriptDetails { public: @@ -30,7 +32,8 @@ public: class EntityTreeRenderer : public OctreeRenderer, public EntityItemFBXService { Q_OBJECT public: - EntityTreeRenderer(bool wantScripts, ViewStateInterface* viewState); + EntityTreeRenderer(bool wantScripts, AbstractViewStateInterface* viewState, + AbstractScriptingServicesInterface* scriptingServices); virtual ~EntityTreeRenderer(); virtual char getMyNodeType() const { return NodeType::EntityServer; } @@ -141,7 +144,8 @@ private: bool _lastMouseEventValid; MouseEvent _lastMouseEvent; - ViewStateInterface* _viewState; + AbstractViewStateInterface* _viewState; + AbstractScriptingServicesInterface* _scriptingServices; bool _displayElementChildProxies; bool _displayModelBounds; bool _displayModelElementProxy; diff --git a/libraries/render-utils/src/AbstractViewStateInterface.h b/libraries/render-utils/src/AbstractViewStateInterface.h index 5f85e998a4..50a75c769a 100644 --- a/libraries/render-utils/src/AbstractViewStateInterface.h +++ b/libraries/render-utils/src/AbstractViewStateInterface.h @@ -1,5 +1,5 @@ // -// ViewStateInterface.h +// AbstractViewStateInterface.h // interface/src/renderer // // Created by Brad Hefta-Gaub on 12/16/14. @@ -9,16 +9,18 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ViewStateInterface_h -#define hifi_ViewStateInterface_h +#ifndef hifi_AbstractViewStateInterface_h +#define hifi_AbstractViewStateInterface_h -#include +#include class Transform; class QThread; +class ViewFrustum; +class PickRay; /// Interface provided by Application to other objects that need access to the current view state details -class ViewStateInterface { +class AbstractViewStateInterface { public: /// Returns the shadow distances for the current view state @@ -41,7 +43,9 @@ public: virtual float getSizeScale() const = 0; virtual int getBoundaryLevelAdjust() const = 0; virtual PickRay computePickRay(float x, float y) = 0; + + virtual const glm::vec3& getAvatarPosition() const = 0; }; -#endif // hifi_ViewStateInterface_h +#endif // hifi_AbstractViewStateInterface_h diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index b9289204c7..40a02a60a4 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -19,6 +19,7 @@ #include #include +#include "AbstractViewStateInterface.h" #include "AmbientOcclusionEffect.h" #include "GlowEffect.h" #include "ProgramObject.h" @@ -28,7 +29,7 @@ const int ROTATION_WIDTH = 4; const int ROTATION_HEIGHT = 4; -void AmbientOcclusionEffect::init(ViewStateInterface* viewState) { +void AmbientOcclusionEffect::init(AbstractViewStateInterface* viewState) { _viewState = viewState; // we will use this for view state services _occlusionProgram = new ProgramObject(); diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index 1ee7269480..59ab8b7c8b 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -14,8 +14,7 @@ #include -#include "ViewStateInterface.h" - +class AbstractViewStateInterface; class ProgramObject; /// A screen space ambient occlusion effect. See John Chapman's tutorial at @@ -23,7 +22,7 @@ class ProgramObject; class AmbientOcclusionEffect: public DependencyManager::Dependency { public: - void init(ViewStateInterface* viewState); + void init(AbstractViewStateInterface* viewState); void render(); private: @@ -44,7 +43,7 @@ private: int _blurScaleLocation; GLuint _rotationTextureID; - ViewStateInterface* _viewState; + AbstractViewStateInterface* _viewState; }; #endif // hifi_AmbientOcclusionEffect_h diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 9f54b25441..5af14b6640 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -12,22 +12,15 @@ // include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL #include - -// TODO: remove these once we migrate away from GLUT calls -#if defined(__APPLE__) -#include -#elif defined(WIN32) -#include -#else -#include -#endif +#include // TODO - we need to get rid of this ASAP #include #include #include +#include - +#include "AbstractViewStateInterface.h" #include "DeferredLightingEffect.h" #include "GeometryCache.h" #include "GlowEffect.h" @@ -35,7 +28,7 @@ #include "TextureCache.h" -void DeferredLightingEffect::init(ViewStateInterface* viewState) { +void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { _viewState = viewState; _simpleProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/simple.vert"); _simpleProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/simple.frag"); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 5dcd7d35f4..955a289f6d 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -18,15 +18,15 @@ #include #include "ProgramObject.h" -#include "ViewStateInterface.h" +class AbstractViewStateInterface; class PostLightingRenderable; /// Handles deferred lighting for the bits that require it (voxels, metavoxels...) class DeferredLightingEffect: public DependencyManager::Dependency { public: - void init(ViewStateInterface* viewState); + void init(AbstractViewStateInterface* viewState); /// Returns a reference to a simple program suitable for rendering static /// untextured geometry (such as that generated by glutSolidSphere, etc.) @@ -125,7 +125,7 @@ private: QVector _spotLights; QVector _postLightingRenderables; - ViewStateInterface* _viewState; + AbstractViewStateInterface* _viewState; }; /// Simple interface for objects that require something to be rendered after deferred lighting. diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 16e6b1bf02..b422a7f404 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -27,7 +27,9 @@ #include #include #include +#include +#include "AbstractViewStateInterface.h" #include "AnimationHandle.h" #include "DeferredLightingEffect.h" #include "GlowEffect.h" @@ -111,7 +113,7 @@ Model::SkinLocations Model::_skinNormalSpecularMapLocations; Model::SkinLocations Model::_skinShadowLocations; Model::SkinLocations Model::_skinTranslucentLocations; -ViewStateInterface* Model::_viewState = NULL; +AbstractViewStateInterface* Model::_viewState = NULL; void Model::setScale(const glm::vec3& scale) { setScaleInternal(scale); diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index d24f349f81..841389073e 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -32,8 +32,8 @@ #include "JointState.h" #include "ProgramObject.h" #include "TextureCache.h" -#include "ViewStateInterface.h" +class AbstractViewStateInterface; class QScriptEngine; class Shape; @@ -47,7 +47,7 @@ class Model : public QObject, public PhysicsEntity { public: - static void setViewStateInterface(ViewStateInterface* viewState) { _viewState = viewState; } + static void setAbstractViewStateInterface(AbstractViewStateInterface* viewState) { _viewState = viewState; } Model(QObject* parent = NULL); virtual ~Model(); @@ -459,7 +459,7 @@ private: bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args); - static ViewStateInterface* _viewState; + static AbstractViewStateInterface* _viewState; };