2 (c) 2010 Perttu Ahola <celeron55@gmail.com>
9 #include "common_irrlicht.h"
12 #include "exceptions.h"
13 #include "serialization.h"
15 // Size of node in rendering units
18 #define MATERIALS_COUNT 256
20 // This is completely ignored. It doesn't create faces with anything.
21 #define MATERIAL_IGNORE 255
22 // This is the common material through which the player can walk
23 // and which is transparent to light
24 #define MATERIAL_AIR 254
30 - Dynamics of gravel: if there is a drop of more than two
31 blocks on any side, it will drop in there. Is this doable?
41 For water, the param is water pressure. 0...127.
42 TODO: No, at least the lowest nibble is used for lighting.
44 - Water will be a bit like light, but with different flow
46 - Water blocks will fall down if there is empty space below.
47 - If there is water below, the pressure of the block below is
48 the pressure of the current block + 1, or higher.
49 - If there is any pressure in a horizontally neighboring
50 block, a water block will try to move away from it.
51 - If there is >=2 of pressure in a block below, water will
53 - NOTE: To keep large operations fast, we have to keep a
54 cache of the water-air-surfaces, just like with light
63 MATERIAL_GRASS_FOOTSTEPS,
67 // This is set to the number of the actual values in this enum
72 If true, the material allows light propagation and brightness is stored
75 inline bool light_propagates_material(u8 m)
77 return (m == MATERIAL_AIR || m == MATERIAL_LIGHT || m == MATERIAL_WATER);
81 If true, the material allows lossless sunlight propagation.
83 inline bool sunlight_propagates_material(u8 m)
85 return (m == MATERIAL_AIR);
89 On a node-node surface, the material of the node with higher solidness
95 inline u8 material_solidness(u8 m)
99 if(m == MATERIAL_WATER)
105 Nodes make a face if materials differ and solidness differs.
108 1: Face uses m1's material
109 2: Face uses m2's material
111 inline u8 face_materials(u8 m1, u8 m2)
113 if(m1 == MATERIAL_IGNORE || m2 == MATERIAL_IGNORE)
116 bool materials_differ = (m1 != m2);
117 bool solidness_differs = (material_solidness(m1) != material_solidness(m2));
118 bool makes_face = materials_differ && solidness_differs;
120 if(makes_face == false)
123 if(material_solidness(m1) > material_solidness(m2))
131 //TODO: block type to differ from material
132 // (e.g. grass edges or something)
136 // Removed because light is now stored in param for air
140 Misc parameter. Initialized to 0.
141 - For light_propagates() blocks, this is light intensity,
142 stored logarithmically from 0 to LIGHT_MAX.
143 Sunlight is LIGHT_SUN, which is LIGHT_MAX+1.
147 MapNode(const MapNode & n)
152 MapNode(u8 data=MATERIAL_AIR, u8 a_param=0)
158 bool light_propagates()
160 return light_propagates_material(d);
163 bool sunlight_propagates()
165 return sunlight_propagates_material(d);
170 return material_solidness(d);
176 Note that a block that isn't light_propagates() can be a light source.
178 if(d == MATERIAL_LIGHT)
186 // Select the brightest of [light_source, transparent_light]
188 if(light_propagates())
189 light = param & 0x0f;
190 if(light_source() > light)
191 light = light_source();
195 void setLight(u8 a_light)
197 // If not transparent, can't set light
198 if(light_propagates() == false)
203 static u32 serializedLength(u8 version)
205 if(!ser_ver_supported(version))
206 throw VersionMismatchException("ERROR: MapNode format not supported");
213 void serialize(u8 *dest, u8 version)
215 if(!ser_ver_supported(version))
216 throw VersionMismatchException("ERROR: MapNode format not supported");
228 void deSerialize(u8 *source, u8 version)
230 if(!ser_ver_supported(version))
231 throw VersionMismatchException("ERROR: MapNode format not supported");
237 else if(version == 1)
240 // This version doesn't support saved lighting
241 if(light_propagates() || light_source() > 0)
255 Returns integer position of the node in given
256 floating point position.
258 inline v3s16 floatToInt(v3f p)
261 (p.X + (p.X>0 ? BS/2 : -BS/2))/BS,
262 (p.Y + (p.Y>0 ? BS/2 : -BS/2))/BS,
263 (p.Z + (p.Z>0 ? BS/2 : -BS/2))/BS);
267 inline v3f intToFloat(v3s16 p)