mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 21:49:55 +00:00
Merge branch 'esmcleanup' into 'master'
Minor ESM code cleanup See merge request OpenMW/openmw!825
This commit is contained in:
commit
6263ade01a
5 changed files with 12 additions and 38 deletions
|
@ -97,13 +97,6 @@ void ESMReader::open(const std::string &file)
|
|||
open (Files::openConstrainedFileStream (file.c_str ()), file);
|
||||
}
|
||||
|
||||
int64_t ESMReader::getHNLong(const char *name)
|
||||
{
|
||||
int64_t val;
|
||||
getHNT(val, name);
|
||||
return val;
|
||||
}
|
||||
|
||||
std::string ESMReader::getHNOString(const char* name)
|
||||
{
|
||||
if (isNextSub(name))
|
||||
|
@ -215,18 +208,6 @@ void ESMReader::getSubName()
|
|||
mCtx.leftRec -= subNameSize;
|
||||
}
|
||||
|
||||
bool ESMReader::isEmptyOrGetName()
|
||||
{
|
||||
if (mCtx.leftRec)
|
||||
{
|
||||
const size_t subNameSize = mCtx.subName.data_size();
|
||||
getExact(mCtx.subName.rw_data(), subNameSize);
|
||||
mCtx.leftRec -= subNameSize;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ESMReader::skipHSub()
|
||||
{
|
||||
getSubHeader();
|
||||
|
@ -343,7 +324,7 @@ std::string ESMReader::getString(int size)
|
|||
mBuffer[s] = 0;
|
||||
|
||||
// read ESM data
|
||||
char *ptr = &mBuffer[0];
|
||||
char *ptr = mBuffer.data();
|
||||
getExact(ptr, size);
|
||||
|
||||
size = strnlen(ptr, size);
|
||||
|
|
|
@ -128,8 +128,6 @@ public:
|
|||
getHT(x);
|
||||
}
|
||||
|
||||
int64_t getHNLong(const char *name);
|
||||
|
||||
// Get data of a given type/size, including subrecord header
|
||||
template <typename X>
|
||||
void getHT(X &x)
|
||||
|
@ -193,9 +191,6 @@ public:
|
|||
// slightly.
|
||||
void getSubName();
|
||||
|
||||
// This is specially optimized for LoadINFO.
|
||||
bool isEmptyOrGetName();
|
||||
|
||||
// Skip current sub record, including header (but not including
|
||||
// name.)
|
||||
void skipHSub();
|
||||
|
|
|
@ -13,8 +13,7 @@ void ESM::GlobalScript::load (ESMReader &esm)
|
|||
esm.getHNOT (mRunning, "RUN_");
|
||||
|
||||
mTargetRef.unset();
|
||||
if (esm.peekNextSub("TARG"))
|
||||
mTargetId = esm.getHNString ("TARG");
|
||||
mTargetId = esm.getHNOString ("TARG");
|
||||
if (esm.peekNextSub("FRMR"))
|
||||
mTargetRef.load(esm, true, "FRMR");
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ void ESM::Header::load (ESMReader &esm)
|
|||
{
|
||||
MasterData m;
|
||||
m.name = esm.getHString();
|
||||
m.size = esm.getHNLong ("DATA");
|
||||
esm.getHNT(m.size, "DATA");
|
||||
mMaster.push_back (m);
|
||||
}
|
||||
|
||||
|
@ -54,14 +54,14 @@ void ESM::Header::load (ESMReader &esm)
|
|||
esm.getSubHeader();
|
||||
mSCRD.resize(esm.getSubSize());
|
||||
if (!mSCRD.empty())
|
||||
esm.getExact(&mSCRD[0], mSCRD.size());
|
||||
esm.getExact(mSCRD.data(), mSCRD.size());
|
||||
}
|
||||
if (esm.isNextSub("SCRS"))
|
||||
{
|
||||
esm.getSubHeader();
|
||||
mSCRS.resize(esm.getSubSize());
|
||||
if (!mSCRS.empty())
|
||||
esm.getExact(&mSCRS[0], mSCRS.size());
|
||||
esm.getExact(mSCRS.data(), mSCRS.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,10 +78,9 @@ void ESM::Header::save (ESMWriter &esm)
|
|||
esm.writeT(mData.records);
|
||||
esm.endRecord("HEDR");
|
||||
|
||||
for (std::vector<Header::MasterData>::iterator iter = mMaster.begin();
|
||||
iter != mMaster.end(); ++iter)
|
||||
for (const Header::MasterData& data : mMaster)
|
||||
{
|
||||
esm.writeHNCString ("MAST", iter->name);
|
||||
esm.writeHNT ("DATA", iter->size);
|
||||
esm.writeHNCString ("MAST", data.name);
|
||||
esm.writeHNT ("DATA", data.size);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,15 +31,15 @@ namespace ESM
|
|||
esm.getHNT(mNextWeather, nextWeatherRecord);
|
||||
esm.getHNT(mQueuedWeather, queuedWeatherRecord);
|
||||
|
||||
while(esm.peekNextSub(regionNameRecord))
|
||||
while (esm.isNextSub(regionNameRecord))
|
||||
{
|
||||
std::string regionID = esm.getHNString(regionNameRecord);
|
||||
std::string regionID = esm.getHString();
|
||||
RegionWeatherState region;
|
||||
esm.getHNT(region.mWeather, regionWeatherRecord);
|
||||
while(esm.peekNextSub(regionChanceRecord))
|
||||
while (esm.isNextSub(regionChanceRecord))
|
||||
{
|
||||
char chance;
|
||||
esm.getHNT(chance, regionChanceRecord);
|
||||
esm.getHT(chance);
|
||||
region.mChances.push_back(chance);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue