map.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. EQEMu: Everquest Server Emulator
  3. Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY except by those people which sell it, which
  9. are required to give you total support for your newly bought product;
  10. without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #ifndef ZONE_MAP_H
  17. #define ZONE_MAP_H
  18. #include "../../common/types.h"
  19. #include "../../common/MiscFunctions.h"
  20. #include "../../common/Mutex.h"
  21. #include "position.h"
  22. #include <stdio.h>
  23. #include "SPGrid.h"
  24. #define BEST_Z_INVALID -99999
  25. class Map
  26. {
  27. public:
  28. Map(string zonename, string filename, SPGrid* grid=nullptr);
  29. ~Map();
  30. float FindBestZ(glm::vec3 &start, glm::vec3 *result);
  31. float FindClosestZ(glm::vec3 &start, glm::vec3 *result);
  32. bool LineIntersectsZone(glm::vec3 start, glm::vec3 end, float step, glm::vec3 *result);
  33. bool LineIntersectsZoneNoZLeaps(glm::vec3 start, glm::vec3 end, float step_mag, glm::vec3 *result);
  34. bool CheckLoS(glm::vec3 myloc, glm::vec3 oloc);
  35. bool DoCollisionCheck(glm::vec3 myloc, glm::vec3 oloc, glm::vec3 &outnorm, float &distance);
  36. bool Load(const std::string& filename);
  37. static Map *LoadMapFile(std::string zonename, std::string file, SPGrid* grid=nullptr);
  38. std::string GetFileName() { return m_ZoneFile; }
  39. void SetMapLoaded(bool val) {
  40. CheckMapMutex.writelock();
  41. mapLoaded = val;
  42. CheckMapMutex.releasewritelock();
  43. }
  44. bool IsMapLoaded() {
  45. bool isMapLoaded = false;
  46. CheckMapMutex.readlock();
  47. isMapLoaded = mapLoaded;
  48. CheckMapMutex.releasereadlock();
  49. return isMapLoaded;
  50. }
  51. void SetMapLoading(bool val) {
  52. CheckMapMutex.writelock();
  53. mapLoading = val;
  54. CheckMapMutex.releasewritelock();
  55. }
  56. bool IsMapLoading() {
  57. bool isMapLoading = false;
  58. CheckMapMutex.readlock();
  59. isMapLoading = mapLoading;
  60. CheckMapMutex.releasereadlock();
  61. return isMapLoading;
  62. }
  63. float GetMinX() { return m_MinX; }
  64. float GetMaxX() { return m_MaxX; }
  65. float GetMinZ() { return m_MinZ; }
  66. float GetMaxZ() { return m_MaxZ; }
  67. void SetFileName(std::string newfile) { m_FileName = string(newfile); }
  68. SPGrid* GetGrid() { return mGrid; }
  69. private:
  70. void RotateVertex(glm::vec3 &v, float rx, float ry, float rz);
  71. void ScaleVertex(glm::vec3 &v, float sx, float sy, float sz);
  72. void TranslateVertex(glm::vec3 &v, float tx, float ty, float tz);
  73. bool LoadV2(FILE *f);
  74. bool LoadV2Deflated(FILE *f);
  75. string m_FileName;
  76. string m_ZoneFile;
  77. string m_ZoneName;
  78. int32 m_CellSize;
  79. float m_MinX;
  80. float m_MinZ;
  81. float m_MaxX;
  82. float m_MaxZ;
  83. int32 m_NumCellsX;
  84. int32 m_NumCellsZ;
  85. int32 m_NumFaceCellsX;
  86. int32 m_NumFaceCellsZ;
  87. struct impl;
  88. impl *imp;
  89. bool mapLoaded;
  90. bool mapLoading;
  91. Mutex CheckMapMutex;
  92. SPGrid* mGrid;
  93. };
  94. class MapRange {
  95. public:
  96. MapRange();
  97. ~MapRange();
  98. void Clear();
  99. void AddVersionRange(std::string zoneName);
  100. map<VersionRange*, Map*>::iterator FindVersionRange(int32 min_version, int32 max_version);
  101. map<VersionRange*, Map*>::iterator FindMapByVersion(int32 version);
  102. map<VersionRange*, Map*>::iterator GetRangeEnd() { return version_map.end(); }
  103. private:
  104. std::map<VersionRange*, Map*> version_map;
  105. string name;
  106. };
  107. #endif