From 7d50b6c2e21739bd432c7bdf6c711c7491977d4c Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 9 Mar 2017 21:05:25 +0100 Subject: [PATCH] Add QuadTreeWorld::cacheCell to preload cells at max LOD for local maps --- components/terrain/quadtreeworld.cpp | 35 ++++++++++++++++++++++++++++ components/terrain/quadtreeworld.hpp | 2 ++ 2 files changed, 37 insertions(+) diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index f17fa8bbe..506c9dc4d 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 d24b9b511..6176d768f 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);