From 5290c8aac43692225a41d8b39882916010a7443e Mon Sep 17 00:00:00 2001 From: Hans Gaiser Date: Sun, 27 Apr 2014 17:34:36 +0200 Subject: [PATCH 1/2] Add partial path result status for dtCrowdAgent --- DetourCrowd/Include/DetourCrowd.h | 3 +++ DetourCrowd/Source/DetourCrowd.cpp | 13 ++++++++++++- DetourCrowd/Source/DetourPathQueue.cpp | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/DetourCrowd/Include/DetourCrowd.h b/DetourCrowd/Include/DetourCrowd.h index 9f92cdf..21e9283 100644 --- a/DetourCrowd/Include/DetourCrowd.h +++ b/DetourCrowd/Include/DetourCrowd.h @@ -121,6 +121,9 @@ struct dtCrowdAgent /// The type of mesh polygon the agent is traversing. (See: #CrowdAgentState) unsigned char state; + /// 1 if the path is a partial path (the path does not lead to the target) + unsigned char partial; + /// The path corridor the agent is using. dtPathCorridor corridor; diff --git a/DetourCrowd/Source/DetourCrowd.cpp b/DetourCrowd/Source/DetourCrowd.cpp index 4297b65..0107b37 100644 --- a/DetourCrowd/Source/DetourCrowd.cpp +++ b/DetourCrowd/Source/DetourCrowd.cpp @@ -538,6 +538,7 @@ int dtCrowd::addAgent(const float* pos, const dtCrowdAgentParams* params) ag->corridor.reset(ref, nearest); ag->boundary.reset(); + ag->partial = 0; updateAgentParameters(idx, params); @@ -716,6 +717,11 @@ void dtCrowd::updateMoveRequest(const float /*dt*/) status = m_navquery->finalizeSlicedFindPath(reqPath, &reqPathCount, MAX_RES); } + if (dtStatusDetail(status, DT_PARTIAL_RESULT)) + ag->partial = 1; + else + ag->partial = 0; + if (!dtStatusFailed(status) && reqPathCount > 0) { // In progress or succeed. @@ -819,7 +825,12 @@ void dtCrowd::updateMoveRequest(const float /*dt*/) status = m_pathq.getPathResult(ag->targetPathqRef, res, &nres, m_maxPathResult); if (dtStatusFailed(status) || !nres) valid = false; - + + if (dtStatusDetail(status, DT_PARTIAL_RESULT)) + ag->partial = 1; + else + ag->partial = 0; + // Merge result and existing path. // The agent might have moved whilst the request is // being processed, so the path may have changed. diff --git a/DetourCrowd/Source/DetourPathQueue.cpp b/DetourCrowd/Source/DetourPathQueue.cpp index de1862a..a8f0ec2 100644 --- a/DetourCrowd/Source/DetourPathQueue.cpp +++ b/DetourCrowd/Source/DetourPathQueue.cpp @@ -185,6 +185,7 @@ dtStatus dtPathQueue::getPathResult(dtPathQueueRef ref, dtPolyRef* path, int* pa if (m_queue[i].ref == ref) { PathQuery& q = m_queue[i]; + dtStatus details = q.status; // Free request for reuse. q.ref = DT_PATHQ_INVALID; q.status = 0; @@ -192,7 +193,7 @@ dtStatus dtPathQueue::getPathResult(dtPathQueueRef ref, dtPolyRef* path, int* pa int n = dtMin(q.npath, maxPath); memcpy(path, q.path, sizeof(dtPolyRef)*n); *pathSize = n; - return DT_SUCCESS; + return details | DT_SUCCESS; } } return DT_FAILURE; From 652317f9e6e5553ee45380da88880a574a564ddb Mon Sep 17 00:00:00 2001 From: Hans Gaiser Date: Sun, 27 Apr 2014 18:25:48 +0200 Subject: [PATCH 2/2] Add commented improvements --- DetourCrowd/Include/DetourCrowd.h | 4 ++-- DetourCrowd/Source/DetourCrowd.cpp | 15 +++++++-------- DetourCrowd/Source/DetourPathQueue.cpp | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/DetourCrowd/Include/DetourCrowd.h b/DetourCrowd/Include/DetourCrowd.h index 21e9283..d265493 100644 --- a/DetourCrowd/Include/DetourCrowd.h +++ b/DetourCrowd/Include/DetourCrowd.h @@ -121,8 +121,8 @@ struct dtCrowdAgent /// The type of mesh polygon the agent is traversing. (See: #CrowdAgentState) unsigned char state; - /// 1 if the path is a partial path (the path does not lead to the target) - unsigned char partial; + /// True if the agent has valid path (targetState == DT_CROWDAGENT_TARGET_VALID) and the path does not lead to the requested position, else false. + bool partial; /// The path corridor the agent is using. dtPathCorridor corridor; diff --git a/DetourCrowd/Source/DetourCrowd.cpp b/DetourCrowd/Source/DetourCrowd.cpp index 0107b37..35f8ebc 100644 --- a/DetourCrowd/Source/DetourCrowd.cpp +++ b/DetourCrowd/Source/DetourCrowd.cpp @@ -538,7 +538,7 @@ int dtCrowd::addAgent(const float* pos, const dtCrowdAgentParams* params) ag->corridor.reset(ref, nearest); ag->boundary.reset(); - ag->partial = 0; + ag->partial = false; updateAgentParameters(idx, params); @@ -717,11 +717,6 @@ void dtCrowd::updateMoveRequest(const float /*dt*/) status = m_navquery->finalizeSlicedFindPath(reqPath, &reqPathCount, MAX_RES); } - if (dtStatusDetail(status, DT_PARTIAL_RESULT)) - ag->partial = 1; - else - ag->partial = 0; - if (!dtStatusFailed(status) && reqPathCount > 0) { // In progress or succeed. @@ -752,6 +747,7 @@ void dtCrowd::updateMoveRequest(const float /*dt*/) ag->corridor.setCorridor(reqPos, reqPath, reqPathCount); ag->boundary.reset(); + ag->partial = false; if (reqPath[reqPathCount-1] == ag->targetRef) { @@ -827,9 +823,9 @@ void dtCrowd::updateMoveRequest(const float /*dt*/) valid = false; if (dtStatusDetail(status, DT_PARTIAL_RESULT)) - ag->partial = 1; + ag->partial = true; else - ag->partial = 0; + ag->partial = false; // Merge result and existing path. // The agent might have moved whilst the request is @@ -975,6 +971,7 @@ void dtCrowd::checkPathValidity(dtCrowdAgent** agents, const int nagents, const { // Could not find location in navmesh, set state to invalid. ag->corridor.reset(0, agentPos); + ag->partial = false; ag->boundary.reset(); ag->state = DT_CROWDAGENT_STATE_INVALID; continue; @@ -1011,6 +1008,7 @@ void dtCrowd::checkPathValidity(dtCrowdAgent** agents, const int nagents, const { // Failed to reposition target, fail moverequest. ag->corridor.reset(agentRef, agentPos); + ag->partial = false; ag->targetState = DT_CROWDAGENT_TARGET_NONE; } } @@ -1403,6 +1401,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug) if (ag->targetState == DT_CROWDAGENT_TARGET_NONE || ag->targetState == DT_CROWDAGENT_TARGET_VELOCITY) { ag->corridor.reset(ag->corridor.getFirstPoly(), ag->npos); + ag->partial = false; } } diff --git a/DetourCrowd/Source/DetourPathQueue.cpp b/DetourCrowd/Source/DetourPathQueue.cpp index a8f0ec2..1ed0cd7 100644 --- a/DetourCrowd/Source/DetourPathQueue.cpp +++ b/DetourCrowd/Source/DetourPathQueue.cpp @@ -185,7 +185,7 @@ dtStatus dtPathQueue::getPathResult(dtPathQueueRef ref, dtPolyRef* path, int* pa if (m_queue[i].ref == ref) { PathQuery& q = m_queue[i]; - dtStatus details = q.status; + dtStatus details = q.status & DT_STATUS_DETAIL_MASK; // Free request for reuse. q.ref = DT_PATHQ_INVALID; q.status = 0;