Merge branch 'drummyfish/openmw-toggleborders'

0.6.3
Miloslav Číž 7 years ago
commit 31c68c534c

@ -22,6 +22,7 @@
Bug #4429: [Windows] Error on build INSTALL.vcxproj project (debug) with cmake 3.7.2 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 #4432: Guards behaviour is incorrect if they do not have AI packages
Bug #4433: Guard behaviour is incorrect with Alarm = 0 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 #4345: Add equivalents for the command line commands to Launcher
Feature #4444: Per-group KF-animation files support Feature #4444: Per-group KF-animation files support

@ -5,20 +5,21 @@
#include <osg/Geode> #include <osg/Geode>
#include "world.hpp" #include "world.hpp"
#include "../esm/loadland.hpp"
namespace MWRender namespace MWRender
{ {
CellBorder::CellBorder(Terrain::World *world, osg::Group *root): CellBorder::CellBorder(Terrain::World *world, osg::Group *root, int borderMask):
mWorld(world), mWorld(world),
mRoot(root), mRoot(root),
mBorderRoot(0) mBorderMask(borderMask)
{ {
} }
void CellBorder::createCellBorderGeometry(int x, int y) void CellBorder::createCellBorderGeometry(int x, int y)
{ {
const int cellSize = 8192; const int cellSize = ESM::Land::REAL_SIZE;
const int borderSegments = 40; const int borderSegments = 40;
const float offset = 10.0; const float offset = 10.0;
@ -68,9 +69,9 @@ void CellBorder::createCellBorderGeometry(int x, int y)
polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE); polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
stateSet->setAttributeAndModes(polygonmode,osg::StateAttribute::ON); stateSet->setAttributeAndModes(polygonmode,osg::StateAttribute::ON);
mRoot->addChild(borderGeode); borderGeode->setNodeMask(mBorderMask);
mBorderRoot = borderGeode; mRoot->addChild(borderGeode);
mCellBorderNodes[std::make_pair(x,y)] = borderGeode; mCellBorderNodes[std::make_pair(x,y)] = borderGeode;
} }
@ -83,9 +84,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);
}
} }

@ -19,17 +19,22 @@ namespace MWRender
public: public:
typedef std::map<std::pair<int, int>, osg::ref_ptr<osg::Node> > CellGrid; typedef std::map<std::pair<int, int>, osg::ref_ptr<osg::Node> > CellGrid;
CellBorder(Terrain::World *world, osg::Group *root); CellBorder(Terrain::World *world, osg::Group *root, int borderMask);
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;
int mBorderMask;
}; };
} }

@ -75,7 +75,7 @@ void TerrainGrid::loadCell(int x, int y)
if (!terrainNode) if (!terrainNode)
return; // no terrain defined return; // no terrain defined
Terrain::World::loadCell(x,y); TerrainGrid::World::loadCell(x,y);
mTerrainRoot->addChild(terrainNode); mTerrainRoot->addChild(terrainNode);
@ -84,12 +84,12 @@ 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;
Terrain::World::unloadCell(x,y);
osg::ref_ptr<osg::Node> terrainNode = it->second; osg::ref_ptr<osg::Node> terrainNode = it->second;
mTerrainRoot->removeChild(terrainNode); mTerrainRoot->removeChild(terrainNode);

@ -7,8 +7,6 @@
#include "world.hpp" #include "world.hpp"
#include "cellborder.hpp"
namespace Terrain namespace Terrain
{ {
@ -37,7 +35,6 @@ namespace Terrain
MWRender::CellBorder::CellGrid mGrid; MWRender::CellBorder::CellGrid mGrid;
}; };
} }
#endif #endif

@ -18,6 +18,7 @@ World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSyst
: mStorage(storage) : mStorage(storage)
, mParent(parent) , mParent(parent)
, mResourceSystem(resourceSystem) , mResourceSystem(resourceSystem)
, mBorderVisible(false)
{ {
mTerrainRoot = new osg::Group; mTerrainRoot = new osg::Group;
mTerrainRoot->setNodeMask(nodeMask); mTerrainRoot->setNodeMask(nodeMask);
@ -28,12 +29,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());
@ -52,44 +47,52 @@ 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(),borderMask));
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); World::~World()
{
mResourceSystem->removeResourceManager(mChunkManager.get());
mResourceSystem->removeResourceManager(mTextureManager.get());
mParent->removeChild(mTerrainRoot);
mCompositeMapCamera->removeChild(mCompositeMapRenderer);
mCompositeMapCamera->getParent(0)->removeChild(mCompositeMapCamera);
delete mStorage;
} }
void World::setBordersVisible(bool visible) void World::setBordersVisible(bool visible)
{ {
mBorderVisible = visible;
if (visible) if (visible)
mBorderRoot->setAllChildrenOn(); {
for (std::set<std::pair<int,int>>::iterator it = mLoadedCells.begin(); it != mLoadedCells.end(); ++it)
mCellBorder->createCellBorderGeometry(it->first,it->second);
}
else else
mBorderRoot->setAllChildrenOff(); mCellBorder->destroyCellBorderGeometry();
} }
void World::loadCell(int x, int y) void World::loadCell(int x, int y)
{ {
mCellBorder->createCellBorderGeometry(x,y); if (mBorderVisible)
} mCellBorder->createCellBorderGeometry(x,y);
void World::unloadCell(int x, int y) mLoadedCells.insert(std::pair<int,int>(x,y));
{
mCellBorder->destroyCellBorderGeometry(x,y);
} }
World::~World() void World::unloadCell(int x, int y)
{ {
mResourceSystem->removeResourceManager(mChunkManager.get()); if (mBorderVisible)
mResourceSystem->removeResourceManager(mTextureManager.get()); mCellBorder->destroyCellBorderGeometry(x,y);
mParent->removeChild(mTerrainRoot);
mCompositeMapCamera->removeChild(mCompositeMapRenderer); mLoadedCells.erase(std::pair<int,int>(x,y));
mCompositeMapCamera->getParent(0)->removeChild(mCompositeMapCamera);
delete mStorage;
} }
void World::setTargetFrameRate(float rate) void World::setTargetFrameRate(float rate)

@ -4,12 +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 <set>
#include "defs.hpp" #include "defs.hpp"
#include "cellborder.hpp" #include "cellborder.hpp"
namespace osg namespace osg
@ -87,7 +86,7 @@ namespace Terrain
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 +103,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;
@ -122,6 +117,10 @@ namespace Terrain
std::unique_ptr<ChunkManager> mChunkManager; std::unique_ptr<ChunkManager> mChunkManager;
std::unique_ptr<MWRender::CellBorder> mCellBorder; std::unique_ptr<MWRender::CellBorder> mCellBorder;
bool mBorderVisible;
std::set<std::pair<int,int>> mLoadedCells;
}; };
} }

Loading…
Cancel
Save