forked from mirror/openmw-tes3mp
Merge branch 'terrain18' into occlusionquery
Conflicts: apps/openmw/CMakeLists.txt apps/openmw/mwrender/renderingmanager.hpp
This commit is contained in:
commit
5fba52c238
18 changed files with 2873 additions and 22 deletions
|
@ -206,6 +206,7 @@ ENDIF(WIN32)
|
||||||
ENDIF(OGRE_STATIC)
|
ENDIF(OGRE_STATIC)
|
||||||
include_directories("."
|
include_directories("."
|
||||||
${OGRE_INCLUDE_DIR} ${OGRE_INCLUDE_DIR}/Ogre ${OGRE_INCLUDE_DIR}/OGRE ${OGRE_PLUGIN_INCLUDE_DIRS}
|
${OGRE_INCLUDE_DIR} ${OGRE_INCLUDE_DIR}/Ogre ${OGRE_INCLUDE_DIR}/OGRE ${OGRE_PLUGIN_INCLUDE_DIRS}
|
||||||
|
${OGRE_Terrain_INCLUDE_DIR}
|
||||||
${OIS_INCLUDE_DIRS} ${Boost_INCLUDE_DIR}
|
${OIS_INCLUDE_DIRS} ${Boost_INCLUDE_DIR}
|
||||||
${PLATFORM_INCLUDE_DIR}
|
${PLATFORM_INCLUDE_DIR}
|
||||||
${MYGUI_INCLUDE_DIRS}
|
${MYGUI_INCLUDE_DIRS}
|
||||||
|
|
|
@ -15,7 +15,7 @@ source_group(game FILES ${GAME} ${GAME_HEADER})
|
||||||
|
|
||||||
add_openmw_dir (mwrender
|
add_openmw_dir (mwrender
|
||||||
renderingmanager debugging sky player animation npcanimation creatureanimation actors objects
|
renderingmanager debugging sky player animation npcanimation creatureanimation actors objects
|
||||||
renderinginterface localmap occlusionquery
|
renderinginterface localmap occlusionquery terrain terrainmaterial
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwinput
|
add_openmw_dir (mwinput
|
||||||
|
@ -82,6 +82,7 @@ add_definitions(${SOUND_DEFINE})
|
||||||
|
|
||||||
target_link_libraries(openmw
|
target_link_libraries(openmw
|
||||||
${OGRE_LIBRARIES}
|
${OGRE_LIBRARIES}
|
||||||
|
${OGRE_Terrain_LIBRARY}
|
||||||
${OGRE_STATIC_PLUGINS}
|
${OGRE_STATIC_PLUGINS}
|
||||||
${OIS_LIBRARIES}
|
${OIS_LIBRARIES}
|
||||||
${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
|
|
|
@ -23,6 +23,11 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
|
||||||
:mRendering(_rend), mObjects(mRendering), mActors(mRendering, environment), mAmbientMode(0), mDebugging(engine)
|
:mRendering(_rend), mObjects(mRendering), mActors(mRendering, environment), mAmbientMode(0), mDebugging(engine)
|
||||||
{
|
{
|
||||||
mRendering.createScene("PlayerCam", 55, 5);
|
mRendering.createScene("PlayerCam", 55, 5);
|
||||||
|
mTerrainManager = new TerrainManager(mRendering.getScene());
|
||||||
|
|
||||||
|
//The fog type must be set before any terrain objects are created as if the
|
||||||
|
//fog type is set to FOG_NONE then the initially created terrain won't have any fog
|
||||||
|
configureFog(1, ColourValue(1,1,1));
|
||||||
|
|
||||||
// Set default mipmap level (NB some APIs ignore this)
|
// Set default mipmap level (NB some APIs ignore this)
|
||||||
TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
||||||
|
@ -66,6 +71,7 @@ RenderingManager::~RenderingManager ()
|
||||||
//TODO: destroy mSun?
|
//TODO: destroy mSun?
|
||||||
delete mPlayer;
|
delete mPlayer;
|
||||||
delete mSkyManager;
|
delete mSkyManager;
|
||||||
|
delete mTerrainManager;
|
||||||
delete mLocalMap;
|
delete mLocalMap;
|
||||||
delete mOcclusionQuery;
|
delete mOcclusionQuery;
|
||||||
}
|
}
|
||||||
|
@ -94,11 +100,15 @@ OEngine::Render::Fader* RenderingManager::getFader()
|
||||||
void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){
|
void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){
|
||||||
mObjects.removeCell(store);
|
mObjects.removeCell(store);
|
||||||
mActors.removeCell(store);
|
mActors.removeCell(store);
|
||||||
|
if (store->cell->isExterior())
|
||||||
|
mTerrainManager->cellRemoved(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingManager::cellAdded (MWWorld::Ptr::CellStore *store)
|
void RenderingManager::cellAdded (MWWorld::Ptr::CellStore *store)
|
||||||
{
|
{
|
||||||
mObjects.buildStaticGeometry (*store);
|
mObjects.buildStaticGeometry (*store);
|
||||||
|
if (store->cell->isExterior())
|
||||||
|
mTerrainManager->cellAdded(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingManager::addObject (const MWWorld::Ptr& ptr){
|
void RenderingManager::addObject (const MWWorld::Ptr& ptr){
|
||||||
|
@ -239,17 +249,17 @@ void RenderingManager::setAmbientMode()
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
|
||||||
mRendering.getScene()->setAmbientLight(mAmbientColor);
|
setAmbientColour(mAmbientColor);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
|
||||||
mRendering.getScene()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1));
|
setAmbientColour(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|
||||||
mRendering.getScene()->setAmbientLight(ColourValue(1,1,1));
|
setAmbientColour(ColourValue(1,1,1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,11 +314,13 @@ void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr)
|
||||||
void RenderingManager::setSunColour(const Ogre::ColourValue& colour)
|
void RenderingManager::setSunColour(const Ogre::ColourValue& colour)
|
||||||
{
|
{
|
||||||
mSun->setDiffuseColour(colour);
|
mSun->setDiffuseColour(colour);
|
||||||
|
mTerrainManager->setDiffuse(colour);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingManager::setAmbientColour(const Ogre::ColourValue& colour)
|
void RenderingManager::setAmbientColour(const Ogre::ColourValue& colour)
|
||||||
{
|
{
|
||||||
mRendering.getScene()->setAmbientLight(colour);
|
mRendering.getScene()->setAmbientLight(colour);
|
||||||
|
mTerrainManager->setAmbient(colour);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingManager::sunEnable()
|
void RenderingManager::sunEnable()
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "sky.hpp"
|
#include "sky.hpp"
|
||||||
|
#include "terrain.hpp"
|
||||||
#include "debugging.hpp"
|
#include "debugging.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
@ -137,6 +138,8 @@ class RenderingManager: private RenderingInterface {
|
||||||
|
|
||||||
OcclusionQuery* mOcclusionQuery;
|
OcclusionQuery* mOcclusionQuery;
|
||||||
|
|
||||||
|
TerrainManager* mTerrainManager;
|
||||||
|
|
||||||
OEngine::Render::OgreRenderer &mRendering;
|
OEngine::Render::OgreRenderer &mRendering;
|
||||||
|
|
||||||
MWRender::Objects mObjects;
|
MWRender::Objects mObjects;
|
||||||
|
|
482
apps/openmw/mwrender/terrain.cpp
Normal file
482
apps/openmw/mwrender/terrain.cpp
Normal file
|
@ -0,0 +1,482 @@
|
||||||
|
#include <OgreTerrain.h>
|
||||||
|
#include <OgreTerrainGroup.h>
|
||||||
|
|
||||||
|
#include "terrainmaterial.hpp"
|
||||||
|
#include "terrain.hpp"
|
||||||
|
|
||||||
|
#include "components/esm/loadland.hpp"
|
||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
using namespace Ogre;
|
||||||
|
|
||||||
|
namespace MWRender
|
||||||
|
{
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TerrainManager::TerrainManager(SceneManager* mgr)
|
||||||
|
{
|
||||||
|
mTerrainGlobals = OGRE_NEW TerrainGlobalOptions();
|
||||||
|
|
||||||
|
TerrainMaterialGeneratorPtr matGen;
|
||||||
|
TerrainMaterialGeneratorB* matGenP = new TerrainMaterialGeneratorB();
|
||||||
|
matGen.bind(matGenP);
|
||||||
|
mTerrainGlobals->setDefaultMaterialGenerator(matGen);
|
||||||
|
|
||||||
|
TerrainMaterialGenerator::Profile* const activeProfile =
|
||||||
|
mTerrainGlobals->getDefaultMaterialGenerator()
|
||||||
|
->getActiveProfile();
|
||||||
|
mActiveProfile = static_cast<TerrainMaterialGeneratorB::SM2Profile*>(activeProfile);
|
||||||
|
|
||||||
|
//The pixel error should be as high as possible without it being noticed
|
||||||
|
//as it governs how fast mesh quality decreases.
|
||||||
|
mTerrainGlobals->setMaxPixelError(8);
|
||||||
|
|
||||||
|
mTerrainGlobals->setLayerBlendMapSize(32);
|
||||||
|
mTerrainGlobals->setDefaultGlobalColourMapSize(65);
|
||||||
|
|
||||||
|
//10 (default) didn't seem to be quite enough
|
||||||
|
mTerrainGlobals->setSkirtSize(128);
|
||||||
|
|
||||||
|
//due to the sudden flick between composite and non composite textures,
|
||||||
|
//this seemed the distance where it wasn't too noticeable
|
||||||
|
mTerrainGlobals->setCompositeMapDistance(mWorldSize*2);
|
||||||
|
|
||||||
|
mActiveProfile->setLightmapEnabled(false);
|
||||||
|
mActiveProfile->setLayerSpecularMappingEnabled(false);
|
||||||
|
mActiveProfile->setLayerNormalMappingEnabled(false);
|
||||||
|
mActiveProfile->setLayerParallaxMappingEnabled(false);
|
||||||
|
mActiveProfile->setReceiveDynamicShadowsEnabled(false);
|
||||||
|
|
||||||
|
//composite maps lead to a drastic reduction in loading time so are
|
||||||
|
//disabled
|
||||||
|
mActiveProfile->setCompositeMapEnabled(false);
|
||||||
|
|
||||||
|
mTerrainGroup = OGRE_NEW TerrainGroup(mgr,
|
||||||
|
Terrain::ALIGN_X_Z,
|
||||||
|
mLandSize,
|
||||||
|
mWorldSize);
|
||||||
|
|
||||||
|
mTerrainGroup->setOrigin(Vector3(mWorldSize/2,
|
||||||
|
0,
|
||||||
|
-mWorldSize/2));
|
||||||
|
|
||||||
|
Terrain::ImportData& importSettings = mTerrainGroup->getDefaultImportSettings();
|
||||||
|
|
||||||
|
importSettings.inputBias = 0;
|
||||||
|
importSettings.terrainSize = mLandSize;
|
||||||
|
importSettings.worldSize = mWorldSize;
|
||||||
|
importSettings.minBatchSize = 9;
|
||||||
|
importSettings.maxBatchSize = mLandSize;
|
||||||
|
|
||||||
|
importSettings.deleteInputData = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TerrainManager::~TerrainManager()
|
||||||
|
{
|
||||||
|
OGRE_DELETE mTerrainGroup;
|
||||||
|
OGRE_DELETE mTerrainGlobals;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void TerrainManager::setDiffuse(const ColourValue& diffuse)
|
||||||
|
{
|
||||||
|
mTerrainGlobals->setCompositeMapDiffuse(diffuse);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void TerrainManager::setAmbient(const ColourValue& ambient)
|
||||||
|
{
|
||||||
|
mTerrainGlobals->setCompositeMapAmbient(ambient);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void TerrainManager::cellAdded(MWWorld::Ptr::CellStore *store)
|
||||||
|
{
|
||||||
|
const int cellX = store->cell->getGridX();
|
||||||
|
const int cellY = store->cell->getGridY();
|
||||||
|
|
||||||
|
//split the cell terrain into four segments
|
||||||
|
const int numTextures = ESM::Land::LAND_TEXTURE_SIZE/2;
|
||||||
|
|
||||||
|
for ( int x = 0; x < 2; x++ )
|
||||||
|
{
|
||||||
|
for ( int y = 0; y < 2; y++ )
|
||||||
|
{
|
||||||
|
Terrain::ImportData terrainData =
|
||||||
|
mTerrainGroup->getDefaultImportSettings();
|
||||||
|
|
||||||
|
const int terrainX = cellX * 2 + x;
|
||||||
|
const int terrainY = cellY * 2 + y;
|
||||||
|
|
||||||
|
//it makes far more sense to reallocate the memory here,
|
||||||
|
//and let Ogre deal with it due to the issues with deleting
|
||||||
|
//it at the wrong time if using threads (Which Terrain does)
|
||||||
|
terrainData.inputFloat = OGRE_ALLOC_T(float,
|
||||||
|
mLandSize*mLandSize,
|
||||||
|
MEMCATEGORY_GEOMETRY);
|
||||||
|
|
||||||
|
//copy the height data row by row
|
||||||
|
for ( int terrainCopyY = 0; terrainCopyY < mLandSize; terrainCopyY++ )
|
||||||
|
{
|
||||||
|
//the offset of the current segment
|
||||||
|
const size_t yOffset = y * (mLandSize-1) * ESM::Land::LAND_SIZE +
|
||||||
|
//offset of the row
|
||||||
|
terrainCopyY * ESM::Land::LAND_SIZE;
|
||||||
|
const size_t xOffset = x * (mLandSize-1);
|
||||||
|
|
||||||
|
memcpy(&terrainData.inputFloat[terrainCopyY*mLandSize],
|
||||||
|
&store->land[1][1]->landData->heights[yOffset + xOffset],
|
||||||
|
mLandSize*sizeof(float));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<uint16_t, int> indexes;
|
||||||
|
initTerrainTextures(&terrainData, store,
|
||||||
|
x * numTextures, y * numTextures,
|
||||||
|
numTextures, indexes);
|
||||||
|
|
||||||
|
if (mTerrainGroup->getTerrain(terrainX, terrainY) == NULL)
|
||||||
|
{
|
||||||
|
mTerrainGroup->defineTerrain(terrainX, terrainY, &terrainData);
|
||||||
|
|
||||||
|
mTerrainGroup->loadTerrain(terrainX, terrainY, true);
|
||||||
|
|
||||||
|
Terrain* terrain = mTerrainGroup->getTerrain(terrainX, terrainY);
|
||||||
|
initTerrainBlendMaps(terrain, store,
|
||||||
|
x * numTextures, y * numTextures,
|
||||||
|
numTextures,
|
||||||
|
indexes);
|
||||||
|
|
||||||
|
if ( store->land[1][1]->landData->usingColours )
|
||||||
|
{
|
||||||
|
// disable or enable global colour map (depends on available vertex colours)
|
||||||
|
mActiveProfile->setGlobalColourMapEnabled(true);
|
||||||
|
TexturePtr vertex = getVertexColours(store,
|
||||||
|
x*(mLandSize-1),
|
||||||
|
y*(mLandSize-1),
|
||||||
|
mLandSize);
|
||||||
|
|
||||||
|
//this is a hack to get around the fact that Ogre seems to
|
||||||
|
//corrupt the global colour map leading to rendering errors
|
||||||
|
MaterialPtr mat = terrain->getMaterial();
|
||||||
|
mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName( vertex->getName() );
|
||||||
|
//mat = terrain->_getCompositeMapMaterial();
|
||||||
|
//mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName( vertex->getName() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mActiveProfile->setGlobalColourMapEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mTerrainGroup->freeTemporaryResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void TerrainManager::cellRemoved(MWWorld::Ptr::CellStore *store)
|
||||||
|
{
|
||||||
|
for ( int x = 0; x < 2; x++ )
|
||||||
|
{
|
||||||
|
for ( int y = 0; y < 2; y++ )
|
||||||
|
{
|
||||||
|
mTerrainGroup->unloadTerrain(store->cell->getGridX() * 2 + x,
|
||||||
|
store->cell->getGridY() * 2 + y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void TerrainManager::initTerrainTextures(Terrain::ImportData* terrainData,
|
||||||
|
MWWorld::Ptr::CellStore* store,
|
||||||
|
int fromX, int fromY, int size,
|
||||||
|
std::map<uint16_t, int>& indexes)
|
||||||
|
{
|
||||||
|
assert(store != NULL && "store must be a valid pointer");
|
||||||
|
assert(terrainData != NULL && "Must have valid terrain data");
|
||||||
|
assert(fromX >= 0 && fromY >= 0 &&
|
||||||
|
"Can't get a terrain texture on terrain outside the current cell");
|
||||||
|
assert(fromX+size <= ESM::Land::LAND_TEXTURE_SIZE &&
|
||||||
|
fromY+size <= ESM::Land::LAND_TEXTURE_SIZE &&
|
||||||
|
"Can't get a terrain texture on terrain outside the current cell");
|
||||||
|
|
||||||
|
//this ensures that the ltex indexes are sorted (or retrived as sorted
|
||||||
|
//which simplifies shading between cells).
|
||||||
|
//
|
||||||
|
//If we don't sort the ltex indexes, the splatting order may differ between
|
||||||
|
//cells which may lead to inconsistent results when shading between cells
|
||||||
|
std::set<uint16_t> ltexIndexes;
|
||||||
|
for ( int y = fromY - 1; y < fromY + size + 1; y++ )
|
||||||
|
{
|
||||||
|
for ( int x = fromX - 1; x < fromX + size + 1; x++ )
|
||||||
|
{
|
||||||
|
ltexIndexes.insert(getLtexIndexAt(store, x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//there is one texture that we want to use as a base (i.e. it won't have
|
||||||
|
//a blend map). This holds the ltex index of that base texture so that
|
||||||
|
//we know not to include it in the output map
|
||||||
|
int baseTexture = -1;
|
||||||
|
for ( std::set<uint16_t>::iterator iter = ltexIndexes.begin();
|
||||||
|
iter != ltexIndexes.end();
|
||||||
|
++iter )
|
||||||
|
{
|
||||||
|
const uint16_t ltexIndex = *iter;
|
||||||
|
//this is the base texture, so we can ignore this at present
|
||||||
|
if ( ltexIndex == baseTexture )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::map<uint16_t, int>::const_iterator it = indexes.find(ltexIndex);
|
||||||
|
|
||||||
|
if ( it == indexes.end() )
|
||||||
|
{
|
||||||
|
//NB: All vtex ids are +1 compared to the ltex ids
|
||||||
|
|
||||||
|
assert( (int)store->landTextures->ltex.size() >= (int)ltexIndex - 1 &&
|
||||||
|
"LAND.VTEX must be within the bounds of the LTEX array");
|
||||||
|
|
||||||
|
std::string texture;
|
||||||
|
if ( ltexIndex == 0 )
|
||||||
|
{
|
||||||
|
texture = "_land_default.dds";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
texture = store->landTextures->ltex[ltexIndex-1].texture;
|
||||||
|
//TODO this is needed due to MWs messed up texture handling
|
||||||
|
texture = texture.substr(0, texture.rfind(".")) + ".dds";
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t position = terrainData->layerList.size();
|
||||||
|
terrainData->layerList.push_back(Terrain::LayerInstance());
|
||||||
|
|
||||||
|
terrainData->layerList[position].worldSize = 256;
|
||||||
|
terrainData->layerList[position].textureNames.push_back("textures\\" + texture);
|
||||||
|
|
||||||
|
if ( baseTexture == -1 )
|
||||||
|
{
|
||||||
|
baseTexture = ltexIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
indexes[ltexIndex] = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void TerrainManager::initTerrainBlendMaps(Terrain* terrain,
|
||||||
|
MWWorld::Ptr::CellStore* store,
|
||||||
|
int fromX, int fromY, int size,
|
||||||
|
const std::map<uint16_t, int>& indexes)
|
||||||
|
{
|
||||||
|
assert(store != NULL && "store must be a valid pointer");
|
||||||
|
assert(terrain != NULL && "Must have valid terrain");
|
||||||
|
assert(fromX >= 0 && fromY >= 0 &&
|
||||||
|
"Can't get a terrain texture on terrain outside the current cell");
|
||||||
|
assert(fromX+size <= ESM::Land::LAND_TEXTURE_SIZE &&
|
||||||
|
fromY+size <= ESM::Land::LAND_TEXTURE_SIZE &&
|
||||||
|
"Can't get a terrain texture on terrain outside the current cell");
|
||||||
|
|
||||||
|
//size must be a power of 2 as we do divisions with a power of 2 number
|
||||||
|
//that need to result in an integer for correct splatting
|
||||||
|
assert( (size & (size - 1)) == 0 && "Size must be a power of 2");
|
||||||
|
|
||||||
|
const int blendMapSize = terrain->getLayerBlendMapSize();
|
||||||
|
const int splatSize = blendMapSize / size;
|
||||||
|
|
||||||
|
//zero out every map
|
||||||
|
std::map<uint16_t, int>::const_iterator iter;
|
||||||
|
for ( iter = indexes.begin(); iter != indexes.end(); ++iter )
|
||||||
|
{
|
||||||
|
float* pBlend = terrain->getLayerBlendMap(iter->second)
|
||||||
|
->getBlendPointer();
|
||||||
|
memset(pBlend, 0, sizeof(float) * blendMapSize * blendMapSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
//covert the ltex data into a set of blend maps
|
||||||
|
for ( int texY = fromY - 1; texY < fromY + size + 1; texY++ )
|
||||||
|
{
|
||||||
|
for ( int texX = fromX - 1; texX < fromX + size + 1; texX++ )
|
||||||
|
{
|
||||||
|
const uint16_t ltexIndex = getLtexIndexAt(store, texX, texY);
|
||||||
|
|
||||||
|
//check if it is the base texture (which isn't in the map) and
|
||||||
|
//if it is don't bother altering the blend map for it
|
||||||
|
if ( indexes.find(ltexIndex) == indexes.end() )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//while texX is the splat index relative to the entire cell,
|
||||||
|
//relX is relative to the current segment we are splatting
|
||||||
|
const int relX = texX - fromX;
|
||||||
|
const int relY = texY - fromY;
|
||||||
|
|
||||||
|
const int layerIndex = indexes.find(ltexIndex)->second;
|
||||||
|
|
||||||
|
float* const pBlend = terrain->getLayerBlendMap(layerIndex)
|
||||||
|
->getBlendPointer();
|
||||||
|
|
||||||
|
for ( int y = -1; y < splatSize + 1; y++ ){
|
||||||
|
for ( int x = -1; x < splatSize + 1; x++ ){
|
||||||
|
|
||||||
|
//Note: Y is reversed
|
||||||
|
const int splatY = blendMapSize - 1 - relY * splatSize - y;
|
||||||
|
const int splatX = relX * splatSize + x;
|
||||||
|
|
||||||
|
if ( splatX >= 0 && splatX < blendMapSize &&
|
||||||
|
splatY >= 0 && splatY < blendMapSize )
|
||||||
|
{
|
||||||
|
const int index = (splatY)*blendMapSize + splatX;
|
||||||
|
|
||||||
|
if ( y >= 0 && y < splatSize &&
|
||||||
|
x >= 0 && x < splatSize )
|
||||||
|
{
|
||||||
|
pBlend[index] = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//this provides a transition shading but also
|
||||||
|
//rounds off the corners slightly
|
||||||
|
pBlend[index] = std::min(1.0f, pBlend[index] + 0.5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( int i = 1; i < terrain->getLayerCount(); i++ )
|
||||||
|
{
|
||||||
|
TerrainLayerBlendMap* blend = terrain->getLayerBlendMap(i);
|
||||||
|
blend->dirty();
|
||||||
|
blend->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int TerrainManager::getLtexIndexAt(MWWorld::Ptr::CellStore* store,
|
||||||
|
int x, int y)
|
||||||
|
{
|
||||||
|
//check texture index falls within the 9 cell bounds
|
||||||
|
//as this function can't cope with anything above that
|
||||||
|
assert(x >= -ESM::Land::LAND_TEXTURE_SIZE &&
|
||||||
|
y >= -ESM::Land::LAND_TEXTURE_SIZE &&
|
||||||
|
"Trying to get land textures that are out of bounds");
|
||||||
|
|
||||||
|
assert(x < 2*ESM::Land::LAND_TEXTURE_SIZE &&
|
||||||
|
y < 2*ESM::Land::LAND_TEXTURE_SIZE &&
|
||||||
|
"Trying to get land textures that are out of bounds");
|
||||||
|
|
||||||
|
assert(store != NULL && "Store pointer must be valid");
|
||||||
|
|
||||||
|
//default center cell is indexed at (1,1)
|
||||||
|
int cellX = 1;
|
||||||
|
int cellY = 1;
|
||||||
|
|
||||||
|
if ( x < 0 )
|
||||||
|
{
|
||||||
|
cellX--;
|
||||||
|
x += ESM::Land::LAND_TEXTURE_SIZE;
|
||||||
|
}
|
||||||
|
else if ( x >= ESM::Land::LAND_TEXTURE_SIZE )
|
||||||
|
{
|
||||||
|
cellX++;
|
||||||
|
x -= ESM::Land::LAND_TEXTURE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( y < 0 )
|
||||||
|
{
|
||||||
|
cellY--;
|
||||||
|
y += ESM::Land::LAND_TEXTURE_SIZE;
|
||||||
|
}
|
||||||
|
else if ( y >= ESM::Land::LAND_TEXTURE_SIZE )
|
||||||
|
{
|
||||||
|
cellY++;
|
||||||
|
y -= ESM::Land::LAND_TEXTURE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return store->land[cellX][cellY]
|
||||||
|
->landData
|
||||||
|
->textures[y * ESM::Land::LAND_TEXTURE_SIZE + x];
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TexturePtr TerrainManager::getVertexColours(MWWorld::Ptr::CellStore* store,
|
||||||
|
int fromX, int fromY, int size)
|
||||||
|
{
|
||||||
|
TextureManager* const texMgr = TextureManager::getSingletonPtr();
|
||||||
|
|
||||||
|
const std::string colourTextureName = "VtexColours_" +
|
||||||
|
boost::lexical_cast<std::string>(store->cell->getGridX()) +
|
||||||
|
"_" +
|
||||||
|
boost::lexical_cast<std::string>(store->cell->getGridY()) +
|
||||||
|
"_" +
|
||||||
|
boost::lexical_cast<std::string>(fromX) +
|
||||||
|
"_" +
|
||||||
|
boost::lexical_cast<std::string>(fromY);
|
||||||
|
|
||||||
|
TexturePtr tex = texMgr->getByName(colourTextureName);
|
||||||
|
if ( !tex.isNull() )
|
||||||
|
{
|
||||||
|
return tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
tex = texMgr->createManual(colourTextureName,
|
||||||
|
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||||
|
TEX_TYPE_2D, size, size, 0, PF_BYTE_BGR);
|
||||||
|
|
||||||
|
HardwarePixelBufferSharedPtr pixelBuffer = tex->getBuffer();
|
||||||
|
|
||||||
|
pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);
|
||||||
|
const PixelBox& pixelBox = pixelBuffer->getCurrentLock();
|
||||||
|
|
||||||
|
uint8* pDest = static_cast<uint8*>(pixelBox.data);
|
||||||
|
|
||||||
|
const char* const colours = store->land[1][1]->landData->colours;
|
||||||
|
for ( int y = 0; y < size; y++ )
|
||||||
|
{
|
||||||
|
for ( int x = 0; x < size; x++ )
|
||||||
|
{
|
||||||
|
const size_t colourOffset = (y+fromY)*3*65 + (x+fromX)*3;
|
||||||
|
|
||||||
|
assert( colourOffset >= 0 && colourOffset < 65*65*3 &&
|
||||||
|
"Colour offset is out of the expected bounds of record" );
|
||||||
|
|
||||||
|
const unsigned char r = colours[colourOffset + 0];
|
||||||
|
const unsigned char g = colours[colourOffset + 1];
|
||||||
|
const unsigned char b = colours[colourOffset + 2];
|
||||||
|
|
||||||
|
//as is the case elsewhere we need to flip the y
|
||||||
|
const size_t imageOffset = (size - 1 - y)*size*4 + x*4;
|
||||||
|
pDest[imageOffset + 0] = b;
|
||||||
|
pDest[imageOffset + 1] = g;
|
||||||
|
pDest[imageOffset + 2] = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pixelBuffer->unlock();
|
||||||
|
|
||||||
|
return tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
109
apps/openmw/mwrender/terrain.hpp
Normal file
109
apps/openmw/mwrender/terrain.hpp
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
#ifndef _GAME_RENDER_TERRAIN_H
|
||||||
|
#define _GAME_RENDER_TERRAIN_H
|
||||||
|
|
||||||
|
#include <OgreTerrain.h>
|
||||||
|
#include "terrainmaterial.hpp"
|
||||||
|
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
|
namespace Ogre{
|
||||||
|
class SceneManager;
|
||||||
|
class TerrainGroup;
|
||||||
|
class TerrainGlobalOptions;
|
||||||
|
class Terrain;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWRender{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements the Morrowind terrain using the Ogre Terrain Component
|
||||||
|
*
|
||||||
|
* Each terrain cell is split into four blocks as this leads to an increase
|
||||||
|
* in performance and means we don't hit splat limits quite as much
|
||||||
|
*/
|
||||||
|
class TerrainManager{
|
||||||
|
public:
|
||||||
|
TerrainManager(Ogre::SceneManager*);
|
||||||
|
virtual ~TerrainManager();
|
||||||
|
|
||||||
|
void setDiffuse(const Ogre::ColourValue& diffuse);
|
||||||
|
void setAmbient(const Ogre::ColourValue& ambient);
|
||||||
|
|
||||||
|
void cellAdded(MWWorld::Ptr::CellStore* store);
|
||||||
|
void cellRemoved(MWWorld::Ptr::CellStore* store);
|
||||||
|
private:
|
||||||
|
Ogre::TerrainGlobalOptions* mTerrainGlobals;
|
||||||
|
Ogre::TerrainGroup* mTerrainGroup;
|
||||||
|
|
||||||
|
Ogre::TerrainMaterialGeneratorB::SM2Profile* mActiveProfile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length in verticies of a single terrain block.
|
||||||
|
*/
|
||||||
|
static const int mLandSize = (ESM::Land::LAND_SIZE - 1)/2 + 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length in game units of a single terrain block.
|
||||||
|
*/
|
||||||
|
static const int mWorldSize = ESM::Land::REAL_SIZE/2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setups up the list of textures for part of a cell, using indexes as
|
||||||
|
* an output to create a mapping of MW LtexIndex to the relevant terrain
|
||||||
|
* layer
|
||||||
|
*
|
||||||
|
* @param terrainData the terrain data to setup the textures for
|
||||||
|
* @param store the cell store for the given terrain cell
|
||||||
|
* @param fromX the ltex index in the current cell to start making the texture from
|
||||||
|
* @param fromY the ltex index in the current cell to start making the texture from
|
||||||
|
* @param size the size (number of splats) to get
|
||||||
|
* @param indexes a mapping of ltex index to the terrain texture layer that
|
||||||
|
* can be used by initTerrainBlendMaps
|
||||||
|
*/
|
||||||
|
void initTerrainTextures(Ogre::Terrain::ImportData* terrainData,
|
||||||
|
MWWorld::Ptr::CellStore* store,
|
||||||
|
int fromX, int fromY, int size,
|
||||||
|
std::map<uint16_t, int>& indexes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the blend (splatting maps) for the given terrain from the ltex data.
|
||||||
|
*
|
||||||
|
* @param terrain the terrain object for the current cell
|
||||||
|
* @param store the cell store for the given terrain cell
|
||||||
|
* @param fromX the ltex index in the current cell to start making the texture from
|
||||||
|
* @param fromY the ltex index in the current cell to start making the texture from
|
||||||
|
* @param size the size (number of splats) to get
|
||||||
|
* @param indexes the mapping of ltex to blend map produced by initTerrainTextures
|
||||||
|
*/
|
||||||
|
void initTerrainBlendMaps(Ogre::Terrain* terrain,
|
||||||
|
MWWorld::Ptr::CellStore* store,
|
||||||
|
int fromX, int fromY, int size,
|
||||||
|
const std::map<uint16_t, int>& indexes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a LTEX index at the given point, assuming the current cell
|
||||||
|
* starts at (0,0). This supports getting values from the surrounding
|
||||||
|
* cells so negative x, y is acceptable
|
||||||
|
*
|
||||||
|
* @param store the cell store for the current cell
|
||||||
|
* @param x, y the splat position of the ltex index to get relative to the
|
||||||
|
* first splat of the current cell
|
||||||
|
*/
|
||||||
|
int getLtexIndexAt(MWWorld::Ptr::CellStore* store, int x, int y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Due to the fact that Ogre terrain doesn't support vertex colours
|
||||||
|
* we have to generate them manually
|
||||||
|
*
|
||||||
|
* @param store the cell store for the given terrain cell
|
||||||
|
* @param fromX the *vertex* index in the current cell to start making texture from
|
||||||
|
* @param fromY the *vertex* index in the current cell to start making the texture from
|
||||||
|
* @param size the size (number of vertexes) to get
|
||||||
|
*/
|
||||||
|
Ogre::TexturePtr getVertexColours(MWWorld::Ptr::CellStore* store,
|
||||||
|
int fromX, int fromY, int size);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _GAME_RENDER_TERRAIN_H
|
1741
apps/openmw/mwrender/terrainmaterial.cpp
Normal file
1741
apps/openmw/mwrender/terrainmaterial.cpp
Normal file
File diff suppressed because it is too large
Load diff
266
apps/openmw/mwrender/terrainmaterial.hpp
Normal file
266
apps/openmw/mwrender/terrainmaterial.hpp
Normal file
|
@ -0,0 +1,266 @@
|
||||||
|
/*
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
This source file is part of OGRE
|
||||||
|
(Object-oriented Graphics Rendering Engine)
|
||||||
|
For the latest info, see http://www.ogre3d.org/
|
||||||
|
|
||||||
|
Copyright (c) 2000-2011 Torus Knot Software Ltd
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __Ogre_TerrainMaterialGeneratorB_H__
|
||||||
|
#define __Ogre_TerrainMaterialGeneratorB_H__
|
||||||
|
|
||||||
|
#include "OgreTerrainPrerequisites.h"
|
||||||
|
#include "OgreTerrainMaterialGenerator.h"
|
||||||
|
#include "OgreGpuProgramParams.h"
|
||||||
|
|
||||||
|
namespace Ogre
|
||||||
|
{
|
||||||
|
class PSSMShadowCameraSetup;
|
||||||
|
|
||||||
|
/** \addtogroup Optional Components
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/** \addtogroup Terrain
|
||||||
|
* Some details on the terrain component
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** A TerrainMaterialGenerator which can cope with normal mapped, specular mapped
|
||||||
|
terrain.
|
||||||
|
@note Requires the Cg plugin to render correctly
|
||||||
|
*/
|
||||||
|
class _OgreTerrainExport TerrainMaterialGeneratorB : public TerrainMaterialGenerator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TerrainMaterialGeneratorB();
|
||||||
|
~TerrainMaterialGeneratorB();
|
||||||
|
|
||||||
|
/** Shader model 2 profile target.
|
||||||
|
*/
|
||||||
|
class _OgreTerrainExport SM2Profile : public TerrainMaterialGenerator::Profile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SM2Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc);
|
||||||
|
~SM2Profile();
|
||||||
|
|
||||||
|
bool isVertexCompressionSupported() const {return false;}
|
||||||
|
|
||||||
|
MaterialPtr generate(const Terrain* terrain);
|
||||||
|
MaterialPtr generateForCompositeMap(const Terrain* terrain);
|
||||||
|
uint8 getMaxLayers(const Terrain* terrain) const;
|
||||||
|
void updateParams(const MaterialPtr& mat, const Terrain* terrain);
|
||||||
|
void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain);
|
||||||
|
void requestOptions(Terrain* terrain);
|
||||||
|
|
||||||
|
/** Whether to support normal mapping per layer in the shader (default true).
|
||||||
|
*/
|
||||||
|
bool isLayerNormalMappingEnabled() const { return mLayerNormalMappingEnabled; }
|
||||||
|
/** Whether to support normal mapping per layer in the shader (default true).
|
||||||
|
*/
|
||||||
|
void setLayerNormalMappingEnabled(bool enabled);
|
||||||
|
/** Whether to support parallax mapping per layer in the shader (default true).
|
||||||
|
*/
|
||||||
|
bool isLayerParallaxMappingEnabled() const { return mLayerParallaxMappingEnabled; }
|
||||||
|
/** Whether to support parallax mapping per layer in the shader (default true).
|
||||||
|
*/
|
||||||
|
void setLayerParallaxMappingEnabled(bool enabled);
|
||||||
|
/** Whether to support specular mapping per layer in the shader (default true).
|
||||||
|
*/
|
||||||
|
bool isLayerSpecularMappingEnabled() const { return mLayerSpecularMappingEnabled; }
|
||||||
|
/** Whether to support specular mapping per layer in the shader (default true).
|
||||||
|
*/
|
||||||
|
void setLayerSpecularMappingEnabled(bool enabled);
|
||||||
|
/** Whether to support a global colour map over the terrain in the shader,
|
||||||
|
if it's present (default true).
|
||||||
|
*/
|
||||||
|
bool isGlobalColourMapEnabled() const { return mGlobalColourMapEnabled; }
|
||||||
|
/** Whether to support a global colour map over the terrain in the shader,
|
||||||
|
if it's present (default true).
|
||||||
|
*/
|
||||||
|
void setGlobalColourMapEnabled(bool enabled);
|
||||||
|
/** Whether to support a light map over the terrain in the shader,
|
||||||
|
if it's present (default true).
|
||||||
|
*/
|
||||||
|
bool isLightmapEnabled() const { return mLightmapEnabled; }
|
||||||
|
/** Whether to support a light map over the terrain in the shader,
|
||||||
|
if it's present (default true).
|
||||||
|
*/
|
||||||
|
void setLightmapEnabled(bool enabled);
|
||||||
|
/** Whether to use the composite map to provide a lower LOD technique
|
||||||
|
in the distance (default true).
|
||||||
|
*/
|
||||||
|
bool isCompositeMapEnabled() const { return mCompositeMapEnabled; }
|
||||||
|
/** Whether to use the composite map to provide a lower LOD technique
|
||||||
|
in the distance (default true).
|
||||||
|
*/
|
||||||
|
void setCompositeMapEnabled(bool enabled);
|
||||||
|
/** Whether to support dynamic texture shadows received from other
|
||||||
|
objects, on the terrain (default true).
|
||||||
|
*/
|
||||||
|
bool getReceiveDynamicShadowsEnabled() const { return mReceiveDynamicShadows; }
|
||||||
|
/** Whether to support dynamic texture shadows received from other
|
||||||
|
objects, on the terrain (default true).
|
||||||
|
*/
|
||||||
|
void setReceiveDynamicShadowsEnabled(bool enabled);
|
||||||
|
|
||||||
|
/** Whether to use PSSM support dynamic texture shadows, and if so the
|
||||||
|
settings to use (default 0).
|
||||||
|
*/
|
||||||
|
void setReceiveDynamicShadowsPSSM(PSSMShadowCameraSetup* pssmSettings);
|
||||||
|
/** Whether to use PSSM support dynamic texture shadows, and if so the
|
||||||
|
settings to use (default 0).
|
||||||
|
*/
|
||||||
|
PSSMShadowCameraSetup* getReceiveDynamicShadowsPSSM() const { return mPSSM; }
|
||||||
|
/** Whether to use depth shadows (default false).
|
||||||
|
*/
|
||||||
|
void setReceiveDynamicShadowsDepth(bool enabled);
|
||||||
|
/** Whether to use depth shadows (default false).
|
||||||
|
*/
|
||||||
|
bool getReceiveDynamicShadowsDepth() const { return mDepthShadows; }
|
||||||
|
/** Whether to use shadows on low LOD material rendering (when using composite map) (default false).
|
||||||
|
*/
|
||||||
|
void setReceiveDynamicShadowsLowLod(bool enabled);
|
||||||
|
/** Whether to use shadows on low LOD material rendering (when using composite map) (default false).
|
||||||
|
*/
|
||||||
|
bool getReceiveDynamicShadowsLowLod() const { return mLowLodShadows; }
|
||||||
|
|
||||||
|
int getNumberOfLightsSupported() const;
|
||||||
|
|
||||||
|
/// Internal
|
||||||
|
bool _isSM3Available() const { return mSM3Available; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
enum TechniqueType
|
||||||
|
{
|
||||||
|
HIGH_LOD,
|
||||||
|
LOW_LOD,
|
||||||
|
RENDER_COMPOSITE_MAP
|
||||||
|
};
|
||||||
|
void addTechnique(const MaterialPtr& mat, const Terrain* terrain, TechniqueType tt);
|
||||||
|
|
||||||
|
/// Interface definition for helper class to generate shaders
|
||||||
|
class _OgreTerrainExport ShaderHelper : public TerrainAlloc
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ShaderHelper() {}
|
||||||
|
virtual ~ShaderHelper() {}
|
||||||
|
virtual HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
virtual HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
virtual void updateParams(const SM2Profile* prof, const MaterialPtr& mat, const Terrain* terrain, bool compositeMap);
|
||||||
|
protected:
|
||||||
|
virtual String getVertexProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
virtual String getFragmentProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
virtual HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
|
||||||
|
virtual HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
|
||||||
|
virtual void generateVertexProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
virtual void generateFragmentProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
virtual void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
|
||||||
|
virtual void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
|
||||||
|
virtual void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0;
|
||||||
|
virtual void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0;
|
||||||
|
virtual void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
|
||||||
|
virtual void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
|
||||||
|
virtual void defaultVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
|
||||||
|
virtual void defaultFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
|
||||||
|
virtual void updateVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
|
||||||
|
virtual void updateFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
|
||||||
|
static String getChannel(uint idx);
|
||||||
|
|
||||||
|
size_t mShadowSamplerStartHi;
|
||||||
|
size_t mShadowSamplerStartLo;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Utility class to help with generating shaders for Cg / HLSL.
|
||||||
|
class _OgreTerrainExport ShaderHelperCg : public ShaderHelper
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
|
||||||
|
void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
|
||||||
|
void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
|
||||||
|
};
|
||||||
|
|
||||||
|
class _OgreTerrainExport ShaderHelperHLSL : public ShaderHelperCg
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Utility class to help with generating shaders for GLSL.
|
||||||
|
class _OgreTerrainExport ShaderHelperGLSL : public ShaderHelper
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
|
||||||
|
void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
|
||||||
|
void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
|
||||||
|
void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) {}
|
||||||
|
void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) {}
|
||||||
|
void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
|
||||||
|
void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
ShaderHelper* mShaderGen;
|
||||||
|
bool mLayerNormalMappingEnabled;
|
||||||
|
bool mLayerParallaxMappingEnabled;
|
||||||
|
bool mLayerSpecularMappingEnabled;
|
||||||
|
bool mGlobalColourMapEnabled;
|
||||||
|
bool mLightmapEnabled;
|
||||||
|
bool mCompositeMapEnabled;
|
||||||
|
bool mReceiveDynamicShadows;
|
||||||
|
PSSMShadowCameraSetup* mPSSM;
|
||||||
|
bool mDepthShadows;
|
||||||
|
bool mLowLodShadows;
|
||||||
|
bool mSM3Available;
|
||||||
|
|
||||||
|
bool isShadowingEnabled(TechniqueType tt, const Terrain* terrain) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -256,8 +256,12 @@ public:
|
||||||
return DataStreamPtr(new Mangle2OgreStream(strm));
|
return DataStreamPtr(new Mangle2OgreStream(strm));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool exists(const String& filename) {
|
||||||
|
return cexists(filename);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the file exists.
|
// Check if the file exists.
|
||||||
bool exists(const String& filename) {
|
bool cexists(const String& filename) const {
|
||||||
String passed = filename;
|
String passed = filename;
|
||||||
if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<'
|
if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<'
|
||||||
|| filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':'
|
|| filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':'
|
||||||
|
@ -308,6 +312,29 @@ return arc.exists(passed.c_str());
|
||||||
located in BSAs. So instead we channel it through exists() and
|
located in BSAs. So instead we channel it through exists() and
|
||||||
set up a single-element result list if the file is found.
|
set up a single-element result list if the file is found.
|
||||||
*/
|
*/
|
||||||
|
FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true,
|
||||||
|
bool dirs = false) const
|
||||||
|
{
|
||||||
|
FileInfoListPtr ptr = FileInfoListPtr(new FileInfoList());
|
||||||
|
|
||||||
|
// Check if the file exists (only works for single files - wild
|
||||||
|
// cards and recursive search isn't implemented.)
|
||||||
|
if(cexists(pattern))
|
||||||
|
{
|
||||||
|
FileInfo fi;
|
||||||
|
fi.archive = this;
|
||||||
|
fi.filename = pattern;
|
||||||
|
// It apparently doesn't matter that we return bogus
|
||||||
|
// information
|
||||||
|
fi.path = "";
|
||||||
|
fi.compressedSize = fi.uncompressedSize = 0;
|
||||||
|
|
||||||
|
ptr->push_back(fi);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true,
|
FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true,
|
||||||
bool dirs = false)
|
bool dirs = false)
|
||||||
{
|
{
|
||||||
|
@ -315,7 +342,7 @@ return arc.exists(passed.c_str());
|
||||||
|
|
||||||
// Check if the file exists (only works for single files - wild
|
// Check if the file exists (only works for single files - wild
|
||||||
// cards and recursive search isn't implemented.)
|
// cards and recursive search isn't implemented.)
|
||||||
if(exists(pattern))
|
if(cexists(pattern))
|
||||||
{
|
{
|
||||||
FileInfo fi;
|
FileInfo fi;
|
||||||
fi.archive = this;
|
fi.archive = this;
|
||||||
|
|
|
@ -148,9 +148,9 @@ void BSAFile::readHeader()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the index of a given file name, or -1 if not found
|
/// Get the index of a given file name, or -1 if not found
|
||||||
int BSAFile::getIndex(const char *str)
|
int BSAFile::getIndex(const char *str) const
|
||||||
{
|
{
|
||||||
Lookup::iterator it;
|
Lookup::const_iterator it;
|
||||||
it = lookup.find(str);
|
it = lookup.find(str);
|
||||||
|
|
||||||
if(it == lookup.end()) return -1;
|
if(it == lookup.end()) return -1;
|
||||||
|
|
|
@ -93,7 +93,7 @@ class BSAFile
|
||||||
void readHeader();
|
void readHeader();
|
||||||
|
|
||||||
/// Get the index of a given file name, or -1 if not found
|
/// Get the index of a given file name, or -1 if not found
|
||||||
int getIndex(const char *str);
|
int getIndex(const char *str) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ class BSAFile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// Check if a file exists
|
/// Check if a file exists
|
||||||
bool exists(const char *file) { return getIndex(file) != -1; }
|
bool exists(const char *file) const { return getIndex(file) != -1; }
|
||||||
|
|
||||||
/** Open a file contained in the archive. Throws an exception if the
|
/** Open a file contained in the archive. Throws an exception if the
|
||||||
file doesn't exist.
|
file doesn't exist.
|
||||||
|
|
|
@ -119,6 +119,21 @@ struct Cell
|
||||||
|
|
||||||
void load(ESMReader &esm);
|
void load(ESMReader &esm);
|
||||||
|
|
||||||
|
bool isExterior() const
|
||||||
|
{
|
||||||
|
return !(data.flags & Interior);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getGridX() const
|
||||||
|
{
|
||||||
|
return data.gridX;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getGridY() const
|
||||||
|
{
|
||||||
|
return data.gridY;
|
||||||
|
}
|
||||||
|
|
||||||
// Restore the given reader to the stored position. Will try to open
|
// Restore the given reader to the stored position. Will try to open
|
||||||
// the file matching the stored file name. If you want to read from
|
// the file matching the stored file name. If you want to read from
|
||||||
// somewhere other than the file system, you need to pre-open the
|
// somewhere other than the file system, you need to pre-open the
|
||||||
|
|
|
@ -19,14 +19,117 @@ void Land::load(ESMReader &esm)
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
// Skip these here. Load the actual data when the cell is loaded.
|
// Skip these here. Load the actual data when the cell is loaded.
|
||||||
if(esm.isNextSub("VNML")) {esm.skipHSubSize(12675);cnt++;}
|
if (esm.isNextSub("VNML"))
|
||||||
if(esm.isNextSub("VHGT")) {esm.skipHSubSize(4232);cnt++;}
|
{
|
||||||
if(esm.isNextSub("WNAM")) esm.skipHSubSize(81);
|
esm.skipHSubSize(12675);
|
||||||
if(esm.isNextSub("VCLR")) esm.skipHSubSize(12675);
|
cnt++;
|
||||||
if(esm.isNextSub("VTEX")) {esm.skipHSubSize(512);cnt++;}
|
}
|
||||||
|
if (esm.isNextSub("VHGT"))
|
||||||
|
{
|
||||||
|
esm.skipHSubSize(4232);
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
if (esm.isNextSub("WNAM"))
|
||||||
|
{
|
||||||
|
esm.skipHSubSize(81);
|
||||||
|
}
|
||||||
|
if (esm.isNextSub("VCLR"))
|
||||||
|
{
|
||||||
|
esm.skipHSubSize(12675);
|
||||||
|
}
|
||||||
|
if (esm.isNextSub("VTEX"))
|
||||||
|
{
|
||||||
|
esm.skipHSubSize(512);
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
// We need all three of VNML, VHGT and VTEX in order to use the
|
// We need all three of VNML, VHGT and VTEX in order to use the
|
||||||
// landscape.
|
// landscape.
|
||||||
hasData = (cnt == 3);
|
hasData = (cnt == 3);
|
||||||
|
|
||||||
|
dataLoaded = false;
|
||||||
|
landData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Land::loadData(ESMReader &esm)
|
||||||
|
{
|
||||||
|
if (dataLoaded)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
landData = new LandData;
|
||||||
|
|
||||||
|
if (hasData)
|
||||||
|
{
|
||||||
|
esm.restoreContext(context);
|
||||||
|
|
||||||
|
//esm.getHNExact(landData->normals, sizeof(VNML), "VNML");
|
||||||
|
if (esm.isNextSub("VNML"))
|
||||||
|
{
|
||||||
|
esm.skipHSubSize(12675);
|
||||||
|
}
|
||||||
|
|
||||||
|
VHGT rawHeights;
|
||||||
|
|
||||||
|
esm.getHNExact(&rawHeights, sizeof(VHGT), "VHGT");
|
||||||
|
int currentHeightOffset = rawHeights.heightOffset;
|
||||||
|
for (int y = 0; y < LAND_SIZE; y++)
|
||||||
|
{
|
||||||
|
currentHeightOffset += rawHeights.heightData[y * LAND_SIZE];
|
||||||
|
landData->heights[y * LAND_SIZE] = currentHeightOffset * HEIGHT_SCALE;
|
||||||
|
|
||||||
|
int tempOffset = currentHeightOffset;
|
||||||
|
for (int x = 1; x < LAND_SIZE; x++)
|
||||||
|
{
|
||||||
|
tempOffset += rawHeights.heightData[y * LAND_SIZE + x];
|
||||||
|
landData->heights[x + y * LAND_SIZE] = tempOffset * HEIGHT_SCALE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (esm.isNextSub("WNAM"))
|
||||||
|
{
|
||||||
|
esm.skipHSubSize(81);
|
||||||
|
}
|
||||||
|
if (esm.isNextSub("VCLR"))
|
||||||
|
{
|
||||||
|
landData->usingColours = true;
|
||||||
|
esm.getHExact(&landData->colours, 3*LAND_NUM_VERTS);
|
||||||
|
}else{
|
||||||
|
landData->usingColours = false;
|
||||||
|
}
|
||||||
|
//TODO fix magic numbers
|
||||||
|
uint16_t vtex[512];
|
||||||
|
esm.getHNExact(&vtex, 512, "VTEX");
|
||||||
|
|
||||||
|
int readPos = 0; //bit ugly, but it works
|
||||||
|
for ( int y1 = 0; y1 < 4; y1++ )
|
||||||
|
for ( int x1 = 0; x1 < 4; x1++ )
|
||||||
|
for ( int y2 = 0; y2 < 4; y2++)
|
||||||
|
for ( int x2 = 0; x2 < 4; x2++ )
|
||||||
|
landData->textures[(y1*4+y2)*16+(x1*4+x2)] = vtex[readPos++];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
landData->usingColours = false;
|
||||||
|
memset(&landData->textures, 0, 512 * sizeof(uint16_t));
|
||||||
|
for (int i = 0; i < LAND_NUM_VERTS; i++)
|
||||||
|
{
|
||||||
|
landData->heights[i] = -256.0f * HEIGHT_SCALE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dataLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Land::unloadData()
|
||||||
|
{
|
||||||
|
if (dataLoaded)
|
||||||
|
{
|
||||||
|
delete landData;
|
||||||
|
landData = NULL;
|
||||||
|
dataLoaded = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,61 @@ struct Land
|
||||||
|
|
||||||
bool hasData;
|
bool hasData;
|
||||||
|
|
||||||
|
bool dataLoaded;
|
||||||
|
|
||||||
|
// number of vertices per side
|
||||||
|
static const int LAND_SIZE = 65;
|
||||||
|
|
||||||
|
// cell terrain size in world coords
|
||||||
|
static const int REAL_SIZE = 8192;
|
||||||
|
|
||||||
|
// total number of vertices
|
||||||
|
static const int LAND_NUM_VERTS = LAND_SIZE * LAND_SIZE;
|
||||||
|
|
||||||
|
static const int HEIGHT_SCALE = 8;
|
||||||
|
|
||||||
|
//number of textures per side of land
|
||||||
|
static const int LAND_TEXTURE_SIZE = 16;
|
||||||
|
|
||||||
|
//total number of textures per land
|
||||||
|
static const int LAND_NUM_TEXTURES = LAND_TEXTURE_SIZE * LAND_TEXTURE_SIZE;
|
||||||
|
|
||||||
|
#pragma pack(push,1)
|
||||||
|
struct VHGT
|
||||||
|
{
|
||||||
|
float heightOffset;
|
||||||
|
int8_t heightData[LAND_NUM_VERTS];
|
||||||
|
short unknown1;
|
||||||
|
char unknown2;
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
typedef uint8_t VNML[LAND_NUM_VERTS * 3];
|
||||||
|
|
||||||
|
struct LandData
|
||||||
|
{
|
||||||
|
float heightOffset;
|
||||||
|
float heights[LAND_NUM_VERTS];
|
||||||
|
//float normals[LAND_NUM_VERTS * 3];
|
||||||
|
uint16_t textures[LAND_NUM_TEXTURES];
|
||||||
|
|
||||||
|
bool usingColours;
|
||||||
|
char colours[3 * LAND_NUM_VERTS];
|
||||||
|
};
|
||||||
|
|
||||||
|
LandData *landData;
|
||||||
|
|
||||||
void load(ESMReader &esm);
|
void load(ESMReader &esm);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actually loads data
|
||||||
|
*/
|
||||||
|
void loadData(ESMReader &esm);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees memory allocated for land data
|
||||||
|
*/
|
||||||
|
void unloadData();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -95,7 +95,8 @@ namespace ESMS
|
||||||
State_Unloaded, State_Preloaded, State_Loaded
|
State_Unloaded, State_Preloaded, State_Loaded
|
||||||
};
|
};
|
||||||
|
|
||||||
CellStore (const ESM::Cell *cell_) : cell (cell_), mState (State_Unloaded) {}
|
CellStore (const ESM::Cell *cell_) : cell (cell_), mState (State_Unloaded)
|
||||||
|
{}
|
||||||
|
|
||||||
const ESM::Cell *cell;
|
const ESM::Cell *cell;
|
||||||
State mState;
|
State mState;
|
||||||
|
@ -123,6 +124,9 @@ namespace ESMS
|
||||||
CellRefList<Static, D> statics;
|
CellRefList<Static, D> statics;
|
||||||
CellRefList<Weapon, D> weapons;
|
CellRefList<Weapon, D> weapons;
|
||||||
|
|
||||||
|
const Land* land[3][3];
|
||||||
|
const LTexList* landTextures;
|
||||||
|
|
||||||
void load (const ESMStore &store, ESMReader &esm)
|
void load (const ESMStore &store, ESMReader &esm)
|
||||||
{
|
{
|
||||||
if (mState!=State_Loaded)
|
if (mState!=State_Loaded)
|
||||||
|
@ -134,6 +138,21 @@ namespace ESMS
|
||||||
|
|
||||||
loadRefs (store, esm);
|
loadRefs (store, esm);
|
||||||
|
|
||||||
|
if ( ! (cell->data.flags & ESM::Cell::Interior) )
|
||||||
|
{
|
||||||
|
for ( size_t x = 0; x < 3; x++ )
|
||||||
|
{
|
||||||
|
for ( size_t y = 0; y < 3; y++ )
|
||||||
|
{
|
||||||
|
land[x][y] = loadTerrain(cell->data.gridX + x - 1,
|
||||||
|
cell->data.gridY + y - 1,
|
||||||
|
store,
|
||||||
|
esm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
landTextures = &store.landTexts;
|
||||||
|
}
|
||||||
|
|
||||||
mState = State_Loaded;
|
mState = State_Loaded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,6 +198,24 @@ namespace ESMS
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Land* loadTerrain(int X, int Y, const ESMStore &store, ESMReader &esm)
|
||||||
|
{
|
||||||
|
// load terrain
|
||||||
|
Land *land = store.lands.search(X, Y);
|
||||||
|
if (land != NULL)
|
||||||
|
{
|
||||||
|
land->loadData(esm);
|
||||||
|
}
|
||||||
|
|
||||||
|
return land;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unloadTerrain(int X, int Y, const ESMStore &store) {
|
||||||
|
assert (false &&
|
||||||
|
"This function is not implemented due to the fact that we now store overlapping land blocks so" &&
|
||||||
|
"we cannot be sure that the land segment is not being used by another CellStore");
|
||||||
|
}
|
||||||
|
|
||||||
template<class Functor, class List>
|
template<class Functor, class List>
|
||||||
bool forEachImp (Functor& functor, List& list)
|
bool forEachImp (Functor& functor, List& list)
|
||||||
{
|
{
|
||||||
|
|
|
@ -247,7 +247,7 @@ namespace ESMS
|
||||||
virtual void listIdentifier (std::vector<std::string>& identifier) const {}
|
virtual void listIdentifier (std::vector<std::string>& identifier) const {}
|
||||||
|
|
||||||
// Find land for the given coordinates. Return null if no data.
|
// Find land for the given coordinates. Return null if no data.
|
||||||
const Land *search(int x, int y) const
|
Land *search(int x, int y) const
|
||||||
{
|
{
|
||||||
Lands::const_iterator it = lands.find(x);
|
Lands::const_iterator it = lands.find(x);
|
||||||
if(it==lands.end())
|
if(it==lands.end())
|
||||||
|
|
|
@ -116,7 +116,7 @@ namespace ESMS
|
||||||
recLists[REC_GLOB] = &globals;
|
recLists[REC_GLOB] = &globals;
|
||||||
recLists[REC_GMST] = &gameSettings;
|
recLists[REC_GMST] = &gameSettings;
|
||||||
recLists[REC_INGR] = &ingreds;
|
recLists[REC_INGR] = &ingreds;
|
||||||
//recLists[REC_LAND] = &lands;
|
recLists[REC_LAND] = &lands;
|
||||||
recLists[REC_LEVC] = &creatureLists;
|
recLists[REC_LEVC] = &creatureLists;
|
||||||
recLists[REC_LEVI] = &itemLists;
|
recLists[REC_LEVI] = &itemLists;
|
||||||
recLists[REC_LIGH] = &lights;
|
recLists[REC_LIGH] = &lights;
|
||||||
|
|
|
@ -62,17 +62,17 @@ size_t BulletShape::calculateSize() const
|
||||||
|
|
||||||
|
|
||||||
//=============================================================================================================
|
//=============================================================================================================
|
||||||
template<> BulletShapeManager *Ogre::Singleton<BulletShapeManager>::ms_Singleton = 0;
|
template<> BulletShapeManager *Ogre::Singleton<BulletShapeManager>::msSingleton = 0;
|
||||||
|
|
||||||
BulletShapeManager *BulletShapeManager::getSingletonPtr()
|
BulletShapeManager *BulletShapeManager::getSingletonPtr()
|
||||||
{
|
{
|
||||||
return ms_Singleton;
|
return msSingleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
BulletShapeManager &BulletShapeManager::getSingleton()
|
BulletShapeManager &BulletShapeManager::getSingleton()
|
||||||
{
|
{
|
||||||
assert(ms_Singleton);
|
assert(msSingleton);
|
||||||
return(*ms_Singleton);
|
return(*msSingleton);
|
||||||
}
|
}
|
||||||
|
|
||||||
BulletShapeManager::BulletShapeManager()
|
BulletShapeManager::BulletShapeManager()
|
||||||
|
|
Loading…
Reference in a new issue