diff --git a/components/terrain/terraingrid.cpp b/components/terrain/terraingrid.cpp index edd7de5da..6329accb2 100644 --- a/components/terrain/terraingrid.cpp +++ b/components/terrain/terraingrid.cpp @@ -19,9 +19,8 @@ public: TerrainGrid::TerrainGrid(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, Storage* storage, int nodeMask, int preCompileMask, int borderMask) : Terrain::World(parent, compileRoot, resourceSystem, storage, nodeMask, preCompileMask, borderMask) - , mNumSplits(4), mBorderVisible(false) + , mNumSplits(4) { - mCellBorder.reset(new MWRender::CellBorder(this,mTerrainRoot.get())); } TerrainGrid::~TerrainGrid() @@ -89,8 +88,7 @@ void TerrainGrid::loadCell(int x, int y) if (!terrainNode) return; // no terrain defined - if (mBorderVisible) - mCellBorder->createCellBorderGeometry(x,y); + TerrainGrid::World::loadCell(x,y); mTerrainRoot->addChild(terrainNode); @@ -103,8 +101,7 @@ void TerrainGrid::unloadCell(int x, int y) if (it == mGrid.end()) return; - if (mBorderVisible) - mCellBorder->destroyCellBorderGeometry(x,y); + Terrain::World::unloadCell(x,y); osg::ref_ptr terrainNode = it->second; mTerrainRoot->removeChild(terrainNode); diff --git a/components/terrain/terraingrid.hpp b/components/terrain/terraingrid.hpp index 164f09bd6..0537dce42 100644 --- a/components/terrain/terraingrid.hpp +++ b/components/terrain/terraingrid.hpp @@ -7,8 +7,6 @@ #include "world.hpp" -#include "cellborder.hpp" - namespace Terrain { @@ -37,10 +35,6 @@ namespace Terrain unsigned int mNumSplits; MWRender::CellBorder::CellGrid mGrid; - - std::unique_ptr mCellBorder; - - bool mBorderVisible; }; } diff --git a/components/terrain/world.cpp b/components/terrain/world.cpp index b88e3f157..578131cc5 100644 --- a/components/terrain/world.cpp +++ b/components/terrain/world.cpp @@ -18,6 +18,7 @@ World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSyst : mStorage(storage) , mParent(parent) , mResourceSystem(resourceSystem) + , mBorderVisible(false) { mTerrainRoot = new osg::Group; mTerrainRoot->setNodeMask(nodeMask); @@ -46,6 +47,7 @@ World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSyst mTextureManager.reset(new TextureManager(mResourceSystem->getSceneManager())); mChunkManager.reset(new ChunkManager(mStorage, mResourceSystem->getSceneManager(), mTextureManager.get(), mCompositeMapRenderer)); + mCellBorder.reset(new MWRender::CellBorder(this,mTerrainRoot.get())); mResourceSystem->addResourceManager(mChunkManager.get()); mResourceSystem->addResourceManager(mTextureManager.get()); @@ -64,6 +66,26 @@ World::~World() delete mStorage; } +void World::setBordersVisible(bool visible) +{ + mBorderVisible = visible; + + if (!visible) + mCellBorder->destroyCellBorderGeometry(); +} + +void World::loadCell(int x, int y) +{ + if (mBorderVisible) + mCellBorder->createCellBorderGeometry(x,y); +} + +void World::unloadCell(int x, int y) +{ + if (mBorderVisible) + mCellBorder->destroyCellBorderGeometry(x,y); +} + void World::setTargetFrameRate(float rate) { mCompositeMapRenderer->setTargetFrameRate(rate); diff --git a/components/terrain/world.hpp b/components/terrain/world.hpp index 77aa1ee28..5ea0559df 100644 --- a/components/terrain/world.hpp +++ b/components/terrain/world.hpp @@ -8,6 +8,7 @@ #include #include "defs.hpp" +#include "cellborder.hpp" namespace osg { @@ -76,15 +77,15 @@ namespace Terrain /// Load the cell into the scene graph. /// @note Not thread safe. - virtual void loadCell(int x, int y) {} + virtual void loadCell(int x, int y); /// Remove the cell from the scene graph. /// @note Not thread safe. - virtual void unloadCell(int x, int y) {} + virtual void unloadCell(int x, int y); virtual void enable(bool enabled) {} - virtual void setBordersVisible(bool visible) {} + virtual void setBordersVisible(bool visible); /// Create a View to use with preload feature. The caller is responsible for deleting the view. /// @note Thread safe. @@ -113,6 +114,10 @@ namespace Terrain std::unique_ptr mTextureManager; std::unique_ptr mChunkManager; + + std::unique_ptr mCellBorder; + + bool mBorderVisible; }; }