mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 11:53:52 +00:00
Merge branch 'pgrd' into pgrd-rendering
This commit is contained in:
commit
a7f89b864e
2 changed files with 32 additions and 36 deletions
|
@ -7,37 +7,28 @@ void Pathgrid::load(ESMReader &esm)
|
||||||
{
|
{
|
||||||
esm.getHNT(data, "DATA", 12);
|
esm.getHNT(data, "DATA", 12);
|
||||||
cell = esm.getHNString("NAME");
|
cell = esm.getHNString("NAME");
|
||||||
// std::cout << "loading PGRD for " <<
|
|
||||||
// cell << " x=" << data.x << " y=" << data.y <<
|
|
||||||
// " " << data.s1
|
|
||||||
// << std::endl;
|
|
||||||
|
|
||||||
// Check that the sizes match up. Size = 16 * s2 (path points)
|
// keep track of total connections so we can reserve edge vector size
|
||||||
|
int edgeCount = 0;
|
||||||
|
|
||||||
if (esm.isNextSub("PGRP"))
|
if (esm.isNextSub("PGRP"))
|
||||||
{
|
{
|
||||||
esm.getSubHeader();
|
esm.getSubHeader();
|
||||||
int size = esm.getSubSize();
|
int size = esm.getSubSize();
|
||||||
//std::cout << "PGRP size is " << size << std::endl;
|
// Check that the sizes match up. Size = 16 * s2 (path points)
|
||||||
if (size != sizeof(Point) * data.s2)
|
if (size != sizeof(Point) * data.s2)
|
||||||
esm.fail("Path grid table size mismatch");
|
esm.fail("Path point subrecord size mismatch");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int pointCount = data.s2;
|
int pointCount = data.s2;
|
||||||
//std::cout << "Path grid points count is " << data.s2 << std::endl;
|
|
||||||
points.reserve(pointCount);
|
points.reserve(pointCount);
|
||||||
for (int i = 0; i < pointCount; ++i)
|
for (int i = 0; i < pointCount; ++i)
|
||||||
{
|
{
|
||||||
Point p;
|
Point p;
|
||||||
esm.getExact(&p, sizeof(Point));
|
esm.getExact(&p, sizeof(Point));
|
||||||
points.push_back(p);
|
points.push_back(p);
|
||||||
|
edgeCount += p.connectionNum;
|
||||||
}
|
}
|
||||||
// for (int i = 0; i < pointCount; ++i)
|
|
||||||
// {
|
|
||||||
// std::cout << i << "'s point: " << points[i].x;
|
|
||||||
// std::cout << " " << points[i].y;
|
|
||||||
// std::cout << " " << points[i].z;
|
|
||||||
// std::cout << std::endl;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,31 +36,34 @@ void Pathgrid::load(ESMReader &esm)
|
||||||
{
|
{
|
||||||
esm.getSubHeader();
|
esm.getSubHeader();
|
||||||
int size = esm.getSubSize();
|
int size = esm.getSubSize();
|
||||||
//std::cout << "PGRC size is " << size << std::endl;
|
|
||||||
if (size % sizeof(int) != 0)
|
if (size % sizeof(int) != 0)
|
||||||
esm.fail("PGRC size not a multiple of 8");
|
esm.fail("PGRC size not a multiple of 4");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int edgeCount = size / sizeof(int) - 1;
|
int rawConnNum = size / sizeof(int);
|
||||||
//std::cout << "Path grid edge count is " << edgeCount << std::endl;
|
std::vector<int> rawConnections;
|
||||||
edges.reserve(edgeCount);
|
rawConnections.reserve(rawConnNum);
|
||||||
int prevValue;
|
for (int i = 0; i < rawConnNum; ++i)
|
||||||
esm.getT(prevValue);
|
|
||||||
for (int i = 0; i < edgeCount; ++i)
|
|
||||||
{
|
{
|
||||||
int nextValue;
|
int currentValue;
|
||||||
esm.getT(nextValue);
|
esm.getT(currentValue);
|
||||||
Edge e;
|
rawConnections.push_back(currentValue);
|
||||||
e.v0 = prevValue;
|
}
|
||||||
e.v1 = nextValue;
|
|
||||||
edges.push_back(e);
|
std::vector<int>::const_iterator rawIt = rawConnections.begin();
|
||||||
prevValue = nextValue;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// for (int i = 0; i < edgeCount; ++i)
|
|
||||||
// {
|
|
||||||
// std::cout << i << "'s edge: " << edges[i].v0 << " "
|
|
||||||
// << edges[i].v1 << std::endl;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,9 @@ struct Pathgrid
|
||||||
struct Point // path grid point
|
struct Point // path grid point
|
||||||
{
|
{
|
||||||
int x, y, z; // Location of point
|
int x, y, z; // Location of point
|
||||||
int unknown; // Possibly flag for coloring/user-placed vs auto-generated
|
unsigned char autogenerated; // autogenerated vs. user coloring flag?
|
||||||
|
unsigned char connectionNum; // number of connections for this point
|
||||||
|
short unknown;
|
||||||
}; // 16 bytes
|
}; // 16 bytes
|
||||||
|
|
||||||
struct Edge // path grid edge
|
struct Edge // path grid edge
|
||||||
|
|
Loading…
Reference in a new issue