map.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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);
  30. float FindClosestZ(glm::vec3 &start, glm::vec3 *result);
  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 GetMinZ() { return m_MinZ; }
  65. float GetMaxZ() { return m_MaxZ; }
  66. void SetFileName(std::string newfile) { m_FileName = string(newfile); }
  67. private:
  68. void RotateVertex(glm::vec3 &v, float rx, float ry, float rz);
  69. void ScaleVertex(glm::vec3 &v, float sx, float sy, float sz);
  70. void TranslateVertex(glm::vec3 &v, float tx, float ty, float tz);
  71. bool LoadV2(FILE *f);
  72. bool LoadV2Deflated(FILE *f);
  73. string m_FileName;
  74. string m_ZoneFile;
  75. string m_ZoneName;
  76. int32 m_CellSize;
  77. float m_MinX;
  78. float m_MinZ;
  79. float m_MaxX;
  80. float m_MaxZ;
  81. struct impl;
  82. impl *imp;
  83. bool mapLoaded;
  84. bool mapLoading;
  85. Mutex CheckMapMutex;
  86. };
  87. class MapRange {
  88. public:
  89. MapRange();
  90. ~MapRange();
  91. void Clear();
  92. void AddVersionRange(std::string zoneName);
  93. map<VersionRange*, Map*>::iterator FindVersionRange(int32 min_version, int32 max_version);
  94. map<VersionRange*, Map*>::iterator FindMapByVersion(int32 version);
  95. map<VersionRange*, Map*>::iterator GetRangeEnd() { return version_map.end(); }
  96. private:
  97. std::map<VersionRange*, Map*> version_map;
  98. string name;
  99. };
  100. #endif