mapsector.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "irrlichttypes.h"
  18. #include "irr_v2d.h"
  19. #include "mapblock.h"
  20. #include <ostream>
  21. #include <map>
  22. #include <vector>
  23. class Map;
  24. class IGameDef;
  25. /*
  26. This is an Y-wise stack of MapBlocks.
  27. */
  28. #define MAPSECTOR_SERVER 0
  29. #define MAPSECTOR_CLIENT 1
  30. class MapSector
  31. {
  32. public:
  33. MapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
  34. virtual ~MapSector();
  35. void deleteBlocks();
  36. v2s16 getPos()
  37. {
  38. return m_pos;
  39. }
  40. MapBlock * getBlockNoCreateNoEx(s16 y);
  41. MapBlock * createBlankBlockNoInsert(s16 y);
  42. MapBlock * createBlankBlock(s16 y);
  43. void insertBlock(MapBlock *block);
  44. void deleteBlock(MapBlock *block);
  45. void getBlocks(MapBlockVect &dest);
  46. bool empty() const { return m_blocks.empty(); }
  47. protected:
  48. // The pile of MapBlocks
  49. std::unordered_map<s16, MapBlock*> m_blocks;
  50. Map *m_parent;
  51. // Position on parent (in MapBlock widths)
  52. v2s16 m_pos;
  53. IGameDef *m_gamedef;
  54. // Last-used block is cached here for quicker access.
  55. // Be sure to set this to nullptr when the cached block is deleted
  56. MapBlock *m_block_cache = nullptr;
  57. s16 m_block_cache_y;
  58. /*
  59. Private methods
  60. */
  61. MapBlock *getBlockBuffered(s16 y);
  62. };