2013-08-27 14:01:16 +00:00
|
|
|
#include "world.hpp"
|
2013-08-16 11:01:52 +00:00
|
|
|
|
2015-06-02 23:18:36 +00:00
|
|
|
#include <osg/Group>
|
2017-03-09 18:17:58 +00:00
|
|
|
#include <osg/Camera>
|
2017-03-07 16:22:47 +00:00
|
|
|
|
2017-03-06 15:32:56 +00:00
|
|
|
#include <components/resource/resourcesystem.hpp>
|
|
|
|
|
2013-08-16 11:01:52 +00:00
|
|
|
#include "storage.hpp"
|
2017-03-06 15:32:56 +00:00
|
|
|
#include "texturemanager.hpp"
|
2017-03-06 19:41:02 +00:00
|
|
|
#include "chunkmanager.hpp"
|
2017-03-07 15:33:31 +00:00
|
|
|
#include "compositemaprenderer.hpp"
|
2013-08-16 11:01:52 +00:00
|
|
|
|
2014-06-29 00:42:36 +00:00
|
|
|
namespace Terrain
|
2013-08-16 11:01:52 +00:00
|
|
|
{
|
|
|
|
|
2020-04-20 16:47:14 +00:00
|
|
|
World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, Storage* storage, int nodeMask, int preCompileMask, int borderMask)
|
2015-06-02 23:18:36 +00:00
|
|
|
: mStorage(storage)
|
|
|
|
, mParent(parent)
|
|
|
|
, mResourceSystem(resourceSystem)
|
2018-06-14 10:27:22 +00:00
|
|
|
, mBorderVisible(false)
|
2019-06-13 13:37:00 +00:00
|
|
|
, mHeightCullCallback(new HeightCullCallback)
|
2014-06-29 00:42:36 +00:00
|
|
|
{
|
2015-06-02 23:18:36 +00:00
|
|
|
mTerrainRoot = new osg::Group;
|
2020-04-20 16:47:14 +00:00
|
|
|
mTerrainRoot->setNodeMask(nodeMask);
|
2017-02-02 20:46:25 +00:00
|
|
|
mTerrainRoot->setName("Terrain Root");
|
2015-06-02 23:18:36 +00:00
|
|
|
|
2017-03-09 18:17:58 +00:00
|
|
|
osg::ref_ptr<osg::Camera> compositeCam = new osg::Camera;
|
|
|
|
compositeCam->setRenderOrder(osg::Camera::PRE_RENDER, -1);
|
|
|
|
compositeCam->setProjectionMatrix(osg::Matrix::identity());
|
|
|
|
compositeCam->setViewMatrix(osg::Matrix::identity());
|
|
|
|
compositeCam->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
2020-04-20 16:47:14 +00:00
|
|
|
compositeCam->setClearMask(0);
|
|
|
|
compositeCam->setNodeMask(preCompileMask);
|
2017-03-09 18:17:58 +00:00
|
|
|
mCompositeMapCamera = compositeCam;
|
|
|
|
|
|
|
|
compileRoot->addChild(compositeCam);
|
|
|
|
|
2017-03-09 00:56:43 +00:00
|
|
|
mCompositeMapRenderer = new CompositeMapRenderer;
|
2017-03-09 18:17:58 +00:00
|
|
|
compositeCam->addChild(mCompositeMapRenderer);
|
2017-03-07 15:33:31 +00:00
|
|
|
|
2015-06-02 23:18:36 +00:00
|
|
|
mParent->addChild(mTerrainRoot);
|
2017-03-06 15:32:56 +00:00
|
|
|
|
|
|
|
mTextureManager.reset(new TextureManager(mResourceSystem->getSceneManager()));
|
2017-03-09 00:56:43 +00:00
|
|
|
mChunkManager.reset(new ChunkManager(mStorage, mResourceSystem->getSceneManager(), mTextureManager.get(), mCompositeMapRenderer));
|
2019-06-13 13:37:00 +00:00
|
|
|
mChunkManager->setNodeMask(nodeMask);
|
2020-04-20 16:47:14 +00:00
|
|
|
mCellBorder.reset(new CellBorder(this,mTerrainRoot.get(),borderMask));
|
2017-03-06 19:45:46 +00:00
|
|
|
|
2017-03-06 19:41:02 +00:00
|
|
|
mResourceSystem->addResourceManager(mChunkManager.get());
|
2017-03-06 19:45:46 +00:00
|
|
|
mResourceSystem->addResourceManager(mTextureManager.get());
|
2013-08-16 11:01:52 +00:00
|
|
|
}
|
|
|
|
|
2014-06-29 00:42:36 +00:00
|
|
|
World::~World()
|
2013-08-16 11:01:52 +00:00
|
|
|
{
|
2017-03-06 19:41:02 +00:00
|
|
|
mResourceSystem->removeResourceManager(mChunkManager.get());
|
2017-03-06 19:45:46 +00:00
|
|
|
mResourceSystem->removeResourceManager(mTextureManager.get());
|
2017-03-06 15:32:56 +00:00
|
|
|
|
2015-06-02 23:18:36 +00:00
|
|
|
mParent->removeChild(mTerrainRoot);
|
2017-03-09 18:17:58 +00:00
|
|
|
|
|
|
|
mCompositeMapCamera->removeChild(mCompositeMapRenderer);
|
|
|
|
mCompositeMapCamera->getParent(0)->removeChild(mCompositeMapCamera);
|
2015-06-02 23:18:36 +00:00
|
|
|
|
2014-06-29 00:42:36 +00:00
|
|
|
delete mStorage;
|
|
|
|
}
|
2013-08-16 11:01:52 +00:00
|
|
|
|
2019-02-20 13:37:00 +00:00
|
|
|
void World::setWorkQueue(SceneUtil::WorkQueue* workQueue)
|
|
|
|
{
|
|
|
|
mCompositeMapRenderer->setWorkQueue(workQueue);
|
|
|
|
}
|
|
|
|
|
2018-06-14 10:27:22 +00:00
|
|
|
void World::setBordersVisible(bool visible)
|
|
|
|
{
|
|
|
|
mBorderVisible = visible;
|
|
|
|
|
2018-06-14 11:14:38 +00:00
|
|
|
if (visible)
|
|
|
|
{
|
|
|
|
for (std::set<std::pair<int,int>>::iterator it = mLoadedCells.begin(); it != mLoadedCells.end(); ++it)
|
|
|
|
mCellBorder->createCellBorderGeometry(it->first,it->second);
|
|
|
|
}
|
|
|
|
else
|
2018-06-14 10:27:22 +00:00
|
|
|
mCellBorder->destroyCellBorderGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void World::loadCell(int x, int y)
|
|
|
|
{
|
|
|
|
if (mBorderVisible)
|
|
|
|
mCellBorder->createCellBorderGeometry(x,y);
|
2018-06-14 11:14:38 +00:00
|
|
|
|
|
|
|
mLoadedCells.insert(std::pair<int,int>(x,y));
|
2018-06-14 10:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void World::unloadCell(int x, int y)
|
|
|
|
{
|
|
|
|
if (mBorderVisible)
|
|
|
|
mCellBorder->destroyCellBorderGeometry(x,y);
|
2018-06-14 11:14:38 +00:00
|
|
|
|
|
|
|
mLoadedCells.erase(std::pair<int,int>(x,y));
|
2018-06-14 10:27:22 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 00:40:41 +00:00
|
|
|
void World::setTargetFrameRate(float rate)
|
|
|
|
{
|
|
|
|
mCompositeMapRenderer->setTargetFrameRate(rate);
|
|
|
|
}
|
|
|
|
|
2015-06-02 23:18:36 +00:00
|
|
|
float World::getHeightAt(const osg::Vec3f &worldPos)
|
2014-06-29 00:42:36 +00:00
|
|
|
{
|
|
|
|
return mStorage->getHeightAt(worldPos);
|
|
|
|
}
|
2014-03-05 20:45:43 +00:00
|
|
|
|
2017-03-07 16:22:47 +00:00
|
|
|
void World::updateTextureFiltering()
|
|
|
|
{
|
|
|
|
mTextureManager->updateTextureFiltering();
|
|
|
|
}
|
|
|
|
|
2017-09-08 18:37:03 +00:00
|
|
|
void World::clearAssociatedCaches()
|
|
|
|
{
|
|
|
|
mChunkManager->clearCache();
|
|
|
|
}
|
|
|
|
|
2019-06-13 13:37:00 +00:00
|
|
|
osg::Callback* World::getHeightCullCallback(float highz, unsigned int mask)
|
|
|
|
{
|
|
|
|
mHeightCullCallback->setHighZ(highz);
|
|
|
|
mHeightCullCallback->setCullMask(mask);
|
|
|
|
return mHeightCullCallback;
|
|
|
|
}
|
|
|
|
|
2013-08-16 11:01:52 +00:00
|
|
|
}
|