mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 16:29:55 +00:00
Fix waiting on initial quad tree build
This commit is contained in:
parent
4dbd224249
commit
433900fca5
2 changed files with 28 additions and 21 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> QuadTreeWorld::cacheCell(int x, int y)
|
||||
{
|
||||
if (!mQuadTreeBuilt)
|
||||
{
|
||||
const float minSize = 1/4.f;
|
||||
mWorkItem = new BuildQuadTreeItem(mStorage, mViewDataMap.get(), minSize);
|
||||
mWorkQueue->addWorkItem(mWorkItem);
|
||||
|
||||
mWorkItem->waitTillDone();
|
||||
|
||||
mQuadTreeBuilt = true;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void QuadTreeWorld::enable(bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
ensureQuadTreeBuilt();
|
||||
|
||||
if (!mRootNode->getNumParents())
|
||||
mTerrainRoot->addChild(mRootNode);
|
||||
}
|
||||
|
||||
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…
Reference in a new issue