From 20d30bb8d736b9fdb116b733741a2036dc02eb8f Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 7 Mar 2017 00:11:01 +0100 Subject: [PATCH] Move mDataLoaded into LandData --- components/esm/loadland.cpp | 29 ++++++++++++++--------------- components/esm/loadland.hpp | 9 +++++++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 5e33e60823..858b457045 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -18,7 +18,6 @@ namespace ESM , mY(0) , mPlugin(0) , mDataTypes(0) - , mDataLoaded(false) , mLandData(NULL) { } @@ -76,7 +75,6 @@ namespace ESM mContext = esm.getContext(); - mDataLoaded = 0; mLandData = NULL; // Skip the land data here. Load it when the cell is loaded. @@ -186,7 +184,7 @@ namespace ESM // Try to load only available data flags = flags & mDataTypes; // Return if all required data is loaded - if ((mDataLoaded & flags) == flags) { + if (mLandData && (mLandData->mDataLoaded & flags) == flags) { return; } // Create storage if nothing is loaded @@ -236,19 +234,18 @@ namespace ESM void Land::unloadData() const { - if (mDataLoaded) + if (mLandData) { delete mLandData; mLandData = NULL; - mDataLoaded = 0; } } 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); - mDataLoaded |= dataFlag; + mLandData->mDataLoaded |= dataFlag; return true; } reader.skipHSubSize(size); @@ -258,13 +255,12 @@ namespace ESM bool Land::isDataLoaded(int flags) const { OpenThreads::ScopedLock lock(mMutex); - return (mDataLoaded & flags) == (flags & mDataTypes); + return mLandData && (mLandData->mDataLoaded & flags) == (flags & mDataTypes); } Land::Land (const Land& land) : mFlags (land.mFlags), mX (land.mX), mY (land.mY), mPlugin (land.mPlugin), mContext (land.mContext), mDataTypes (land.mDataTypes), - mDataLoaded (land.mDataLoaded), mLandData (land.mLandData ? new LandData (*land.mLandData) : 0) {} @@ -282,7 +278,6 @@ namespace ESM std::swap (mPlugin, land.mPlugin); std::swap (mContext, land.mContext); std::swap (mDataTypes, land.mDataTypes); - std::swap (mDataLoaded, land.mDataLoaded); std::swap (mLandData, land.mLandData); } @@ -311,18 +306,22 @@ namespace ESM mLandData = new LandData; mDataTypes |= flags; - mDataLoaded |= flags; + mLandData->mDataLoaded |= flags; } void Land::remove (int flags) { mDataTypes &= ~flags; - mDataLoaded &= ~flags; - if (!mDataLoaded) + if (mLandData) { - delete mLandData; - mLandData = 0; + mLandData->mDataLoaded &= ~flags; + + if (!mLandData->mDataLoaded) + { + delete mLandData; + mLandData = 0; + } } } } diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index bdaf6cce83..eaffb2e464 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -80,6 +80,11 @@ struct Land struct LandData { + LandData() + : mDataLoaded(0) + { + } + // Initial reference height for the first vertex, only needed for filling mHeights float mHeightOffset; // Height in world space for each vertex @@ -99,6 +104,8 @@ struct Land // ??? short mUnk1; uint8_t mUnk2; + + int mDataLoaded; }; // low-LOD heightmap (used for rendering the global map) @@ -157,8 +164,6 @@ struct Land mutable OpenThreads::Mutex mMutex; - mutable int mDataLoaded; - mutable LandData *mLandData; };