Move mDataLoaded into LandData

pull/1225/head
scrawl 8 years ago
parent 16b5cadd9e
commit 20d30bb8d7

@ -18,7 +18,6 @@ namespace ESM
, mY(0) , mY(0)
, mPlugin(0) , mPlugin(0)
, mDataTypes(0) , mDataTypes(0)
, mDataLoaded(false)
, mLandData(NULL) , mLandData(NULL)
{ {
} }
@ -76,7 +75,6 @@ namespace ESM
mContext = esm.getContext(); mContext = esm.getContext();
mDataLoaded = 0;
mLandData = NULL; 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.
@ -186,7 +184,7 @@ namespace ESM
// Try to load only available data // Try to load only available data
flags = flags & mDataTypes; flags = flags & mDataTypes;
// Return if all required data is loaded // Return if all required data is loaded
if ((mDataLoaded & flags) == flags) { if (mLandData && (mLandData->mDataLoaded & flags) == flags) {
return; return;
} }
// Create storage if nothing is loaded // Create storage if nothing is loaded
@ -236,19 +234,18 @@ namespace ESM
void Land::unloadData() const void Land::unloadData() const
{ {
if (mDataLoaded) if (mLandData)
{ {
delete mLandData; delete mLandData;
mLandData = NULL; mLandData = NULL;
mDataLoaded = 0;
} }
} }
bool Land::condLoad(ESM::ESMReader& reader, int flags, int dataFlag, void *ptr, unsigned int size) const bool Land::condLoad(ESM::ESMReader& reader, int flags, int dataFlag, void *ptr, unsigned int size) const
{ {
if ((mDataLoaded & dataFlag) == 0 && (flags & dataFlag) != 0) { if ((mLandData->mDataLoaded & dataFlag) == 0 && (flags & dataFlag) != 0) {
reader.getHExact(ptr, size); reader.getHExact(ptr, size);
mDataLoaded |= dataFlag; mLandData->mDataLoaded |= dataFlag;
return true; return true;
} }
reader.skipHSubSize(size); reader.skipHSubSize(size);
@ -258,13 +255,12 @@ namespace ESM
bool Land::isDataLoaded(int flags) const bool Land::isDataLoaded(int flags) const
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
return (mDataLoaded & flags) == (flags & mDataTypes); return mLandData && (mLandData->mDataLoaded & flags) == (flags & mDataTypes);
} }
Land::Land (const Land& land) Land::Land (const Land& land)
: mFlags (land.mFlags), mX (land.mX), mY (land.mY), mPlugin (land.mPlugin), : mFlags (land.mFlags), mX (land.mX), mY (land.mY), mPlugin (land.mPlugin),
mContext (land.mContext), mDataTypes (land.mDataTypes), mContext (land.mContext), mDataTypes (land.mDataTypes),
mDataLoaded (land.mDataLoaded),
mLandData (land.mLandData ? new LandData (*land.mLandData) : 0) mLandData (land.mLandData ? new LandData (*land.mLandData) : 0)
{} {}
@ -282,7 +278,6 @@ namespace ESM
std::swap (mPlugin, land.mPlugin); std::swap (mPlugin, land.mPlugin);
std::swap (mContext, land.mContext); std::swap (mContext, land.mContext);
std::swap (mDataTypes, land.mDataTypes); std::swap (mDataTypes, land.mDataTypes);
std::swap (mDataLoaded, land.mDataLoaded);
std::swap (mLandData, land.mLandData); std::swap (mLandData, land.mLandData);
} }
@ -311,18 +306,22 @@ namespace ESM
mLandData = new LandData; mLandData = new LandData;
mDataTypes |= flags; mDataTypes |= flags;
mDataLoaded |= flags; mLandData->mDataLoaded |= flags;
} }
void Land::remove (int flags) void Land::remove (int flags)
{ {
mDataTypes &= ~flags; mDataTypes &= ~flags;
mDataLoaded &= ~flags;
if (!mDataLoaded) if (mLandData)
{
mLandData->mDataLoaded &= ~flags;
if (!mLandData->mDataLoaded)
{ {
delete mLandData; delete mLandData;
mLandData = 0; mLandData = 0;
} }
} }
}
} }

@ -80,6 +80,11 @@ struct Land
struct LandData struct LandData
{ {
LandData()
: mDataLoaded(0)
{
}
// Initial reference height for the first vertex, only needed for filling mHeights // Initial reference height for the first vertex, only needed for filling mHeights
float mHeightOffset; float mHeightOffset;
// Height in world space for each vertex // Height in world space for each vertex
@ -99,6 +104,8 @@ struct Land
// ??? // ???
short mUnk1; short mUnk1;
uint8_t mUnk2; uint8_t mUnk2;
int mDataLoaded;
}; };
// low-LOD heightmap (used for rendering the global map) // low-LOD heightmap (used for rendering the global map)
@ -157,8 +164,6 @@ struct Land
mutable OpenThreads::Mutex mMutex; mutable OpenThreads::Mutex mMutex;
mutable int mDataLoaded;
mutable LandData *mLandData; mutable LandData *mLandData;
}; };

Loading…
Cancel
Save