Add reference moving logic - untested

openmw-38
scrawl 9 years ago
parent 7a983340bf
commit 64b4926127

@ -179,8 +179,54 @@ namespace MWWorld
return (ref.mRef.mRefnum == pRefnum);
}
void CellStore::moveFrom(const Ptr &object, CellStore *from)
{
MovedRefTracker::iterator found = mMovedToAnotherCell.find(object.getBase());
if (found != mMovedToAnotherCell.end())
{
// A cell we had previously moved an object to is returning it to us.
assert (found->second == from);
mMovedToAnotherCell.erase(found);
}
else
{
mMovedHere.insert(std::make_pair(object.getBase(), from));
}
}
void CellStore::moveTo(const Ptr &object, CellStore *cellToMoveTo)
{
MovedRefTracker::iterator found = mMovedHere.find(object.getBase());
if (found != mMovedHere.end())
{
// Special case - object didn't originate in this cell
// Move it back to its original cell first
CellStore* originalCell = found->second;
assert (originalCell != this);
originalCell->moveFrom(object, this);
mMovedHere.erase(found);
// Now that object is back to its rightful owner, we can move it
originalCell->moveTo(object, cellToMoveTo);
updateMergedRefs();
return;
}
cellToMoveTo->moveFrom(object, this);
mMovedToAnotherCell.insert(std::make_pair(object.getBase(), cellToMoveTo));
updateMergedRefs();
}
void CellStore::updateMergedRefs()
{
}
CellStore::CellStore (const ESM::Cell *cell)
: mCell (cell), mState (State_Unloaded), mHasState (false), mLastRespawn(0,0)
: mCell (cell), mState (State_Unloaded), mHasState (false), mLastRespawn(0,0)
{
mWaterLevel = cell->mWater;
}

@ -95,8 +95,29 @@ namespace MWWorld
CellRefList<ESM::Static> mStatics;
CellRefList<ESM::Weapon> mWeapons;
typedef std::map<LiveCellRefBase*, MWWorld::CellStore*> MovedRefTracker;
// References owned by a different cell that have been moved here.
// <reference, cell the reference originally came from>
MovedRefTracker mMovedHere;
// References owned by this cell that have been moved to another cell.
// <reference, cell the reference was moved to>
MovedRefTracker mMovedToAnotherCell;
// Merged list of ref's currently in this cell - i.e. with added refs from mMovedHere, removed refs from mMovedToAnotherCell
std::vector<LiveCellRefBase*> mMergedRefs;
/// Moves object from the given cell to this cell.
void moveFrom(const MWWorld::Ptr& object, MWWorld::CellStore* from);
/// Repopulate mMergedRefs.
void updateMergedRefs();
public:
/// Moves object from this cell to the given cell.
/// @note automatically updates given cell by calling cellToMoveTo->moveFrom(...)
void moveTo(const MWWorld::Ptr& object, MWWorld::CellStore* cellToMoveTo);
/// Make a copy of the given object and insert it into this cell.
/// @note If you get a linker error here, this means the given type can not be inserted into a cell.
/// The supported types are defined at the bottom of this file.

Loading…
Cancel
Save