refactors ESM::Land (#3213)

With this PR we reduce coupling, simplify code, encapsulate a variable and separate actual `ESM` data from its context.
pull/3217/head
Bo Svensson 3 years ago committed by GitHub
parent 1979ee1491
commit 6cf74f7041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -296,7 +296,7 @@ namespace CSMWorld
const std::string& destination, const UniversalId::Type type) const std::string& destination, const UniversalId::Type type)
{ {
int index = cloneRecordImp(origin, destination, type); int index = cloneRecordImp(origin, destination, type);
mRecords.at(index)->get().mPlugin = 0; mRecords.at(index)->get().setPlugin(0);
} }
template<typename ESXRecordT, typename IdAccessorT> template<typename ESXRecordT, typename IdAccessorT>
@ -311,7 +311,7 @@ namespace CSMWorld
int index = touchRecordImp(id); int index = touchRecordImp(id);
if (index >= 0) if (index >= 0)
{ {
mRecords.at(index)->get().mPlugin = 0; mRecords.at(index)->get().setPlugin(0);
return true; return true;
} }

@ -52,7 +52,7 @@ namespace CSMWorld
QVariant LandPluginIndexColumn::get(const Record<Land>& record) const QVariant LandPluginIndexColumn::get(const Record<Land>& record) const
{ {
return record.get().mPlugin; return record.get().getPlugin();
} }
bool LandPluginIndexColumn::isEditable() const bool LandPluginIndexColumn::isEditable() const

@ -153,7 +153,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener)
// Land texture loading needs to use a separate internal store for each plugin. // Land texture loading needs to use a separate internal store for each plugin.
// We set the number of plugins here so we can properly verify if valid plugin // We set the number of plugins here so we can properly verify if valid plugin
// indices are being passed to the LandTexture Store retrieval methods. // indices are being passed to the LandTexture Store retrieval methods.
mLandTextures.resize(mLandTextures.getSize()+1); mLandTextures.addPlugin();
// Loop through all records // Loop through all records
while(esm.hasMoreRecs()) while(esm.hasMoreRecs())

@ -322,15 +322,13 @@ namespace MWWorld
assert(plugin < mStatic.size()); assert(plugin < mStatic.size());
return mStatic[plugin].size(); return mStatic[plugin].size();
} }
RecordId Store<ESM::LandTexture>::load(ESM::ESMReader &esm, size_t plugin) RecordId Store<ESM::LandTexture>::load(ESM::ESMReader &esm)
{ {
ESM::LandTexture lt; ESM::LandTexture lt;
bool isDeleted = false; bool isDeleted = false;
lt.load(esm, isDeleted); lt.load(esm, isDeleted);
assert(plugin < mStatic.size());
// Replace texture for records with given ID and index from all plugins. // Replace texture for records with given ID and index from all plugins.
for (unsigned int i=0; i<mStatic.size(); i++) for (unsigned int i=0; i<mStatic.size(); i++)
{ {
@ -342,7 +340,7 @@ namespace MWWorld
} }
} }
LandTextureList &ltexl = mStatic[plugin]; LandTextureList &ltexl = mStatic.back();
if(lt.mIndex + 1 > (int)ltexl.size()) if(lt.mIndex + 1 > (int)ltexl.size())
ltexl.resize(lt.mIndex+1); ltexl.resize(lt.mIndex+1);
@ -352,10 +350,6 @@ namespace MWWorld
return RecordId(ltexl[idx].mId, isDeleted); return RecordId(ltexl[idx].mId, isDeleted);
} }
RecordId Store<ESM::LandTexture>::load(ESM::ESMReader &esm)
{
return load(esm, esm.getIndex());
}
Store<ESM::LandTexture>::iterator Store<ESM::LandTexture>::begin(size_t plugin) const Store<ESM::LandTexture>::iterator Store<ESM::LandTexture>::begin(size_t plugin) const
{ {
assert(plugin < mStatic.size()); assert(plugin < mStatic.size());
@ -366,11 +360,6 @@ namespace MWWorld
assert(plugin < mStatic.size()); assert(plugin < mStatic.size());
return mStatic[plugin].end(); return mStatic[plugin].end();
} }
void Store<ESM::LandTexture>::resize(size_t num)
{
if (mStatic.size() < num)
mStatic.resize(num);
}
// Land // Land
//========================================================================= //=========================================================================

