diff --git a/components/terrain/quadtreenode.hpp b/components/terrain/quadtreenode.hpp index c7a6a09d9..ca0ee97c4 100644 --- a/components/terrain/quadtreenode.hpp +++ b/components/terrain/quadtreenode.hpp @@ -90,7 +90,7 @@ namespace Terrain osg::ref_ptr mLodCallback; - osg::ref_ptr mViewDataMap; + ViewDataMap* mViewDataMap; }; } diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 15835b004..535b3a583 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -110,10 +110,11 @@ private: class BuildQuadTreeItem : public SceneUtil::WorkItem { public: - BuildQuadTreeItem(Terrain::Storage* storage, float minSize) + BuildQuadTreeItem(Terrain::Storage* storage, ViewDataMap* viewDataMap, float minSize) : mStorage(storage) , mMinX(0.f), mMaxX(0.f), mMinY(0.f), mMaxY(0.f) , mMinSize(minSize) + , mViewDataMap(viewDataMap) { } @@ -131,7 +132,7 @@ public: float centerY = (mMinY+mMaxY)/2.f + (size-origSizeY)/2.f; mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY)); - mRootNode->setViewDataMap(new ViewDataMap); + mRootNode->setViewDataMap(mViewDataMap); addChildren(mRootNode); mRootNode->initNeighbours(); @@ -174,7 +175,7 @@ public: osg::ref_ptr node = new QuadTreeNode(parent, direction, size, center); node->setLodCallback(new DefaultLodCallback); - node->setViewDataMap(parent->getViewDataMap()); + node->setViewDataMap(mViewDataMap); parent->addChild(node); if (center.x() - size > mMaxX @@ -218,6 +219,7 @@ private: float mMinX, mMaxX, mMinY, mMaxY; float mMinSize; + ViewDataMap* mViewDataMap; osg::ref_ptr mRootNode; }; @@ -225,6 +227,7 @@ private: QuadTreeWorld::QuadTreeWorld(SceneUtil::WorkQueue* workQueue, osg::Group *parent, osg::Group *compileRoot, Resource::ResourceSystem *resourceSystem, Storage *storage, int nodeMask, int preCompileMask) : World(parent, compileRoot, resourceSystem, storage, nodeMask, preCompileMask) , mWorkQueue(workQueue) + , mViewDataMap(new ViewDataMap) , mQuadTreeBuilt(false) { } @@ -237,10 +240,7 @@ QuadTreeWorld::~QuadTreeWorld() mWorkItem->waitTillDone(); } - if (mRootNode && mRootNode->getViewDataMap()) - { - mRootNode->getViewDataMap()->clear(); - } + mViewDataMap->clear(); } @@ -351,7 +351,7 @@ osg::ref_ptr QuadTreeWorld::cacheCell(int x, int y) if (!mQuadTreeBuilt) { const float minSize = 1/4.f; - mWorkItem = new BuildQuadTreeItem(mStorage, minSize); + mWorkItem = new BuildQuadTreeItem(mStorage, mViewDataMap.get(), minSize); mWorkQueue->addWorkItem(mWorkItem); mWorkItem->waitTillDone(); diff --git a/components/terrain/quadtreeworld.hpp b/components/terrain/quadtreeworld.hpp index 320f53120..ebea60fc5 100644 --- a/components/terrain/quadtreeworld.hpp +++ b/components/terrain/quadtreeworld.hpp @@ -19,6 +19,7 @@ namespace Terrain { class RootNode; class BuildQuadTreeItem; + class ViewDataMap; /// @brief Terrain implementation that loads cells into a Quad Tree, with geometry LOD and texture LOD. The entire world is displayed at all times. class QuadTreeWorld : public Terrain::World @@ -39,6 +40,8 @@ namespace Terrain osg::ref_ptr mWorkItem; + osg::ref_ptr mViewDataMap; + bool mQuadTreeBuilt; };