Make tb command work again

0.6.3
Miloslav Číž 7 years ago
parent 1fd5ad3e56
commit 1b8d500c07

@ -12,8 +12,7 @@ namespace MWRender
CellBorder::CellBorder(Terrain::World *world, osg::Group *root): CellBorder::CellBorder(Terrain::World *world, osg::Group *root):
mWorld(world), mWorld(world),
mRoot(root), mRoot(root)
mBorderRoot(0)
{ {
} }
@ -71,8 +70,6 @@ void CellBorder::createCellBorderGeometry(int x, int y)
mRoot->addChild(borderGeode); mRoot->addChild(borderGeode);
mBorderRoot = borderGeode;
mCellBorderNodes[std::make_pair(x,y)] = borderGeode; mCellBorderNodes[std::make_pair(x,y)] = borderGeode;
} }
@ -84,9 +81,15 @@ void CellBorder::destroyCellBorderGeometry(int x, int y)
return; return;
osg::ref_ptr<osg::Node> borderNode = it->second; osg::ref_ptr<osg::Node> borderNode = it->second;
mBorderRoot->removeChild(borderNode); mRoot->removeChild(borderNode);
mCellBorderNodes.erase(it); 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 createCellBorderGeometry(int x, int y);
void destroyCellBorderGeometry(int x, int y); void destroyCellBorderGeometry(int x, int y);
/**
Destroys the geometry for all borders.
*/
void destroyCellBorderGeometry();
protected: protected:
Terrain::World *mWorld; Terrain::World *mWorld;
osg::Group *mRoot; osg::Group *mRoot;
osg::Group *mBorderRoot;
CellGrid mCellBorderNodes; 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) 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) : 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() 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) void TerrainGrid::loadCell(int x, int y)
{ {
if (mGrid.find(std::make_pair(x, y)) != mGrid.end()) if (mGrid.find(std::make_pair(x, y)) != mGrid.end())
@ -75,7 +89,8 @@ void TerrainGrid::loadCell(int x, int y)
if (!terrainNode) if (!terrainNode)
return; // no terrain defined return; // no terrain defined
Terrain::World::loadCell(x,y); if (mBorderVisible)
mCellBorder->createCellBorderGeometry(x,y);
mTerrainRoot->addChild(terrainNode); mTerrainRoot->addChild(terrainNode);
@ -84,12 +99,13 @@ void TerrainGrid::loadCell(int x, int y)
void TerrainGrid::unloadCell(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)); MWRender::CellBorder::CellGrid::iterator it = mGrid.find(std::make_pair(x,y));
if (it == mGrid.end()) if (it == mGrid.end())
return; return;
if (mBorderVisible)
mCellBorder->destroyCellBorderGeometry(x,y);
osg::ref_ptr<osg::Node> terrainNode = it->second; osg::ref_ptr<osg::Node> terrainNode = it->second;
mTerrainRoot->removeChild(terrainNode); mTerrainRoot->removeChild(terrainNode);

@ -29,6 +29,7 @@ namespace Terrain
View* createView(); View* createView();
virtual void setBordersVisible(bool visible) override;
private: private:
osg::ref_ptr<osg::Node> buildTerrain (osg::Group* parent, float chunkSize, const osg::Vec2f& chunkCenter); osg::ref_ptr<osg::Node> buildTerrain (osg::Group* parent, float chunkSize, const osg::Vec2f& chunkCenter);
@ -36,8 +37,11 @@ namespace Terrain
unsigned int mNumSplits; unsigned int mNumSplits;
MWRender::CellBorder::CellGrid mGrid; MWRender::CellBorder::CellGrid mGrid;
};
std::unique_ptr<MWRender::CellBorder> mCellBorder;
bool mBorderVisible;
};
} }
#endif #endif

@ -28,12 +28,6 @@ World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSyst
mTerrainRoot->setName("Terrain Root"); 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; osg::ref_ptr<osg::Camera> compositeCam = new osg::Camera;
compositeCam->setRenderOrder(osg::Camera::PRE_RENDER, -1); compositeCam->setRenderOrder(osg::Camera::PRE_RENDER, -1);
compositeCam->setProjectionMatrix(osg::Matrix::identity()); 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())); mTextureManager.reset(new TextureManager(mResourceSystem->getSceneManager()));
mChunkManager.reset(new ChunkManager(mStorage, mResourceSystem->getSceneManager(), mTextureManager.get(), mCompositeMapRenderer)); mChunkManager.reset(new ChunkManager(mStorage, mResourceSystem->getSceneManager(), mTextureManager.get(), mCompositeMapRenderer));
mCellBorder.reset(new MWRender::CellBorder(this,mTerrainRoot.get()));
mResourceSystem->addResourceManager(mChunkManager.get()); mResourceSystem->addResourceManager(mChunkManager.get());
mResourceSystem->addResourceManager(mTextureManager.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() World::~World()

@ -4,14 +4,11 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <osg/Referenced> #include <osg/Referenced>
#include <osg/Vec3f> #include <osg/Vec3f>
#include <osg/Switch>
#include <memory> #include <memory>
#include "defs.hpp" #include "defs.hpp"
#include "cellborder.hpp"
namespace osg namespace osg
{ {
class Group; class Group;
@ -79,15 +76,15 @@ namespace Terrain
/// Load the cell into the scene graph. /// Load the cell into the scene graph.
/// @note Not thread safe. /// @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. /// Remove the cell from the scene graph.
/// @note Not thread safe. /// @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 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. /// Create a View to use with preload feature. The caller is responsible for deleting the view.
/// @note Thread safe. /// @note Thread safe.
@ -104,14 +101,10 @@ namespace Terrain
Storage* getStorage() { return mStorage; } Storage* getStorage() { return mStorage; }
protected: protected:
void createCellBorderGeometry(int x, int y);
void destroyCellBorderGeometry(int x, int y);
Storage* mStorage; Storage* mStorage;
osg::ref_ptr<osg::Group> mParent; osg::ref_ptr<osg::Group> mParent;
osg::ref_ptr<osg::Group> mTerrainRoot; osg::ref_ptr<osg::Group> mTerrainRoot;
osg::ref_ptr<osg::Switch> mBorderRoot;
osg::ref_ptr<osg::Group> mCompositeMapCamera; osg::ref_ptr<osg::Group> mCompositeMapCamera;
osg::ref_ptr<CompositeMapRenderer> mCompositeMapRenderer; osg::ref_ptr<CompositeMapRenderer> mCompositeMapRenderer;
@ -120,8 +113,6 @@ namespace Terrain
std::unique_ptr<TextureManager> mTextureManager; std::unique_ptr<TextureManager> mTextureManager;
std::unique_ptr<ChunkManager> mChunkManager; std::unique_ptr<ChunkManager> mChunkManager;
std::unique_ptr<MWRender::CellBorder> mCellBorder;
}; };
} }

Loading…
Cancel
Save