diff --git a/components/esm3/loadland.cpp b/components/esm3/loadland.cpp index 1cf5074161..ba04e11dcf 100644 --- a/components/esm3/loadland.cpp +++ b/components/esm3/loadland.cpp @@ -38,11 +38,6 @@ namespace ESM } } - Land::~Land() - { - delete mLandData; - } - void Land::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -204,8 +199,8 @@ namespace ESM std::fill(std::begin(mWnam), std::end(mWnam), 0); - if (!mLandData) - mLandData = new LandData; + if (mLandData == nullptr) + mLandData = std::make_unique(); mLandData->mHeightOffset = 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 { // Create storage if nothing is loaded - if (!target && !mLandData) - { - mLandData = new LandData; - } + if (target == nullptr && mLandData == nullptr) + mLandData = std::make_unique(); - if (!target) - target = mLandData; + if (target == nullptr) + target = mLandData.get(); // Try to load only available data flags = flags & mDataTypes; @@ -252,7 +245,7 @@ namespace ESM if (mContext.filename.empty()) { // 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; return; @@ -318,11 +311,7 @@ namespace ESM void Land::unloadData() const { - if (mLandData) - { - delete mLandData; - mLandData = nullptr; - } + mLandData = nullptr; } bool Land::isDataLoaded(int flags) const @@ -336,7 +325,7 @@ namespace ESM , mY(land.mY) , mContext(land.mContext) , mDataTypes(land.mDataTypes) - , mLandData(land.mLandData ? new LandData(*land.mLandData) : nullptr) + , mLandData(land.mLandData != nullptr ? std::make_unique(*land.mLandData) : nullptr) { std::copy(land.mWnam, land.mWnam + LAND_GLOBAL_MAP_LOD_SIZE, mWnam); } @@ -365,13 +354,13 @@ namespace ESM return nullptr; loadData(flags); - return mLandData; + return mLandData.get(); } void Land::add(int flags) { - if (!mLandData) - mLandData = new LandData; + if (mLandData == nullptr) + mLandData = std::make_unique(); mDataTypes |= flags; mLandData->mDataLoaded |= flags; diff --git a/components/esm3/loadland.hpp b/components/esm3/loadland.hpp index e95e30c8f1..e0dbca8400 100644 --- a/components/esm3/loadland.hpp +++ b/components/esm3/loadland.hpp @@ -2,6 +2,7 @@ #define OPENMW_ESM_LAND_H #include +#include #include @@ -26,7 +27,6 @@ namespace ESM static std::string_view getRecordType() { return "Land"; } Land() = default; - ~Land(); // Only first four bits seem to be used, don't know what they mean. std::uint32_t mFlags = 0; @@ -152,13 +152,13 @@ namespace ESM /// Return land data without loading first anything. Can return a 0-pointer. const LandData* getLandData() const { - return mLandData; + return mLandData.get(); } /// Return land data without loading first anything. Can return a 0-pointer. LandData* getLandData() { - return mLandData; + return mLandData.get(); } /// \attention Must not be called on objects that aren't fully loaded. @@ -167,7 +167,7 @@ namespace ESM void add(int flags); private: - mutable LandData* mLandData = nullptr; + mutable std::unique_ptr mLandData; }; }