1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 13:23:53 +00:00

Feature #161 (Resolved) Load REC_PGRD records

This commit is contained in:
Nikolay Kasyanov 2012-03-10 13:37:35 +04:00
parent fda5b59eb6
commit de5b692f9f
4 changed files with 25 additions and 20 deletions

View file

@ -12,17 +12,17 @@ void Pathgrid::load(ESMReader &esm)
// " " << data.s1 // " " << data.s1
// << std::endl; // << std::endl;
// Check that the sizes match up. Size = 16 * s2 (path points?) // Check that the sizes match up. Size = 16 * s2 (path points)
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; //std::cout << "PGRP size is " << size << std::endl;
if (size != 16 * data.s2) if (size != sizeof(Point) * data.s2)
esm.fail("Path grid table size mismatch"); esm.fail("Path grid table size mismatch");
else else
{ {
pointCount = data.s2; int pointCount = data.s2;
//std::cout << "Path grid points count is " << data.s2 << std::endl; //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)
@ -41,30 +41,24 @@ void Pathgrid::load(ESMReader &esm)
} }
} }
// 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")) if (esm.isNextSub("PGRC"))
{ {
esm.getSubHeader(); esm.getSubHeader();
//esm.skipHSub();
int size = esm.getSubSize(); int size = esm.getSubSize();
//std::cout << "PGRC size is " << size << std::endl; //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 8");
else else
{ {
edgeCount = size / sizeof(int) - 1; int edgeCount = size / sizeof(int) - 1;
//std::cout << "Path grid edge count is " << edgeCount << std::endl; //std::cout << "Path grid edge count is " << edgeCount << std::endl;
edges.reserve(edgeCount); edges.reserve(edgeCount);
int prevValue; int prevValue;
esm.getT(prevValue); esm.getT(prevValue);
//esm.getExact(&prevValue, sizeof(int));
for (int i = 0; i < edgeCount; ++i) for (int i = 0; i < edgeCount; ++i)
{ {
int nextValue; int nextValue;
esm.getT(nextValue); esm.getT(nextValue);
//esm.getExact(&nextValue, sizeof(int));
Edge e; Edge e;
e.v0 = prevValue; e.v0 = prevValue;
e.v1 = nextValue; e.v1 = nextValue;

View file

@ -16,7 +16,7 @@ struct Pathgrid
int x, y; // Grid location, matches cell for exterior cells int x, y; // Grid location, matches cell for exterior cells
short s1; // ?? Usually but not always a power of 2. Doesn't seem short s1; // ?? Usually but not always a power of 2. Doesn't seem
// to have any relation to the size of PGRC. // to have any relation to the size of PGRC.
short s2; // Number of path points? Size of PGRP block is always 16 * s2; short s2; // Number of path points.
}; // 12 bytes }; // 12 bytes
struct Point // path grid point struct Point // path grid point
@ -33,11 +33,11 @@ struct Pathgrid
std::string cell; // Cell name std::string cell; // Cell name
DATAstruct data; DATAstruct data;
std::vector<Point> points; typedef std::vector<Point> PointList;
int pointCount; PointList points;
std::vector<Edge> edges; typedef std::vector<Edge> EdgeList;
int edgeCount; EdgeList edges;
void load(ESMReader &esm); void load(ESMReader &esm);
}; };

View file

@ -123,8 +123,6 @@ namespace ESMS
CellRefList<Static, D> statics; CellRefList<Static, D> statics;
CellRefList<Weapon, D> weapons; CellRefList<Weapon, D> weapons;
ESM::Pathgrid *pathgrid;
void load (const ESMStore &store, ESMReader &esm) void load (const ESMStore &store, ESMReader &esm)
{ {
if (mState!=State_Loaded) if (mState!=State_Loaded)
@ -136,8 +134,6 @@ namespace ESMS
loadRefs (store, esm); loadRefs (store, esm);
pathgrid = store.pathgrids.search(cell->data.gridX, cell->data.gridY, cell->name);
mState = State_Loaded; mState = State_Loaded;
} }
} }

View file

@ -425,7 +425,7 @@ namespace ESMS
count++; count++;
ESM::Pathgrid *grid = new ESM::Pathgrid; ESM::Pathgrid *grid = new ESM::Pathgrid;
grid->load(esm); grid->load(esm);
if (grid->data.x == 0 && grid->data.y) if (grid->data.x == 0 && grid->data.y == 0)
{ {
intGrids[grid->cell] = grid; intGrids[grid->cell] = grid;
} }
@ -462,6 +462,21 @@ namespace ESMS
} }
return result; return result;
} }
Pathgrid *search(const ESM::Cell &cell) const
{
int cellX, cellY;
if (cell.data.flags & ESM::Cell::Interior)
{
cellX = cellY = 0;
}
else
{
cellX = cell.data.gridX;
cellY = cell.data.gridY;
}
return search(cellX, cellY, cell.name);
}
}; };
template <typename X> template <typename X>