1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 03:59:56 +00:00

Split ESM::Land::loadData

This commit is contained in:
elsid 2023-08-12 15:04:44 +02:00
parent a027cd898b
commit 955790dc31
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
4 changed files with 35 additions and 37 deletions

View file

@ -206,7 +206,7 @@ namespace NavMeshTool
ESM::Land::DEFAULT_HEIGHT };
ESM::Land::LandData& landData = *landDatas.emplace_back(std::make_unique<ESM::Land::LandData>());
land->loadData(ESM::Land::DATA_VHGT, &landData);
land->loadData(ESM::Land::DATA_VHGT, landData);
heightfields.push_back(std::vector<float>(std::begin(landData.mHeights), std::end(landData.mHeights)));
HeightfieldSurface surface;
surface.mHeights = heightfields.back().data();

View file

@ -9,7 +9,7 @@ ESM::LandData::LandData(const ESM::Land& land, int loadFlags)
, mPlugin(land.getPlugin())
{
ESM::Land::LandData data;
land.loadData(loadFlags, &data);
land.loadData(loadFlags, data);
mLoadFlags = data.mDataLoaded;
std::span<const float> heights(data.mHeights);
mHeights = std::vector(heights.begin(), heights.end());

View file

@ -227,29 +227,29 @@ namespace ESM
mContext.filename.clear();
}
void Land::loadData(int flags, LandData* target) const
void Land::loadData(int flags) const
{
// Create storage if nothing is loaded
if (target == nullptr && mLandData == nullptr)
if (mLandData == nullptr)
mLandData = std::make_unique<LandData>();
if (target == nullptr)
target = mLandData.get();
loadData(flags, *mLandData);
}
void Land::loadData(int flags, LandData& data) const
{
// Try to load only available data
flags = flags & mDataTypes;
// Return if all required data is loaded
if ((target->mDataLoaded & flags) == flags)
if ((data.mDataLoaded & flags) == flags)
{
return;
}
// Copy data to target if no file
if (mContext.filename.empty())
{
// Make sure there is data, and that it doesn't point to the same object.
if (mLandData != nullptr && mLandData.get() != target)
*target = *mLandData;
if (mLandData != nullptr && mLandData.get() != &data)
data = *mLandData;
return;
}
@ -259,41 +259,41 @@ namespace ESM
if (reader.isNextSub("VNML"))
{
condLoad(reader, flags, target->mDataLoaded, DATA_VNML, target->mNormals, sizeof(target->mNormals));
condLoad(reader, flags, data.mDataLoaded, DATA_VNML, data.mNormals, sizeof(data.mNormals));
}
if (reader.isNextSub("VHGT"))
{
VHGT vhgt;
if (condLoad(reader, flags, target->mDataLoaded, DATA_VHGT, &vhgt, sizeof(vhgt)))
if (condLoad(reader, flags, data.mDataLoaded, DATA_VHGT, &vhgt, sizeof(vhgt)))
{
target->mMinHeight = std::numeric_limits<float>::max();
target->mMaxHeight = -std::numeric_limits<float>::max();
data.mMinHeight = std::numeric_limits<float>::max();
data.mMaxHeight = -std::numeric_limits<float>::max();
float rowOffset = vhgt.mHeightOffset;
for (int y = 0; y < LAND_SIZE; y++)
{
rowOffset += vhgt.mHeightData[y * LAND_SIZE];
target->mHeights[y * LAND_SIZE] = rowOffset * HEIGHT_SCALE;
if (rowOffset * HEIGHT_SCALE > target->mMaxHeight)
target->mMaxHeight = rowOffset * HEIGHT_SCALE;
if (rowOffset * HEIGHT_SCALE < target->mMinHeight)
target->mMinHeight = rowOffset * HEIGHT_SCALE;
data.mHeights[y * LAND_SIZE] = rowOffset * HEIGHT_SCALE;
if (rowOffset * HEIGHT_SCALE > data.mMaxHeight)
data.mMaxHeight = rowOffset * HEIGHT_SCALE;
if (rowOffset * HEIGHT_SCALE < data.mMinHeight)
data.mMinHeight = rowOffset * HEIGHT_SCALE;
float colOffset = rowOffset;
for (int x = 1; x < LAND_SIZE; x++)
{
colOffset += vhgt.mHeightData[y * LAND_SIZE + x];
target->mHeights[x + y * LAND_SIZE] = colOffset * HEIGHT_SCALE;
data.mHeights[x + y * LAND_SIZE] = colOffset * HEIGHT_SCALE;
if (colOffset * HEIGHT_SCALE > target->mMaxHeight)
target->mMaxHeight = colOffset * HEIGHT_SCALE;
if (colOffset * HEIGHT_SCALE < target->mMinHeight)
target->mMinHeight = colOffset * HEIGHT_SCALE;
if (colOffset * HEIGHT_SCALE > data.mMaxHeight)
data.mMaxHeight = colOffset * HEIGHT_SCALE;
if (colOffset * HEIGHT_SCALE < data.mMinHeight)
data.mMinHeight = colOffset * HEIGHT_SCALE;
}
}
target->mUnk1 = vhgt.mUnk1;
target->mUnk2 = vhgt.mUnk2;
data.mUnk1 = vhgt.mUnk1;
data.mUnk2 = vhgt.mUnk2;
}
}
@ -301,18 +301,18 @@ namespace ESM
reader.skipHSub();
if (reader.isNextSub("VCLR"))
condLoad(reader, flags, target->mDataLoaded, DATA_VCLR, target->mColours, 3 * LAND_NUM_VERTS);
condLoad(reader, flags, data.mDataLoaded, DATA_VCLR, data.mColours, 3 * LAND_NUM_VERTS);
if (reader.isNextSub("VTEX"))
{
uint16_t vtex[LAND_NUM_TEXTURES];
if (condLoad(reader, flags, target->mDataLoaded, DATA_VTEX, vtex, sizeof(vtex)))
if (condLoad(reader, flags, data.mDataLoaded, DATA_VTEX, vtex, sizeof(vtex)))
{
transposeTextureData(vtex, target->mTextures);
transposeTextureData(vtex, data.mTextures);
}
}
}
void Land::unloadData() const
void Land::unloadData()
{
mLandData = nullptr;
}

View file

@ -133,16 +133,14 @@ namespace ESM
void blank();
/**
* Actually loads data into target
* If target is nullptr, assumed target is mLandData
*/
void loadData(int flags, LandData* target = nullptr) const;
void loadData(int flags) const;
void loadData(int flags, LandData& data) const;
/**
* Frees memory allocated for mLandData
*/
void unloadData() const;
void unloadData();
/// Check if given data type is loaded
bool isDataLoaded(int flags) const;