zones.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (C) 2000 Sean Cavanaugh
  2. // This file is licensed under the terms of the Lesser GNU Public License
  3. // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt)
  4. #ifndef ZONING_H__
  5. #define ZONING_H__
  6. #if _MSC_VER >= 1000
  7. #pragma once
  8. #endif
  9. #include "basictypes.h"
  10. #include "winding.h"
  11. #include "boundingbox.h"
  12. // Simple class of visibily flags and zone id's. No concept of location is in this class
  13. class Zones
  14. {
  15. public:
  16. inline void flag(UINT32 src, UINT32 dst)
  17. {
  18. if ((src < m_ZoneCount) && (dst < m_ZoneCount))
  19. {
  20. m_ZonePtrs[src][dst] = true;
  21. m_ZonePtrs[dst][src] = true;
  22. }
  23. }
  24. inline bool check(UINT32 zone1, UINT32 zone2)
  25. {
  26. if ((zone1 < m_ZoneCount) && (zone2 < m_ZoneCount))
  27. {
  28. return m_ZonePtrs[zone1][zone2];
  29. }
  30. return false;
  31. }
  32. void set(UINT32 zone, const BoundingBox& bounds);
  33. UINT32 getZoneFromBounds(const BoundingBox& bounds);
  34. UINT32 getZoneFromWinding(const Winding& winding);
  35. public:
  36. Zones(UINT32 ZoneCount)
  37. {
  38. m_ZoneCount = ZoneCount + 1; // Zone 0 is used for all points outside all nodes
  39. m_ZoneVisMatrix = new bool[m_ZoneCount * m_ZoneCount];
  40. memset(m_ZoneVisMatrix, 0, sizeof(bool) * m_ZoneCount * m_ZoneCount);
  41. m_ZonePtrs = new bool*[m_ZoneCount];
  42. m_ZoneBounds = new BoundingBox[m_ZoneCount];
  43. UINT32 x;
  44. bool* dstPtr = m_ZoneVisMatrix;
  45. bool** srcPtr = m_ZonePtrs;
  46. for (x=0; x<m_ZoneCount; x++, srcPtr++, dstPtr += m_ZoneCount)
  47. {
  48. *srcPtr = dstPtr;
  49. }
  50. }
  51. virtual ~Zones()
  52. {
  53. delete[] m_ZoneVisMatrix;
  54. delete[] m_ZonePtrs;
  55. delete[] m_ZoneBounds;
  56. }
  57. protected:
  58. UINT32 m_ZoneCount;
  59. bool* m_ZoneVisMatrix; // Size is (m_ZoneCount * m_ZoneCount) and data is duplicated for efficiency
  60. bool** m_ZonePtrs; // Lookups into m_ZoneMatrix for m_ZonePtrs[x][y] style;
  61. BoundingBox* m_ZoneBounds;
  62. };
  63. Zones* MakeZones();
  64. #endif