Make tb command work again

pull/456/head
Miloslav Číž 7 years ago
parent 1fd5ad3e56
commit 1b8d500c07

@ -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<osg::Node> 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);
}
}

@ -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;
};

@ -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<osg::Node> 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<osg::Node> terrainNode = it->second;
mTerrainRoot->removeChild(terrainNode);

@ -29,6 +29,7 @@ namespace Terrain
View* createView();
virtual void setBordersVisible(bool visible) override;
private:
osg::ref_ptr<osg::Node> 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<MWRender::CellBorder> mCellBorder;
bool mBorderVisible;
};
}
#endif

@ -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<osg::Camera> 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()

@ -4,14 +4,11 @@
#include <osg/ref_ptr>
#include <osg/Referenced>
#include <osg/Vec3f>
#include <osg/Switch>
#include <memory>
#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<osg::Group> mParent;
osg::ref_ptr<osg::Group> mTerrainRoot;
osg::ref_ptr<osg::Switch> mBorderRoot;
osg::ref_ptr<osg::Group> mCompositeMapCamera;
osg::ref_ptr<CompositeMapRenderer> mCompositeMapRenderer;
@ -120,8 +113,6 @@ namespace Terrain
std::unique_ptr<TextureManager> mTextureManager;
std::unique_ptr<ChunkManager> mChunkManager;
std::unique_ptr<MWRender::CellBorder> mCellBorder;
};
}

Loading…
Cancel
Save