3 Copyright (C) 2010-2013 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
37 typedef u16 content_t;
38 #define MAX_CONTENT 0xfff
43 Anything that stores MapNodes doesn't have to preserve parameters
44 associated with this material.
46 Doesn't create faces with anything and is considered being
47 out-of-map in the game map.
49 #define CONTENT_IGNORE 127
50 #define CONTENT_IGNORE_DEFAULT_PARAM 0
53 The common material through which the player can walk and which
54 is transparent to light
56 #define CONTENT_AIR 126
65 Masks for MapNode.param2 of flowing liquids
67 #define LIQUID_LEVEL_MASK 0x07
68 #define LIQUID_FLOW_DOWN_MASK 0x08
70 //#define LIQUID_LEVEL_MASK 0x3f // better finite water
71 //#define LIQUID_FLOW_DOWN_MASK 0x40 // not used when finite water
73 /* maximum amount of liquid in a block */
74 #define LIQUID_LEVEL_MAX LIQUID_LEVEL_MASK
75 #define LIQUID_LEVEL_SOURCE (LIQUID_LEVEL_MAX+1)
77 #define LIQUID_INFINITY_MASK 0x80 //0b10000000
80 This is the stuff what the whole world consists of.
92 Misc parameter. Initialized to 0.
93 - For light_propagates() blocks, this is light intensity,
94 stored logarithmically from 0 to LIGHT_MAX.
95 Sunlight is LIGHT_SUN, which is LIGHT_MAX+1.
96 - Contains 2 values, day- and night lighting. Each takes 4 bits.
97 - Uhh... well, most blocks have light or nothing in here.
102 The second parameter. Initialized to 0.
103 E.g. direction for torches and flowing water.
107 MapNode(const MapNode & n)
112 MapNode(content_t content=CONTENT_AIR, u8 a_param1=0, u8 a_param2=0)
119 // Create directly from a nodename
120 // If name is unknown, sets CONTENT_IGNORE
121 MapNode(INodeDefManager *ndef, const std::string &name,
122 u8 a_param1=0, u8 a_param2=0);
124 bool operator==(const MapNode &other)
126 return (param0 == other.param0
127 && param1 == other.param1
128 && param2 == other.param2);
131 // To be used everywhere
132 content_t getContent() const
136 void setContent(content_t c)
157 void setLight(enum LightBank bank, u8 a_light, INodeDefManager *nodemgr);
158 u8 getLight(enum LightBank bank, INodeDefManager *nodemgr) const;
159 bool getLightBanks(u8 &lightday, u8 &lightnight, INodeDefManager *nodemgr) const;
161 // 0 <= daylight_factor <= 1000
162 // 0 <= return value <= LIGHT_SUN
163 u8 getLightBlend(u32 daylight_factor, INodeDefManager *nodemgr) const
167 getLightBanks(lightday, lightnight, nodemgr);
168 return blend_light(daylight_factor, lightday, lightnight);
171 // 0.0 <= daylight_factor <= 1.0
172 // 0 <= return value <= LIGHT_SUN
173 u8 getLightBlendF1(float daylight_factor, INodeDefManager *nodemgr) const
177 getLightBanks(lightday, lightnight, nodemgr);
178 return blend_light_f1(daylight_factor, lightday, lightnight);
181 u8 getFaceDir(INodeDefManager *nodemgr) const;
182 u8 getWallMounted(INodeDefManager *nodemgr) const;
183 v3s16 getWallMountedDir(INodeDefManager *nodemgr) const;
186 Gets list of node boxes (used for rendering (NDT_NODEBOX)
189 std::vector<aabb3f> getNodeBoxes(INodeDefManager *nodemgr) const;
192 Gets list of selection boxes
194 std::vector<aabb3f> getSelectionBoxes(INodeDefManager *nodemgr) const;
197 Serialization functions
200 static u32 serializedLength(u8 version);
201 void serialize(u8 *dest, u8 version);
202 void deSerialize(u8 *source, u8 version);
204 // Serializes or deserializes a list of nodes in bulk format (first the
205 // content of all nodes, then the param1 of all nodes, then the param2
207 // version = serialization version. Must be >= 22
208 // content_width = the number of bytes of content per node
209 // params_width = the number of bytes of params per node
210 // compressed = true to zlib-compress output
211 static void serializeBulk(std::ostream &os, int version,
212 const MapNode *nodes, u32 nodecount,
213 u8 content_width, u8 params_width, bool compressed);
214 static void deSerializeBulk(std::istream &is, int version,
215 MapNode *nodes, u32 nodecount,
216 u8 content_width, u8 params_width, bool compressed);
219 // Deprecated serialization methods
220 void deSerialize_pre22(u8 *source, u8 version);