more reliable method of obtaining the cell coordinates in CSVRender::Cell

openmw-37
Marc Zinnschlag 9 years ago
parent b81ee606c8
commit 3f9db7ba3c

@ -32,6 +32,23 @@ std::string CSMWorld::CellCoordinates::getId (const std::string& worldspace) con
return stream.str();
}
std::pair<CSMWorld::CellCoordinates, bool> CSMWorld::CellCoordinates::fromId (
const std::string& id)
{
// no worldspace for now, needs to be changed for 1.1
if (!id.empty() && id[0]=='#')
{
int x, y;
char ignore;
std::istringstream stream (id);
if (stream >> ignore >> x >> y)
return std::make_pair (CellCoordinates (x, y), true);
}
return std::make_pair (CellCoordinates(), false);
}
bool CSMWorld::operator== (const CellCoordinates& left, const CellCoordinates& right)
{
return left.getX()==right.getX() && left.getY()==right.getY();

@ -28,6 +28,12 @@ namespace CSMWorld
std::string getId (const std::string& worldspace) const;
///< Return the ID for the cell at these coordinates.
/// \return first: CellCoordinates (or 0, 0 if cell does not have coordinates),
/// second: is cell paged?
///
/// \note The worldspace part of \a id is ignored
static std::pair<CellCoordinates, bool> fromId (const std::string& id);
};
bool operator== (const CellCoordinates& left, const CellCoordinates& right);

@ -54,6 +54,11 @@ bool CSVRender::Cell::addObjects (int start, int end)
CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::string& id)
: mData (data), mId (Misc::StringUtils::lowerCase (id))
{
std::pair<CSMWorld::CellCoordinates, bool> result = CSMWorld::CellCoordinates::fromId (id);
if (result.second)
mCoordinates = result.first;
mCellNode = new osg::Group;
rootNode->addChild(mCellNode);
@ -75,8 +80,6 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::st
mTerrain.reset(new Terrain::TerrainGrid(mCellNode, data.getResourceSystem().get(), NULL, new TerrainStorage(mData), Element_Terrain<<1));
mTerrain->loadCell(esmLand.mX,
esmLand.mY);
mCoordinates = CSMWorld::CellCoordinates (esmLand.mX, esmLand.mY);
}
}
}

Loading…
Cancel
Save