forked from mirror/openmw-tes3mp
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"
|
#include "manualref.hpp"
|
||||||
|
|
||||||
|
MWWorld::ContainerStore::ContainerStore() : mStateId (0) {}
|
||||||
|
|
||||||
MWWorld::ContainerStore::~ContainerStore() {}
|
MWWorld::ContainerStore::~ContainerStore() {}
|
||||||
|
|
||||||
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::begin (int mask)
|
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_Repair: repairs.list.push_back (*ptr.get<ESM::Repair>()); break;
|
||||||
case Type_Weapon: weapons.list.push_back (*ptr.get<ESM::Weapon>()); 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)
|
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);
|
ref.getPtr().getRefData().setCount (iter->count);
|
||||||
add (ref.getPtr());
|
add (ref.getPtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flagAsModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWWorld::ContainerStore::clear()
|
void MWWorld::ContainerStore::clear()
|
||||||
|
@ -74,6 +80,18 @@ void MWWorld::ContainerStore::clear()
|
||||||
probes.list.clear();
|
probes.list.clear();
|
||||||
repairs.list.clear();
|
repairs.list.clear();
|
||||||
weapons.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)
|
int MWWorld::ContainerStore::getType (const Ptr& ptr)
|
||||||
|
|
|
@ -52,9 +52,12 @@ namespace MWWorld
|
||||||
ESMS::CellRefList<ESM::Probe, RefData> probes;
|
ESMS::CellRefList<ESM::Probe, RefData> probes;
|
||||||
ESMS::CellRefList<ESM::Repair, RefData> repairs;
|
ESMS::CellRefList<ESM::Repair, RefData> repairs;
|
||||||
ESMS::CellRefList<ESM::Weapon, RefData> weapons;
|
ESMS::CellRefList<ESM::Weapon, RefData> weapons;
|
||||||
|
int mStateId;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
ContainerStore();
|
||||||
|
|
||||||
virtual ~ContainerStore();
|
virtual ~ContainerStore();
|
||||||
|
|
||||||
ContainerStoreIterator begin (int mask = Type_All);
|
ContainerStoreIterator begin (int mask = Type_All);
|
||||||
|
@ -75,6 +78,15 @@ namespace MWWorld
|
||||||
void clear();
|
void clear();
|
||||||
///< Empty container.
|
///< 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);
|
static int getType (const Ptr& ptr);
|
||||||
///< This function throws an exception, if ptr does not point to an object, that can be
|
///< This function throws an exception, if ptr does not point to an object, that can be
|
||||||
/// put into a container.
|
/// 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)
|
/// \todo unstack item pointed to by iterator if required)
|
||||||
|
|
||||||
mSlots[slot] = iterator;
|
mSlots[slot] = iterator;
|
||||||
|
|
||||||
|
flagAsModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
|
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
|
||||||
|
|
|
@ -3,15 +3,25 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "containerstore.hpp"
|
||||||
|
|
||||||
ESM::CellRef& MWWorld::Ptr::getCellRef() const
|
ESM::CellRef& MWWorld::Ptr::getCellRef() const
|
||||||
{
|
{
|
||||||
assert (mCellRef);
|
assert (mCellRef);
|
||||||
|
|
||||||
|
if (mContainerStore)
|
||||||
|
mContainerStore->flagAsModified();
|
||||||
|
|
||||||
return *mCellRef;
|
return *mCellRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::RefData& MWWorld::Ptr::getRefData() const
|
MWWorld::RefData& MWWorld::Ptr::getRefData() const
|
||||||
{
|
{
|
||||||
assert (mRefData);
|
assert (mRefData);
|
||||||
|
|
||||||
|
if (mContainerStore)
|
||||||
|
mContainerStore->flagAsModified();
|
||||||
|
|
||||||
return *mRefData;
|
return *mRefData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue