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