DetourPathQueue.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // Copyright (c) 2009-2010 Mikko Mononen [email protected]
  3. //
  4. // This software is provided 'as-is', without any express or implied
  5. // warranty. In no event will the authors be held liable for any damages
  6. // arising from the use of this software.
  7. // Permission is granted to anyone to use this software for any purpose,
  8. // including commercial applications, and to alter it and redistribute it
  9. // freely, subject to the following restrictions:
  10. // 1. The origin of this software must not be misrepresented; you must not
  11. // claim that you wrote the original software. If you use this software
  12. // in a product, an acknowledgment in the product documentation would be
  13. // appreciated but is not required.
  14. // 2. Altered source versions must be plainly marked as such, and must not be
  15. // misrepresented as being the original software.
  16. // 3. This notice may not be removed or altered from any source distribution.
  17. //
  18. #ifndef DETOURPATHQUEUE_H
  19. #define DETOURPATHQUEUE_H
  20. // ATOMIC BEGIN
  21. #include "../../Detour/include/DetourNavMesh.h"
  22. #include "../../Detour/include/DetourNavMeshQuery.h"
  23. // ATOMIC END
  24. static const unsigned int DT_PATHQ_INVALID = 0;
  25. typedef unsigned int dtPathQueueRef;
  26. class dtPathQueue
  27. {
  28. struct PathQuery
  29. {
  30. dtPathQueueRef ref;
  31. /// Path find start and end location.
  32. float startPos[3], endPos[3];
  33. dtPolyRef startRef, endRef;
  34. /// Result.
  35. dtPolyRef* path;
  36. int npath;
  37. /// State.
  38. dtStatus status;
  39. int keepAlive;
  40. const dtQueryFilter* filter; ///< TODO: This is potentially dangerous!
  41. };
  42. static const int MAX_QUEUE = 8;
  43. PathQuery m_queue[MAX_QUEUE];
  44. dtPathQueueRef m_nextHandle;
  45. int m_maxPathSize;
  46. int m_queueHead;
  47. dtNavMeshQuery* m_navquery;
  48. void purge();
  49. public:
  50. dtPathQueue();
  51. ~dtPathQueue();
  52. bool init(const int maxPathSize, const int maxSearchNodeCount, dtNavMesh* nav);
  53. void update(const int maxIters);
  54. dtPathQueueRef request(dtPolyRef startRef, dtPolyRef endRef,
  55. const float* startPos, const float* endPos,
  56. const dtQueryFilter* filter);
  57. dtStatus getRequestStatus(dtPathQueueRef ref) const;
  58. dtStatus getPathResult(dtPathQueueRef ref, dtPolyRef* path, int* pathSize, const int maxPath);
  59. inline const dtNavMeshQuery* getNavQuery() const { return m_navquery; }
  60. };
  61. #endif // DETOURPATHQUEUE_H