2013-08-27 16:01:16 +02:00
|
|
|
#include "world.hpp"
|
2013-08-16 13:01:52 +02:00
|
|
|
|
2015-06-03 01:18:36 +02:00
|
|
|
#include <osg/Group>
|
2017-03-07 17:22:47 +01:00
|
|
|
#include <osg/Material>
|
|
|
|
|
2017-03-06 16:32:56 +01:00
|
|
|
#include <components/resource/resourcesystem.hpp>
|
|
|
|
|
2013-08-16 13:01:52 +02:00
|
|
|
#include "storage.hpp"
|
2017-03-06 16:32:56 +01:00
|
|
|
#include "texturemanager.hpp"
|
2017-03-06 20:41:02 +01:00
|
|
|
#include "chunkmanager.hpp"
|
2017-03-07 16:33:31 +01:00
|
|
|
#include "compositemaprenderer.hpp"
|
2013-08-16 13:01:52 +02:00
|
|
|
|
2014-06-29 02:42:36 +02:00
|
|
|
namespace Terrain
|
2013-08-16 13:01:52 +02:00
|
|
|
{
|
|
|
|
|
2017-03-07 17:25:23 +01:00
|
|
|
World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, Storage* storage, int nodeMask, int preCompileMask)
|
2015-06-03 01:18:36 +02:00
|
|
|
: mStorage(storage)
|
|
|
|
, mParent(parent)
|
|
|
|
, mResourceSystem(resourceSystem)
|
2014-06-29 02:42:36 +02:00
|
|
|
{
|
2015-06-03 01:18:36 +02:00
|
|
|
mTerrainRoot = new osg::Group;
|
|
|
|
mTerrainRoot->setNodeMask(nodeMask);
|
|
|
|
mTerrainRoot->getOrCreateStateSet()->setRenderingHint(osg::StateSet::OPAQUE_BIN);
|
2017-03-07 17:22:47 +01: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 21:46:25 +01:00
|
|
|
mTerrainRoot->setName("Terrain Root");
|
2015-06-03 01:18:36 +02:00
|
|
|
|
2017-03-09 01:56:43 +01:00
|
|
|
mCompositeMapRenderer = new CompositeMapRenderer;
|
|
|
|
mCompositeMapRenderer->setNodeMask(preCompileMask);
|
|
|
|
compileRoot->addChild(mCompositeMapRenderer);
|
2017-03-07 16:33:31 +01:00
|
|
|
|
2015-06-03 01:18:36 +02:00
|
|
|
mParent->addChild(mTerrainRoot);
|
2017-03-06 16:32:56 +01:00
|
|
|
|
|
|
|
mTextureManager.reset(new TextureManager(mResourceSystem->getSceneManager()));
|
2017-03-09 01:56:43 +01:00
|
|
|
mChunkManager.reset(new ChunkManager(mStorage, mResourceSystem->getSceneManager(), mTextureManager.get(), mCompositeMapRenderer));
|
2017-03-06 20:45:46 +01:00
|
|
|
|
2017-03-06 20:41:02 +01:00
|
|
|
mResourceSystem->addResourceManager(mChunkManager.get());
|
2017-03-06 20:45:46 +01:00
|
|
|
mResourceSystem->addResourceManager(mTextureManager.get());
|
2013-08-16 13:01:52 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 02:42:36 +02:00
|
|
|
World::~World()
|
2013-08-16 13:01:52 +02:00
|
|
|
{
|
2017-03-06 20:41:02 +01:00
|
|
|
mResourceSystem->removeResourceManager(mChunkManager.get());
|
2017-03-06 20:45:46 +01:00
|
|
|
mResourceSystem->removeResourceManager(mTextureManager.get());
|
2017-03-06 16:32:56 +01:00
|
|
|
|
2015-06-03 01:18:36 +02:00
|
|
|
mParent->removeChild(mTerrainRoot);
|
2017-03-07 17:10:46 +01:00
|
|
|
mCompositeMapRenderer->getParent(0)->removeChild(mCompositeMapRenderer);
|
2015-06-03 01:18:36 +02:00
|
|
|
|
2014-06-29 02:42:36 +02:00
|
|
|
delete mStorage;
|
|
|
|
}
|
2013-08-16 13:01:52 +02:00
|
|
|
|
2015-06-03 01:18:36 +02:00
|
|
|
float World::getHeightAt(const osg::Vec3f &worldPos)
|
2014-06-29 02:42:36 +02:00
|
|
|
{
|
|
|
|
return mStorage->getHeightAt(worldPos);
|
|
|
|
}
|
2014-03-05 21:45:43 +01:00
|
|
|
|
2017-03-08 01:53:13 +01:00
|
|
|
osg::ref_ptr<osg::Node> World::cacheCell(int x, int y)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-07 17:22:47 +01:00
|
|
|
void World::updateTextureFiltering()
|
|
|
|
{
|
|
|
|
mTextureManager->updateTextureFiltering();
|
|
|
|
}
|
|
|
|
|
2013-08-16 13:01:52 +02:00
|
|
|
}
|