Recast: rename structure fields and add more documentation

A more consistent name with what has bee reversed so far. Also added documentation on what has been reversed entirely and as much information that i have about stuff that has been partially figured out.
This commit is contained in:
Kawe Mazidjatari 2024-07-05 10:38:16 +02:00
parent 2b16295d0e
commit 615f63d82a
5 changed files with 45 additions and 29 deletions

View File

@ -618,7 +618,7 @@ bool Editor_TileMesh::handleBuild()
params.disjointPolyGroupCount = 0;
params.reachabilityTableSize = 0;
params.reachabilityTableCount = DT_NUM_REACHABILITY_TABLES;
params.allocSize = 0;
params.magicDataCount = 0;
dtStatus status;

View File

@ -24,14 +24,14 @@
static unsigned int getPolySurfaceColor(const dtPoly* poly, duDebugDraw* dd)
{
return poly->disjointSetId == DT_STRAY_POLY_GROUP
return poly->groupId == DT_STRAY_POLY_GROUP
? duTransCol(duRGBA(240,20,10,255), 170)
: duTransCol(dd->areaToCol(poly->getArea()), 170);
}
static unsigned int getPolyBoundaryColor(const dtPoly* poly, const bool inner)
{
return poly->disjointSetId == DT_STRAY_POLY_GROUP
return poly->groupId == DT_STRAY_POLY_GROUP
? inner ? duRGBA(32,24,0,32) : duRGBA(32,24,0,220)
: inner ? duRGBA(0,48,64,32) : duRGBA(0,48,64,220);
}

View File

@ -198,9 +198,16 @@ struct dtPoly
/// @note Use the structure's set and get methods to access this value.
unsigned char areaAndtype;
unsigned short disjointSetId;
unsigned short unk; //IDK but looks filled
unsigned int unk1; //!TODO: debug this if you ever find where this gets used in the engine..
/// The poly group id determining to which island it belongs, and to which it connects.
unsigned short groupId;
// These 3 are most likely related, it needs to be reversed still.
// No use case has been found in the executable yet, its possible these are
// used internally in the editor. Dynamic reverse engineering required to
// confirm this.
unsigned short unk0;
unsigned short unk1;
unsigned short unk2;
/// The center of the polygon; see abstracted script function 'Navmesh_RandomPositions'.
float center[3];
@ -391,12 +398,14 @@ struct dtNavMeshParams
float tileHeight; ///< The height of each tile. (Along the z-axis.)
int maxTiles; ///< The maximum number of tiles the navigation mesh can contain. This and maxPolys are used to calculate how many bits are needed to identify tiles and polygons uniquely.
int maxPolys; ///< The maximum number of polygons each tile can contain. This and maxTiles are used to calculate how many bits are needed to identify tiles and polygons uniquely.
//
//// i hate this
int disjointPolyGroupCount;
int reachabilityTableSize;
int reachabilityTableCount;
int allocSize;
int disjointPolyGroupCount; ///< The total number of unique polygon groups.
int reachabilityTableSize; ///< The total size of the reachability (static pathing) table. This is computed using calcStaticPathingTableSize(disjointPolyGroupcount).
int reachabilityTableCount; ///< The total number of reachability (static pathing) tables in this navmesh. Each TraverseAnimType uses its own table as their available jump links should match their behavior and abilities.
// NOTE: this seems to be used for some wallrunning code. This allocates a buffer of size 0x30 * magicDataCount,
// then copies in the data 0x30 * magicDataCount at the end of the navmesh file (past the reachability tables).
// See [r5apex_ds + F43600] for buffer allocation and data copy, see note at dtNavMesh::m_someMagicData for usage.
int magicDataCount;
};
#pragma pack(push, 4)
@ -731,7 +740,10 @@ public:
dtMeshTile* m_nextFree; ///< Freelist of tiles.
dtMeshTile* m_tiles; ///< List of tiles.
int** m_setTables; ///< Array of set tables.
void* m_unk0; ///< FIXME: unknown structure pointer.
///< FIXME: unknown structure pointer, used for some wallrunning code, see [r5apex_ds + F12687] for usage.
///< See note at dtNavMeshParams::magicDataCount for buffer allocation.
void* m_someMagicData;
char m_meshFlags; // Maybe.
char m_tileFlags; // Maybe.

