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-07 16:22:47 +00:00
|
|
|
#include <osg/Material>
|
|
|
|
|
2015-06-02 23:18:36 +00:00
|
|
|
#include <osgUtil/IncrementalCompileOperation>
|
2013-08-16 11:01:52 +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
|
|
|
{
|
|
|
|
|
2017-03-07 16:10:46 +00:00
|
|
|
World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico,
|
|
|
|
Storage* storage, int nodeMask, int preCompileMask)
|
2015-06-02 23:18:36 +00:00
|
|
|
: mStorage(storage)
|
|
|
|
, mParent(parent)
|
|
|
|
, mResourceSystem(resourceSystem)
|
|
|
|
, mIncrementalCompileOperation(ico)
|
2014-06-29 00:42:36 +00:00
|
|
|
{
|
2015-06-02 23:18:36 +00:00
|
|
|
mTerrainRoot = new osg::Group;
|
|
|
|
mTerrainRoot->setNodeMask(nodeMask);
|
|
|
|
mTerrainRoot->getOrCreateStateSet()->setRenderingHint(osg::StateSet::OPAQUE_BIN);
|
2017-03-07 16:22:47 +00:00
|
|
|
osg::ref_ptr<osg::Material> material (new osg::Material);
|
|
|
|
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
|
|
|
|
mTerrainRoot->getOrCreateStateSet()->setAttributeAndModes(material, osg::StateAttribute::ON);
|
|
|
|
|
2017-02-02 20:46:25 +00:00
|
|
|
mTerrainRoot->setName("Terrain Root");
|
2015-06-02 23:18:36 +00:00
|
|
|
|
2017-03-07 15:33:31 +00:00
|
|
|
osg::ref_ptr<CompositeMapRenderer> renderer (new CompositeMapRenderer);
|
2017-03-07 16:10:46 +00:00
|
|
|
renderer->setNodeMask(preCompileMask);
|
|
|
|
compileRoot->addChild(renderer);
|
|
|
|
mCompositeMapRenderer = renderer;
|
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-07 15:33:31 +00:00
|
|
|
mChunkManager.reset(new ChunkManager(mStorage, mResourceSystem->getSceneManager(), mTextureManager.get(), renderer));
|
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-07 16:10:46 +00:00
|
|
|
mCompositeMapRenderer->getParent(0)->removeChild(mCompositeMapRenderer);
|
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
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-08-16 11:01:52 +00:00
|
|
|
}
|