]> git.lizzy.rs Git - minetest-m13.git/blob - src/mapsector.h
Update to 4.6 base
[minetest-m13.git] / src / mapsector.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
14
15 You should have received a copy of the GNU 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 /*
21 (c) 2010 Perttu Ahola <celeron55@gmail.com>
22 */
23
24 #ifndef MAPSECTOR_HEADER
25 #define MAPSECTOR_HEADER
26
27 #include <jmutex.h>
28 #include "common_irrlicht.h"
29 #include "exceptions.h"
30 #include <ostream>
31
32 class MapBlock;
33 class Map;
34 class IGameDef;
35
36 /*
37         This is an Y-wise stack of MapBlocks.
38 */
39
40 #define MAPSECTOR_SERVER 0
41 #define MAPSECTOR_CLIENT 1
42
43 class MapSector
44 {
45 public:
46         
47         MapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
48         virtual ~MapSector();
49
50         virtual u32 getId() const = 0;
51
52         void deleteBlocks();
53
54         v2s16 getPos()
55         {
56                 return m_pos;
57         }
58
59         MapBlock * getBlockNoCreateNoEx(s16 y);
60         MapBlock * createBlankBlockNoInsert(s16 y);
61         MapBlock * createBlankBlock(s16 y);
62
63         void insertBlock(MapBlock *block);
64         
65         void deleteBlock(MapBlock *block);
66         
67         void getBlocks(core::list<MapBlock*> &dest);
68         
69         // Always false at the moment, because sector contains no metadata.
70         bool differs_from_disk;
71
72 protected:
73         
74         // The pile of MapBlocks
75         core::map<s16, MapBlock*> m_blocks;
76
77         Map *m_parent;
78         // Position on parent (in MapBlock widths)
79         v2s16 m_pos;
80
81         IGameDef *m_gamedef;
82         
83         // Last-used block is cached here for quicker access.
84         // Be sure to set this to NULL when the cached block is deleted 
85         MapBlock *m_block_cache;
86         s16 m_block_cache_y;
87         
88         /*
89                 Private methods
90         */
91         MapBlock *getBlockBuffered(s16 y);
92
93 };
94
95 class ServerMapSector : public MapSector
96 {
97 public:
98         ServerMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
99         ~ServerMapSector();
100         
101         u32 getId() const
102         {
103                 return MAPSECTOR_SERVER;
104         }
105
106         /*
107                 These functions handle metadata.
108                 They do not handle blocks.
109         */
110
111         void serialize(std::ostream &os, u8 version);
112         
113         static ServerMapSector* deSerialize(
114                         std::istream &is,
115                         Map *parent,
116                         v2s16 p2d,
117                         core::map<v2s16, MapSector*> & sectors,
118                         IGameDef *gamedef
119                 );
120                 
121 private:
122 };
123
124 #ifndef SERVER
125 class ClientMapSector : public MapSector
126 {
127 public:
128         ClientMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
129         ~ClientMapSector();
130         
131         u32 getId() const
132         {
133                 return MAPSECTOR_CLIENT;
134         }
135
136 private:
137 };
138 #endif
139         
140 #endif
141