mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-02 08:15:54 +00:00
Issue #217: made Ptr track container; fixed a cmake script bug
This commit is contained in:
parent
95d27090d7
commit
0adbe258fd
4 changed files with 50 additions and 16 deletions
|
@ -44,7 +44,7 @@ add_openmw_dir (mwsound
|
||||||
add_openmw_dir (mwworld
|
add_openmw_dir (mwworld
|
||||||
refdata world physicssystem scene environment globals class action nullaction actionteleport
|
refdata world physicssystem scene environment globals class action nullaction actionteleport
|
||||||
containerstore actiontalk actiontake manualref player cellfunctors
|
containerstore actiontalk actiontake manualref player cellfunctors
|
||||||
cells localscripts customdata weather inventorystore
|
cells localscripts customdata weather inventorystore ptr
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwclass
|
add_openmw_dir (mwclass
|
||||||
|
|
|
@ -301,23 +301,30 @@ MWWorld::Ptr *MWWorld::ContainerStoreIterator::operator->() const
|
||||||
|
|
||||||
MWWorld::Ptr MWWorld::ContainerStoreIterator::operator*() const
|
MWWorld::Ptr MWWorld::ContainerStoreIterator::operator*() const
|
||||||
{
|
{
|
||||||
|
Ptr ptr;
|
||||||
|
|
||||||
switch (mType)
|
switch (mType)
|
||||||
{
|
{
|
||||||
case ContainerStore::Type_Potion: return MWWorld::Ptr (&*mPotion, 0);
|
case ContainerStore::Type_Potion: ptr = MWWorld::Ptr (&*mPotion, 0); break;
|
||||||
case ContainerStore::Type_Apparatus: return MWWorld::Ptr (&*mApparatus, 0);
|
case ContainerStore::Type_Apparatus: ptr = MWWorld::Ptr (&*mApparatus, 0); break;
|
||||||
case ContainerStore::Type_Armor: return MWWorld::Ptr (&*mArmor, 0);
|
case ContainerStore::Type_Armor: ptr = MWWorld::Ptr (&*mArmor, 0); break;
|
||||||
case ContainerStore::Type_Book: return MWWorld::Ptr (&*mBook, 0);
|
case ContainerStore::Type_Book: ptr = MWWorld::Ptr (&*mBook, 0); break;
|
||||||
case ContainerStore::Type_Clothing: return MWWorld::Ptr (&*mClothing, 0);
|
case ContainerStore::Type_Clothing: ptr = MWWorld::Ptr (&*mClothing, 0); break;
|
||||||
case ContainerStore::Type_Ingredient: return MWWorld::Ptr (&*mIngredient, 0);
|
case ContainerStore::Type_Ingredient: ptr = MWWorld::Ptr (&*mIngredient, 0); break;
|
||||||
case ContainerStore::Type_Light: return MWWorld::Ptr (&*mLight, 0);
|
case ContainerStore::Type_Light: ptr = MWWorld::Ptr (&*mLight, 0); break;
|
||||||
case ContainerStore::Type_Lockpick: return MWWorld::Ptr (&*mLockpick, 0);
|
case ContainerStore::Type_Lockpick: ptr = MWWorld::Ptr (&*mLockpick, 0); break;
|
||||||
case ContainerStore::Type_Miscellaneous: return MWWorld::Ptr (&*mMiscellaneous, 0);
|
case ContainerStore::Type_Miscellaneous: ptr = MWWorld::Ptr (&*mMiscellaneous, 0); break;
|
||||||
case ContainerStore::Type_Probe: return MWWorld::Ptr (&*mProbe, 0);
|
case ContainerStore::Type_Probe: ptr = MWWorld::Ptr (&*mProbe, 0); break;
|
||||||
case ContainerStore::Type_Repair: return MWWorld::Ptr (&*mRepair, 0);
|
case ContainerStore::Type_Repair: ptr = MWWorld::Ptr (&*mRepair, 0); break;
|
||||||
case ContainerStore::Type_Weapon: return MWWorld::Ptr (&*mWeapon, 0);
|
case ContainerStore::Type_Weapon: ptr = MWWorld::Ptr (&*mWeapon, 0); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::runtime_error ("invalid pointer");
|
if (ptr.isEmpty())
|
||||||
|
throw std::runtime_error ("invalid iterator");
|
||||||
|
|
||||||
|
ptr.setContainerStore (mContainer);
|
||||||
|
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::ContainerStoreIterator& MWWorld::ContainerStoreIterator::operator++()
|
MWWorld::ContainerStoreIterator& MWWorld::ContainerStoreIterator::operator++()
|
||||||
|
|
17
apps/openmw/mwworld/ptr.cpp
Normal file
17
apps/openmw/mwworld/ptr.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
#include "ptr.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
void MWWorld::Ptr::setContainerStore (ContainerStore *store)
|
||||||
|
{
|
||||||
|
assert (store);
|
||||||
|
assert (!mCell);
|
||||||
|
|
||||||
|
mContainerStore = store;
|
||||||
|
}
|
||||||
|
|
||||||
|
MWWorld::ContainerStore *MWWorld::Ptr::getContainerStore() const
|
||||||
|
{
|
||||||
|
return mContainerStore;
|
||||||
|
}
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
|
class ContainerStore;
|
||||||
|
|
||||||
/// \brief Pointer to a LiveCellRef
|
/// \brief Pointer to a LiveCellRef
|
||||||
|
|
||||||
class Ptr
|
class Ptr
|
||||||
|
@ -26,10 +28,11 @@ namespace MWWorld
|
||||||
RefData *mRefData;
|
RefData *mRefData;
|
||||||
CellStore *mCell;
|
CellStore *mCell;
|
||||||
std::string mTypeName;
|
std::string mTypeName;
|
||||||
|
ContainerStore *mContainerStore;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Ptr() : mCellRef (0), mRefData (0), mCell (0) {}
|
Ptr() : mCellRef (0), mRefData (0), mCell (0), mContainerStore (0) {}
|
||||||
|
|
||||||
bool isEmpty() const
|
bool isEmpty() const
|
||||||
{
|
{
|
||||||
|
@ -49,6 +52,7 @@ namespace MWWorld
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Ptr (ESMS::LiveCellRef<T, RefData> *liveCellRef, CellStore *cell)
|
Ptr (ESMS::LiveCellRef<T, RefData> *liveCellRef, CellStore *cell)
|
||||||
|
: mContainerStore (0)
|
||||||
{
|
{
|
||||||
mPtr = liveCellRef;
|
mPtr = liveCellRef;
|
||||||
mCellRef = &liveCellRef->ref;
|
mCellRef = &liveCellRef->ref;
|
||||||
|
@ -80,6 +84,12 @@ namespace MWWorld
|
||||||
assert (mCell);
|
assert (mCell);
|
||||||
return mCell;
|
return mCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setContainerStore (ContainerStore *store);
|
||||||
|
///< Must not be called on references that are in a cell.
|
||||||
|
|
||||||
|
ContainerStore *getContainerStore() const;
|
||||||
|
///< May return a 0-pointer, if reference is not in a container.
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator== (const Ptr& left, const Ptr& right)
|
inline bool operator== (const Ptr& left, const Ptr& right)
|
||||||
|
|
Loading…
Reference in a new issue