Issue #225: Correction to commit ae98904.

Changed pointer to LandData struct to simple member variable.
pull/21/head
Lukasz Gromanowski 13 years ago
parent ae989040e5
commit 0e5c90d3e7

@ -98,10 +98,7 @@ namespace MWRender
ESM::Land* land = mEnvironment.mWorld->getStore().lands.search(cellX, cellY); ESM::Land* land = mEnvironment.mWorld->getStore().lands.search(cellX, cellY);
if ( land != NULL ) if ( land != NULL )
{ {
if (!land->dataLoaded) land->loadData();
{
land->loadData();
}
} }
//split the cell terrain into four segments //split the cell terrain into four segments
@ -136,7 +133,7 @@ namespace MWRender
const size_t xOffset = x * (mLandSize-1); const size_t xOffset = x * (mLandSize-1);
memcpy(&terrainData.inputFloat[terrainCopyY*mLandSize], memcpy(&terrainData.inputFloat[terrainCopyY*mLandSize],
&land->landData->heights[yOffset + xOffset], &land->landData.heights[yOffset + xOffset],
mLandSize*sizeof(float)); mLandSize*sizeof(float));
} }
} }
@ -163,7 +160,7 @@ namespace MWRender
numTextures, numTextures,
indexes); indexes);
if ( land && land->landData->usingColours ) if ( land && land->landData.usingColours )
{ {
// disable or enable global colour map (depends on available vertex colours) // disable or enable global colour map (depends on available vertex colours)
mActiveProfile->setGlobalColourMapEnabled(true); mActiveProfile->setGlobalColourMapEnabled(true);
@ -423,18 +420,12 @@ namespace MWRender
ESM::Land* land = mEnvironment.mWorld->getStore().lands.search(cellX, cellY); ESM::Land* land = mEnvironment.mWorld->getStore().lands.search(cellX, cellY);
if ( land != NULL ) if ( land != NULL )
{ {
if (!land->dataLoaded) land->loadData();
{
land->loadData();
}
return land->landData return land->landData.textures[y * ESM::Land::LAND_TEXTURE_SIZE + x];
->textures[y * ESM::Land::LAND_TEXTURE_SIZE + x];
}
else
{
return 0;
} }
return 0;
} }
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
@ -473,7 +464,7 @@ namespace MWRender
if ( land != NULL ) if ( land != NULL )
{ {
const char* const colours = land->landData->colours; const char* const colours = land->landData.colours;
for ( int y = 0; y < size; y++ ) for ( int y = 0; y < size; y++ )
{ {
for ( int x = 0; x < size; x++ ) for ( int x = 0; x < size; x++ )

@ -10,16 +10,10 @@ Land::Land()
, mEsm(NULL) , mEsm(NULL)
, hasData(false) , hasData(false)
, dataLoaded(false) , dataLoaded(false)
, landData(NULL)
{ {
memset(&landData, 0, sizeof(landData));
} }
Land::~Land()
{
delete landData;
}
void Land::load(ESMReader &esm) void Land::load(ESMReader &esm)
{ {
mEsm = &esm; mEsm = &esm;
@ -68,7 +62,6 @@ void Land::load(ESMReader &esm)
hasData = (cnt == 3); hasData = (cnt == 3);
dataLoaded = false; dataLoaded = false;
landData = NULL;
} }
void Land::loadData() void Land::loadData()
@ -78,8 +71,6 @@ void Land::loadData()
return; return;
} }
landData = new LandData;
if (hasData) if (hasData)
{ {
mEsm->restoreContext(context); mEsm->restoreContext(context);
@ -91,19 +82,20 @@ void Land::loadData()
} }
VHGT rawHeights; VHGT rawHeights;
memset(&rawHeights, 0, sizeof(rawHeights));
mEsm->getHNExact(&rawHeights, sizeof(VHGT), "VHGT"); mEsm->getHNExact(&rawHeights, sizeof(VHGT), "VHGT");
int currentHeightOffset = rawHeights.heightOffset; int currentHeightOffset = rawHeights.heightOffset;
for (int y = 0; y < LAND_SIZE; y++) for (int y = 0; y < LAND_SIZE; y++)
{ {
currentHeightOffset += rawHeights.heightData[y * LAND_SIZE]; currentHeightOffset += rawHeights.heightData[y * LAND_SIZE];
landData->heights[y * LAND_SIZE] = currentHeightOffset * HEIGHT_SCALE; landData.heights[y * LAND_SIZE] = currentHeightOffset * HEIGHT_SCALE;
int tempOffset = currentHeightOffset; int tempOffset = currentHeightOffset;
for (int x = 1; x < LAND_SIZE; x++) for (int x = 1; x < LAND_SIZE; x++)
{ {
tempOffset += rawHeights.heightData[y * LAND_SIZE + x]; tempOffset += rawHeights.heightData[y * LAND_SIZE + x];
landData->heights[x + y * LAND_SIZE] = tempOffset * HEIGHT_SCALE; landData.heights[x + y * LAND_SIZE] = tempOffset * HEIGHT_SCALE;
} }
} }
@ -113,10 +105,10 @@ void Land::loadData()
} }
if (mEsm->isNextSub("VCLR")) if (mEsm->isNextSub("VCLR"))
{ {
landData->usingColours = true; landData.usingColours = true;
mEsm->getHExact(&landData->colours, 3*LAND_NUM_VERTS); mEsm->getHExact(&landData.colours, 3*LAND_NUM_VERTS);
}else{ }else{
landData->usingColours = false; landData.usingColours = false;
} }
//TODO fix magic numbers //TODO fix magic numbers
uint16_t vtex[512]; uint16_t vtex[512];
@ -127,29 +119,19 @@ void Land::loadData()
for ( int x1 = 0; x1 < 4; x1++ ) for ( int x1 = 0; x1 < 4; x1++ )
for ( int y2 = 0; y2 < 4; y2++) for ( int y2 = 0; y2 < 4; y2++)
for ( int x2 = 0; x2 < 4; x2++ ) for ( int x2 = 0; x2 < 4; x2++ )
landData->textures[(y1*4+y2)*16+(x1*4+x2)] = vtex[readPos++]; landData.textures[(y1*4+y2)*16+(x1*4+x2)] = vtex[readPos++];
} }
else else
{ {
landData->usingColours = false; landData.usingColours = false;
memset(&landData->textures, 0, 512 * sizeof(uint16_t)); memset(landData.textures, 0, sizeof(landData.textures));
for (int i = 0; i < LAND_NUM_VERTS; i++) for (int i = 0; i < LAND_NUM_VERTS; i++)
{ {
landData->heights[i] = -256.0f * HEIGHT_SCALE; landData.heights[i] = -256.0f * HEIGHT_SCALE;
} }
} }
dataLoaded = true; dataLoaded = true;
} }
void Land::unloadData()
{
if (dataLoaded)
{
delete landData;
landData = NULL;
dataLoaded = false;
}
}
} }

@ -12,7 +12,6 @@ namespace ESM
struct Land struct Land
{ {
Land(); Land();
~Land();
int flags; // Only first four bits seem to be used, don't know what int flags; // Only first four bits seem to be used, don't know what
// they mean. // they mean.
@ -67,7 +66,7 @@ struct Land
char colours[3 * LAND_NUM_VERTS]; char colours[3 * LAND_NUM_VERTS];
}; };
LandData *landData; LandData landData;
void load(ESMReader &esm); void load(ESMReader &esm);
@ -75,11 +74,6 @@ struct Land
* Actually loads data * Actually loads data
*/ */
void loadData(); void loadData();
/**
* Frees memory allocated for land data
*/
void unloadData();
}; };
} }
#endif #endif

Loading…
Cancel
Save