From 9049e61d34cb3f52627b8ca10f1b7da21e147ad9 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 27 Aug 2023 23:56:11 +0200 Subject: [PATCH] Move pointers to 'dtQueryData' struct In the engine, m_query gets memset to size '0x58', and it passes this field as reference to other functions which then access the 3 pointers. Moving the 3 pointers there made the struct size 0x58, and showed a much better disassembly. Moved these type here to reflect the changes made in the engine. --- .../Detour/Include/DetourNavMeshQuery.h | 13 +- .../Detour/Source/DetourNavMeshQuery.cpp | 277 +++++++++--------- 2 files changed, 145 insertions(+), 145 deletions(-) diff --git a/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshQuery.h b/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshQuery.h index 0a3e786b..6313d12a 100644 --- a/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshQuery.h +++ b/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshQuery.h @@ -514,7 +514,7 @@ public: /// Gets the node pool. /// @returns The node pool. - class dtNodePool* getNodePool() const { return m_nodePool; } + class dtNodePool* getNodePool() const { return m_query.m_nodePool; } /// Gets the navigation mesh the query object is using. /// @return The navigation mesh the query object is using. @@ -568,12 +568,13 @@ private: float startPos[3], endPos[3]; unsigned int options; float raycastLimitSqr; - }; - dtQueryData m_query; ///< Sliced query state. - class dtNodePool* m_tinyNodePool; ///< Pointer to small node pool. - class dtNodePool* m_nodePool; ///< Pointer to node pool. - class dtNodeQueue* m_openList; ///< Pointer to open list queue. + class dtNodePool* m_tinyNodePool; ///< Pointer to small node pool. + class dtNodePool* m_nodePool; ///< Pointer to node pool. + class dtNodeQueue* m_openList; ///< Pointer to open list queue. + }; + + dtQueryData m_query; ///< Sliced query state. const dtQueryFilter* m_queryFilter; ///< Pointer to query filter. }; diff --git a/r5dev/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp b/r5dev/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp index b7f53991..0f11b7bd 100644 --- a/r5dev/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp +++ b/r5dev/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp @@ -137,24 +137,23 @@ void dtFreeNavMeshQuery(dtNavMeshQuery* navmesh) dtNavMeshQuery::dtNavMeshQuery() : m_nav(0), - m_tinyNodePool(0), - m_nodePool(0), - m_openList(0) + m_queryFilter(0) { memset(&m_query, 0, sizeof(dtQueryData)); } dtNavMeshQuery::~dtNavMeshQuery() { - if (m_tinyNodePool) - m_tinyNodePool->~dtNodePool(); - if (m_nodePool) - m_nodePool->~dtNodePool(); - if (m_openList) - m_openList->~dtNodeQueue(); - dtFree(m_tinyNodePool); - dtFree(m_nodePool); - dtFree(m_openList); + if (m_query.m_tinyNodePool) + m_query.m_tinyNodePool->~dtNodePool(); + if (m_query.m_nodePool) + m_query.m_nodePool->~dtNodePool(); + if (m_query.m_openList) + m_query.m_openList->~dtNodeQueue(); + + dtFree(m_query.m_tinyNodePool); + dtFree(m_query.m_nodePool); + dtFree(m_query.m_openList); } /// @par @@ -170,49 +169,49 @@ dtStatus dtNavMeshQuery::init(const dtNavMesh* nav, const int maxNodes) m_nav = nav; - if (!m_nodePool || m_nodePool->getMaxNodes() < maxNodes) + if (!m_query.m_nodePool || m_query.m_nodePool->getMaxNodes() < maxNodes) { - if (m_nodePool) + if (m_query.m_nodePool) { - m_nodePool->~dtNodePool(); - dtFree(m_nodePool); - m_nodePool = 0; + m_query.m_nodePool->~dtNodePool(); + dtFree(m_query.m_nodePool); + m_query.m_nodePool = 0; } - m_nodePool = new (dtAlloc(sizeof(dtNodePool), DT_ALLOC_PERM)) dtNodePool(maxNodes, dtNextPow2(maxNodes/4)); - if (!m_nodePool) + m_query.m_nodePool = new (dtAlloc(sizeof(dtNodePool), DT_ALLOC_PERM)) dtNodePool(maxNodes, dtNextPow2(maxNodes/4)); + if (!m_query.m_nodePool) return DT_FAILURE | DT_OUT_OF_MEMORY; } else { - m_nodePool->clear(); + m_query.m_nodePool->clear(); } - if (!m_tinyNodePool) + if (!m_query.m_tinyNodePool) { - m_tinyNodePool = new (dtAlloc(sizeof(dtNodePool), DT_ALLOC_PERM)) dtNodePool(64, 32); - if (!m_tinyNodePool) + m_query.m_tinyNodePool = new (dtAlloc(sizeof(dtNodePool), DT_ALLOC_PERM)) dtNodePool(64, 32); + if (!m_query.m_tinyNodePool) return DT_FAILURE | DT_OUT_OF_MEMORY; } else { - m_tinyNodePool->clear(); + m_query.m_tinyNodePool->clear(); } - if (!m_openList || m_openList->getCapacity() < maxNodes) + if (!m_query.m_openList || m_query.m_openList->getCapacity() < maxNodes) { - if (m_openList) + if (m_query.m_openList) { - m_openList->~dtNodeQueue(); - dtFree(m_openList); - m_openList = 0; + m_query.m_openList->~dtNodeQueue(); + dtFree(m_query.m_openList); + m_query.m_openList = 0; } - m_openList = new (dtAlloc(sizeof(dtNodeQueue), DT_ALLOC_PERM)) dtNodeQueue(maxNodes); - if (!m_openList) + m_query.m_openList = new (dtAlloc(sizeof(dtNodeQueue), DT_ALLOC_PERM)) dtNodeQueue(maxNodes); + if (!m_query.m_openList) return DT_FAILURE | DT_OUT_OF_MEMORY; } else { - m_openList->clear(); + m_query.m_openList->clear(); } return DT_SUCCESS; @@ -314,8 +313,8 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f dtPolyRef* randomRef, float* randomPt) const { dtAssert(m_nav); - dtAssert(m_nodePool); - dtAssert(m_openList); + dtAssert(m_query.m_nodePool); + dtAssert(m_query.m_openList); // Validate input if (!m_nav->isValidPolyRef(startRef) || @@ -332,17 +331,17 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f if (!filter->passFilter(startRef, startTile, startPoly)) return DT_FAILURE | DT_INVALID_PARAM; - m_nodePool->clear(); - m_openList->clear(); + m_query.m_nodePool->clear(); + m_query.m_openList->clear(); - dtNode* startNode = m_nodePool->getNode(startRef); + dtNode* startNode = m_query.m_nodePool->getNode(startRef); dtVcopy(startNode->pos, centerPos); startNode->pidx = 0; startNode->cost = 0; startNode->total = 0; startNode->id = startRef; startNode->flags = DT_NODE_OPEN; - m_openList->push(startNode); + m_query.m_openList->push(startNode); dtStatus status = DT_SUCCESS; @@ -353,9 +352,9 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f const dtPoly* randomPoly = 0; dtPolyRef randomPolyRef = 0; - while (!m_openList->empty()) + while (!m_query.m_openList->empty()) { - dtNode* bestNode = m_openList->pop(); + dtNode* bestNode = m_query.m_openList->pop(); bestNode->flags &= ~DT_NODE_OPEN; bestNode->flags |= DT_NODE_CLOSED; @@ -395,7 +394,7 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f const dtMeshTile* parentTile = 0; const dtPoly* parentPoly = 0; if (bestNode->pidx) - parentRef = m_nodePool->getNodeAtIdx(bestNode->pidx)->id; + parentRef = m_query.m_nodePool->getNodeAtIdx(bestNode->pidx)->id; if (parentRef) m_nav->getTileAndPolyByRefUnsafe(parentRef, &parentTile, &parentPoly); @@ -427,7 +426,7 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f if (distSqr > radiusSqr) continue; - dtNode* neighbourNode = m_nodePool->getNode(neighbourRef); + dtNode* neighbourNode = m_query.m_nodePool->getNode(neighbourRef); if (!neighbourNode) { status |= DT_OUT_OF_NODES; @@ -449,17 +448,17 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f neighbourNode->id = neighbourRef; neighbourNode->flags = (neighbourNode->flags & ~DT_NODE_CLOSED); - neighbourNode->pidx = m_nodePool->getNodeIdx(bestNode); + neighbourNode->pidx = m_query.m_nodePool->getNodeIdx(bestNode); neighbourNode->total = total; if (neighbourNode->flags & DT_NODE_OPEN) { - m_openList->modify(neighbourNode); + m_query.m_openList->modify(neighbourNode); } else { neighbourNode->flags = DT_NODE_OPEN; - m_openList->push(neighbourNode); + m_query.m_openList->push(neighbourNode); } } } @@ -957,8 +956,8 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef, dtPolyRef* path, int* pathCount, const int maxPath) const { dtAssert(m_nav); - dtAssert(m_nodePool); - dtAssert(m_openList); + dtAssert(m_query.m_nodePool); + dtAssert(m_query.m_openList); if (!pathCount) return DT_FAILURE | DT_INVALID_PARAM; @@ -981,27 +980,27 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef, return DT_SUCCESS; } - m_nodePool->clear(); - m_openList->clear(); + m_query.m_nodePool->clear(); + m_query.m_openList->clear(); - dtNode* startNode = m_nodePool->getNode(startRef); + dtNode* startNode = m_query.m_nodePool->getNode(startRef); dtVcopy(startNode->pos, startPos); startNode->pidx = 0; startNode->cost = 0; startNode->total = dtVdist(startPos, endPos) * H_SCALE; startNode->id = startRef; startNode->flags = DT_NODE_OPEN; - m_openList->push(startNode); + m_query.m_openList->push(startNode); dtNode* lastBestNode = startNode; float lastBestNodeCost = startNode->total; bool outOfNodes = false; - while (!m_openList->empty()) + while (!m_query.m_openList->empty()) { // Remove node from open list and put it in closed list. - dtNode* bestNode = m_openList->pop(); + dtNode* bestNode = m_query.m_openList->pop(); bestNode->flags &= ~DT_NODE_OPEN; bestNode->flags |= DT_NODE_CLOSED; @@ -1024,7 +1023,7 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef, const dtMeshTile* parentTile = 0; const dtPoly* parentPoly = 0; if (bestNode->pidx) - parentRef = m_nodePool->getNodeAtIdx(bestNode->pidx)->id; + parentRef = m_query.m_nodePool->getNodeAtIdx(bestNode->pidx)->id; if (parentRef) m_nav->getTileAndPolyByRefUnsafe(parentRef, &parentTile, &parentPoly); @@ -1051,7 +1050,7 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef, crossSide = bestTile->links[i].side >> 1; // get the node - dtNode* neighbourNode = m_nodePool->getNode(neighbourRef, crossSide); + dtNode* neighbourNode = m_query.m_nodePool->getNode(neighbourRef, crossSide); if (!neighbourNode) { outOfNodes = true; @@ -1107,7 +1106,7 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef, continue; // Add or update the node. - neighbourNode->pidx = m_nodePool->getNodeIdx(bestNode); + neighbourNode->pidx = m_query.m_nodePool->getNodeIdx(bestNode); neighbourNode->id = neighbourRef; neighbourNode->flags = (neighbourNode->flags & ~DT_NODE_CLOSED); neighbourNode->cost = cost; @@ -1116,13 +1115,13 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef, if (neighbourNode->flags & DT_NODE_OPEN) { // Already in open, update node location. - m_openList->modify(neighbourNode); + m_query.m_openList->modify(neighbourNode); } else { // Put the node in open list. neighbourNode->flags |= DT_NODE_OPEN; - m_openList->push(neighbourNode); + m_query.m_openList->push(neighbourNode); } // Update nearest node to target so far. @@ -1153,7 +1152,7 @@ dtStatus dtNavMeshQuery::getPathToNode(dtNode* endNode, dtPolyRef* path, int* pa do { length++; - curNode = m_nodePool->getNodeAtIdx(curNode->pidx); + curNode = m_query.m_nodePool->getNodeAtIdx(curNode->pidx); } while (curNode); // If the path cannot be fully stored then advance to the last node we will be able to store. @@ -1163,7 +1162,7 @@ dtStatus dtNavMeshQuery::getPathToNode(dtNode* endNode, dtPolyRef* path, int* pa { dtAssert(curNode); - curNode = m_nodePool->getNodeAtIdx(curNode->pidx); + curNode = m_query.m_nodePool->getNodeAtIdx(curNode->pidx); } // Write path @@ -1172,7 +1171,7 @@ dtStatus dtNavMeshQuery::getPathToNode(dtNode* endNode, dtPolyRef* path, int* pa dtAssert(curNode); path[i] = curNode->id; - curNode = m_nodePool->getNodeAtIdx(curNode->pidx); + curNode = m_query.m_nodePool->getNodeAtIdx(curNode->pidx); } dtAssert(!curNode); @@ -1199,8 +1198,8 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef const dtQueryFilter* filter, const unsigned int options) { dtAssert(m_nav); - dtAssert(m_nodePool); - dtAssert(m_openList); + dtAssert(m_query.m_nodePool); + dtAssert(m_query.m_openList); // Init path state. memset(&m_query, 0, sizeof(dtQueryData)); @@ -1239,17 +1238,17 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef return DT_SUCCESS; } - m_nodePool->clear(); - m_openList->clear(); + m_query.m_nodePool->clear(); + m_query.m_openList->clear(); - dtNode* startNode = m_nodePool->getNode(startRef); + dtNode* startNode = m_query.m_nodePool->getNode(startRef); dtVcopy(startNode->pos, startPos); startNode->pidx = 0; startNode->cost = 0; startNode->total = dtVdist(startPos, endPos) * H_SCALE; startNode->id = startRef; startNode->flags = DT_NODE_OPEN; - m_openList->push(startNode); + m_query.m_openList->push(startNode); m_query.status = DT_IN_PROGRESS; m_query.lastBestNode = startNode; @@ -1274,12 +1273,12 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) rayHit.maxPath = 0; int iter = 0; - while (iter < maxIter && !m_openList->empty()) + while (iter < maxIter && !m_query.m_openList->empty()) { iter++; // Remove node from open list and put it in closed list. - dtNode* bestNode = m_openList->pop(); + dtNode* bestNode = m_query.m_openList->pop(); bestNode->flags &= ~DT_NODE_OPEN; bestNode->flags |= DT_NODE_CLOSED; @@ -1315,10 +1314,10 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) dtNode* parentNode = 0; if (bestNode->pidx) { - parentNode = m_nodePool->getNodeAtIdx(bestNode->pidx); + parentNode = m_query.m_nodePool->getNodeAtIdx(bestNode->pidx); parentRef = parentNode->id; if (parentNode->pidx) - grandpaRef = m_nodePool->getNodeAtIdx(parentNode->pidx)->id; + grandpaRef = m_query.m_nodePool->getNodeAtIdx(parentNode->pidx)->id; } if (parentRef) { @@ -1350,7 +1349,7 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) continue; // Get neighbour poly and tile. - // The API input has been cheked already, skip checking internal data. + // The API input has been checked already, skip checking internal data. const dtMeshTile* neighbourTile = 0; const dtPoly* neighbourPoly = 0; m_nav->getTileAndPolyByRefUnsafe(neighbourRef, &neighbourTile, &neighbourPoly); @@ -1359,7 +1358,7 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) continue; // get the neighbor node - dtNode* neighbourNode = m_nodePool->getNode(neighbourRef, 0); + dtNode* neighbourNode = m_query.m_nodePool->getNode(neighbourRef, 0); if (!neighbourNode) { m_query.status |= DT_OUT_OF_NODES; @@ -1433,7 +1432,7 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) continue; // Add or update the node. - neighbourNode->pidx = foundShortCut ? bestNode->pidx : m_nodePool->getNodeIdx(bestNode); + neighbourNode->pidx = foundShortCut ? bestNode->pidx : m_query.m_nodePool->getNodeIdx(bestNode); neighbourNode->id = neighbourRef; neighbourNode->flags = (neighbourNode->flags & ~(DT_NODE_CLOSED | DT_NODE_PARENT_DETACHED)); neighbourNode->cost = cost; @@ -1444,13 +1443,13 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) if (neighbourNode->flags & DT_NODE_OPEN) { // Already in open, update node location. - m_openList->modify(neighbourNode); + m_query.m_openList->modify(neighbourNode); } else { // Put the node in open list. neighbourNode->flags |= DT_NODE_OPEN; - m_openList->push(neighbourNode); + m_query.m_openList->push(neighbourNode); } // Update nearest node to target so far. @@ -1463,7 +1462,7 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) } // Exhausted all nodes, but could not find path. - if (m_openList->empty()) + if (m_query.m_openList->empty()) { const dtStatus details = m_query.status & DT_STATUS_DETAIL_MASK; m_query.status = DT_SUCCESS | details; @@ -1512,8 +1511,8 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, int prevRay = 0; do { - dtNode* next = m_nodePool->getNodeAtIdx(node->pidx); - node->pidx = m_nodePool->getNodeIdx(prev); + dtNode* next = m_query.m_nodePool->getNodeAtIdx(node->pidx); + node->pidx = m_query.m_nodePool->getNodeIdx(prev); prev = node; int nextRay = node->flags & DT_NODE_PARENT_DETACHED; // keep track of whether parent is not adjacent (i.e. due to raycast shortcut) node->flags = (node->flags & ~DT_NODE_PARENT_DETACHED) | prevRay; // and store it in the reversed path's node @@ -1526,7 +1525,7 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, node = prev; do { - dtNode* next = m_nodePool->getNodeAtIdx(node->pidx); + dtNode* next = m_query.m_nodePool->getNodeAtIdx(node->pidx); dtStatus status = 0; if (node->flags & DT_NODE_PARENT_DETACHED) { @@ -1597,7 +1596,7 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing dtNode* node = 0; for (int i = existingSize-1; i >= 0; --i) { - m_nodePool->findNodes(existing[i], &node, 1); + m_query.m_nodePool->findNodes(existing[i], &node, 1); if (node) break; } @@ -1613,8 +1612,8 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing int prevRay = 0; do { - dtNode* next = m_nodePool->getNodeAtIdx(node->pidx); - node->pidx = m_nodePool->getNodeIdx(prev); + dtNode* next = m_query.m_nodePool->getNodeAtIdx(node->pidx); + node->pidx = m_query.m_nodePool->getNodeIdx(prev); prev = node; int nextRay = node->flags & DT_NODE_PARENT_DETACHED; // keep track of whether parent is not adjacent (i.e. due to raycast shortcut) node->flags = (node->flags & ~DT_NODE_PARENT_DETACHED) | prevRay; // and store it in the reversed path's node @@ -1627,7 +1626,7 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing node = prev; do { - dtNode* next = m_nodePool->getNodeAtIdx(node->pidx); + dtNode* next = m_query.m_nodePool->getNodeAtIdx(node->pidx); dtStatus status = 0; if (node->flags & DT_NODE_PARENT_DETACHED) { @@ -2027,7 +2026,7 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start float* resultPos, dtPolyRef* visited, int* visitedCount, const int maxVisitedSize) const { dtAssert(m_nav); - dtAssert(m_tinyNodePool); + dtAssert(m_query.m_tinyNodePool); if (!visitedCount) return DT_FAILURE | DT_INVALID_PARAM; @@ -2049,9 +2048,9 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start dtNode* stack[MAX_STACK]; int nstack = 0; - m_tinyNodePool->clear(); + m_query.m_tinyNodePool->clear(); - dtNode* startNode = m_tinyNodePool->getNode(startRef); + dtNode* startNode = m_query.m_tinyNodePool->getNode(startRef); startNode->pidx = 0; startNode->cost = 0; startNode->total = 0; @@ -2160,7 +2159,7 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start for (int k = 0; k < nneis; ++k) { // Skip if no node can be allocated. - dtNode* neighbourNode = m_tinyNodePool->getNode(neis[k]); + dtNode* neighbourNode = m_query.m_tinyNodePool->getNode(neis[k]); if (!neighbourNode) continue; // Skip if already visited. @@ -2179,7 +2178,7 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start // Mark as the node as visited and push to queue. if (nstack < MAX_STACK) { - neighbourNode->pidx = m_tinyNodePool->getNodeIdx(curNode); + neighbourNode->pidx = m_query.m_tinyNodePool->getNodeIdx(curNode); neighbourNode->flags |= DT_NODE_CLOSED; stack[nstack++] = neighbourNode; } @@ -2196,8 +2195,8 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start dtNode* node = bestNode; do { - dtNode* next = m_tinyNodePool->getNodeAtIdx(node->pidx); - node->pidx = m_tinyNodePool->getNodeIdx(prev); + dtNode* next = m_query.m_tinyNodePool->getNodeAtIdx(node->pidx); + node->pidx = m_query.m_tinyNodePool->getNodeIdx(prev); prev = node; node = next; } @@ -2213,7 +2212,7 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start status |= DT_BUFFER_TOO_SMALL; break; } - node = m_tinyNodePool->getNodeAtIdx(node->pidx); + node = m_query.m_tinyNodePool->getNodeAtIdx(node->pidx); } while (node); } @@ -2704,8 +2703,8 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float* int* resultCount, const int maxResult) const { dtAssert(m_nav); - dtAssert(m_nodePool); - dtAssert(m_openList); + dtAssert(m_query.m_nodePool); + dtAssert(m_query.m_openList); if (!resultCount) return DT_FAILURE | DT_INVALID_PARAM; @@ -2720,17 +2719,17 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float* return DT_FAILURE | DT_INVALID_PARAM; } - m_nodePool->clear(); - m_openList->clear(); + m_query.m_nodePool->clear(); + m_query.m_openList->clear(); - dtNode* startNode = m_nodePool->getNode(startRef); + dtNode* startNode = m_query.m_nodePool->getNode(startRef); dtVcopy(startNode->pos, centerPos); startNode->pidx = 0; startNode->cost = 0; startNode->total = 0; startNode->id = startRef; startNode->flags = DT_NODE_OPEN; - m_openList->push(startNode); + m_query.m_openList->push(startNode); dtStatus status = DT_SUCCESS; @@ -2738,9 +2737,9 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float* const float radiusSqr = dtSqr(radius); - while (!m_openList->empty()) + while (!m_query.m_openList->empty()) { - dtNode* bestNode = m_openList->pop(); + dtNode* bestNode = m_query.m_openList->pop(); bestNode->flags &= ~DT_NODE_OPEN; bestNode->flags |= DT_NODE_CLOSED; @@ -2756,7 +2755,7 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float* const dtMeshTile* parentTile = 0; const dtPoly* parentPoly = 0; if (bestNode->pidx) - parentRef = m_nodePool->getNodeAtIdx(bestNode->pidx)->id; + parentRef = m_query.m_nodePool->getNodeAtIdx(bestNode->pidx)->id; if (parentRef) m_nav->getTileAndPolyByRefUnsafe(parentRef, &parentTile, &parentPoly); @@ -2803,7 +2802,7 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float* if (distSqr > radiusSqr) continue; - dtNode* neighbourNode = m_nodePool->getNode(neighbourRef); + dtNode* neighbourNode = m_query.m_nodePool->getNode(neighbourRef); if (!neighbourNode) { status |= DT_OUT_OF_NODES; @@ -2830,17 +2829,17 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float* continue; neighbourNode->id = neighbourRef; - neighbourNode->pidx = m_nodePool->getNodeIdx(bestNode); + neighbourNode->pidx = m_query.m_nodePool->getNodeIdx(bestNode); neighbourNode->total = total; if (neighbourNode->flags & DT_NODE_OPEN) { - m_openList->modify(neighbourNode); + m_query.m_openList->modify(neighbourNode); } else { neighbourNode->flags = DT_NODE_OPEN; - m_openList->push(neighbourNode); + m_query.m_openList->push(neighbourNode); } } } @@ -2878,8 +2877,8 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v int* resultCount, const int maxResult) const { dtAssert(m_nav); - dtAssert(m_nodePool); - dtAssert(m_openList); + dtAssert(m_query.m_nodePool); + dtAssert(m_query.m_openList); if (!resultCount) return DT_FAILURE | DT_INVALID_PARAM; @@ -2897,30 +2896,30 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v if (!startRef || !m_nav->isValidPolyRef(startRef)) return DT_FAILURE | DT_INVALID_PARAM; - m_nodePool->clear(); - m_openList->clear(); + m_query.m_nodePool->clear(); + m_query.m_openList->clear(); float centerPos[3] = {0,0,0}; for (int i = 0; i < nverts; ++i) dtVadd(centerPos,centerPos,&verts[i*3]); dtVscale(centerPos,centerPos,1.0f/nverts); - dtNode* startNode = m_nodePool->getNode(startRef); + dtNode* startNode = m_query.m_nodePool->getNode(startRef); dtVcopy(startNode->pos, centerPos); startNode->pidx = 0; startNode->cost = 0; startNode->total = 0; startNode->id = startRef; startNode->flags = DT_NODE_OPEN; - m_openList->push(startNode); + m_query.m_openList->push(startNode); dtStatus status = DT_SUCCESS; int n = 0; - while (!m_openList->empty()) + while (!m_query.m_openList->empty()) { - dtNode* bestNode = m_openList->pop(); + dtNode* bestNode = m_query.m_openList->pop(); bestNode->flags &= ~DT_NODE_OPEN; bestNode->flags |= DT_NODE_CLOSED; @@ -2936,7 +2935,7 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v const dtMeshTile* parentTile = 0; const dtPoly* parentPoly = 0; if (bestNode->pidx) - parentRef = m_nodePool->getNodeAtIdx(bestNode->pidx)->id; + parentRef = m_query.m_nodePool->getNodeAtIdx(bestNode->pidx)->id; if (parentRef) m_nav->getTileAndPolyByRefUnsafe(parentRef, &parentTile, &parentPoly); @@ -2986,7 +2985,7 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v if (tmin > 1.0f || tmax < 0.0f) continue; - dtNode* neighbourNode = m_nodePool->getNode(neighbourRef); + dtNode* neighbourNode = m_query.m_nodePool->getNode(neighbourRef); if (!neighbourNode) { status |= DT_OUT_OF_NODES; @@ -3013,17 +3012,17 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v continue; neighbourNode->id = neighbourRef; - neighbourNode->pidx = m_nodePool->getNodeIdx(bestNode); + neighbourNode->pidx = m_query.m_nodePool->getNodeIdx(bestNode); neighbourNode->total = total; if (neighbourNode->flags & DT_NODE_OPEN) { - m_openList->modify(neighbourNode); + m_query.m_openList->modify(neighbourNode); } else { neighbourNode->flags = DT_NODE_OPEN; - m_openList->push(neighbourNode); + m_query.m_openList->push(neighbourNode); } } } @@ -3041,7 +3040,7 @@ dtStatus dtNavMeshQuery::getPathFromDijkstraSearch(dtPolyRef endRef, dtPolyRef* *pathCount = 0; dtNode* endNode; - if (m_nodePool->findNodes(endRef, &endNode, 1) != 1 || + if (m_query.m_nodePool->findNodes(endRef, &endNode, 1) != 1 || (endNode->flags & DT_NODE_CLOSED) == 0) return DT_FAILURE | DT_INVALID_PARAM; @@ -3076,7 +3075,7 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float* int* resultCount, const int maxResult) const { dtAssert(m_nav); - dtAssert(m_tinyNodePool); + dtAssert(m_query.m_tinyNodePool); if (!resultCount) return DT_FAILURE | DT_INVALID_PARAM; @@ -3095,9 +3094,9 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float* dtNode* stack[MAX_STACK]; int nstack = 0; - m_tinyNodePool->clear(); + m_query.m_tinyNodePool->clear(); - dtNode* startNode = m_tinyNodePool->getNode(startRef); + dtNode* startNode = m_query.m_tinyNodePool->getNode(startRef); startNode->pidx = 0; startNode->id = startRef; startNode->flags = DT_NODE_CLOSED; @@ -3147,7 +3146,7 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float* continue; // Skip if cannot alloca more nodes. - dtNode* neighbourNode = m_tinyNodePool->getNode(neighbourRef); + dtNode* neighbourNode = m_query.m_tinyNodePool->getNode(neighbourRef); if (!neighbourNode) continue; // Skip visited. @@ -3181,7 +3180,7 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float* // Mark node visited, this is done before the overlap test so that // we will not visit the poly again if the test fails. neighbourNode->flags |= DT_NODE_CLOSED; - neighbourNode->pidx = m_tinyNodePool->getNodeIdx(curNode); + neighbourNode->pidx = m_query.m_tinyNodePool->getNodeIdx(curNode); // Check that the polygon does not collide with existing polygons. @@ -3453,8 +3452,8 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen float* hitDist, float* hitPos, float* hitNormal) const { dtAssert(m_nav); - dtAssert(m_nodePool); - dtAssert(m_openList); + dtAssert(m_query.m_nodePool); + dtAssert(m_query.m_openList); // Validate input if (!m_nav->isValidPolyRef(startRef) || @@ -3465,25 +3464,25 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen return DT_FAILURE | DT_INVALID_PARAM; } - m_nodePool->clear(); - m_openList->clear(); + m_query.m_nodePool->clear(); + m_query.m_openList->clear(); - dtNode* startNode = m_nodePool->getNode(startRef); + dtNode* startNode = m_query.m_nodePool->getNode(startRef); dtVcopy(startNode->pos, centerPos); startNode->pidx = 0; startNode->cost = 0; startNode->total = 0; startNode->id = startRef; startNode->flags = DT_NODE_OPEN; - m_openList->push(startNode); + m_query.m_openList->push(startNode); float radiusSqr = dtSqr(maxRadius); dtStatus status = DT_SUCCESS; - while (!m_openList->empty()) + while (!m_query.m_openList->empty()) { - dtNode* bestNode = m_openList->pop(); + dtNode* bestNode = m_query.m_openList->pop(); bestNode->flags &= ~DT_NODE_OPEN; bestNode->flags |= DT_NODE_CLOSED; @@ -3499,7 +3498,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen const dtMeshTile* parentTile = 0; const dtPoly* parentPoly = 0; if (bestNode->pidx) - parentRef = m_nodePool->getNodeAtIdx(bestNode->pidx)->id; + parentRef = m_query.m_nodePool->getNodeAtIdx(bestNode->pidx)->id; if (parentRef) m_nav->getTileAndPolyByRefUnsafe(parentRef, &parentTile, &parentPoly); @@ -3586,7 +3585,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen if (!filter->passFilter(neighbourRef, neighbourTile, neighbourPoly)) continue; - dtNode* neighbourNode = m_nodePool->getNode(neighbourRef); + dtNode* neighbourNode = m_query.m_nodePool->getNode(neighbourRef); if (!neighbourNode) { status |= DT_OUT_OF_NODES; @@ -3611,17 +3610,17 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen neighbourNode->id = neighbourRef; neighbourNode->flags = (neighbourNode->flags & ~DT_NODE_CLOSED); - neighbourNode->pidx = m_nodePool->getNodeIdx(bestNode); + neighbourNode->pidx = m_query.m_nodePool->getNodeIdx(bestNode); neighbourNode->total = total; if (neighbourNode->flags & DT_NODE_OPEN) { - m_openList->modify(neighbourNode); + m_query.m_openList->modify(neighbourNode); } else { neighbourNode->flags |= DT_NODE_OPEN; - m_openList->push(neighbourNode); + m_query.m_openList->push(neighbourNode); } } } @@ -3656,10 +3655,10 @@ bool dtNavMeshQuery::isValidPolyRef(dtPolyRef ref, const dtQueryFilter* filter) /// bool dtNavMeshQuery::isInClosedList(dtPolyRef ref) const { - if (!m_nodePool) return false; + if (!m_query.m_nodePool) return false; dtNode* nodes[DT_MAX_STATES_PER_NODE]; - int n= m_nodePool->findNodes(ref, nodes, DT_MAX_STATES_PER_NODE); + int n= m_query.m_nodePool->findNodes(ref, nodes, DT_MAX_STATES_PER_NODE); for (int i=0; i