1
0
Fork 1
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:
psi29a 2021-05-07 06:47:45 +00:00
commit 6263ade01a
5 changed files with 12 additions and 38 deletions

View file

@ -97,13 +97,6 @@ void ESMReader::open(const std::string &file)
open (Files::openConstrainedFileStream (file.c_str ()), 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) std::string ESMReader::getHNOString(const char* name)
{ {
if (isNextSub(name)) if (isNextSub(name))
@ -215,18 +208,6 @@ void ESMReader::getSubName()
mCtx.leftRec -= subNameSize; 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() void ESMReader::skipHSub()
{ {
getSubHeader(); getSubHeader();
@ -343,7 +324,7 @@ std::string ESMReader::getString(int size)
mBuffer[s] = 0; mBuffer[s] = 0;
// read ESM data // read ESM data
char *ptr = &mBuffer[0]; char *ptr = mBuffer.data();
getExact(ptr, size); getExact(ptr, size);
size = strnlen(ptr, size); size = strnlen(ptr, size);

View file

@ -128,8 +128,6 @@ public:
getHT(x); getHT(x);
} }
int64_t getHNLong(const char *name);
// Get data of a given type/size, including subrecord header // Get data of a given type/size, including subrecord header
template <typename X> template <typename X>
void getHT(X &x) void getHT(X &x)
@ -193,9 +191,6 @@ public:
// slightly. // slightly.
void getSubName(); void getSubName();
// This is specially optimized for LoadINFO.
bool isEmptyOrGetName();
// Skip current sub record, including header (but not including // Skip current sub record, including header (but not including
// name.) // name.)
void skipHSub(); void skipHSub();

View file

@ -13,8 +13,7 @@ void ESM::GlobalScript::load (ESMReader &esm)
esm.getHNOT (mRunning, "RUN_"); esm.getHNOT (mRunning, "RUN_");
mTargetRef.unset(); mTargetRef.unset();
if (esm.peekNextSub("TARG")) mTargetId = esm.getHNOString ("TARG");
mTargetId = esm.getHNString ("TARG");
if (esm.peekNextSub("FRMR")) if (esm.peekNextSub("FRMR"))
mTargetRef.load(esm, true, "FRMR"); mTargetRef.load(esm, true, "FRMR");
} }

View file

@ -41,7 +41,7 @@ void ESM::Header::load (ESMReader &esm)
{ {
MasterData m; MasterData m;
m.name = esm.getHString(); m.name = esm.getHString();
m.size = esm.getHNLong ("DATA"); esm.getHNT(m.size, "DATA");
mMaster.push_back (m); mMaster.push_back (m);
} }
@ -54,14 +54,14 @@ void ESM::Header::load (ESMReader &esm)
esm.getSubHeader(); esm.getSubHeader();
mSCRD.resize(esm.getSubSize()); mSCRD.resize(esm.getSubSize());
if (!mSCRD.empty()) if (!mSCRD.empty())
esm.getExact(&mSCRD[0], mSCRD.size()); esm.getExact(mSCRD.data(), mSCRD.size());
} }
if (esm.isNextSub("SCRS")) if (esm.isNextSub("SCRS"))
{ {
esm.getSubHeader(); esm.getSubHeader();
mSCRS.resize(esm.getSubSize()); mSCRS.resize(esm.getSubSize());
if (!mSCRS.empty()) 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.writeT(mData.records);
esm.endRecord("HEDR"); esm.endRecord("HEDR");
for (std::vector<Header::MasterData>::iterator iter = mMaster.begin(); for (const Header::MasterData& data : mMaster)
iter != mMaster.end(); ++iter)
{ {
esm.writeHNCString ("MAST", iter->name); esm.writeHNCString ("MAST", data.name);
esm.writeHNT ("DATA", iter->size); esm.writeHNT ("DATA", data.size);
} }
} }

View file

@ -31,15 +31,15 @@ namespace ESM
esm.getHNT(mNextWeather, nextWeatherRecord); esm.getHNT(mNextWeather, nextWeatherRecord);
esm.getHNT(mQueuedWeather, queuedWeatherRecord); 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; RegionWeatherState region;
esm.getHNT(region.mWeather, regionWeatherRecord); esm.getHNT(region.mWeather, regionWeatherRecord);
while(esm.peekNextSub(regionChanceRecord)) while (esm.isNextSub(regionChanceRecord))
{ {
char chance; char chance;
esm.getHNT(chance, regionChanceRecord); esm.getHT(chance);
region.mChances.push_back(chance); region.mChances.push_back(chance);
} }