From 0e5c90d3e783cd471197637ae281494de4dd0b08 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Mon, 2 Apr 2012 23:50:53 +0200 Subject: [PATCH] Issue #225: Correction to commit ae98904. Changed pointer to LandData struct to simple member variable. --- apps/openmw/mwrender/terrain.cpp | 25 +++++++------------- components/esm/loadland.cpp | 40 +++++++++----------------------- components/esm/loadland.hpp | 8 +------ 3 files changed, 20 insertions(+), 53 deletions(-) diff --git a/apps/openmw/mwrender/terrain.cpp b/apps/openmw/mwrender/terrain.cpp index 0b8f933a2..f1920490d 100644 --- a/apps/openmw/mwrender/terrain.cpp +++ b/apps/openmw/mwrender/terrain.cpp @@ -98,10 +98,7 @@ namespace MWRender ESM::Land* land = mEnvironment.mWorld->getStore().lands.search(cellX, cellY); if ( land != NULL ) { - if (!land->dataLoaded) - { - land->loadData(); - } + land->loadData(); } //split the cell terrain into four segments @@ -136,7 +133,7 @@ namespace MWRender const size_t xOffset = x * (mLandSize-1); memcpy(&terrainData.inputFloat[terrainCopyY*mLandSize], - &land->landData->heights[yOffset + xOffset], + &land->landData.heights[yOffset + xOffset], mLandSize*sizeof(float)); } } @@ -163,7 +160,7 @@ namespace MWRender numTextures, indexes); - if ( land && land->landData->usingColours ) + if ( land && land->landData.usingColours ) { // disable or enable global colour map (depends on available vertex colours) mActiveProfile->setGlobalColourMapEnabled(true); @@ -423,18 +420,12 @@ namespace MWRender ESM::Land* land = mEnvironment.mWorld->getStore().lands.search(cellX, cellY); if ( land != NULL ) { - if (!land->dataLoaded) - { - land->loadData(); - } + land->loadData(); - return land->landData - ->textures[y * ESM::Land::LAND_TEXTURE_SIZE + x]; - } - else - { - return 0; + return land->landData.textures[y * ESM::Land::LAND_TEXTURE_SIZE + x]; } + + return 0; } //---------------------------------------------------------------------------------------------- @@ -473,7 +464,7 @@ namespace MWRender 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 x = 0; x < size; x++ ) diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 96afdf831..c6dc3c6f2 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -10,16 +10,10 @@ Land::Land() , mEsm(NULL) , hasData(false) , dataLoaded(false) - , landData(NULL) { + memset(&landData, 0, sizeof(landData)); } -Land::~Land() -{ - delete landData; -} - - void Land::load(ESMReader &esm) { mEsm = &esm; @@ -68,7 +62,6 @@ void Land::load(ESMReader &esm) hasData = (cnt == 3); dataLoaded = false; - landData = NULL; } void Land::loadData() @@ -78,8 +71,6 @@ void Land::loadData() return; } - landData = new LandData; - if (hasData) { mEsm->restoreContext(context); @@ -91,19 +82,20 @@ void Land::loadData() } VHGT rawHeights; + memset(&rawHeights, 0, sizeof(rawHeights)); mEsm->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; + 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; + landData.heights[x + y * LAND_SIZE] = tempOffset * HEIGHT_SCALE; } } @@ -113,10 +105,10 @@ void Land::loadData() } if (mEsm->isNextSub("VCLR")) { - landData->usingColours = true; - mEsm->getHExact(&landData->colours, 3*LAND_NUM_VERTS); + landData.usingColours = true; + mEsm->getHExact(&landData.colours, 3*LAND_NUM_VERTS); }else{ - landData->usingColours = false; + landData.usingColours = false; } //TODO fix magic numbers uint16_t vtex[512]; @@ -127,29 +119,19 @@ void Land::loadData() 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++]; + landData.textures[(y1*4+y2)*16+(x1*4+x2)] = vtex[readPos++]; } else { - landData->usingColours = false; - memset(&landData->textures, 0, 512 * sizeof(uint16_t)); + landData.usingColours = false; + memset(landData.textures, 0, sizeof(landData.textures)); 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; } -void Land::unloadData() -{ - if (dataLoaded) - { - delete landData; - landData = NULL; - dataLoaded = false; - } -} - } diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 64baecd34..86f37d575 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -12,7 +12,6 @@ namespace ESM struct Land { Land(); - ~Land(); int flags; // Only first four bits seem to be used, don't know what // they mean. @@ -67,7 +66,7 @@ struct Land char colours[3 * LAND_NUM_VERTS]; }; - LandData *landData; + LandData landData; void load(ESMReader &esm); @@ -75,11 +74,6 @@ struct Land * Actually loads data */ void loadData(); - - /** - * Frees memory allocated for land data - */ - void unloadData(); }; } #endif