From ebcf8ca062857da2bc3bed52395329464612896d Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH] Do not store a ViewDataMap in the every QuadTreeNode --- components/terrain/quadtreenode.cpp | 29 ---------------------------- components/terrain/quadtreenode.hpp | 10 ---------- components/terrain/quadtreeworld.cpp | 21 +++++++++++--------- 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/components/terrain/quadtreenode.cpp b/components/terrain/quadtreenode.cpp index b842c172dc..10f46c0eb9 100644 --- a/components/terrain/quadtreenode.cpp +++ b/components/terrain/quadtreenode.cpp @@ -61,7 +61,6 @@ QuadTreeNode::QuadTreeNode(QuadTreeNode* parent, ChildDirection direction, float , mValidBounds(false) , mSize(size) , mCenter(center) - , mViewDataMap(nullptr) { for (unsigned int i=0; i<4; ++i) mNeighbours[i] = 0; @@ -181,34 +180,6 @@ LodCallback *QuadTreeNode::getLodCallback() return mLodCallback; } -void QuadTreeNode::setViewDataMap(ViewDataMap *map) -{ - mViewDataMap = map; -} - -ViewDataMap *QuadTreeNode::getViewDataMap() -{ - return mViewDataMap; -} - -ViewData* QuadTreeNode::getView(osg::NodeVisitor &nv, bool& needsUpdate) -{ - ViewData* vd = NULL; - if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR) - { - osgUtil::CullVisitor* cv = static_cast(&nv); - vd = mViewDataMap->getViewData(cv->getCurrentCamera(), nv.getViewPoint(), needsUpdate); - } - else // INTERSECTION_VISITOR - { - osg::Vec3f viewPoint = nv.getViewPoint(); - static osg::ref_ptr dummyObj = new osg::DummyObject; - vd = mViewDataMap->getViewData(dummyObj.get(), viewPoint, needsUpdate); - needsUpdate = true; - } - return vd; -} - void QuadTreeNode::setBoundingBox(const osg::BoundingBox &boundingBox) { mBoundingBox = boundingBox; diff --git a/components/terrain/quadtreenode.hpp b/components/terrain/quadtreenode.hpp index e52d2db938..96b08842fd 100644 --- a/components/terrain/quadtreenode.hpp +++ b/components/terrain/quadtreenode.hpp @@ -106,14 +106,6 @@ namespace Terrain LodCallback* getLodCallback(); - /// Set the view data map that the finally used nodes for a given camera/intersection are pushed onto. - void setViewDataMap(ViewDataMap* map); - - ViewDataMap* getViewDataMap(); - - /// Create or retrieve a view for the given traversal. - ViewData* getView(osg::NodeVisitor& nv, bool& needsUpdate); - private: QuadTreeNode* mParent; @@ -127,8 +119,6 @@ namespace Terrain osg::Vec2f mCenter; osg::ref_ptr mLodCallback; - - ViewDataMap* mViewDataMap; }; } diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 899e9c7f14..6fc41b04ac 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -97,12 +97,11 @@ private: class QuadTreeBuilder { public: - QuadTreeBuilder(Terrain::Storage* storage, ViewDataMap* viewDataMap, float lodFactor, float minSize) + QuadTreeBuilder(Terrain::Storage* storage, float lodFactor, float minSize) : mStorage(storage) , mLodFactor(lodFactor) , mMinX(0.f), mMaxX(0.f), mMinY(0.f), mMaxY(0.f) , mMinSize(minSize) - , mViewDataMap(viewDataMap) { } @@ -120,7 +119,6 @@ public: float centerY = (mMinY+mMaxY)/2.f + (size-origSizeY)/2.f; mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY)); - mRootNode->setViewDataMap(mViewDataMap); mRootNode->setLodCallback(new DefaultLodCallback(mLodFactor, mMinSize)); addChildren(mRootNode); @@ -171,7 +169,6 @@ public: osg::ref_ptr node = new QuadTreeNode(parent, direction, size, center); node->setLodCallback(parent->getLodCallback()); - node->setViewDataMap(mViewDataMap); if (center.x() - halfSize > mMaxX || center.x() + halfSize < mMinX @@ -220,7 +217,6 @@ private: float mLodFactor; float mMinX, mMaxX, mMinY, mMaxY; float mMinSize; - ViewDataMap* mViewDataMap; osg::ref_ptr mRootNode; }; @@ -337,8 +333,15 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv) return; } - bool needsUpdate = false; - ViewData* vd = mRootNode->getView(nv, needsUpdate); + bool needsUpdate = true; + ViewData* vd = nullptr; + if (isCullVisitor) + vd = mViewDataMap->getViewData(static_cast(&nv)->getCurrentCamera(), nv.getViewPoint(), needsUpdate); + else + { + static ViewData sIntersectionViewData; + vd = &sIntersectionViewData; + } if (needsUpdate) { @@ -403,7 +406,7 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv) } if (!isCullVisitor) - vd->reset(); // we can't reuse intersection views in the next frame because they only contain what is touched by the intersection ray. + vd->clear(); // we can't reuse intersection views in the next frame because they only contain what is touched by the intersection ray. vd->markUnchanged(); @@ -422,7 +425,7 @@ void QuadTreeWorld::ensureQuadTreeBuilt() return; const float minSize = 1/8.f; - QuadTreeBuilder builder(mStorage, mViewDataMap.get(), mLodFactor, minSize); + QuadTreeBuilder builder(mStorage, mLodFactor, minSize); builder.build(); mRootNode = builder.getRootNode();