]> git.lizzy.rs Git - minetest.git/blob - src/mapsector.h
Merge pull request #482 from proller/liquid
[minetest.git] / src / mapsector.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MAPSECTOR_HEADER
21 #define MAPSECTOR_HEADER
22
23 #include <jmutex.h>
24 #include "irrlichttypes_bloated.h"
25 #include "exceptions.h"
26 #include <ostream>
27
28 class MapBlock;
29 class Map;
30 class IGameDef;
31
32 /*
33         This is an Y-wise stack of MapBlocks.
34 */
35
36 #define MAPSECTOR_SERVER 0
37 #define MAPSECTOR_CLIENT 1
38
39 class MapSector
40 {
41 public:
42         
43         MapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
44         virtual ~MapSector();
45
46         virtual u32 getId() const = 0;
47
48         void deleteBlocks();
49
50         v2s16 getPos()
51         {
52                 return m_pos;
53         }
54
55         MapBlock * getBlockNoCreateNoEx(s16 y);
56         MapBlock * createBlankBlockNoInsert(s16 y);
57         MapBlock * createBlankBlock(s16 y);
58
59         void insertBlock(MapBlock *block);
60         
61         void deleteBlock(MapBlock *block);
62         
63         void getBlocks(core::list<MapBlock*> &dest);
64         
65         // Always false at the moment, because sector contains no metadata.
66         bool differs_from_disk;
67
68 protected:
69         
70         // The pile of MapBlocks
71         core::map<s16, MapBlock*> m_blocks;
72
73         Map *m_parent;
74         // Position on parent (in MapBlock widths)
75         v2s16 m_pos;
76
77         IGameDef *m_gamedef;
78         
79         // Last-used block is cached here for quicker access.
80         // Be sure to set this to NULL when the cached block is deleted 
81         MapBlock *m_block_cache;
82         s16 m_block_cache_y;
83         
84         /*
85                 Private methods
86         */
87         MapBlock *getBlockBuffered(s16 y);
88
89 };
90
91 class ServerMapSector : public MapSector
92 {
93 public:
94         ServerMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
95         ~ServerMapSector();
96         
97         u32 getId() const
98         {
99                 return MAPSECTOR_SERVER;
100         }
101
102         /*
103                 These functions handle metadata.
104                 They do not handle blocks.
105         */
106
107         void serialize(std::ostream &os, u8 version);
108         
109         static ServerMapSector* deSerialize(
110                         std::istream &is,
111                         Map *parent,
112                         v2s16 p2d,
113                         core::map<v2s16, MapSector*> & sectors,
114                         IGameDef *gamedef
115                 );
116                 
117 private:
118 };
119
120 #ifndef SERVER
121 class ClientMapSector : public MapSector
122 {
123 public:
124         ClientMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
125         ~ClientMapSector();
126         
127         u32 getId() const
128         {
129                 return MAPSECTOR_CLIENT;
130         }
131
132 private:
133 };
134 #endif
135         
136 #endif
137