map.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #define BEST_Z_INVALID -99999
  24. class Map
  25. {
  26. public:
  27. Map(string zonename, string filename);
  28. ~Map();
  29. float FindBestZ(glm::vec3 &start, glm::vec3 *result, uint32 *GridID = 0, uint32* WidgetID = 0);
  30. float FindClosestZ(glm::vec3 &start, glm::vec3 *result, uint32 *GridID = 0, uint32* WidgetID = 0);
  31. bool LineIntersectsZone(glm::vec3 start, glm::vec3 end, float step, glm::vec3 *result);
  32. bool LineIntersectsZoneNoZLeaps(glm::vec3 start, glm::vec3 end, float step_mag, glm::vec3 *result);
  33. bool CheckLoS(glm::vec3 myloc, glm::vec3 oloc);
  34. bool DoCollisionCheck(glm::vec3 myloc, glm::vec3 oloc, glm::vec3 &outnorm, float &distance);
  35. bool Load(const std::string& filename);
  36. static Map *LoadMapFile(std::string zonename, std::string file);
  37. std::string GetFileName() { return m_ZoneFile; }
  38. void SetMapLoaded(bool val) {
  39. CheckMapMutex.writelock();
  40. mapLoaded = val;
  41. CheckMapMutex.releasewritelock();
  42. }
  43. bool IsMapLoaded() {
  44. bool isMapLoaded = false;
  45. CheckMapMutex.readlock();
  46. isMapLoaded = mapLoaded;
  47. CheckMapMutex.releasereadlock();
  48. return isMapLoaded;
  49. }
  50. void SetMapLoading(bool val) {
  51. CheckMapMutex.writelock();
  52. mapLoading = val;
  53. CheckMapMutex.releasewritelock();
  54. }
  55. bool IsMapLoading() {
  56. bool isMapLoading = false;
  57. CheckMapMutex.readlock();
  58. isMapLoading = mapLoading;
  59. CheckMapMutex.releasereadlock();
  60. return isMapLoading;
  61. }
  62. float GetMinX() { return m_MinX; }
  63. float GetMaxX() { return m_MaxX; }
  64. float GetMinY() { return m_MinY; }
  65. float GetMaxY() { return m_MaxY; }
  66. float GetMinZ() { return m_MinZ; }
  67. float GetMaxZ() { return m_MaxZ; }
  68. void SetFileName(std::string newfile) { m_FileName = string(newfile); }
  69. void MapMinMaxY(float y);
  70. std::map<int32, glm::vec3> widget_map;
  71. private:
  72. void RotateVertex(glm::vec3 &v, float rx, float ry, float rz);
  73. void ScaleVertex(glm::vec3 &v, float sx, float sy, float sz);
  74. void TranslateVertex(glm::vec3 &v, float tx, float ty, float tz);
  75. bool LoadV2(FILE *f);
  76. bool LoadV2Deflated(FILE *f);
  77. bool LoadV3Deflated(std::ifstream* file, std::streambuf * const srcbuf);
  78. string m_FileName;
  79. string m_ZoneFile;
  80. string m_ZoneName;
  81. int32 m_CellSize;
  82. float m_MinX;
  83. float m_MinY;
  84. float m_MinZ;
  85. float m_MaxX;
  86. float m_MaxY;
  87. float m_MaxZ;
  88. struct impl;
  89. impl *imp;
  90. bool mapLoaded;
  91. bool mapLoading;
  92. Mutex CheckMapMutex;
  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