Move terrain grid implementation to a component so the editor can use it (Feature #1597)

This commit is contained in:
scrawl 2014-08-07 20:43:33 +02:00
parent 982453d4f6
commit 8c26f802e6
5 changed files with 14 additions and 19 deletions

View file

@ -23,7 +23,7 @@ add_openmw_dir (mwrender
renderingmanager debugging sky camera animation npcanimation creatureanimation activatoranimation
actors objects renderinginterface localmap occlusionquery water shadows
characterpreview globalmap videoplayer ripplesimulation refraction
terrainstorage renderconst effectmanager weaponanimation terraingrid
terrainstorage renderconst effectmanager weaponanimation
)
add_openmw_dir (mwinput

View file

@ -23,6 +23,7 @@
#include <components/settings/settings.hpp>
#include <components/terrain/defaultworld.hpp>
#include <components/terrain/terraingrid.hpp>
#include "../mwworld/esmstore.hpp"
#include "../mwworld/class.hpp"
@ -45,7 +46,6 @@
#include "globalmap.hpp"
#include "terrainstorage.hpp"
#include "effectmanager.hpp"
#include "terraingrid.hpp"
using namespace MWRender;
using namespace Ogre;
@ -1045,7 +1045,7 @@ void RenderingManager::enableTerrain(bool enable)
mTerrain = new Terrain::DefaultWorld(mRendering.getScene(), new MWRender::TerrainStorage(), RV_Terrain,
Settings::Manager::getBool("shader", "Terrain"), Terrain::Align_XY, 1, 64);
else
mTerrain = new MWRender::TerrainGrid(mRendering.getScene(), new MWRender::TerrainStorage(), RV_Terrain,
mTerrain = new Terrain::TerrainGrid(mRendering.getScene(), new MWRender::TerrainStorage(), RV_Terrain,
Settings::Manager::getBool("shader", "Terrain"), Terrain::Align_XY);
mTerrain->applyMaterials(Settings::Manager::getBool("enabled", "Shadows"),
Settings::Manager::getBool("split", "Shadows"));

View file

@ -76,7 +76,7 @@ add_component_dir (translation
add_definitions(-DTERRAIN_USE_SHADER=1)
add_component_dir (terrain
quadtreenode chunk world defaultworld storage material buffercache defs
quadtreenode chunk world defaultworld terraingrid storage material buffercache defs
)
add_component_dir (loadinglistener

View file

@ -4,12 +4,9 @@
#include <OgreSceneNode.h>
#include <OgreAxisAlignedBox.h>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "chunk.hpp"
#include <components/terrain/chunk.hpp>
namespace MWRender
namespace Terrain
{
TerrainGrid::TerrainGrid(Ogre::SceneManager *sceneMgr, Terrain::Storage *storage, int visibilityFlags, bool shaders, Terrain::Alignment align)
@ -145,8 +142,10 @@ void TerrainGrid::setVisible(bool visible)
Ogre::AxisAlignedBox TerrainGrid::getWorldBoundingBox (const Ogre::Vector2& center)
{
int cellX, cellY;
MWBase::Environment::get().getWorld()->positionToIndex(center.x, center.y, cellX, cellY);
float cellSize = getStorage()->getCellWorldSize();
int cellX = std::floor(center.x/cellSize);
int cellY = std::floor(center.y/cellSize);
Grid::iterator it = mGrid.find(std::make_pair(cellX, cellY));
if (it == mGrid.end())

View file

@ -1,16 +1,12 @@
#ifndef OPENMW_MWRENDER_TERRAINGRID_H
#define OPENMW_MWRENDER_TERRAINGRID_H
#ifndef COMPONENTS_TERRAIN_TERRAINGRID_H
#define COMPONENTS_TERRAIN_TERRAINGRID_H
#include <components/terrain/world.hpp>
#include <components/terrain/material.hpp>
#include "world.hpp"
#include "material.hpp"
namespace Terrain
{
class Chunk;
}
namespace MWRender
{
struct GridElement
{