From bff572659f01dc9721620148196d584043da717c Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:39:05 +0200 Subject: [PATCH] Recast: enable reachability table building code It was commented as it was offset with 4x4 bytes, this has been fixed and therefore reachability tables allocate properly in memory now. --- src/naveditor/Editor.cpp | 49 +++++++--------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/src/naveditor/Editor.cpp b/src/naveditor/Editor.cpp index 177b8440..d400c1dd 100644 --- a/src/naveditor/Editor.cpp +++ b/src/naveditor/Editor.cpp @@ -433,33 +433,11 @@ void Editor::saveAll(std::string path, dtNavMesh* mesh) } memcpy(&header.params, mesh->getParams(), sizeof(dtNavMeshParams)); - //LinkTableData linkData; - //buildLinkTable(mesh, linkData); - //int tableSize = ((linkData.setCount + 31) / 32) * linkData.setCount * 32; + // TODO: this has to be done during navmesh init, not here!!! + LinkTableData linkData; + buildLinkTable(mesh, linkData); - //std::vector reachability(tableSize, 0); - //for (int i = 0; i < linkData.setCount; i++) - // setReachable(reachability, linkData.setCount, i, i, true); - - //if (reachability.size() > 0) - //{ - // for (size_t i = reachability.size() - 1; i >= 0; i--) - // { - // if (reachability[i] == 0) - // { - // reachability.erase(reachability.begin() + i); - // tableSize--; - // } - // else - // break; - // } - //} - - //header.params.disjointPolyGroupCount = linkData.setCount; - //header.params.reachabilityTableCount = m_reachabilityTableCount; - //header.params.reachabilityTableSize = tableSize; - - header.params.disjointPolyGroupCount = 4; + header.params.disjointPolyGroupCount = linkData.setCount; header.params.reachabilityTableCount = m_reachabilityTableCount; header.params.reachabilityTableSize = ((header.params.disjointPolyGroupCount + 31) / 32) * header.params.disjointPolyGroupCount * 32; @@ -480,23 +458,12 @@ void Editor::saveAll(std::string path, dtNavMesh* mesh) fwrite(tile->data, tile->dataSize, 1, fp); } - ////still dont know what this thing is... - //int header_sth = 0; - //for (int i = 0; i < linkData.setCount; i++) - // fwrite(&header_sth, sizeof(int), 1, fp); - - //for (int i = 0; i < header.params.reachabilityTableCount; i++) - // fwrite(reachability.data(), sizeof(int), tableSize, fp); - - int header_sth[4] = { 0,0,0 }; - fwrite(header_sth, sizeof(int), 4, fp); - - unsigned int reachability[32 * 4]; - for (int i = 0; i < 32 * 4; i++) - reachability[i] = 0xffffffff; + std::vector reachability(tableSize, 0); + for (int i = 0; i < linkData.setCount; i++) + setReachable(reachability, linkData.setCount, i, i, true); for (int i = 0; i < header.params.reachabilityTableCount; i++) - fwrite(reachability, sizeof(int), (header.params.reachabilityTableSize / 4), fp); + fwrite(reachability.data(), sizeof(int), (header.params.reachabilityTableSize / 4), fp); fclose(fp); } \ No newline at end of file