diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index f17fa8bbe4..506c9dc4d9 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -384,6 +384,41 @@ void QuadTreeWorld::enable(bool enabled) mRootNode->setNodeMask(enabled ? ~0 : 0); } +void traverseToCell(QuadTreeNode* node, ViewData* vd, int cellX, int cellY) +{ + if (!node->hasValidBounds()) + return; + + if (node->getCenter().x() + node->getSize()/2.f <= cellX + || node->getCenter().x() - node->getSize()/2.f >= cellX+1 + || node->getCenter().y() + node->getSize()/2.f <= cellY + || node->getCenter().y() - node->getSize()/2.f >= cellY+1) + return; + + bool stopTraversal = !node->getNumChildren(); + + if (stopTraversal) + vd->add(node, true); + else + { + for (unsigned int i=0; igetNumChildren(); ++i) + traverseToCell(node->getChild(i), vd, cellX, cellY); + } +} + +void QuadTreeWorld::cacheCell(View *view, int x, int y) +{ + ensureQuadTreeBuilt(); + ViewData* vd = static_cast(view); + traverseToCell(mRootNode.get(), vd, x, y); + + for (unsigned int i=0; igetNumEntries(); ++i) + { + ViewData::Entry& entry = vd->getEntry(i); + loadRenderingNode(entry, vd, mChunkManager.get()); + } +} + View* QuadTreeWorld::createView() { return new ViewData; diff --git a/components/terrain/quadtreeworld.hpp b/components/terrain/quadtreeworld.hpp index d24b9b5117..6176d768ff 100644 --- a/components/terrain/quadtreeworld.hpp +++ b/components/terrain/quadtreeworld.hpp @@ -28,6 +28,8 @@ namespace Terrain virtual void enable(bool enabled); + void cacheCell(View *view, int x, int y); + View* createView(); void preload(View* view, const osg::Vec3f& eyePoint);