mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-02 03:15:35 +00:00
Issue #217: container change tracking
This commit is contained in:
parent
a0ee2954bd
commit
3dcfcf46cb
4 changed files with 42 additions and 0 deletions
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include "manualref.hpp"
|
||||
|
||||
MWWorld::ContainerStore::ContainerStore() : mStateId (0) {}
|
||||
|
||||
MWWorld::ContainerStore::~ContainerStore() {}
|
||||
|
||||
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::begin (int mask)
|
||||
|
@ -40,6 +42,8 @@ void MWWorld::ContainerStore::add (const Ptr& ptr)
|
|||
case Type_Repair: repairs.list.push_back (*ptr.get<ESM::Repair>()); break;
|
||||
case Type_Weapon: weapons.list.push_back (*ptr.get<ESM::Weapon>()); break;
|
||||
}
|
||||
|
||||
flagAsModified();
|
||||
}
|
||||
|
||||
void MWWorld::ContainerStore::fill (const ESM::InventoryList& items, const ESMS::ESMStore& store)
|
||||
|
@ -58,6 +62,8 @@ void MWWorld::ContainerStore::fill (const ESM::InventoryList& items, const ESMS:
|
|||
ref.getPtr().getRefData().setCount (iter->count);
|
||||
add (ref.getPtr());
|
||||
}
|
||||
|
||||
flagAsModified();
|
||||
}
|
||||
|
||||
void MWWorld::ContainerStore::clear()
|
||||
|
@ -74,6 +80,18 @@ void MWWorld::ContainerStore::clear()
|
|||
probes.list.clear();
|
||||
repairs.list.clear();
|
||||
weapons.list.clear();
|
||||
|
||||
flagAsModified();
|
||||
}
|
||||
|
||||
void MWWorld::ContainerStore::flagAsModified()
|
||||
{
|
||||
++mStateId;
|
||||
}
|
||||
|
||||
int MWWorld::ContainerStore::getStateId() const
|
||||
{
|
||||
return mStateId;
|
||||
}
|
||||
|
||||
int MWWorld::ContainerStore::getType (const Ptr& ptr)
|
||||
|
|
|
@ -52,9 +52,12 @@ namespace MWWorld
|
|||
ESMS::CellRefList<ESM::Probe, RefData> probes;
|
||||
ESMS::CellRefList<ESM::Repair, RefData> repairs;
|
||||
ESMS::CellRefList<ESM::Weapon, RefData> weapons;
|
||||
int mStateId;
|
||||
|
||||
public:
|
||||
|
||||
ContainerStore();
|
||||
|
||||
virtual ~ContainerStore();
|
||||
|
||||
ContainerStoreIterator begin (int mask = Type_All);
|
||||
|
@ -75,6 +78,15 @@ namespace MWWorld
|
|||
void clear();
|
||||
///< Empty container.
|
||||
|
||||
void flagAsModified();
|
||||
///< \attention This function is internal to the world model and should not be called from
|
||||
/// outside.
|
||||
|
||||
int getStateId() const;
|
||||
///< This ID is changed every time the container is modified or items in the container
|
||||
/// are accessed in a way that may be used to modify the item.
|
||||
/// \note This method of change-tracking will ocasionally yield false positives.
|
||||
|
||||
static int getType (const Ptr& ptr);
|
||||
///< This function throws an exception, if ptr does not point to an object, that can be
|
||||
/// put into a container.
|
||||
|
|
|
@ -65,6 +65,8 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite
|
|||
/// \todo unstack item pointed to by iterator if required)
|
||||
|
||||
mSlots[slot] = iterator;
|
||||
|
||||
flagAsModified();
|
||||
}
|
||||
|
||||
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
|
||||
|
|
|
@ -3,15 +3,25 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
#include "containerstore.hpp"
|
||||
|
||||
ESM::CellRef& MWWorld::Ptr::getCellRef() const
|
||||
{
|
||||
assert (mCellRef);
|
||||
|
||||
if (mContainerStore)
|
||||
mContainerStore->flagAsModified();
|
||||
|
||||
return *mCellRef;
|
||||
}
|
||||
|
||||
MWWorld::RefData& MWWorld::Ptr::getRefData() const
|
||||
{
|
||||
assert (mRefData);
|
||||
|
||||
if (mContainerStore)
|
||||
mContainerStore->flagAsModified();
|
||||
|
||||
return *mRefData;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue