mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-05 06:40:09 +00:00
Use unique_ptr to store LandData in ESM::Land
This commit is contained in:
parent
d0f8ab5767
commit
c88e9dee27
@ -38,11 +38,6 @@ namespace ESM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Land::~Land()
|
|
||||||
{
|
|
||||||
delete mLandData;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Land::load(ESMReader& esm, bool& isDeleted)
|
void Land::load(ESMReader& esm, bool& isDeleted)
|
||||||
{
|
{
|
||||||
isDeleted = false;
|
isDeleted = false;
|
||||||
@ -204,8 +199,8 @@ namespace ESM
|
|||||||
|
|
||||||
std::fill(std::begin(mWnam), std::end(mWnam), 0);
|
std::fill(std::begin(mWnam), std::end(mWnam), 0);
|
||||||
|
|
||||||
if (!mLandData)
|
if (mLandData == nullptr)
|
||||||
mLandData = new LandData;
|
mLandData = std::make_unique<LandData>();
|
||||||
|
|
||||||
mLandData->mHeightOffset = 0;
|
mLandData->mHeightOffset = 0;
|
||||||
std::fill(std::begin(mLandData->mHeights), std::end(mLandData->mHeights), 0);
|
std::fill(std::begin(mLandData->mHeights), std::end(mLandData->mHeights), 0);
|
||||||
@ -232,13 +227,11 @@ namespace ESM
|
|||||||
void Land::loadData(int flags, LandData* target) const
|
void Land::loadData(int flags, LandData* target) const
|
||||||
{
|
{
|
||||||
// Create storage if nothing is loaded
|
// Create storage if nothing is loaded
|
||||||
if (!target && !mLandData)
|
if (target == nullptr && mLandData == nullptr)
|
||||||
{
|
mLandData = std::make_unique<LandData>();
|
||||||
mLandData = new LandData;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!target)
|
if (target == nullptr)
|
||||||
target = mLandData;
|
target = mLandData.get();
|
||||||
|
|
||||||
// Try to load only available data
|
// Try to load only available data
|
||||||
flags = flags & mDataTypes;
|
flags = flags & mDataTypes;
|
||||||
@ -252,7 +245,7 @@ namespace ESM
|
|||||||
if (mContext.filename.empty())
|
if (mContext.filename.empty())
|
||||||
{
|
{
|
||||||
// Make sure there is data, and that it doesn't point to the same object.
|
// Make sure there is data, and that it doesn't point to the same object.
|
||||||
if (mLandData && mLandData != target)
|
if (mLandData != nullptr && mLandData.get() != target)
|
||||||
*target = *mLandData;
|
*target = *mLandData;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -318,11 +311,7 @@ namespace ESM
|
|||||||
|
|
||||||
void Land::unloadData() const
|
void Land::unloadData() const
|
||||||
{
|
{
|
||||||
if (mLandData)
|
mLandData = nullptr;
|
||||||
{
|
|
||||||
delete mLandData;
|
|
||||||
mLandData = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Land::isDataLoaded(int flags) const
|
bool Land::isDataLoaded(int flags) const
|
||||||
@ -336,7 +325,7 @@ namespace ESM
|
|||||||
, mY(land.mY)
|
, mY(land.mY)
|
||||||
, mContext(land.mContext)
|
, mContext(land.mContext)
|
||||||
, mDataTypes(land.mDataTypes)
|
, mDataTypes(land.mDataTypes)
|
||||||
, mLandData(land.mLandData ? new LandData(*land.mLandData) : nullptr)
|
, mLandData(land.mLandData != nullptr ? std::make_unique<LandData>(*land.mLandData) : nullptr)
|
||||||
{
|
{
|
||||||
std::copy(land.mWnam, land.mWnam + LAND_GLOBAL_MAP_LOD_SIZE, mWnam);
|
std::copy(land.mWnam, land.mWnam + LAND_GLOBAL_MAP_LOD_SIZE, mWnam);
|
||||||
}
|
}
|
||||||
@ -365,13 +354,13 @@ namespace ESM
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
loadData(flags);
|
loadData(flags);
|
||||||
return mLandData;
|
return mLandData.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Land::add(int flags)
|
void Land::add(int flags)
|
||||||
{
|
{
|
||||||
if (!mLandData)
|
if (mLandData == nullptr)
|
||||||
mLandData = new LandData;
|
mLandData = std::make_unique<LandData>();
|
||||||
|
|
||||||
mDataTypes |= flags;
|
mDataTypes |= flags;
|
||||||
mLandData->mDataLoaded |= flags;
|
mLandData->mDataLoaded |= flags;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define OPENMW_ESM_LAND_H
|
#define OPENMW_ESM_LAND_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <components/misc/constants.hpp>
|
#include <components/misc/constants.hpp>
|
||||||
|
|
||||||
@ -26,7 +27,6 @@ namespace ESM
|
|||||||
static std::string_view getRecordType() { return "Land"; }
|
static std::string_view getRecordType() { return "Land"; }
|
||||||
|
|
||||||
Land() = default;
|
Land() = default;
|
||||||
~Land();
|
|
||||||
|
|
||||||
// Only first four bits seem to be used, don't know what they mean.
|
// Only first four bits seem to be used, don't know what they mean.
|
||||||
std::uint32_t mFlags = 0;
|
std::uint32_t mFlags = 0;
|
||||||
@ -152,13 +152,13 @@ namespace ESM
|
|||||||
/// Return land data without loading first anything. Can return a 0-pointer.
|
/// Return land data without loading first anything. Can return a 0-pointer.
|
||||||
const LandData* getLandData() const
|
const LandData* getLandData() const
|
||||||
{
|
{
|
||||||
return mLandData;
|
return mLandData.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return land data without loading first anything. Can return a 0-pointer.
|
/// Return land data without loading first anything. Can return a 0-pointer.
|
||||||
LandData* getLandData()
|
LandData* getLandData()
|
||||||
{
|
{
|
||||||
return mLandData;
|
return mLandData.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \attention Must not be called on objects that aren't fully loaded.
|
/// \attention Must not be called on objects that aren't fully loaded.
|
||||||
@ -167,7 +167,7 @@ namespace ESM
|
|||||||
void add(int flags);
|
void add(int flags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable LandData* mLandData = nullptr;
|
mutable std::unique_ptr<LandData> mLandData;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user