DetourProximityGrid.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 DETOURPROXIMITYGRID_H
  19. #define DETOURPROXIMITYGRID_H
  20. class dtProximityGrid
  21. {
  22. int m_maxItems;
  23. float m_cellSize;
  24. float m_invCellSize;
  25. struct Item
  26. {
  27. unsigned short id;
  28. short x,y;
  29. unsigned short next;
  30. };
  31. Item* m_pool;
  32. int m_poolHead;
  33. int m_poolSize;
  34. unsigned short* m_buckets;
  35. int m_bucketsSize;
  36. int m_bounds[4];
  37. public:
  38. dtProximityGrid();
  39. ~dtProximityGrid();
  40. bool init(const int maxItems, const float cellSize);
  41. void clear();
  42. void addItem(const unsigned short id,
  43. const float minx, const float miny,
  44. const float maxx, const float maxy);
  45. int queryItems(const float minx, const float miny,
  46. const float maxx, const float maxy,
  47. unsigned short* ids, const int maxIds) const;
  48. int getItemCountAt(const int x, const int y) const;
  49. inline const int* getBounds() const { return m_bounds; }
  50. inline float getCellSize() const { return m_cellSize; }
  51. };
  52. dtProximityGrid* dtAllocProximityGrid();
  53. void dtFreeProximityGrid(dtProximityGrid* ptr);
  54. #endif // DETOURPROXIMITYGRID_H