mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 07:23:51 +00:00
Merge pull request #2756 from elsid/write_hnt_arrays
Use template specialization for writeHNT to write raw arrays
This commit is contained in:
commit
3a1b2307ce
4 changed files with 26 additions and 14 deletions
|
@ -356,7 +356,7 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
|
|||
istream >> ignore >> moved.mTarget[0] >> moved.mTarget[1];
|
||||
|
||||
refRecord.mRefNum.save (writer, false, "MVRF");
|
||||
writer.writeHNT ("CNDT", moved.mTarget, 8);
|
||||
writer.writeHNT ("CNDT", moved.mTarget);
|
||||
}
|
||||
|
||||
refRecord.save (writer, false, false, ref.mState == CSMWorld::RecordBase::State_Deleted);
|
||||
|
|
|
@ -82,17 +82,23 @@ class ESMWriter
|
|||
endRecord(name);
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename T, std::size_t size>
|
||||
void writeHNT(const std::string& name, const T (&data)[size])
|
||||
{
|
||||
startSubRecord(name);
|
||||
writeT(data);
|
||||
endRecord(name);
|
||||
}
|
||||
|
||||
// Prevent using writeHNT with strings. This already happened by accident and results in
|
||||
// state being discarded without any error on writing or reading it. :(
|
||||
// writeHNString and friends must be used instead.
|
||||
void writeHNT(const std::string& name, const std::string& data)
|
||||
{
|
||||
}
|
||||
void writeT(const std::string& data)
|
||||
{
|
||||
}
|
||||
public:
|
||||
void writeHNT(const std::string& name, const std::string& data) = delete;
|
||||
|
||||
void writeT(const std::string& data) = delete;
|
||||
|
||||
template<typename T, std::size_t size>
|
||||
void writeHNT(const std::string& name, const T (&data)[size], int) = delete;
|
||||
|
||||
template<typename T>
|
||||
void writeHNT(const std::string& name, const T& data, int size)
|
||||
|
@ -108,6 +114,12 @@ public:
|
|||
write((char*)&data, sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T, std::size_t size>
|
||||
void writeT(const T (&data)[size])
|
||||
{
|
||||
write(reinterpret_cast<const char*>(data), size * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void writeT(const T& data, size_t size)
|
||||
{
|
||||
|
|
|
@ -127,7 +127,7 @@ namespace ESM
|
|||
if (mLandData)
|
||||
{
|
||||
if (mDataTypes & Land::DATA_VNML) {
|
||||
esm.writeHNT("VNML", mLandData->mNormals, sizeof(mLandData->mNormals));
|
||||
esm.writeHNT("VNML", mLandData->mNormals);
|
||||
}
|
||||
if (mDataTypes & Land::DATA_VHGT) {
|
||||
VHGT offsets;
|
||||
|
@ -175,18 +175,18 @@ namespace ESM
|
|||
wnam[row * LAND_GLOBAL_MAP_LOD_SIZE_SQRT + col] = static_cast<signed char>(height);
|
||||
}
|
||||
}
|
||||
esm.writeHNT("WNAM", wnam, 81);
|
||||
esm.writeHNT("WNAM", wnam);
|
||||
}
|
||||
|
||||
if (mLandData)
|
||||
{
|
||||
if (mDataTypes & Land::DATA_VCLR) {
|
||||
esm.writeHNT("VCLR", mLandData->mColours, 3*LAND_NUM_VERTS);
|
||||
esm.writeHNT("VCLR", mLandData->mColours);
|
||||
}
|
||||
if (mDataTypes & Land::DATA_VTEX) {
|
||||
uint16_t vtex[LAND_NUM_TEXTURES];
|
||||
transposeTextureData(mLandData->mTextures, vtex);
|
||||
esm.writeHNT("VTEX", vtex, sizeof(vtex));
|
||||
esm.writeHNT("VTEX", vtex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ void ESM::Player::save (ESMWriter &esm) const
|
|||
|
||||
mCellId.save (esm);
|
||||
|
||||
esm.writeHNT ("LKEP", mLastKnownExteriorPosition, 12);
|
||||
esm.writeHNT ("LKEP", mLastKnownExteriorPosition);
|
||||
|
||||
if (mHasMark)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue