mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 20:09:43 +00:00
Store CustomData and ContainerStore as unique_ptr
This commit is contained in:
parent
86719c26b3
commit
045bb7cbd7
11 changed files with 52 additions and 48 deletions
|
@ -46,9 +46,9 @@ namespace MWClass
|
|||
mStore.readState(inventory);
|
||||
}
|
||||
|
||||
MWWorld::CustomData *ContainerCustomData::clone() const
|
||||
std::unique_ptr<MWWorld::CustomData> ContainerCustomData::clone() const
|
||||
{
|
||||
return new ContainerCustomData (*this);
|
||||
return std::make_unique<ContainerCustomData>(*this);
|
||||
}
|
||||
|
||||
ContainerCustomData& ContainerCustomData::asContainerCustomData()
|
||||
|
@ -72,7 +72,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
||||
|
||||
// store
|
||||
ptr.getRefData().setCustomData (std::make_unique<ContainerCustomData>(*ref->mBase, ptr.getCell()).release());
|
||||
ptr.getRefData().setCustomData (std::make_unique<ContainerCustomData>(*ref->mBase, ptr.getCell()));
|
||||
|
||||
MWBase::Environment::get().getWorld()->addContainerScripts(ptr, ptr.getCell());
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ namespace MWClass
|
|||
return;
|
||||
|
||||
const ESM::ContainerState& containerState = state.asContainerState();
|
||||
ptr.getRefData().setCustomData(std::make_unique<ContainerCustomData>(containerState.mInventory).release());
|
||||
ptr.getRefData().setCustomData(std::make_unique<ContainerCustomData>(containerState.mInventory));
|
||||
}
|
||||
|
||||
void Container::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace MWClass
|
|||
ContainerCustomData(const ESM::Container& container, MWWorld::CellStore* cell);
|
||||
ContainerCustomData(const ESM::InventoryState& inventory);
|
||||
|
||||
MWWorld::CustomData *clone() const override;
|
||||
std::unique_ptr<MWWorld::CustomData> clone() const override;
|
||||
|
||||
ContainerCustomData& asContainerCustomData() override;
|
||||
const ContainerCustomData& asContainerCustomData() const override;
|
||||
|
|
|
@ -55,10 +55,14 @@ namespace MWClass
|
|||
{
|
||||
public:
|
||||
MWMechanics::CreatureStats mCreatureStats;
|
||||
MWWorld::ContainerStore* mContainerStore; // may be InventoryStore for some creatures
|
||||
std::unique_ptr<MWWorld::ContainerStore> mContainerStore; // may be InventoryStore for some creatures
|
||||
MWMechanics::Movement mMovement;
|
||||
|
||||
MWWorld::CustomData *clone() const override;
|
||||
CreatureCustomData() = default;
|
||||
CreatureCustomData(const CreatureCustomData& other);
|
||||
CreatureCustomData(CreatureCustomData&& other) noexcept = default;
|
||||
|
||||
std::unique_ptr<MWWorld::CustomData> clone() const override;
|
||||
|
||||
CreatureCustomData& asCreatureCustomData() override
|
||||
{
|
||||
|
@ -68,16 +72,18 @@ namespace MWClass
|
|||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
CreatureCustomData() : mContainerStore(nullptr) {}
|
||||
virtual ~CreatureCustomData() { delete mContainerStore; }
|
||||
};
|
||||
|
||||
MWWorld::CustomData *CreatureCustomData::clone() const
|
||||
CreatureCustomData::CreatureCustomData(const CreatureCustomData& other)
|
||||
: mCreatureStats(other.mCreatureStats),
|
||||
mContainerStore(other.mContainerStore->clone()),
|
||||
mMovement(other.mMovement)
|
||||
{
|
||||
CreatureCustomData* cloned = new CreatureCustomData (*this);
|
||||
cloned->mContainerStore = mContainerStore->clone();
|
||||
return cloned;
|
||||
}
|
||||
|
||||
std::unique_ptr<MWWorld::CustomData> CreatureCustomData::clone() const
|
||||
{
|
||||
return std::make_unique<CreatureCustomData>(*this);
|
||||
}
|
||||
|
||||
const Creature::GMST& Creature::getGmst()
|
||||
|
@ -148,16 +154,16 @@ namespace MWClass
|
|||
// inventory
|
||||
bool hasInventory = hasInventoryStore(ptr);
|
||||
if (hasInventory)
|
||||
data->mContainerStore = new MWWorld::InventoryStore();
|
||||
data->mContainerStore = std::make_unique<MWWorld::InventoryStore>();
|
||||
else
|
||||
data->mContainerStore = new MWWorld::ContainerStore();
|
||||
data->mContainerStore = std::make_unique<MWWorld::ContainerStore>();
|
||||
|
||||
data->mCreatureStats.setGoldPool(ref->mBase->mData.mGold);
|
||||
|
||||
data->mCreatureStats.setNeedRecalcDynamicStats(false);
|
||||
|
||||
// store
|
||||
ptr.getRefData().setCustomData(data.release());
|
||||
ptr.getRefData().setCustomData(std::move(data));
|
||||
|
||||
getContainerStore(ptr).fill(ref->mBase->mInventory, ptr.getCellRef().getRefId());
|
||||
|
||||
|
@ -758,11 +764,11 @@ namespace MWClass
|
|||
std::unique_ptr<CreatureCustomData> data (new CreatureCustomData);
|
||||
|
||||
if (hasInventoryStore(ptr))
|
||||
data->mContainerStore = new MWWorld::InventoryStore();
|
||||
data->mContainerStore = std::make_unique<MWWorld::InventoryStore>();
|
||||
else
|
||||
data->mContainerStore = new MWWorld::ContainerStore();
|
||||
data->mContainerStore = std::make_unique<MWWorld::ContainerStore>();
|
||||
|
||||
ptr.getRefData().setCustomData (data.release());
|
||||
ptr.getRefData().setCustomData (std::move(data));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace MWClass
|
|||
int mSpawnActorId;
|
||||
bool mSpawn; // Should a new creature be spawned?
|
||||
|
||||
MWWorld::CustomData *clone() const override;
|
||||
std::unique_ptr<MWWorld::CustomData> clone() const override;
|
||||
|
||||
CreatureLevListCustomData& asCreatureLevListCustomData() override
|
||||
{
|
||||
|
@ -29,9 +29,9 @@ namespace MWClass
|
|||
}
|
||||
};
|
||||
|
||||
MWWorld::CustomData *CreatureLevListCustomData::clone() const
|
||||
std::unique_ptr<MWWorld::CustomData> CreatureLevListCustomData::clone() const
|
||||
{
|
||||
return new CreatureLevListCustomData (*this);
|
||||
return std::make_unique<CreatureLevListCustomData>(*this);
|
||||
}
|
||||
|
||||
std::string CreatureLevList::getName (const MWWorld::ConstPtr& ptr) const
|
||||
|
@ -138,11 +138,11 @@ namespace MWClass
|
|||
{
|
||||
if (!ptr.getRefData().getCustomData())
|
||||
{
|
||||
std::unique_ptr<CreatureLevListCustomData> data (new CreatureLevListCustomData);
|
||||
std::unique_ptr<CreatureLevListCustomData> data = std::make_unique<CreatureLevListCustomData>();
|
||||
data->mSpawnActorId = -1;
|
||||
data->mSpawn = true;
|
||||
|
||||
ptr.getRefData().setCustomData(data.release());
|
||||
ptr.getRefData().setCustomData(std::move(data));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace MWClass
|
|||
public:
|
||||
MWWorld::DoorState mDoorState = MWWorld::DoorState::Idle;
|
||||
|
||||
MWWorld::CustomData *clone() const override;
|
||||
std::unique_ptr<MWWorld::CustomData> clone() const override;
|
||||
|
||||
DoorCustomData& asDoorCustomData() override
|
||||
{
|
||||
|
@ -48,9 +48,9 @@ namespace MWClass
|
|||
}
|
||||
};
|
||||
|
||||
MWWorld::CustomData *DoorCustomData::clone() const
|
||||
std::unique_ptr<MWWorld::CustomData> DoorCustomData::clone() const
|
||||
{
|
||||
return new DoorCustomData (*this);
|
||||
return std::make_unique<DoorCustomData>(*this);
|
||||
}
|
||||
|
||||
void Door::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
|
||||
|
@ -327,8 +327,7 @@ namespace MWClass
|
|||
{
|
||||
if (!ptr.getRefData().getCustomData())
|
||||
{
|
||||
std::unique_ptr<DoorCustomData> data(new DoorCustomData);
|
||||
ptr.getRefData().setCustomData(data.release());
|
||||
ptr.getRefData().setCustomData(std::make_unique<DoorCustomData>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -253,7 +253,7 @@ namespace MWClass
|
|||
MWMechanics::Movement mMovement;
|
||||
MWWorld::InventoryStore mInventoryStore;
|
||||
|
||||
MWWorld::CustomData *clone() const override;
|
||||
std::unique_ptr<MWWorld::CustomData> clone() const override;
|
||||
|
||||
NpcCustomData& asNpcCustomData() override
|
||||
{
|
||||
|
@ -265,9 +265,9 @@ namespace MWClass
|
|||
}
|
||||
};
|
||||
|
||||
MWWorld::CustomData *NpcCustomData::clone() const
|
||||
std::unique_ptr<MWWorld::CustomData> NpcCustomData::clone() const
|
||||
{
|
||||
return new NpcCustomData (*this);
|
||||
return std::make_unique<NpcCustomData>(*this);
|
||||
}
|
||||
|
||||
const Npc::GMST& Npc::getGmst()
|
||||
|
@ -397,7 +397,7 @@ namespace MWClass
|
|||
data->mNpcStats.setGoldPool(gold);
|
||||
|
||||
// store
|
||||
ptr.getRefData().setCustomData (data.release());
|
||||
ptr.getRefData().setCustomData(std::move(data));
|
||||
|
||||
getInventoryStore(ptr).autoEquip(ptr);
|
||||
}
|
||||
|
@ -1302,8 +1302,7 @@ namespace MWClass
|
|||
if (!ptr.getRefData().getCustomData())
|
||||
{
|
||||
// Create a CustomData, but don't fill it from ESM records (not needed)
|
||||
std::unique_ptr<NpcCustomData> data (new NpcCustomData);
|
||||
ptr.getRefData().setCustomData (data.release());
|
||||
ptr.getRefData().setCustomData(std::make_unique<NpcCustomData>());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -153,7 +153,7 @@ namespace MWWorld
|
|||
|
||||
virtual ~ContainerStore();
|
||||
|
||||
virtual ContainerStore* clone() { return new ContainerStore(*this); }
|
||||
virtual std::unique_ptr<ContainerStore> clone() { return std::make_unique<ContainerStore>(*this); }
|
||||
|
||||
ConstContainerStoreIterator cbegin (int mask = Type_All) const;
|
||||
ConstContainerStoreIterator cend() const;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef GAME_MWWORLD_CUSTOMDATA_H
|
||||
#define GAME_MWWORLD_CUSTOMDATA_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace MWClass
|
||||
{
|
||||
class CreatureCustomData;
|
||||
|
@ -19,7 +21,7 @@ namespace MWWorld
|
|||
|
||||
virtual ~CustomData() {}
|
||||
|
||||
virtual CustomData *clone() const = 0;
|
||||
virtual std::unique_ptr<CustomData> clone() const = 0;
|
||||
|
||||
// Fast version of dynamic_cast<X&>. Needs to be overridden in the respective class.
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace MWWorld
|
|||
|
||||
InventoryStore& operator= (const InventoryStore& store);
|
||||
|
||||
InventoryStore* clone() override { return new InventoryStore(*this); }
|
||||
std::unique_ptr<ContainerStore> clone() override { return std::make_unique<InventoryStore>(*this); }
|
||||
|
||||
ContainerStoreIterator add (const Ptr& itemPtr, int count, const Ptr& actorPtr, bool allowAutoEquip = true, bool resolve = true) override;
|
||||
///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
|
||||
|
|
|
@ -40,8 +40,6 @@ namespace MWWorld
|
|||
void RefData::cleanup()
|
||||
{
|
||||
mBaseNode = nullptr;
|
||||
|
||||
delete mCustomData;
|
||||
mCustomData = nullptr;
|
||||
}
|
||||
|
||||
|
@ -223,21 +221,20 @@ namespace MWWorld
|
|||
return mPosition;
|
||||
}
|
||||
|
||||
void RefData::setCustomData (CustomData *data)
|
||||
void RefData::setCustomData(std::unique_ptr<CustomData>&& value) noexcept
|
||||
{
|
||||
mChanged = true; // We do not currently track CustomData, so assume anything with a CustomData is changed
|
||||
delete mCustomData;
|
||||
mCustomData = data;
|
||||
mCustomData = std::move(value);
|
||||
}
|
||||
|
||||
CustomData *RefData::getCustomData()
|
||||
{
|
||||
return mCustomData;
|
||||
return mCustomData.get();
|
||||
}
|
||||
|
||||
const CustomData *RefData::getCustomData() const
|
||||
{
|
||||
return mCustomData;
|
||||
return mCustomData.get();
|
||||
}
|
||||
|
||||
bool RefData::hasChanged() const
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "../mwscript/locals.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
|
@ -44,7 +45,7 @@ namespace MWWorld
|
|||
|
||||
ESM::AnimationState mAnimationState;
|
||||
|
||||
CustomData *mCustomData;
|
||||
std::unique_ptr<CustomData> mCustomData;
|
||||
|
||||
void copy (const RefData& refData);
|
||||
|
||||
|
@ -117,7 +118,7 @@ namespace MWWorld
|
|||
void setPosition (const ESM::Position& pos);
|
||||
const ESM::Position& getPosition() const;
|
||||
|
||||
void setCustomData (CustomData *data);
|
||||
void setCustomData(std::unique_ptr<CustomData>&& value) noexcept;
|
||||
///< Set custom data (potentially replacing old custom data). The ownership of \a data is
|
||||
/// transferred to this.
|
||||
|
||||
|
|
Loading…
Reference in a new issue