mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Removed memory leak, allocated more on the stack
This commit is contained in:
parent
b76b62e5e4
commit
ec21ff21cc
@ -16,33 +16,32 @@ namespace MWRender
|
|||||||
//----------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
TerrainManager::TerrainManager(Ogre::SceneManager* mgr, const MWWorld::Environment& evn) :
|
TerrainManager::TerrainManager(Ogre::SceneManager* mgr, const MWWorld::Environment& evn) :
|
||||||
mEnvironment(evn)
|
mEnvironment(evn), mTerrainGroup(TerrainGroup(mgr, Terrain::ALIGN_X_Z, mLandSize, mWorldSize))
|
||||||
{
|
{
|
||||||
mTerrainGlobals = OGRE_NEW TerrainGlobalOptions();
|
|
||||||
|
|
||||||
TerrainMaterialGeneratorPtr matGen;
|
TerrainMaterialGeneratorPtr matGen;
|
||||||
TerrainMaterialGeneratorB* matGenP = new TerrainMaterialGeneratorB();
|
TerrainMaterialGeneratorB* matGenP = new TerrainMaterialGeneratorB();
|
||||||
matGen.bind(matGenP);
|
matGen.bind(matGenP);
|
||||||
mTerrainGlobals->setDefaultMaterialGenerator(matGen);
|
mTerrainGlobals.setDefaultMaterialGenerator(matGen);
|
||||||
|
|
||||||
TerrainMaterialGenerator::Profile* const activeProfile =
|
TerrainMaterialGenerator::Profile* const activeProfile =
|
||||||
mTerrainGlobals->getDefaultMaterialGenerator()
|
mTerrainGlobals.getDefaultMaterialGenerator()
|
||||||
->getActiveProfile();
|
->getActiveProfile();
|
||||||
mActiveProfile = static_cast<TerrainMaterialGeneratorB::SM2Profile*>(activeProfile);
|
mActiveProfile = static_cast<TerrainMaterialGeneratorB::SM2Profile*>(activeProfile);
|
||||||
|
|
||||||
//The pixel error should be as high as possible without it being noticed
|
//The pixel error should be as high as possible without it being noticed
|
||||||
//as it governs how fast mesh quality decreases.
|
//as it governs how fast mesh quality decreases.
|
||||||
mTerrainGlobals->setMaxPixelError(8);
|
mTerrainGlobals.setMaxPixelError(8);
|
||||||
|
|
||||||
mTerrainGlobals->setLayerBlendMapSize(32);
|
mTerrainGlobals.setLayerBlendMapSize(32);
|
||||||
mTerrainGlobals->setDefaultGlobalColourMapSize(65);
|
mTerrainGlobals.setDefaultGlobalColourMapSize(65);
|
||||||
|
|
||||||
//10 (default) didn't seem to be quite enough
|
//10 (default) didn't seem to be quite enough
|
||||||
mTerrainGlobals->setSkirtSize(128);
|
mTerrainGlobals.setSkirtSize(128);
|
||||||
|
|
||||||
//due to the sudden flick between composite and non composite textures,
|
//due to the sudden flick between composite and non composite textures,
|
||||||
//this seemed the distance where it wasn't too noticeable
|
//this seemed the distance where it wasn't too noticeable
|
||||||
mTerrainGlobals->setCompositeMapDistance(mWorldSize*2);
|
mTerrainGlobals.setCompositeMapDistance(mWorldSize*2);
|
||||||
|
|
||||||
mActiveProfile->setLightmapEnabled(false);
|
mActiveProfile->setLightmapEnabled(false);
|
||||||
mActiveProfile->setLayerSpecularMappingEnabled(false);
|
mActiveProfile->setLayerSpecularMappingEnabled(false);
|
||||||
@ -54,16 +53,11 @@ namespace MWRender
|
|||||||
//disabled
|
//disabled
|
||||||
mActiveProfile->setCompositeMapEnabled(false);
|
mActiveProfile->setCompositeMapEnabled(false);
|
||||||
|
|
||||||
mTerrainGroup = OGRE_NEW TerrainGroup(mgr,
|
mTerrainGroup.setOrigin(Vector3(mWorldSize/2,
|
||||||
Terrain::ALIGN_X_Z,
|
|
||||||
mLandSize,
|
|
||||||
mWorldSize);
|
|
||||||
|
|
||||||
mTerrainGroup->setOrigin(Vector3(mWorldSize/2,
|
|
||||||
0,
|
0,
|
||||||
-mWorldSize/2));
|
-mWorldSize/2));
|
||||||
|
|
||||||
Terrain::ImportData& importSettings = mTerrainGroup->getDefaultImportSettings();
|
Terrain::ImportData& importSettings = mTerrainGroup.getDefaultImportSettings();
|
||||||
|
|
||||||
importSettings.inputBias = 0;
|
importSettings.inputBias = 0;
|
||||||
importSettings.terrainSize = mLandSize;
|
importSettings.terrainSize = mLandSize;
|
||||||
@ -78,22 +72,20 @@ namespace MWRender
|
|||||||
|
|
||||||
TerrainManager::~TerrainManager()
|
TerrainManager::~TerrainManager()
|
||||||
{
|
{
|
||||||
OGRE_DELETE mTerrainGroup;
|
|
||||||
OGRE_DELETE mTerrainGlobals;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void TerrainManager::setDiffuse(const ColourValue& diffuse)
|
void TerrainManager::setDiffuse(const ColourValue& diffuse)
|
||||||
{
|
{
|
||||||
mTerrainGlobals->setCompositeMapDiffuse(diffuse);
|
mTerrainGlobals.setCompositeMapDiffuse(diffuse);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void TerrainManager::setAmbient(const ColourValue& ambient)
|
void TerrainManager::setAmbient(const ColourValue& ambient)
|
||||||
{
|
{
|
||||||
mTerrainGlobals->setCompositeMapAmbient(ambient);
|
mTerrainGlobals.setCompositeMapAmbient(ambient);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------
|
||||||
@ -117,7 +109,7 @@ namespace MWRender
|
|||||||
for ( int y = 0; y < 2; y++ )
|
for ( int y = 0; y < 2; y++ )
|
||||||
{
|
{
|
||||||
Terrain::ImportData terrainData =
|
Terrain::ImportData terrainData =
|
||||||
mTerrainGroup->getDefaultImportSettings();
|
mTerrainGroup.getDefaultImportSettings();
|
||||||
|
|
||||||
const int terrainX = cellX * 2 + x;
|
const int terrainX = cellX * 2 + x;
|
||||||
const int terrainY = cellY * 2 + y;
|
const int terrainY = cellY * 2 + y;
|
||||||
@ -155,13 +147,13 @@ namespace MWRender
|
|||||||
x * numTextures, y * numTextures,
|
x * numTextures, y * numTextures,
|
||||||
numTextures, indexes);
|
numTextures, indexes);
|
||||||
|
|
||||||
if (mTerrainGroup->getTerrain(terrainX, terrainY) == NULL)
|
if (mTerrainGroup.getTerrain(terrainX, terrainY) == NULL)
|
||||||
{
|
{
|
||||||
mTerrainGroup->defineTerrain(terrainX, terrainY, &terrainData);
|
mTerrainGroup.defineTerrain(terrainX, terrainY, &terrainData);
|
||||||
|
|
||||||
mTerrainGroup->loadTerrain(terrainX, terrainY, true);
|
mTerrainGroup.loadTerrain(terrainX, terrainY, true);
|
||||||
|
|
||||||
Terrain* terrain = mTerrainGroup->getTerrain(terrainX, terrainY);
|
Terrain* terrain = mTerrainGroup.getTerrain(terrainX, terrainY);
|
||||||
initTerrainBlendMaps(terrain,
|
initTerrainBlendMaps(terrain,
|
||||||
cellX, cellY,
|
cellX, cellY,
|
||||||
x * numTextures, y * numTextures,
|
x * numTextures, y * numTextures,
|
||||||
@ -193,7 +185,7 @@ namespace MWRender
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mTerrainGroup->freeTemporaryResources();
|
mTerrainGroup.freeTemporaryResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------
|
||||||
@ -204,8 +196,8 @@ namespace MWRender
|
|||||||
{
|
{
|
||||||
for ( int y = 0; y < 2; y++ )
|
for ( int y = 0; y < 2; y++ )
|
||||||
{
|
{
|
||||||
mTerrainGroup->unloadTerrain(store->cell->getGridX() * 2 + x,
|
mTerrainGroup.unloadTerrain(store->cell->getGridX() * 2 + x,
|
||||||
store->cell->getGridY() * 2 + y);
|
store->cell->getGridY() * 2 + y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define _GAME_RENDER_TERRAIN_H
|
#define _GAME_RENDER_TERRAIN_H
|
||||||
|
|
||||||
#include <OgreTerrain.h>
|
#include <OgreTerrain.h>
|
||||||
|
#include <OgreTerrainGroup.h>
|
||||||
#include "terrainmaterial.hpp"
|
#include "terrainmaterial.hpp"
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
@ -32,8 +33,8 @@ namespace MWRender{
|
|||||||
void cellAdded(MWWorld::Ptr::CellStore* store);
|
void cellAdded(MWWorld::Ptr::CellStore* store);
|
||||||
void cellRemoved(MWWorld::Ptr::CellStore* store);
|
void cellRemoved(MWWorld::Ptr::CellStore* store);
|
||||||
private:
|
private:
|
||||||
Ogre::TerrainGlobalOptions* mTerrainGlobals;
|
Ogre::TerrainGlobalOptions mTerrainGlobals;
|
||||||
Ogre::TerrainGroup* mTerrainGroup;
|
Ogre::TerrainGroup mTerrainGroup;
|
||||||
|
|
||||||
const MWWorld::Environment& mEnvironment;
|
const MWWorld::Environment& mEnvironment;
|
||||||
|
|
||||||
|
@ -239,7 +239,13 @@ namespace ESMS
|
|||||||
*/
|
*/
|
||||||
struct LandList : RecList
|
struct LandList : RecList
|
||||||
{
|
{
|
||||||
virtual ~LandList() {}
|
virtual ~LandList()
|
||||||
|
{
|
||||||
|
for ( LandMap::iterator itr = lands.begin(); itr != lands.end(); ++itr )
|
||||||
|
{
|
||||||
|
delete itr->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Map containing all landscapes
|
// Map containing all landscapes
|
||||||
typedef std::pair<int, int> LandCoord;
|
typedef std::pair<int, int> LandCoord;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user