handle moved references on load

moveref
Marc Zinnschlag 10 years ago
parent ba7b74217b
commit e32402a040

@ -1,8 +1,18 @@
#include "ref.hpp" #include "ref.hpp"
#include <cmath>
CSMWorld::CellRef::CellRef() CSMWorld::CellRef::CellRef()
{ {
mRefNum.mIndex = 0; mRefNum.mIndex = 0;
mRefNum.mContentFile = 0; mRefNum.mContentFile = 0;
}
std::pair<int, int> CSMWorld::CellRef::getCellIndex() const
{
const int cellSize = 8192;
return std::make_pair (
std::floor (mPos.pos[0]/cellSize), std::floor (mPos.pos[1]/cellSize));
} }

@ -1,6 +1,8 @@
#ifndef CSM_WOLRD_REF_H #ifndef CSM_WOLRD_REF_H
#define CSM_WOLRD_REF_H #define CSM_WOLRD_REF_H
#include <utility>
#include <components/esm/cellref.hpp> #include <components/esm/cellref.hpp>
namespace CSMWorld namespace CSMWorld
@ -15,6 +17,9 @@ namespace CSMWorld
std::string mOriginalCell; std::string mOriginalCell;
CellRef(); CellRef();
/// Calculate cell index based on coordinates (x and y)
std::pair<int, int> getCellIndex() const;
}; };
} }

@ -24,9 +24,19 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
while (ESM::Cell::getNextRef (reader, ref, deleted)) while (ESM::Cell::getNextRef (reader, ref, deleted))
{ {
ref.mOriginalCell = cell2.mId; ref.mOriginalCell = cell2.mId;
ref.mCell = cell2.mId;
/// \todo handle moved references if (cell.get().isExterior())
{
// ignoring moved references sub-record; instead calculate cell from coordinates
std::pair<int, int> index = ref.getCellIndex();
std::ostringstream stream;
stream << "#" << index.first << " " << index.second;
ref.mCell = stream.str();
}
else
ref.mCell = cell2.mId;
std::map<ESM::RefNum, std::string>::iterator iter = cache.find (ref.mRefNum); std::map<ESM::RefNum, std::string>::iterator iter = cache.find (ref.mRefNum);

Loading…
Cancel
Save