SPGrid.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. };
  28. /*struct GridBounds {
  29. int32 Grid;
  30. float MinBounds[3];
  31. float MaxBounds[3];
  32. };*/
  33. struct Cell {
  34. std::vector<Spawn*> SpawnList;
  35. //std::map<int32, vector<Face*> > FaceList;
  36. //std::map<int32, GridBounds*> GridBounds;
  37. };
  38. struct FaceCell {
  39. std::map<int32, vector<Face*> > FaceList;
  40. };
  41. class SPGrid {
  42. public:
  43. SPGrid(string file, int32 cellSize);
  44. ~SPGrid();
  45. // Sets up the spacial partioning grid
  46. bool Init();
  47. // Get cell based on cell coordinates
  48. Cell* GetCell(int32 x, int32 z);
  49. // Get cell based on world coordinates
  50. Cell* GetCell(float x, float z);
  51. // Adds a face to the cells it needs to be in and sets its GridID
  52. void AddFace(Face* face, int32 grid);
  53. // Checks the faces below the given spawn to determine the GridID
  54. int32 GetGridID(Spawn* spawn);
  55. // Calculate a cell from spawn's position and add the spawn to it
  56. void AddSpawn(Spawn* spawn);
  57. // Adds the spawn to a specific spell
  58. void AddSpawn(Spawn* spawn, Cell* cell);
  59. // Removes the spawn from the cell it is currently in
  60. void RemoveSpawnFromCell(Spawn* spawn);
  61. // Get cell based on cell coordinates
  62. FaceCell* GetFaceCell(int32 x, int32 z);
  63. // Get cell based on world coordinates
  64. FaceCell* GetFaceCell(float x, float z);
  65. private:
  66. // 1-D array for cells as it is better performance wise then 2-D
  67. std::vector<Cell> m_Cells;
  68. std::vector<FaceCell> m_FaceCells;
  69. string m_ZoneFile;
  70. int32 m_CellSize;
  71. float m_MinX;
  72. float m_MinZ;
  73. float m_MaxX;
  74. float m_MaxZ;
  75. int32 m_NumCellsX;
  76. int32 m_NumCellsZ;
  77. int32 m_NumFaceCellsX;
  78. int32 m_NumFaceCellsZ;
  79. };