DetourPathQueue.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
  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. #include "DetourNavMesh.h"
  21. #include "DetourNavMeshQuery.h"
  22. static const unsigned int DT_PATHQ_INVALID = 0;
  23. typedef unsigned int dtPathQueueRef;
  24. class dtPathQueue
  25. {
  26. struct PathQuery
  27. {
  28. dtPathQueueRef ref;
  29. /// Path find start and end location.
  30. float startPos[3], endPos[3];
  31. dtPolyRef startRef, endRef;
  32. /// Result.
  33. dtPolyRef* path;
  34. int npath;
  35. /// State.
  36. dtStatus status;
  37. int keepAlive;
  38. const dtQueryFilter* filter; ///< TODO: This is potentially dangerous!
  39. };
  40. static const int MAX_QUEUE = 8;
  41. PathQuery m_queue[MAX_QUEUE];
  42. dtPathQueueRef m_nextHandle;
  43. int m_maxPathSize;
  44. int m_queueHead;
  45. dtNavMeshQuery* m_navquery;
  46. void purge();
  47. public:
  48. dtPathQueue();
  49. ~dtPathQueue();
  50. bool init(const int maxPathSize, const int maxSearchNodeCount, dtNavMesh* nav);
  51. void update(const int maxIters);
  52. dtPathQueueRef request(dtPolyRef startRef, dtPolyRef endRef,
  53. const float* startPos, const float* endPos,
  54. const dtQueryFilter* filter);
  55. dtStatus getRequestStatus(dtPathQueueRef ref) const;
  56. dtStatus getPathResult(dtPathQueueRef ref, dtPolyRef* path, int* pathSize, const int maxPath);
  57. inline const dtNavMeshQuery* getNavQuery() const { return m_navquery; }
  58. private:
  59. // Explicitly disabled copy constructor and copy assignment operator.
  60. dtPathQueue(const dtPathQueue&);
  61. dtPathQueue& operator=(const dtPathQueue&);
  62. };
  63. #endif // DETOURPATHQUEUE_H