SPGrid.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <vector>
  18. #include <map>
  19. #include "../../common/types.h"
  20. class Spawn;
  21. #define CELLSIZEDEFAULT 150
  22. #define FACECELLSIZEDEFAULT 15
  23. struct Face {
  24. float Vertex1[3];
  25. float Vertex2[3];
  26. float Vertex3[3];
  27. int32 grid_id;
  28. };
  29. /*struct GridBounds {
  30. int32 Grid;
  31. float MinBounds[3];
  32. float MaxBounds[3];
  33. };*/
  34. struct Cell {
  35. std::vector<Spawn*> SpawnList;
  36. //std::map<int32, vector<Face*> > FaceList;
  37. //std::map<int32, GridBounds*> GridBounds;
  38. };
  39. struct FaceCell {
  40. std::map<int32, vector<Face*> > FaceList;
  41. };
  42. class SPGrid {
  43. public:
  44. SPGrid(string file, int32 cellSize);
  45. ~SPGrid();
  46. // Sets up the spacial partioning grid
  47. bool Init();
  48. // Get cell based on cell coordinates
  49. Cell* GetCell(int32 x, int32 z);
  50. // Get cell based on world coordinates
  51. Cell* GetCell(float x, float z);
  52. // Adds a face to the cells it needs to be in and sets its GridID
  53. void AddFace(Face* face, int32 grid);
  54. // Checks the faces below the given spawn to determine the GridID
  55. int32 GetGridID(Spawn* spawn);
  56. // Calculate a cell from spawn's position and add the spawn to it
  57. void AddSpawn(Spawn* spawn);
  58. // Adds the spawn to a specific spell
  59. void AddSpawn(Spawn* spawn, Cell* cell);
  60. // Removes the spawn from the cell it is currently in
  61. void RemoveSpawnFromCell(Spawn* spawn);
  62. // Get cell based on cell coordinates
  63. FaceCell* GetFaceCell(int32 x, int32 z);
  64. // Get cell based on world coordinates
  65. FaceCell* GetFaceCell(float x, float z);
  66. float GetBestY(float x, float y, float z);
  67. Face* GetClosestFace(float x, float y, float z);
  68. Face* FindPath(float x, float y, float z, float targX, float targY, float targZ, bool forceEndCell=false);
  69. private:
  70. // 1-D array for cells as it is better performance wise then 2-D
  71. std::vector<Cell> m_Cells;
  72. std::vector<FaceCell> m_FaceCells;
  73. string m_ZoneFile;
  74. int32 m_CellSize;
  75. float m_MinX;
  76. float m_MinZ;
  77. float m_MaxX;
  78. float m_MaxZ;
  79. int32 m_NumCellsX;
  80. int32 m_NumCellsZ;
  81. int32 m_NumFaceCellsX;
  82. int32 m_NumFaceCellsZ;
  83. };