3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #ifndef MAPNODE_HEADER
21 #define MAPNODE_HEADER
23 #include "irrlichttypes.h"
25 #include "irr_aabb3d.h"
29 class INodeDefManager;
33 - Material = irrlicht's Material class
34 - Content = (content_t) content of a node
35 - Tile = TileSpec at some side of a node of some content type
38 0x000...0x07f: param2 is fully usable
39 0x800...0xfff: param2 lower 4 bits are free
41 typedef u16 content_t;
42 #define MAX_CONTENT 0xfff
47 Anything that stores MapNodes doesn't have to preserve parameters
48 associated with this material.
50 Doesn't create faces with anything and is considered being
51 out-of-map in the game map.
53 #define CONTENT_IGNORE 127
54 #define CONTENT_IGNORE_DEFAULT_PARAM 0
57 The common material through which the player can walk and which
58 is transparent to light
60 #define CONTENT_AIR 126
69 Masks for MapNode.param2 of flowing liquids
71 #define LIQUID_LEVEL_MASK 0x07
72 #define LIQUID_FLOW_DOWN_MASK 0x08
74 /* maximum amount of liquid in a block */
75 #define LIQUID_LEVEL_MAX LIQUID_LEVEL_MASK
76 #define LIQUID_LEVEL_SOURCE (LIQUID_LEVEL_MAX+1)
79 This is the stuff what the whole world consists of.
87 0x00-0x7f: Short content type
88 0x80-0xff: Long content type
93 Misc parameter. Initialized to 0.
94 - For light_propagates() blocks, this is light intensity,
95 stored logarithmically from 0 to LIGHT_MAX.
96 Sunlight is LIGHT_SUN, which is LIGHT_MAX+1.
97 - Contains 2 values, day- and night lighting. Each takes 4 bits.
98 - Uhh... well, most blocks have light or nothing in here.
103 The second parameter. Initialized to 0.
104 E.g. direction for torches and flowing water.
108 MapNode(const MapNode & n)
113 MapNode(content_t content=CONTENT_AIR, u8 a_param1=0, u8 a_param2=0)
120 // Create directly from a nodename
121 // If name is unknown, sets CONTENT_IGNORE
122 MapNode(INodeDefManager *ndef, const std::string &name,
123 u8 a_param1=0, u8 a_param2=0);
125 bool operator==(const MapNode &other)
127 return (param0 == other.param0
128 && param1 == other.param1
129 && param2 == other.param2);
132 // To be used everywhere
133 content_t getContent() const
137 void setContent(content_t c)
158 void setLight(enum LightBank bank, u8 a_light, INodeDefManager *nodemgr);
159 u8 getLight(enum LightBank bank, INodeDefManager *nodemgr) const;
160 bool getLightBanks(u8 &lightday, u8 &lightnight, INodeDefManager *nodemgr) const;
162 // 0 <= daylight_factor <= 1000
163 // 0 <= return value <= LIGHT_SUN
164 u8 getLightBlend(u32 daylight_factor, INodeDefManager *nodemgr) const
168 getLightBanks(lightday, lightnight, nodemgr);
169 return blend_light(daylight_factor, lightday, lightnight);
172 u8 getFaceDir(INodeDefManager *nodemgr) const;
173 u8 getWallMounted(INodeDefManager *nodemgr) const;
174 v3s16 getWallMountedDir(INodeDefManager *nodemgr) const;
177 Gets list of node boxes (used for rendering (NDT_NODEBOX)
180 std::vector<aabb3f> getNodeBoxes(INodeDefManager *nodemgr) const;
183 Gets list of selection boxes
185 std::vector<aabb3f> getSelectionBoxes(INodeDefManager *nodemgr) const;
188 Serialization functions
191 static u32 serializedLength(u8 version);
192 void serialize(u8 *dest, u8 version);
193 void deSerialize(u8 *source, u8 version);
195 // Serializes or deserializes a list of nodes in bulk format (first the
196 // content of all nodes, then the param1 of all nodes, then the param2
198 // version = serialization version. Must be >= 22
199 // content_width = the number of bytes of content per node
200 // params_width = the number of bytes of params per node
201 // compressed = true to zlib-compress output
202 static void serializeBulk(std::ostream &os, int version,
203 const MapNode *nodes, u32 nodecount,
204 u8 content_width, u8 params_width, bool compressed);
205 static void deSerializeBulk(std::istream &is, int version,
206 MapNode *nodes, u32 nodecount,
207 u8 content_width, u8 params_width, bool compressed);
210 // Deprecated serialization methods
211 void serialize_pre22(u8 *dest, u8 version);
212 void deSerialize_pre22(u8 *source, u8 version);