@ -222,13 +222,12 @@ namespace MWWorld
const ESM::LandTexture *search(size_t index, size_t plugin) const; const ESM::LandTexture *search(size_t index, size_t plugin) const;
const ESM::LandTexture *find(size_t index, size_t plugin) const; const ESM::LandTexture *find(size_t index, size_t plugin) const;
/// Resize the internal store to hold at least \a num plugins. /// Resize the internal store to hold another plugin.
void resize(size_t num); void addPlugin() { mStatic.emplace_back(); }
size_t getSize() const override; size_t getSize() const override;
size_t getSize(size_t plugin) const; size_t getSize(size_t plugin) const;
RecordId load(ESM::ESMReader &esm, size_t plugin);
RecordId load(ESM::ESMReader &esm) override; RecordId load(ESM::ESMReader &esm) override;
iterator begin(size_t plugin) const; iterator begin(size_t plugin) const;

@ -15,7 +15,6 @@ namespace ESM
: mFlags(0) : mFlags(0)
, mX(0) , mX(0)
, mY(0) , mY(0)
, mPlugin(0)
, mDataTypes(0) , mDataTypes(0)
, mLandData(nullptr) , mLandData(nullptr)
{ {
@ -40,8 +39,6 @@ namespace ESM
{ {
isDeleted = false; isDeleted = false;
mPlugin = esm.getIndex();
bool hasLocation = false; bool hasLocation = false;
bool isLoaded = false; bool isLoaded = false;
while (!isLoaded && esm.hasMoreSubs()) while (!isLoaded && esm.hasMoreSubs())
@ -192,7 +189,7 @@ namespace ESM
void Land::blank() void Land::blank()
{ {
mPlugin = 0; setPlugin(0);
std::fill(std::begin(mWnam), std::end(mWnam), 0); std::fill(std::begin(mWnam), std::end(mWnam), 0);
@ -326,7 +323,7 @@ namespace ESM
} }
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),
mContext (land.mContext), mDataTypes (land.mDataTypes), mContext (land.mContext), mDataTypes (land.mDataTypes),
mLandData (land.mLandData ? new LandData (*land.mLandData) : nullptr) mLandData (land.mLandData ? new LandData (*land.mLandData) : nullptr)
{ {
@ -345,7 +342,6 @@ namespace ESM
std::swap (mFlags, land.mFlags); std::swap (mFlags, land.mFlags);
std::swap (mX, land.mX); std::swap (mX, land.mX);
std::swap (mY, land.mY); std::swap (mY, land.mY);
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 (mLandData, land.mLandData); std::swap (mLandData, land.mLandData);

@ -29,7 +29,10 @@ struct Land
int mFlags; // Only first four bits seem to be used, don't know what int mFlags; // Only first four bits seem to be used, don't know what
// they mean. // they mean.
int mX, mY; // Map coordinates. int mX, mY; // Map coordinates.
int mPlugin; // Plugin index, used to reference the correct material palette.
// Plugin index, used to reference the correct material palette.
int getPlugin() const { return mContext.index; }
void setPlugin(int index) { mContext.index = index; }
// File context. This allows the ESM reader to be 'reset' to this // File context. This allows the ESM reader to be 'reset' to this
// location later when we are ready to load the full data set. // location later when we are ready to load the full data set.

@ -36,11 +36,7 @@ namespace ESMTerrain
return nullptr; return nullptr;
return &mData; return &mData;
} }
inline int getPlugin() const { return mLand->getPlugin(); }
inline int getPlugin() const
{
return mLand->mPlugin;
}
private: private:
const ESM::Land* mLand; const ESM::Land* mLand;

Loading…
Cancel
Save