|
|
|
@ -7,18 +7,18 @@ namespace ESM
|
|
|
|
|
{
|
|
|
|
|
Pathgrid::Point& Pathgrid::Point::operator=(const float rhs[3])
|
|
|
|
|
{
|
|
|
|
|
mX = static_cast<int>(rhs[0]);
|
|
|
|
|
mY = static_cast<int>(rhs[1]);
|
|
|
|
|
mZ = static_cast<int>(rhs[2]);
|
|
|
|
|
mX = static_cast<int32_t>(rhs[0]);
|
|
|
|
|
mY = static_cast<int32_t>(rhs[1]);
|
|
|
|
|
mZ = static_cast<int32_t>(rhs[2]);
|
|
|
|
|
mAutogenerated = 0;
|
|
|
|
|
mConnectionNum = 0;
|
|
|
|
|
mUnknown = 0;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
Pathgrid::Point::Point(const float rhs[3])
|
|
|
|
|
: mX(static_cast<int>(rhs[0]))
|
|
|
|
|
, mY(static_cast<int>(rhs[1]))
|
|
|
|
|
, mZ(static_cast<int>(rhs[2]))
|
|
|
|
|
: mX(static_cast<int32_t>(rhs[0]))
|
|
|
|
|
, mY(static_cast<int32_t>(rhs[1]))
|
|
|
|
|
, mZ(static_cast<int32_t>(rhs[2]))
|
|
|
|
|
, mAutogenerated(0)
|
|
|
|
|
, mConnectionNum(0)
|
|
|
|
|
, mUnknown(0)
|
|
|
|
@ -42,7 +42,7 @@ namespace ESM
|
|
|
|
|
mEdges.clear();
|
|
|
|
|
|
|
|
|
|
// keep track of total connections so we can reserve edge vector size
|
|
|
|
|
int edgeCount = 0;
|
|
|
|
|
size_t edgeCount = 0;
|
|
|
|
|
|
|
|
|
|
bool hasData = false;
|
|
|
|
|
while (esm.hasMoreSubs())
|
|
|
|
@ -54,21 +54,20 @@ namespace ESM
|
|
|
|
|
mCell = esm.getRefId();
|
|
|
|
|
break;
|
|
|
|
|
case fourCC("DATA"):
|
|
|
|
|
esm.getHTSized<12>(mData);
|
|
|
|
|
esm.getHT(mData.mX, mData.mY, mData.mGranularity, mData.mPoints);
|
|
|
|
|
hasData = true;
|
|
|
|
|
break;
|
|
|
|
|
case fourCC("PGRP"):
|
|
|
|
|
{
|
|
|
|
|
esm.getSubHeader();
|
|
|
|
|
int size = esm.getSubSize();
|
|
|
|
|
// Check that the sizes match up. Size = 16 * s2 (path points)
|
|
|
|
|
if (size != static_cast<int>(sizeof(Point) * mData.mS2))
|
|
|
|
|
uint32_t size = esm.getSubSize();
|
|
|
|
|
// Check that the sizes match up. Size = 16 * path points
|
|
|
|
|
if (size != sizeof(Point) * mData.mPoints)
|
|
|
|
|
esm.fail("Path point subrecord size mismatch");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pointCount = mData.mS2;
|
|
|
|
|
mPoints.reserve(pointCount);
|
|
|
|
|
for (int i = 0; i < pointCount; ++i)
|
|
|
|
|
mPoints.reserve(mData.mPoints);
|
|
|
|
|
for (uint16_t i = 0; i < mData.mPoints; ++i)
|
|
|
|
|
{
|
|
|
|
|
Point p;
|
|
|
|
|
esm.getExact(&p, sizeof(Point));
|
|
|
|
@ -81,21 +80,19 @@ namespace ESM
|
|
|
|
|
case fourCC("PGRC"):
|
|
|
|
|
{
|
|
|
|
|
esm.getSubHeader();
|
|
|
|
|
int size = esm.getSubSize();
|
|
|
|
|
if (size % sizeof(int) != 0)
|
|
|
|
|
uint32_t size = esm.getSubSize();
|
|
|
|
|
if (size % sizeof(uint32_t) != 0)
|
|
|
|
|
esm.fail("PGRC size not a multiple of 4");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int rawConnNum = size / sizeof(int);
|
|
|
|
|
size_t rawConnNum = size / sizeof(uint32_t);
|
|
|
|
|
std::vector<size_t> rawConnections;
|
|
|
|
|
rawConnections.reserve(rawConnNum);
|
|
|
|
|
for (int i = 0; i < rawConnNum; ++i)
|
|
|
|
|
for (size_t i = 0; i < rawConnNum; ++i)
|
|
|
|
|
{
|
|
|
|
|
int currentValue;
|
|
|
|
|
uint32_t currentValue;
|
|
|
|
|
esm.getT(currentValue);
|
|
|
|
|
if (currentValue < 0)
|
|
|
|
|
esm.fail("currentValue is less than 0");
|
|
|
|
|
rawConnections.push_back(static_cast<size_t>(currentValue));
|
|
|
|
|
rawConnections.push_back(currentValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto rawIt = rawConnections.begin();
|
|
|
|
@ -138,7 +135,7 @@ namespace ESM
|
|
|
|
|
// Correct connection count and sort edges by point
|
|
|
|
|
// Can probably be optimized
|
|
|
|
|
PointList correctedPoints = mPoints;
|
|
|
|
|
std::vector<int> sortedEdges;
|
|
|
|
|
std::vector<uint32_t> sortedEdges;
|
|
|
|
|
|
|
|
|
|
sortedEdges.reserve(mEdges.size());
|
|
|
|
|
|
|
|
|
@ -150,7 +147,7 @@ namespace ESM
|
|
|
|
|
{
|
|
|
|
|
if (edge.mV0 == point)
|
|
|
|
|
{
|
|
|
|
|
sortedEdges.push_back(static_cast<int>(edge.mV1));
|
|
|
|
|
sortedEdges.push_back(static_cast<uint32_t>(edge.mV1));
|
|
|
|
|
++correctedPoints[point].mConnectionNum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -162,16 +159,16 @@ namespace ESM
|
|
|
|
|
|
|
|
|
|
if (isDeleted)
|
|
|
|
|
{
|
|
|
|
|
esm.writeHNString("DELE", "", 3);
|
|
|
|
|
esm.writeHNString("DELE", {}, 3);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!correctedPoints.empty())
|
|
|
|
|
{
|
|
|
|
|
esm.startSubRecord("PGRP");
|
|
|
|
|
for (PointList::const_iterator it = correctedPoints.begin(); it != correctedPoints.end(); ++it)
|
|
|
|
|
for (const Point& point : correctedPoints)
|
|
|
|
|
{
|
|
|
|
|
esm.writeT(*it);
|
|
|
|
|
esm.writeT(point);
|
|
|
|
|
}
|
|
|
|
|
esm.endRecord("PGRP");
|
|
|
|
|
}
|
|
|
|
@ -179,9 +176,9 @@ namespace ESM
|
|
|
|
|
if (!sortedEdges.empty())
|
|
|
|
|
{
|
|
|
|
|
esm.startSubRecord("PGRC");
|
|
|
|
|
for (std::vector<int>::const_iterator it = sortedEdges.begin(); it != sortedEdges.end(); ++it)
|
|
|
|
|
for (const uint32_t& edge : sortedEdges)
|
|
|
|
|
{
|
|
|
|
|
esm.writeT(*it);
|
|
|
|
|
esm.writeT(edge);
|
|
|
|
|
}
|
|
|
|
|
esm.endRecord("PGRC");
|
|
|
|
|
}
|
|
|
|
@ -192,8 +189,8 @@ namespace ESM
|
|
|
|
|
mCell = ESM::RefId();
|
|
|
|
|
mData.mX = 0;
|
|
|
|
|
mData.mY = 0;
|
|
|
|
|
mData.mS1 = 0;
|
|
|
|
|
mData.mS2 = 0;
|
|
|
|
|
mData.mGranularity = 0;
|
|
|
|
|
mData.mPoints = 0;
|
|
|
|
|
mPoints.clear();
|
|
|
|
|
mEdges.clear();
|
|
|
|
|
}
|
|
|
|
|