mapsector.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef MAPSECTOR_HEADER
  17. #define MAPSECTOR_HEADER
  18. #include "irrlichttypes.h"
  19. #include "irr_v2d.h"
  20. #include <ostream>
  21. #include <map>
  22. #include <list>
  23. class MapBlock;
  24. class Map;
  25. class IGameDef;
  26. /*
  27. This is an Y-wise stack of MapBlocks.
  28. */
  29. #define MAPSECTOR_SERVER 0
  30. #define MAPSECTOR_CLIENT 1
  31. class MapSector
  32. {
  33. public:
  34. MapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
  35. virtual ~MapSector();
  36. virtual u32 getId() const = 0;
  37. void deleteBlocks();
  38. v2s16 getPos()
  39. {
  40. return m_pos;
  41. }
  42. MapBlock * getBlockNoCreateNoEx(s16 y);
  43. MapBlock * createBlankBlockNoInsert(s16 y);
  44. MapBlock * createBlankBlock(s16 y);
  45. void insertBlock(MapBlock *block);
  46. void deleteBlock(MapBlock *block);
  47. void getBlocks(std::list<MapBlock*> &dest);
  48. // Always false at the moment, because sector contains no metadata.
  49. bool differs_from_disk;
  50. protected:
  51. // The pile of MapBlocks
  52. std::map<s16, MapBlock*> m_blocks;
  53. Map *m_parent;
  54. // Position on parent (in MapBlock widths)
  55. v2s16 m_pos;
  56. IGameDef *m_gamedef;
  57. // Last-used block is cached here for quicker access.
  58. // Be sure to set this to NULL when the cached block is deleted
  59. MapBlock *m_block_cache;
  60. s16 m_block_cache_y;
  61. /*
  62. Private methods
  63. */
  64. MapBlock *getBlockBuffered(s16 y);
  65. };
  66. class ServerMapSector : public MapSector
  67. {
  68. public:
  69. ServerMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
  70. ~ServerMapSector();
  71. u32 getId() const
  72. {
  73. return MAPSECTOR_SERVER;
  74. }
  75. /*
  76. These functions handle metadata.
  77. They do not handle blocks.
  78. */
  79. void serialize(std::ostream &os, u8 version);
  80. static ServerMapSector* deSerialize(
  81. std::istream &is,
  82. Map *parent,
  83. v2s16 p2d,
  84. std::map<v2s16, MapSector*> & sectors,
  85. IGameDef *gamedef
  86. );
  87. private:
  88. };
  89. #ifndef SERVER
  90. class ClientMapSector : public MapSector
  91. {
  92. public:
  93. ClientMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
  94. ~ClientMapSector();
  95. u32 getId() const
  96. {
  97. return MAPSECTOR_CLIENT;
  98. }
  99. private:
  100. };
  101. #endif
  102. #endif