Move WNAM out of LandData to avoid redundant (de)allocations on startup

coverity_scan^2
scrawl 8 years ago
parent e00b420f68
commit ddd6605608

@ -129,7 +129,7 @@ void CSMTools::ListLandTexturesMergeStage::perform (int stage, CSMDoc::Messages&
// make sure record is loaded // make sure record is loaded
land.loadData (ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML | land.loadData (ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML |
ESM::Land::DATA_VCLR | ESM::Land::DATA_VTEX | ESM::Land::DATA_WNAM); ESM::Land::DATA_VCLR | ESM::Land::DATA_VTEX);
if (const ESM::Land::LandData *data = land.getLandData (ESM::Land::DATA_VTEX)) if (const ESM::Land::LandData *data = land.getLandData (ESM::Land::DATA_VTEX))
{ {
@ -221,7 +221,7 @@ void CSMTools::MergeLandStage::perform (int stage, CSMDoc::Messages& messages)
const CSMWorld::Land& land = record.get(); const CSMWorld::Land& land = record.get();
land.loadData (ESM::Land::DATA_VCLR | ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML | land.loadData (ESM::Land::DATA_VCLR | ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML |
ESM::Land::DATA_VTEX | ESM::Land::DATA_WNAM); ESM::Land::DATA_VTEX);
CSMWorld::Land newLand (land); CSMWorld::Land newLand (land);

@ -993,7 +993,7 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages)
if (index!=-1/* && !mBase*/) if (index!=-1/* && !mBase*/)
mLand.getRecord (index).get().loadData ( mLand.getRecord (index).get().loadData (
ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML | ESM::Land::DATA_VCLR | ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML | ESM::Land::DATA_VCLR |
ESM::Land::DATA_VTEX | ESM::Land::DATA_WNAM); ESM::Land::DATA_VTEX);
break; break;
} }

@ -155,16 +155,6 @@ namespace MWRender
{ {
const ESM::Land* land = esmStore.get<ESM::Land>().search (x,y); const ESM::Land* land = esmStore.get<ESM::Land>().search (x,y);
if (land)
{
int mask = ESM::Land::DATA_WNAM;
if (!land->isDataLoaded(mask))
land->loadData(mask);
}
const ESM::Land::LandData *landData =
land ? land->getLandData (ESM::Land::DATA_WNAM) : 0;
for (int cellY=0; cellY<mCellSize; ++cellY) for (int cellY=0; cellY<mCellSize; ++cellY)
{ {
for (int cellX=0; cellX<mCellSize; ++cellX) for (int cellX=0; cellX<mCellSize; ++cellX)
@ -178,8 +168,8 @@ namespace MWRender
unsigned char r,g,b; unsigned char r,g,b;
float y2 = 0; float y2 = 0;
if (landData) if (land && (land->mDataTypes & ESM::Land::DATA_WNAM))
y2 = (landData->mWnam[vertexY * 9 + vertexX] << 4) / 2048.f; y2 = (land->mWnam[vertexY * 9 + vertexX] << 4) / 2048.f;
else else
y2 = (SCHAR_MIN << 4) / 2048.f; y2 = (SCHAR_MIN << 4) / 2048.f;
if (y2 < 0) if (y2 < 0)
@ -218,8 +208,6 @@ namespace MWRender
} }
} }
loadingListener->increaseProgress(); loadingListener->increaseProgress();
if (land)
land->unloadData();
} }
} }

@ -76,6 +76,9 @@ namespace ESM
mContext = esm.getContext(); mContext = esm.getContext();
mDataLoaded = 0;
mLandData = NULL;
// Skip the land data here. Load it when the cell is loaded. // Skip the land data here. Load it when the cell is loaded.
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
@ -91,7 +94,7 @@ namespace ESM
mDataTypes |= DATA_VHGT; mDataTypes |= DATA_VHGT;
break; break;
case ESM::FourCC<'W','N','A','M'>::value: case ESM::FourCC<'W','N','A','M'>::value:
esm.skipHSub(); esm.getHExact(mWnam, sizeof(mWnam));
mDataTypes |= DATA_WNAM; mDataTypes |= DATA_WNAM;
break; break;
case ESM::FourCC<'V','C','L','R'>::value: case ESM::FourCC<'V','C','L','R'>::value:
@ -107,9 +110,6 @@ namespace ESM
break; break;
} }
} }
mDataLoaded = 0;
mLandData = NULL;
} }
void Land::save(ESMWriter &esm, bool isDeleted) const void Land::save(ESMWriter &esm, bool isDeleted) const
@ -159,9 +159,14 @@ namespace ESM
} }
esm.writeHNT("VHGT", offsets, sizeof(VHGT)); esm.writeHNT("VHGT", offsets, sizeof(VHGT));
} }
if (mDataTypes & Land::DATA_WNAM) { }
esm.writeHNT("WNAM", mLandData->mWnam, 81);
} if (mDataTypes & Land::DATA_WNAM) {
esm.writeHNT("WNAM", mWnam, 81);
}
if (mLandData)
{
if (mDataTypes & Land::DATA_VCLR) { if (mDataTypes & Land::DATA_VCLR) {
esm.writeHNT("VCLR", mLandData->mColours, 3*LAND_NUM_VERTS); esm.writeHNT("VCLR", mLandData->mColours, 3*LAND_NUM_VERTS);
} }
@ -216,9 +221,9 @@ namespace ESM
} }
} }
if (reader.isNextSub("WNAM")) { if (reader.isNextSub("WNAM"))
condLoad(reader, flags, DATA_WNAM, mLandData->mWnam, 81); reader.skipHSub();
}
if (reader.isNextSub("VCLR")) if (reader.isNextSub("VCLR"))
condLoad(reader, flags, DATA_VCLR, mLandData->mColours, 3 * LAND_NUM_VERTS); condLoad(reader, flags, DATA_VCLR, mLandData->mColours, 3 * LAND_NUM_VERTS);
if (reader.isNextSub("VTEX")) { if (reader.isNextSub("VTEX")) {

@ -96,14 +96,14 @@ struct Land
// 24-bit RGB color for each vertex // 24-bit RGB color for each vertex
unsigned char mColours[3 * LAND_NUM_VERTS]; unsigned char mColours[3 * LAND_NUM_VERTS];
// low-LOD heightmap (used for rendering the global map)
signed char mWnam[81];
// ??? // ???
short mUnk1; short mUnk1;
uint8_t mUnk2; uint8_t mUnk2;
}; };
// low-LOD heightmap (used for rendering the global map)
signed char mWnam[81];
void load(ESMReader &esm, bool &isDeleted); void load(ESMReader &esm, bool &isDeleted);
void save(ESMWriter &esm, bool isDeleted = false) const; void save(ESMWriter &esm, bool isDeleted = false) const;

Loading…
Cancel
Save