From 414e6caafe9c8626a18d1b42975c454892e92572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Thu, 14 Jun 2018 13:14:38 +0200 Subject: [PATCH] Make tb work with distant terrain --- components/terrain/terraingrid.cpp | 13 ------------- components/terrain/terraingrid.hpp | 1 - components/terrain/world.cpp | 11 ++++++++++- components/terrain/world.hpp | 5 ++++- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/components/terrain/terraingrid.cpp b/components/terrain/terraingrid.cpp index 6329accb2..74f683774 100644 --- a/components/terrain/terraingrid.cpp +++ b/components/terrain/terraingrid.cpp @@ -65,19 +65,6 @@ osg::ref_ptr TerrainGrid::buildTerrain (osg::Group* parent, float chu } } -void TerrainGrid::setBordersVisible(bool visible) -{ - mBorderVisible = visible; - - if (visible) - { - for (MWRender::CellBorder::CellGrid::iterator it = mGrid.begin(); it != mGrid.end(); ++it) - mCellBorder->createCellBorderGeometry(it->first.first,it->first.second); - } - else - mCellBorder->destroyCellBorderGeometry(); -} - void TerrainGrid::loadCell(int x, int y) { if (mGrid.find(std::make_pair(x, y)) != mGrid.end()) diff --git a/components/terrain/terraingrid.hpp b/components/terrain/terraingrid.hpp index 0537dce42..87e3b432c 100644 --- a/components/terrain/terraingrid.hpp +++ b/components/terrain/terraingrid.hpp @@ -27,7 +27,6 @@ namespace Terrain View* createView(); - virtual void setBordersVisible(bool visible) override; private: osg::ref_ptr buildTerrain (osg::Group* parent, float chunkSize, const osg::Vec2f& chunkCenter); diff --git a/components/terrain/world.cpp b/components/terrain/world.cpp index 578131cc5..f0f628561 100644 --- a/components/terrain/world.cpp +++ b/components/terrain/world.cpp @@ -70,7 +70,12 @@ void World::setBordersVisible(bool visible) { mBorderVisible = visible; - if (!visible) + if (visible) + { + for (std::set>::iterator it = mLoadedCells.begin(); it != mLoadedCells.end(); ++it) + mCellBorder->createCellBorderGeometry(it->first,it->second); + } + else mCellBorder->destroyCellBorderGeometry(); } @@ -78,12 +83,16 @@ void World::loadCell(int x, int y) { if (mBorderVisible) mCellBorder->createCellBorderGeometry(x,y); + + mLoadedCells.insert(std::pair(x,y)); } void World::unloadCell(int x, int y) { if (mBorderVisible) mCellBorder->destroyCellBorderGeometry(x,y); + + mLoadedCells.erase(std::pair(x,y)); } void World::setTargetFrameRate(float rate) diff --git a/components/terrain/world.hpp b/components/terrain/world.hpp index 5ea0559df..ae71693bd 100644 --- a/components/terrain/world.hpp +++ b/components/terrain/world.hpp @@ -6,6 +6,7 @@ #include #include +#include #include "defs.hpp" #include "cellborder.hpp" @@ -117,7 +118,9 @@ namespace Terrain std::unique_ptr mCellBorder; - bool mBorderVisible; + bool mBorderVisible; + + std::set> mLoadedCells; }; }