map.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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/Mutex.h"
  20. #include "position.h"
  21. #include <stdio.h>
  22. #include "SPGrid.h"
  23. #define BEST_Z_INVALID -99999
  24. class Map
  25. {
  26. public:
  27. Map(string filename, SPGrid* grid=nullptr);
  28. ~Map();
  29. float FindBestZ(glm::vec3 &start, glm::vec3 *result);
  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. #ifdef USE_MAP_MMFS
  36. bool Load(std::string filename, bool force_mmf_overwrite = false);
  37. #else
  38. bool Load(const std::string& filename);
  39. #endif
  40. static Map *LoadMapFile(std::string file, SPGrid* grid=nullptr);
  41. std::string GetFileName() { return m_ZoneFile; }
  42. void SetMapLoaded(bool val) {
  43. CheckMapMutex.writelock();
  44. mapLoaded = val;
  45. CheckMapMutex.releasewritelock();
  46. }
  47. bool IsMapLoaded() {
  48. bool isMapLoaded = false;
  49. CheckMapMutex.readlock();
  50. isMapLoaded = mapLoaded;
  51. CheckMapMutex.releasereadlock();
  52. return isMapLoaded;
  53. }
  54. void SetMapLoading(bool val) {
  55. CheckMapMutex.writelock();
  56. mapLoading = val;
  57. CheckMapMutex.releasewritelock();
  58. }
  59. bool IsMapLoading() {
  60. bool isMapLoading = false;
  61. CheckMapMutex.readlock();
  62. isMapLoading = mapLoading;
  63. CheckMapMutex.releasereadlock();
  64. return isMapLoading;
  65. }
  66. float GetMinX() { return m_MinX; }
  67. float GetMaxX() { return m_MaxX; }
  68. float GetMinZ() { return m_MinZ; }
  69. float GetMaxZ() { return m_MaxZ; }
  70. private:
  71. void RotateVertex(glm::vec3 &v, float rx, float ry, float rz);
  72. void ScaleVertex(glm::vec3 &v, float sx, float sy, float sz);
  73. void TranslateVertex(glm::vec3 &v, float tx, float ty, float tz);
  74. bool LoadV2(FILE *f);
  75. #ifdef USE_MAP_MMFS
  76. bool LoadMMF(const std::string& map_file_name, bool force_mmf_overwrite);
  77. bool SaveMMF(const std::string& map_file_name, bool force_mmf_overwrite);
  78. #endif /*USE_MAP_MMFS*/
  79. string m_ZoneFile;
  80. int32 m_CellSize;
  81. float m_MinX;
  82. float m_MinZ;
  83. float m_MaxX;
  84. float m_MaxZ;
  85. int32 m_NumCellsX;
  86. int32 m_NumCellsZ;
  87. int32 m_NumFaceCellsX;
  88. int32 m_NumFaceCellsZ;
  89. struct impl;
  90. impl *imp;
  91. bool mapLoaded;
  92. bool mapLoading;
  93. Mutex CheckMapMutex;
  94. SPGrid* mGrid;
  95. };
  96. #endif