From 1fd5ad3e56ce9f3690569b95b3287a0d19be6bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Thu, 14 Jun 2018 01:01:22 +0200 Subject: [PATCH 1/6] Use REAL_SIZE constant --- components/terrain/cellborder.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/terrain/cellborder.cpp b/components/terrain/cellborder.cpp index b74e2e9bea..31a162af7d 100644 --- a/components/terrain/cellborder.cpp +++ b/components/terrain/cellborder.cpp @@ -5,6 +5,7 @@ #include #include "world.hpp" +#include "../esm/loadland.hpp" namespace MWRender { @@ -18,7 +19,7 @@ CellBorder::CellBorder(Terrain::World *world, osg::Group *root): void CellBorder::createCellBorderGeometry(int x, int y) { - const int cellSize = 8192; + const int cellSize = ESM::Land::REAL_SIZE; const int borderSegments = 40; const float offset = 10.0; From 1b8d500c07892eda46219c63ebd324f38e9cd2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Thu, 14 Jun 2018 12:01:09 +0200 Subject: [PATCH 2/6] Make tb command work again --- components/terrain/cellborder.cpp | 13 ++++++++----- components/terrain/cellborder.hpp | 6 +++++- components/terrain/terraingrid.cpp | 24 ++++++++++++++++++++---- components/terrain/terraingrid.hpp | 6 +++++- components/terrain/world.cpp | 28 ---------------------------- components/terrain/world.hpp | 15 +++------------ 6 files changed, 41 insertions(+), 51 deletions(-) diff --git a/components/terrain/cellborder.cpp b/components/terrain/cellborder.cpp index 31a162af7d..f9af60b750 100644 --- a/components/terrain/cellborder.cpp +++ b/components/terrain/cellborder.cpp @@ -12,8 +12,7 @@ namespace MWRender CellBorder::CellBorder(Terrain::World *world, osg::Group *root): mWorld(world), - mRoot(root), - mBorderRoot(0) + mRoot(root) { } @@ -71,8 +70,6 @@ void CellBorder::createCellBorderGeometry(int x, int y) mRoot->addChild(borderGeode); - mBorderRoot = borderGeode; - mCellBorderNodes[std::make_pair(x,y)] = borderGeode; } @@ -84,9 +81,15 @@ void CellBorder::destroyCellBorderGeometry(int x, int y) return; osg::ref_ptr borderNode = it->second; - mBorderRoot->removeChild(borderNode); + mRoot->removeChild(borderNode); mCellBorderNodes.erase(it); } +void CellBorder::destroyCellBorderGeometry() +{ + for (CellGrid::iterator it = mCellBorderNodes.begin(); it != mCellBorderNodes.end(); ++it) + destroyCellBorderGeometry(it->first.first,it->first.second); +} + } diff --git a/components/terrain/cellborder.hpp b/components/terrain/cellborder.hpp index 6144f8c32d..a505aec9cf 100644 --- a/components/terrain/cellborder.hpp +++ b/components/terrain/cellborder.hpp @@ -24,10 +24,14 @@ namespace MWRender void createCellBorderGeometry(int x, int y); void destroyCellBorderGeometry(int x, int y); + /** + Destroys the geometry for all borders. + */ + void destroyCellBorderGeometry(); + protected: Terrain::World *mWorld; osg::Group *mRoot; - osg::Group *mBorderRoot; CellGrid mCellBorderNodes; }; diff --git a/components/terrain/terraingrid.cpp b/components/terrain/terraingrid.cpp index f5ab6f64b6..edd7de5da4 100644 --- a/components/terrain/terraingrid.cpp +++ b/components/terrain/terraingrid.cpp @@ -19,8 +19,9 @@ 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) + , mNumSplits(4), mBorderVisible(false) { + mCellBorder.reset(new MWRender::CellBorder(this,mTerrainRoot.get())); } TerrainGrid::~TerrainGrid() @@ -65,6 +66,19 @@ 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()) @@ -75,7 +89,8 @@ void TerrainGrid::loadCell(int x, int y) if (!terrainNode) return; // no terrain defined - Terrain::World::loadCell(x,y); + if (mBorderVisible) + mCellBorder->createCellBorderGeometry(x,y); mTerrainRoot->addChild(terrainNode); @@ -84,12 +99,13 @@ void TerrainGrid::loadCell(int x, int y) void TerrainGrid::unloadCell(int x, int y) { - World::unloadCell(x,y); - MWRender::CellBorder::CellGrid::iterator it = mGrid.find(std::make_pair(x,y)); if (it == mGrid.end()) return; + if (mBorderVisible) + mCellBorder->destroyCellBorderGeometry(x,y); + osg::ref_ptr terrainNode = it->second; mTerrainRoot->removeChild(terrainNode); diff --git a/components/terrain/terraingrid.hpp b/components/terrain/terraingrid.hpp index f21dd39d31..164f09bd62 100644 --- a/components/terrain/terraingrid.hpp +++ b/components/terrain/terraingrid.hpp @@ -29,6 +29,7 @@ namespace Terrain View* createView(); + virtual void setBordersVisible(bool visible) override; private: osg::ref_ptr buildTerrain (osg::Group* parent, float chunkSize, const osg::Vec2f& chunkCenter); @@ -36,8 +37,11 @@ namespace Terrain unsigned int mNumSplits; MWRender::CellBorder::CellGrid mGrid; - }; + std::unique_ptr mCellBorder; + + bool mBorderVisible; + }; } #endif diff --git a/components/terrain/world.cpp b/components/terrain/world.cpp index d871d141b7..b88e3f1578 100644 --- a/components/terrain/world.cpp +++ b/components/terrain/world.cpp @@ -28,12 +28,6 @@ World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSyst mTerrainRoot->setName("Terrain Root"); - mBorderRoot = new osg::Switch; - mBorderRoot->setName("Border Root"); - mBorderRoot->setNodeMask(borderMask); - - mTerrainRoot->addChild(mBorderRoot); - osg::ref_ptr compositeCam = new osg::Camera; compositeCam->setRenderOrder(osg::Camera::PRE_RENDER, -1); compositeCam->setProjectionMatrix(osg::Matrix::identity()); @@ -53,30 +47,8 @@ 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()); - - setBordersVisible(false); -} - -void World::setBordersVisible(bool visible) -{ - if (visible) - mBorderRoot->setAllChildrenOn(); - else - mBorderRoot->setAllChildrenOff(); -} - -void World::loadCell(int x, int y) -{ - mCellBorder->createCellBorderGeometry(x,y); -} - -void World::unloadCell(int x, int y) -{ - mCellBorder->destroyCellBorderGeometry(x,y); } World::~World() diff --git a/components/terrain/world.hpp b/components/terrain/world.hpp index b847d08ab0..77aa1ee282 100644 --- a/components/terrain/world.hpp +++ b/components/terrain/world.hpp @@ -4,14 +4,11 @@ #include #include #include -#include #include #include "defs.hpp" -#include "cellborder.hpp" - namespace osg { class Group; @@ -79,15 +76,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) {} - 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. @@ -104,14 +101,10 @@ namespace Terrain Storage* getStorage() { return mStorage; } protected: - void createCellBorderGeometry(int x, int y); - void destroyCellBorderGeometry(int x, int y); - Storage* mStorage; osg::ref_ptr mParent; osg::ref_ptr mTerrainRoot; - osg::ref_ptr mBorderRoot; osg::ref_ptr mCompositeMapCamera; osg::ref_ptr mCompositeMapRenderer; @@ -120,8 +113,6 @@ namespace Terrain std::unique_ptr mTextureManager; std::unique_ptr mChunkManager; - - std::unique_ptr mCellBorder; }; } From f18d57429e434505e3e428255cc46e2c6d245ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Thu, 14 Jun 2018 12:27:22 +0200 Subject: [PATCH 3/6] Move cell border management to World --- components/terrain/terraingrid.cpp | 9 +++------ components/terrain/terraingrid.hpp | 6 ------ components/terrain/world.cpp | 22 ++++++++++++++++++++++ components/terrain/world.hpp | 11 ++++++++--- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/components/terrain/terraingrid.cpp b/components/terrain/terraingrid.cpp index edd7de5da4..6329accb20 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 164f09bd62..0537dce420 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 b88e3f1578..578131cc50 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 77aa1ee282..5ea0559df5 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; }; } 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 4/6] 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 6329accb20..74f683774c 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 0537dce420..87e3b432c0 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 578131cc50..f0f6285610 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 5ea0559df5..ae71693bdf 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; }; } From ab8de9fa14e0302f097c181196ff0db205406dfd 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:18:37 +0200 Subject: [PATCH 5/6] Set node mask to cell borders --- components/terrain/cellborder.cpp | 7 +++++-- components/terrain/cellborder.hpp | 3 ++- components/terrain/world.cpp | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/components/terrain/cellborder.cpp b/components/terrain/cellborder.cpp index f9af60b750..d9e6d52fc1 100644 --- a/components/terrain/cellborder.cpp +++ b/components/terrain/cellborder.cpp @@ -10,9 +10,10 @@ namespace MWRender { -CellBorder::CellBorder(Terrain::World *world, osg::Group *root): +CellBorder::CellBorder(Terrain::World *world, osg::Group *root, int borderMask): mWorld(world), - mRoot(root) + mRoot(root), + mBorderMask(borderMask) { } @@ -68,6 +69,8 @@ void CellBorder::createCellBorderGeometry(int x, int y) polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE); stateSet->setAttributeAndModes(polygonmode,osg::StateAttribute::ON); + borderGeode->setNodeMask(mBorderMask); + mRoot->addChild(borderGeode); mCellBorderNodes[std::make_pair(x,y)] = borderGeode; diff --git a/components/terrain/cellborder.hpp b/components/terrain/cellborder.hpp index a505aec9cf..0cbe7b8993 100644 --- a/components/terrain/cellborder.hpp +++ b/components/terrain/cellborder.hpp @@ -19,7 +19,7 @@ namespace MWRender public: typedef std::map, osg::ref_ptr > CellGrid; - CellBorder(Terrain::World *world, osg::Group *root); + CellBorder(Terrain::World *world, osg::Group *root, int borderMask); void createCellBorderGeometry(int x, int y); void destroyCellBorderGeometry(int x, int y); @@ -34,6 +34,7 @@ namespace MWRender osg::Group *mRoot; CellGrid mCellBorderNodes; + int mBorderMask; }; } diff --git a/components/terrain/world.cpp b/components/terrain/world.cpp index f0f6285610..cc81dbef8e 100644 --- a/components/terrain/world.cpp +++ b/components/terrain/world.cpp @@ -47,7 +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())); + mCellBorder.reset(new MWRender::CellBorder(this,mTerrainRoot.get(),borderMask)); mResourceSystem->addResourceManager(mChunkManager.get()); mResourceSystem->addResourceManager(mTextureManager.get()); From 24078d4a72343d388b39438f1afdfeb19a43e741 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:22:12 +0200 Subject: [PATCH 6/6] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f407a156e8..4c7930f037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Bug #4429: [Windows] Error on build INSTALL.vcxproj project (debug) with cmake 3.7.2 Bug #4432: Guards behaviour is incorrect if they do not have AI packages Bug #4433: Guard behaviour is incorrect with Alarm = 0 + Feature #4256: Implement ToggleBorders (TB) console command Feature #4345: Add equivalents for the command line commands to Launcher Feature #4444: Per-group KF-animation files support