Merge branch 'fix_fog_state_load' into 'master'

Fix loading fog state

See merge request OpenMW/openmw!2743
pull/3229/head
psi29a 2 years ago
commit 0ed1310417

@ -4,6 +4,8 @@
#include <iostream>
#include <sstream>
#include <components/esm3/cellstate.hpp>
#include <components/esm3/esmreader.hpp>
#include <components/misc/strings/format.hpp>
namespace
@ -213,11 +215,19 @@ namespace
std::cout << " Destination Cell: " << dest.mCellName << std::endl;
}
}
}
namespace EsmTool
{
void CellState::load(ESM::ESMReader& reader, bool& deleted)
{
mCellState.mId.load(reader);
mCellState.load(reader);
if (mCellState.mHasFogOfWar)
mFogState.load(reader);
deleted = false;
reader.skipRecord();
}
std::unique_ptr<RecordBase> RecordBase::create(const ESM::NAME type)
{
@ -435,6 +445,11 @@ namespace EsmTool
record = std::make_unique<EsmTool::Record<ESM::StartScript>>();
break;
}
case ESM::REC_CSTA:
{
record = std::make_unique<EsmTool::Record<CellState>>();
break;
}
default:
break;
}
@ -1339,6 +1354,38 @@ namespace EsmTool
std::cout << " Deleted: " << mIsDeleted << std::endl;
}
template <>
void Record<CellState>::print()
{
std::cout << " Id:" << std::endl;
std::cout << " Worldspace: " << mData.mCellState.mId.mWorldspace << std::endl;
std::cout << " Index:" << std::endl;
std::cout << " X: " << mData.mCellState.mId.mIndex.mX << std::endl;
std::cout << " Y: " << mData.mCellState.mId.mIndex.mY << std::endl;
std::cout << " Paged: " << mData.mCellState.mId.mPaged << std::endl;
std::cout << " WaterLevel: " << mData.mCellState.mWaterLevel << std::endl;
std::cout << " HasFogOfWar: " << mData.mCellState.mHasFogOfWar << std::endl;
std::cout << " LastRespawn:" << std::endl;
std::cout << " Day:" << mData.mCellState.mLastRespawn.mDay << std::endl;
std::cout << " Hour:" << mData.mCellState.mLastRespawn.mHour << std::endl;
if (mData.mCellState.mHasFogOfWar)
{
std::cout << " NorthMarkerAngle: " << mData.mFogState.mNorthMarkerAngle << std::endl;
std::cout << " Bounds:" << std::endl;
std::cout << " MinX: " << mData.mFogState.mBounds.mMinX << std::endl;
std::cout << " MinY: " << mData.mFogState.mBounds.mMinY << std::endl;
std::cout << " MaxX: " << mData.mFogState.mBounds.mMaxX << std::endl;
std::cout << " MaxY: " << mData.mFogState.mBounds.mMaxY << std::endl;
for (const ESM::FogTexture& fogTexture : mData.mFogState.mFogTextures)
{
std::cout << " FogTexture:" << std::endl;
std::cout << " X: " << fogTexture.mX << std::endl;
std::cout << " Y: " << fogTexture.mY << std::endl;
std::cout << " ImageData: (" << fogTexture.mImageData.size() << ")" << std::endl;
}
}
}
template <>
std::string Record<ESM::Cell>::getId() const
{
@ -1369,4 +1416,13 @@ namespace EsmTool
return std::string(); // No ID for Skill record
}
template <>
std::string Record<CellState>::getId() const
{
std::ostringstream stream;
stream << mData.mCellState.mId.mWorldspace << " " << mData.mCellState.mId.mIndex.mX << " "
<< mData.mCellState.mId.mIndex.mY << " " << mData.mCellState.mId.mPaged;
return stream.str();
}
} // end namespace

@ -5,6 +5,8 @@
#include <string>
#include <components/esm/records.hpp>
#include <components/esm3/cellstate.hpp>
#include <components/esm3/fogstate.hpp>
namespace ESM
{
@ -58,6 +60,16 @@ namespace EsmTool
}
};
struct CellState
{
ESM::CellState mCellState;
ESM::FogState mFogState;
void load(ESM::ESMReader& reader, bool& deleted);
void save(ESM::ESMWriter& /*writer*/, bool /*deleted*/) {}
};
template <class T>
class Record : public RecordBase
{
@ -91,6 +103,8 @@ namespace EsmTool
std::string Record<ESM::Pathgrid>::getId() const;
template <>
std::string Record<ESM::Skill>::getId() const;
template <>
std::string Record<CellState>::getId() const;
template <>
void Record<ESM::Activator>::print();
@ -176,6 +190,8 @@ namespace EsmTool
void Record<ESM::Static>::print();
template <>
void Record<ESM::Weapon>::print();
template <>
void Record<CellState>::print();
}
#endif

@ -69,9 +69,9 @@ namespace ESM
esm.getT(tex.mX);
esm.getT(tex.mY);
size_t imageSize = esm.getSubSize() - sizeof(int) * 2;
const std::size_t imageSize = esm.getSubSize() - sizeof(int) * 2;
tex.mImageData.resize(imageSize);
esm.getExact(&tex.mImageData[0], imageSize);
esm.getExact(tex.mImageData.data(), imageSize);
if (dataFormat <= MaxOldForOfWarFormatVersion)
convertFogOfWar(tex.mImageData);
@ -92,7 +92,7 @@ namespace ESM
esm.startSubRecord("FTEX");
esm.writeT(it->mX);
esm.writeT(it->mY);
esm.write(&it->mImageData[0], it->mImageData.size());
esm.write(it->mImageData.data(), it->mImageData.size());
esm.endRecord("FTEX");
}
}

Loading…
Cancel
Save