Fix waiting on initial quad tree build

0.6.1
scrawl 8 years ago
parent 4dbd224249
commit 433900fca5

@ -337,34 +337,39 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
mRootNode->getViewDataMap()->clearUnusedViews(nv.getTraversalNumber());
}
void QuadTreeWorld::loadCell(int x, int y)
void QuadTreeWorld::ensureQuadTreeBuilt()
{
if (mQuadTreeBuilt && !mRootNode)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mQuadTreeMutex);
if (mQuadTreeBuilt)
return;
if (!mQuadTreeBuilt && !mWorkItem)
{
const float minSize = 1/4.f;
mWorkItem = new BuildQuadTreeItem(mStorage, mViewDataMap.get(), minSize);
mWorkQueue->addWorkItem(mWorkItem);
}
}
mWorkItem->waitTillDone();
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mQuadTreeMutex);
mRootNode = mWorkItem->getRootNode();
mRootNode->setWorld(this);
mTerrainRoot->addChild(mRootNode);
mWorkItem = NULL;
mQuadTreeBuilt = true;
}
}
osg::ref_ptr<osg::Node> QuadTreeWorld::cacheCell(int x, int y)
void QuadTreeWorld::enable(bool enabled)
{
if (!mQuadTreeBuilt)
if (enabled)
{
const float minSize = 1/4.f;
mWorkItem = new BuildQuadTreeItem(mStorage, mViewDataMap.get(), minSize);
mWorkQueue->addWorkItem(mWorkItem);
mWorkItem->waitTillDone();
ensureQuadTreeBuilt();
mQuadTreeBuilt = true;
if (!mRootNode->getNumParents())
mTerrainRoot->addChild(mRootNode);
}
return NULL;
}
void QuadTreeWorld::enable(bool enabled)
{
if (mRootNode)
mRootNode->setNodeMask(enabled ? ~0 : 0);
}

@ -5,6 +5,8 @@
#include "world.hpp"
#include <OpenThreads/Mutex>
namespace SceneUtil
{
class WorkQueue;
@ -30,12 +32,11 @@ namespace Terrain
void accept(osg::NodeVisitor& nv);
virtual void loadCell(int x, int y);
virtual osg::ref_ptr<osg::Node> cacheCell(int x, int y);
virtual void enable(bool enabled);
private:
void ensureQuadTreeBuilt();
osg::ref_ptr<RootNode> mRootNode;
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
@ -44,6 +45,7 @@ namespace Terrain
osg::ref_ptr<ViewDataMap> mViewDataMap;
OpenThreads::Mutex mQuadTreeMutex;
bool mQuadTreeBuilt;
};

Loading…
Cancel
Save