View File

@ -195,7 +195,7 @@ dtNavMesh::dtNavMesh() :
m_nextFree(0),
m_tiles(0),
m_setTables(0),
m_unk0(0),
m_someMagicData(0),
m_meshFlags(0),
m_tileFlags(0),
m_unk1(0)
@ -309,7 +309,7 @@ dtStatus dtNavMesh::init(unsigned char* data, const int dataSize, const int flag
params.disjointPolyGroupCount = 0;
params.reachabilityTableSize = 0;
params.reachabilityTableCount = DT_NUM_REACHABILITY_TABLES;
params.allocSize = 0;
params.magicDataCount = 0;
dtStatus status = init(&params);
if (dtStatusFailed(status))

View File

@ -299,7 +299,13 @@ bool dtCreateStaticPathingData(dtNavMesh* nav)
for (int j = 0; j < pcount; j++)
{
dtPoly& poly = tile->polys[j];
poly.disjointSetId = (unsigned short)-1;
poly.groupId = (unsigned short)-1;
// NOTE: these fields are unknown and need to be reversed.
// It is possible these are used internally only.
poly.unk0 = (unsigned short)-1;
poly.unk1 = (unsigned short)-1;
poly.unk2 = (unsigned short)-1;
}
}
@ -321,8 +327,8 @@ bool dtCreateStaticPathingData(dtNavMesh* nav)
const dtPoly* p;
nav->getTileAndPolyByRefUnsafe(l.ref, &t, &p);
if (p->disjointSetId != (unsigned short)-1)
nlabels.insert(p->disjointSetId);
if (p->groupId != (unsigned short)-1)
nlabels.insert(p->groupId);
plink = l.next;
}
@ -331,14 +337,14 @@ bool dtCreateStaticPathingData(dtNavMesh* nav)
// This poly isn't connected to anything, mark it so the game
// won't consider this poly in path generation.
if (poly.firstLink == DT_NULL_LINK)
poly.disjointSetId = DT_STRAY_POLY_GROUP;
poly.groupId = DT_STRAY_POLY_GROUP;
else
poly.disjointSetId = (unsigned short)data.insertNew();
poly.groupId = (unsigned short)data.insertNew();
}
else
{
const int l = *nlabels.begin();
poly.disjointSetId = (unsigned short)l;
poly.groupId = (unsigned short)l;
for (const int nl : nlabels)
data.setUnion(l, nl);
@ -356,10 +362,10 @@ bool dtCreateStaticPathingData(dtNavMesh* nav)
for (int j = 0; j < pcount; j++)
{
dtPoly& poly = tile->polys[j];
if (poly.disjointSetId != DT_STRAY_POLY_GROUP)
if (poly.groupId != DT_STRAY_POLY_GROUP)
{
int id = data.find(poly.disjointSetId);
poly.disjointSetId = (unsigned short)id;
int id = data.find(poly.groupId);
poly.groupId = (unsigned short)id;
}
}
}
@ -375,7 +381,7 @@ bool dtCreateStaticPathingData(dtNavMesh* nav)
for (int j = 0; j < pcount; j++)
{
dtPoly& poly = tile->polys[j];
unsigned short oldId = poly.disjointSetId;
unsigned short oldId = poly.groupId;
if (oldId != DT_STRAY_POLY_GROUP && groupMap.find(oldId) == groupMap.end())
groupMap[oldId] = numPolyGroups++;
}
@ -390,8 +396,8 @@ bool dtCreateStaticPathingData(dtNavMesh* nav)
for (int j = 0; j < pcount; j++)
{
dtPoly& poly = tile->polys[j];
if (poly.disjointSetId != DT_STRAY_POLY_GROUP)
poly.disjointSetId = groupMap[poly.disjointSetId];
if (poly.groupId != DT_STRAY_POLY_GROUP)
poly.groupId = groupMap[poly.groupId];
}
}
@ -702,8 +708,6 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
p->flags = params->polyFlags[i];
p->setArea(params->polyAreas[i]);
p->setType(DT_POLYTYPE_GROUND);
//p->org=params->polys
p->disjointSetId = 2; //0 is invalid 1 is special?
for (int j = 0; j < nvp; ++j)
{
if (src[j] == MESH_NULL_IDX) break;