|
|
|
@ -3,32 +3,68 @@
|
|
|
|
|
namespace ESM
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
void PathGrid::load(ESMReader &esm)
|
|
|
|
|
void Pathgrid::load(ESMReader &esm)
|
|
|
|
|
{
|
|
|
|
|
esm.getHNT(data, "DATA", 12);
|
|
|
|
|
cell = esm.getHNString("NAME");
|
|
|
|
|
|
|
|
|
|
// Remember this file position
|
|
|
|
|
context = esm.getContext();
|
|
|
|
|
// keep track of total connections so we can reserve edge vector size
|
|
|
|
|
int edgeCount = 0;
|
|
|
|
|
|
|
|
|
|
// Check that the sizes match up. Size = 16 * s2 (path points?)
|
|
|
|
|
if (esm.isNextSub("PGRP"))
|
|
|
|
|
{
|
|
|
|
|
esm.skipHSub();
|
|
|
|
|
esm.getSubHeader();
|
|
|
|
|
int size = esm.getSubSize();
|
|
|
|
|
if (size != 16 * data.s2)
|
|
|
|
|
esm.fail("Path grid table size mismatch");
|
|
|
|
|
// Check that the sizes match up. Size = 16 * s2 (path points)
|
|
|
|
|
if (size != static_cast<int> (sizeof(Point) * data.s2))
|
|
|
|
|
esm.fail("Path point subrecord size mismatch");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pointCount = data.s2;
|
|
|
|
|
points.reserve(pointCount);
|
|
|
|
|
for (int i = 0; i < pointCount; ++i)
|
|
|
|
|
{
|
|
|
|
|
Point p;
|
|
|
|
|
esm.getExact(&p, sizeof(Point));
|
|
|
|
|
points.push_back(p);
|
|
|
|
|
edgeCount += p.connectionNum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Size varies. Path grid chances? Connections? Multiples of 4
|
|
|
|
|
// suggest either int or two shorts, or perhaps a float. Study
|
|
|
|
|
// it later.
|
|
|
|
|
if (esm.isNextSub("PGRC"))
|
|
|
|
|
{
|
|
|
|
|
esm.skipHSub();
|
|
|
|
|
esm.getSubHeader();
|
|
|
|
|
int size = esm.getSubSize();
|
|
|
|
|
if (size % 4 != 0)
|
|
|
|
|
if (size % sizeof(int) != 0)
|
|
|
|
|
esm.fail("PGRC size not a multiple of 4");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int rawConnNum = size / sizeof(int);
|
|
|
|
|
std::vector<int> rawConnections;
|
|
|
|
|
rawConnections.reserve(rawConnNum);
|
|
|
|
|
for (int i = 0; i < rawConnNum; ++i)
|
|
|
|
|
{
|
|
|
|
|
int currentValue;
|
|
|
|
|
esm.getT(currentValue);
|
|
|
|
|
rawConnections.push_back(currentValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<int>::const_iterator rawIt = rawConnections.begin();
|
|
|
|
|
int pointIndex = 0;
|
|
|
|
|
edges.reserve(edgeCount);
|
|
|
|
|
for(PointList::const_iterator it = points.begin(); it != points.end(); it++, pointIndex++)
|
|
|
|
|
{
|
|
|
|
|
unsigned char connectionNum = (*it).connectionNum;
|
|
|
|
|
for (int i = 0; i < connectionNum; ++i) {
|
|
|
|
|
Edge edge;
|
|
|
|
|
edge.v0 = pointIndex;
|
|
|
|
|
edge.v1 = *rawIt;
|
|
|
|
|
rawIt++;
|
|
|
|
|
edges.push_back(edge);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|