3 Copyright (C) 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.
22 #include "main.h" // For g_settings
29 #include "nameidmapping.h"
30 #include "util/serialize.h"
31 //#include "profiler.h" // For TimeTaker
39 type = NODEBOX_REGULAR;
42 // default is sign/ladder-like
43 wall_top = aabb3f(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2);
44 wall_bottom = aabb3f(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2);
45 wall_side = aabb3f(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2);
48 void NodeBox::serialize(std::ostream &os) const
50 writeU8(os, 1); // version
53 if(type == NODEBOX_FIXED)
55 writeU16(os, fixed.size());
56 for(std::vector<aabb3f>::const_iterator
58 i != fixed.end(); i++)
60 writeV3F1000(os, i->MinEdge);
61 writeV3F1000(os, i->MaxEdge);
64 else if(type == NODEBOX_WALLMOUNTED)
66 writeV3F1000(os, wall_top.MinEdge);
67 writeV3F1000(os, wall_top.MaxEdge);
68 writeV3F1000(os, wall_bottom.MinEdge);
69 writeV3F1000(os, wall_bottom.MaxEdge);
70 writeV3F1000(os, wall_side.MinEdge);
71 writeV3F1000(os, wall_side.MaxEdge);
75 void NodeBox::deSerialize(std::istream &is)
77 int version = readU8(is);
79 throw SerializationError("unsupported NodeBox version");
83 type = (enum NodeBoxType)readU8(is);
85 if(type == NODEBOX_FIXED)
87 u16 fixed_count = readU16(is);
91 box.MinEdge = readV3F1000(is);
92 box.MaxEdge = readV3F1000(is);
96 else if(type == NODEBOX_WALLMOUNTED)
98 wall_top.MinEdge = readV3F1000(is);
99 wall_top.MaxEdge = readV3F1000(is);
100 wall_bottom.MinEdge = readV3F1000(is);
101 wall_bottom.MaxEdge = readV3F1000(is);
102 wall_side.MinEdge = readV3F1000(is);
103 wall_side.MaxEdge = readV3F1000(is);
111 void TileDef::serialize(std::ostream &os, u16 protocol_version) const
113 if(protocol_version >= 17)
117 os<<serializeString(name);
118 writeU8(os, animation.type);
119 writeU16(os, animation.aspect_w);
120 writeU16(os, animation.aspect_h);
121 writeF1000(os, animation.length);
122 if(protocol_version >= 17)
123 writeU8(os, backface_culling);
126 void TileDef::deSerialize(std::istream &is)
128 int version = readU8(is);
129 name = deSerializeString(is);
130 animation.type = (TileAnimationType)readU8(is);
131 animation.aspect_w = readU16(is);
132 animation.aspect_h = readU16(is);
133 animation.length = readF1000(is);
135 backface_culling = readU8(is);
139 SimpleSoundSpec serialization
142 static void serializeSimpleSoundSpec(const SimpleSoundSpec &ss,
145 os<<serializeString(ss.name);
146 writeF1000(os, ss.gain);
148 static void deSerializeSimpleSoundSpec(SimpleSoundSpec &ss, std::istream &is)
150 ss.name = deSerializeString(is);
151 ss.gain = readF1000(is);
158 ContentFeatures::ContentFeatures()
163 ContentFeatures::~ContentFeatures()
167 void ContentFeatures::reset()
174 visual_solidness = 0;
175 backface_culling = true;
177 has_on_construct = false;
178 has_on_destruct = false;
179 has_after_destruct = false;
183 NOTE: Most of this is always overridden by the default values given
188 // Unknown nodes can be dug
189 groups["dig_immediate"] = 2;
190 drawtype = NDT_NORMAL;
192 for(u32 i=0; i<6; i++)
193 tiledef[i] = TileDef();
194 for(u16 j=0; j<CF_SPECIAL_COUNT; j++)
195 tiledef_special[j] = TileDef();
197 post_effect_color = video::SColor(0, 0, 0, 0);
198 param_type = CPT_NONE;
199 param_type_2 = CPT2_NONE;
200 is_ground_content = false;
201 light_propagates = false;
202 sunlight_propagates = false;
207 buildable_to = false;
208 rightclickable = true;
209 liquid_type = LIQUID_NONE;
210 liquid_alternative_flowing = "";
211 liquid_alternative_source = "";
212 liquid_viscosity = 0;
213 liquid_renewable = true;
216 damage_per_second = 0;
217 node_box = NodeBox();
218 selection_box = NodeBox();
219 legacy_facedir_simple = false;
220 legacy_wallmounted = false;
221 sound_footstep = SimpleSoundSpec();
222 sound_dig = SimpleSoundSpec("__group");
223 sound_dug = SimpleSoundSpec();
226 void ContentFeatures::serialize(std::ostream &os, u16 protocol_version)
228 if(protocol_version < 14){
229 serializeOld(os, protocol_version);
233 writeU8(os, 6); // version
234 os<<serializeString(name);
235 writeU16(os, groups.size());
236 for(ItemGroupList::const_iterator
237 i = groups.begin(); i != groups.end(); i++){
238 os<<serializeString(i->first);
239 writeS16(os, i->second);
241 writeU8(os, drawtype);
242 writeF1000(os, visual_scale);
244 for(u32 i=0; i<6; i++)
245 tiledef[i].serialize(os, protocol_version);
246 writeU8(os, CF_SPECIAL_COUNT);
247 for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
248 tiledef_special[i].serialize(os, protocol_version);
251 writeU8(os, post_effect_color.getAlpha());
252 writeU8(os, post_effect_color.getRed());
253 writeU8(os, post_effect_color.getGreen());
254 writeU8(os, post_effect_color.getBlue());
255 writeU8(os, param_type);
256 writeU8(os, param_type_2);
257 writeU8(os, is_ground_content);
258 writeU8(os, light_propagates);
259 writeU8(os, sunlight_propagates);
260 writeU8(os, walkable);
261 writeU8(os, pointable);
262 writeU8(os, diggable);
263 writeU8(os, climbable);
264 writeU8(os, buildable_to);
265 os<<serializeString(""); // legacy: used to be metadata_name
266 writeU8(os, liquid_type);
267 os<<serializeString(liquid_alternative_flowing);
268 os<<serializeString(liquid_alternative_source);
269 writeU8(os, liquid_viscosity);
270 writeU8(os, liquid_renewable);
271 writeU8(os, light_source);
272 writeU32(os, damage_per_second);
273 node_box.serialize(os);
274 selection_box.serialize(os);
275 writeU8(os, legacy_facedir_simple);
276 writeU8(os, legacy_wallmounted);
277 serializeSimpleSoundSpec(sound_footstep, os);
278 serializeSimpleSoundSpec(sound_dig, os);
279 serializeSimpleSoundSpec(sound_dug, os);
280 writeU8(os, rightclickable);
281 // Stuff below should be moved to correct place in a version that otherwise changes
282 // the protocol version
283 writeU8(os, drowning);
286 void ContentFeatures::deSerialize(std::istream &is)
288 int version = readU8(is);
290 deSerializeOld(is, version);
294 name = deSerializeString(is);
296 u32 groups_size = readU16(is);
297 for(u32 i=0; i<groups_size; i++){
298 std::string name = deSerializeString(is);
299 int value = readS16(is);
300 groups[name] = value;
302 drawtype = (enum NodeDrawType)readU8(is);
303 visual_scale = readF1000(is);
305 throw SerializationError("unsupported tile count");
306 for(u32 i=0; i<6; i++)
307 tiledef[i].deSerialize(is);
308 if(readU8(is) != CF_SPECIAL_COUNT)
309 throw SerializationError("unsupported CF_SPECIAL_COUNT");
310 for(u32 i=0; i<CF_SPECIAL_COUNT; i++)
311 tiledef_special[i].deSerialize(is);
313 post_effect_color.setAlpha(readU8(is));
314 post_effect_color.setRed(readU8(is));
315 post_effect_color.setGreen(readU8(is));
316 post_effect_color.setBlue(readU8(is));
317 param_type = (enum ContentParamType)readU8(is);
318 param_type_2 = (enum ContentParamType2)readU8(is);
319 is_ground_content = readU8(is);
320 light_propagates = readU8(is);
321 sunlight_propagates = readU8(is);
322 walkable = readU8(is);
323 pointable = readU8(is);
324 diggable = readU8(is);
325 climbable = readU8(is);
326 buildable_to = readU8(is);
327 deSerializeString(is); // legacy: used to be metadata_name
328 liquid_type = (enum LiquidType)readU8(is);
329 liquid_alternative_flowing = deSerializeString(is);
330 liquid_alternative_source = deSerializeString(is);
331 liquid_viscosity = readU8(is);
332 liquid_renewable = readU8(is);
333 light_source = readU8(is);
334 damage_per_second = readU32(is);
335 node_box.deSerialize(is);
336 selection_box.deSerialize(is);
337 legacy_facedir_simple = readU8(is);
338 legacy_wallmounted = readU8(is);
339 deSerializeSimpleSoundSpec(sound_footstep, is);
340 deSerializeSimpleSoundSpec(sound_dig, is);
341 deSerializeSimpleSoundSpec(sound_dug, is);
342 rightclickable = readU8(is);
343 // If you add anything here, insert it primarily inside the try-catch
344 // block to not need to increase the version.
346 // Stuff below should be moved to correct place in a version that
347 // otherwise changes the protocol version
348 drowning = readU8(is);
349 }catch(SerializationError &e) {};
356 class CNodeDefManager: public IWritableNodeDefManager
361 m_name_id_mapping.clear();
362 m_name_id_mapping_with_aliases.clear();
364 for(u16 i=0; i<=MAX_CONTENT; i++)
366 ContentFeatures &f = m_content_features[i];
367 f.reset(); // Reset to defaults
374 f.drawtype = NDT_AIRLIKE;
375 f.param_type = CPT_LIGHT;
376 f.light_propagates = true;
377 f.sunlight_propagates = true;
381 f.buildable_to = true;
382 // Insert directly into containers
383 content_t c = CONTENT_AIR;
384 m_content_features[c] = f;
385 addNameIdMapping(c, f.name);
387 // Set CONTENT_IGNORE
391 f.drawtype = NDT_AIRLIKE;
392 f.param_type = CPT_NONE;
393 f.light_propagates = false;
394 f.sunlight_propagates = false;
398 // A way to remove accidental CONTENT_IGNOREs
399 f.buildable_to = true;
400 // Insert directly into containers
401 content_t c = CONTENT_IGNORE;
402 m_content_features[c] = f;
403 addNameIdMapping(c, f.name);
406 // CONTENT_IGNORE = not found
407 content_t getFreeId()
409 for(u32 i=0; i<=0xffff; i++){
410 const ContentFeatures &f = m_content_features[i];
414 return CONTENT_IGNORE;
420 virtual ~CNodeDefManager()
423 virtual IWritableNodeDefManager* clone()
425 CNodeDefManager *mgr = new CNodeDefManager();
426 for(u16 i=0; i<=MAX_CONTENT; i++)
432 virtual const ContentFeatures& get(content_t c) const
434 assert(c <= MAX_CONTENT);
435 return m_content_features[c];
437 virtual const ContentFeatures& get(const MapNode &n) const
439 return get(n.getContent());
441 virtual bool getId(const std::string &name, content_t &result) const
443 std::map<std::string, content_t>::const_iterator
444 i = m_name_id_mapping_with_aliases.find(name);
445 if(i == m_name_id_mapping_with_aliases.end())
450 virtual content_t getId(const std::string &name) const
452 content_t id = CONTENT_IGNORE;
456 virtual void getIds(const std::string &name, std::set<content_t> &result)
459 //TimeTaker t("getIds", NULL, PRECISION_MICRO);
460 if(name.substr(0,6) != "group:"){
461 content_t id = CONTENT_IGNORE;
466 std::string group = name.substr(6);
468 #if 1 // Optimized version, takes less than 1 microsecond at -O1
469 std::map<std::string, GroupItems>::const_iterator
470 i = m_group_to_items.find(group);
471 if (i == m_group_to_items.end())
474 const GroupItems &items = i->second;
475 for (GroupItems::const_iterator j = items.begin();
476 j != items.end(); ++j) {
477 if ((*j).second != 0)
478 result.insert((*j).first);
480 #else // Old version, takes about ~150-200us at -O1
481 for(u16 id=0; id<=MAX_CONTENT; id++)
483 const ContentFeatures &f = m_content_features[id];
484 if(f.name == "") // Quickly discard undefined nodes
486 if(itemgroup_get(f.groups, group) != 0)
490 //printf("getIds: %dus\n", t.stop());
492 virtual const ContentFeatures& get(const std::string &name) const
494 content_t id = CONTENT_IGNORE;
498 // IWritableNodeDefManager
499 virtual void set(content_t c, const ContentFeatures &def)
501 verbosestream<<"registerNode: registering content id \""<<c
502 <<"\": name=\""<<def.name<<"\""<<std::endl;
503 assert(c <= MAX_CONTENT);
504 // Don't allow redefining CONTENT_IGNORE (but allow air)
505 if(def.name == "ignore" || c == CONTENT_IGNORE){
506 infostream<<"registerNode: WARNING: Ignoring "
507 <<"CONTENT_IGNORE redefinition"<<std::endl;
510 // Check that the special contents are not redefined as different id
511 // because it would mess up everything
512 if((def.name == "ignore" && c != CONTENT_IGNORE) ||
513 (def.name == "air" && c != CONTENT_AIR)){
514 errorstream<<"registerNode: IGNORING ERROR: "
515 <<"trying to register built-in type \""
516 <<def.name<<"\" as different id"<<std::endl;
519 m_content_features[c] = def;
521 addNameIdMapping(c, def.name);
523 // Add this content to the list of all groups it belongs to
524 for (ItemGroupList::const_iterator i = def.groups.begin();
525 i != def.groups.end(); ++i) {
526 std::string group_name = i->first;
528 std::map<std::string, GroupItems>::iterator
529 j = m_group_to_items.find(group_name);
530 if (j == m_group_to_items.end()) {
531 m_group_to_items[group_name].push_back(std::make_pair(c, i->second));
533 GroupItems &items = j->second;
534 items.push_back(std::make_pair(c, i->second));
538 virtual content_t set(const std::string &name,
539 const ContentFeatures &def)
541 assert(name == def.name);
542 u16 id = CONTENT_IGNORE;
543 bool found = m_name_id_mapping.getId(name, id); // ignore aliases
547 if(id == CONTENT_IGNORE)
548 return CONTENT_IGNORE;
550 addNameIdMapping(id, name);
555 virtual content_t allocateDummy(const std::string &name)
562 virtual void updateAliases(IItemDefManager *idef)
564 std::set<std::string> all = idef->getAll();
565 m_name_id_mapping_with_aliases.clear();
566 for(std::set<std::string>::iterator
567 i = all.begin(); i != all.end(); i++)
569 std::string name = *i;
570 std::string convert_to = idef->getAlias(name);
572 if(m_name_id_mapping.getId(convert_to, id))
574 m_name_id_mapping_with_aliases.insert(
575 std::make_pair(name, id));
579 virtual void updateTextures(ITextureSource *tsrc)
582 infostream<<"CNodeDefManager::updateTextures(): Updating "
583 <<"textures in node definitions"<<std::endl;
585 bool new_style_water = g_settings->getBool("new_style_water");
586 bool new_style_leaves = g_settings->getBool("new_style_leaves");
587 bool opaque_water = g_settings->getBool("opaque_water");
589 for(u16 i=0; i<=MAX_CONTENT; i++)
591 ContentFeatures *f = &m_content_features[i];
593 // Figure out the actual tiles to use
595 for(u32 j=0; j<6; j++)
597 tiledef[j] = f->tiledef[j];
598 if(tiledef[j].name == "")
599 tiledef[j].name = "unknown_node.png";
602 bool is_liquid = false;
612 assert(f->liquid_type == LIQUID_SOURCE);
619 f->backface_culling = false;
623 case NDT_FLOWINGLIQUID:
624 assert(f->liquid_type == LIQUID_FLOWING);
632 f->visual_solidness = 1;
634 case NDT_GLASSLIKE_FRAMED:
636 f->visual_solidness = 1;
640 f->visual_solidness = 1;
642 case NDT_ALLFACES_OPTIONAL:
643 if(new_style_leaves){
644 f->drawtype = NDT_ALLFACES;
646 f->visual_solidness = 1;
648 f->drawtype = NDT_NORMAL;
650 for(u32 i=0; i<6; i++){
651 tiledef[i].name += std::string("^[noalpha");
657 f->backface_culling = false;
670 material_type = (f->alpha == 255) ? TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT;
672 material_type = (f->alpha == 255) ? TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA;
674 // Tiles (fill in f->tiles[])
675 for(u16 j=0; j<6; j++){
677 f->tiles[j].texture = tsrc->getTexture(
679 &f->tiles[j].texture_id);
681 f->tiles[j].alpha = f->alpha;
683 f->tiles[j].material_type = material_type;
685 f->tiles[j].material_flags = 0;
686 if(f->backface_culling)
687 f->tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
688 if(tiledef[j].animation.type == TAT_VERTICAL_FRAMES)
689 f->tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
690 // Animation parameters
691 if(f->tiles[j].material_flags &
692 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
694 // Get texture size to determine frame count by
696 v2u32 size = f->tiles[j].texture->getOriginalSize();
697 int frame_height = (float)size.X /
698 (float)tiledef[j].animation.aspect_w *
699 (float)tiledef[j].animation.aspect_h;
700 int frame_count = size.Y / frame_height;
701 int frame_length_ms = 1000.0 *
702 tiledef[j].animation.length / frame_count;
703 f->tiles[j].animation_frame_count = frame_count;
704 f->tiles[j].animation_frame_length_ms = frame_length_ms;
706 // If there are no frames for an animation, switch
707 // animation off (so that having specified an animation
708 // for something but not using it in the texture pack
709 // gives no overhead)
710 if(frame_count == 1){
711 f->tiles[j].material_flags &=
712 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
716 // Special tiles (fill in f->special_tiles[])
717 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
719 f->special_tiles[j].texture = tsrc->getTexture(
720 f->tiledef_special[j].name,
721 &f->special_tiles[j].texture_id);
723 f->special_tiles[j].alpha = f->alpha;
725 f->special_tiles[j].material_type = material_type;
727 f->special_tiles[j].material_flags = 0;
728 if(f->tiledef_special[j].backface_culling)
729 f->special_tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
730 if(f->tiledef_special[j].animation.type == TAT_VERTICAL_FRAMES)
731 f->special_tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
732 // Animation parameters
733 if(f->special_tiles[j].material_flags &
734 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
736 // Get texture size to determine frame count by
738 v2u32 size = f->special_tiles[j].texture->getOriginalSize();
739 int frame_height = (float)size.X /
740 (float)f->tiledef_special[j].animation.aspect_w *
741 (float)f->tiledef_special[j].animation.aspect_h;
742 int frame_count = size.Y / frame_height;
743 int frame_length_ms = 1000.0 *
744 f->tiledef_special[j].animation.length / frame_count;
745 f->special_tiles[j].animation_frame_count = frame_count;
746 f->special_tiles[j].animation_frame_length_ms = frame_length_ms;
748 // If there are no frames for an animation, switch
749 // animation off (so that having specified an animation
750 // for something but not using it in the texture pack
751 // gives no overhead)
752 if(frame_count == 1){
753 f->special_tiles[j].material_flags &=
754 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
761 void serialize(std::ostream &os, u16 protocol_version)
763 writeU8(os, 1); // version
765 std::ostringstream os2(std::ios::binary);
766 for(u16 i=0; i<=MAX_CONTENT; i++)
768 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
770 ContentFeatures *f = &m_content_features[i];
774 // Wrap it in a string to allow different lengths without
775 // strict version incompatibilities
776 std::ostringstream wrapper_os(std::ios::binary);
777 f->serialize(wrapper_os, protocol_version);
778 os2<<serializeString(wrapper_os.str());
782 os<<serializeLongString(os2.str());
784 void deSerialize(std::istream &is)
787 int version = readU8(is);
789 throw SerializationError("unsupported NodeDefinitionManager version");
790 u16 count = readU16(is);
791 std::istringstream is2(deSerializeLongString(is), std::ios::binary);
792 for(u16 n=0; n<count; n++){
793 u16 i = readU16(is2);
795 errorstream<<"ContentFeatures::deSerialize(): "
796 <<"Too large content id: "<<i<<std::endl;
799 /*// Do not deserialize special types
800 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
802 ContentFeatures *f = &m_content_features[i];
803 // Read it from the string wrapper
804 std::string wrapper = deSerializeString(is2);
805 std::istringstream wrapper_is(wrapper, std::ios::binary);
806 f->deSerialize(wrapper_is);
807 verbosestream<<"deserialized "<<f->name<<std::endl;
809 addNameIdMapping(i, f->name);
813 void addNameIdMapping(content_t i, std::string name)
815 m_name_id_mapping.set(i, name);
816 m_name_id_mapping_with_aliases.insert(std::make_pair(name, i));
819 // Features indexed by id
820 ContentFeatures m_content_features[MAX_CONTENT+1];
821 // A mapping for fast converting back and forth between names and ids
822 NameIdMapping m_name_id_mapping;
823 // Like m_name_id_mapping, but only from names to ids, and includes
824 // item aliases too. Updated by updateAliases()
825 // Note: Not serialized.
826 std::map<std::string, content_t> m_name_id_mapping_with_aliases;
827 // A mapping from groups to a list of content_ts (and their levels)
828 // that belong to it. Necessary for a direct lookup in getIds().
829 // Note: Not serialized.
830 std::map<std::string, GroupItems> m_group_to_items;
833 IWritableNodeDefManager* createNodeDefManager()
835 return new CNodeDefManager();
839 Serialization of old ContentFeatures formats
842 void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version)
844 if(protocol_version == 13)
846 writeU8(os, 5); // version
847 os<<serializeString(name);
848 writeU16(os, groups.size());
849 for(ItemGroupList::const_iterator
850 i = groups.begin(); i != groups.end(); i++){
851 os<<serializeString(i->first);
852 writeS16(os, i->second);
854 writeU8(os, drawtype);
855 writeF1000(os, visual_scale);
857 for(u32 i=0; i<6; i++)
858 tiledef[i].serialize(os, protocol_version);
859 writeU8(os, CF_SPECIAL_COUNT);
860 for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
861 tiledef_special[i].serialize(os, protocol_version);
864 writeU8(os, post_effect_color.getAlpha());
865 writeU8(os, post_effect_color.getRed());
866 writeU8(os, post_effect_color.getGreen());
867 writeU8(os, post_effect_color.getBlue());
868 writeU8(os, param_type);
869 writeU8(os, param_type_2);
870 writeU8(os, is_ground_content);
871 writeU8(os, light_propagates);
872 writeU8(os, sunlight_propagates);
873 writeU8(os, walkable);
874 writeU8(os, pointable);
875 writeU8(os, diggable);
876 writeU8(os, climbable);
877 writeU8(os, buildable_to);
878 os<<serializeString(""); // legacy: used to be metadata_name
879 writeU8(os, liquid_type);
880 os<<serializeString(liquid_alternative_flowing);
881 os<<serializeString(liquid_alternative_source);
882 writeU8(os, liquid_viscosity);
883 writeU8(os, light_source);
884 writeU32(os, damage_per_second);
885 node_box.serialize(os);
886 selection_box.serialize(os);
887 writeU8(os, legacy_facedir_simple);
888 writeU8(os, legacy_wallmounted);
889 serializeSimpleSoundSpec(sound_footstep, os);
890 serializeSimpleSoundSpec(sound_dig, os);
891 serializeSimpleSoundSpec(sound_dug, os);
895 throw SerializationError("ContentFeatures::serialize(): Unsupported version requested");
899 void ContentFeatures::deSerializeOld(std::istream &is, int version)
901 if(version == 5) // In PROTOCOL_VERSION 13
903 name = deSerializeString(is);
905 u32 groups_size = readU16(is);
906 for(u32 i=0; i<groups_size; i++){
907 std::string name = deSerializeString(is);
908 int value = readS16(is);
909 groups[name] = value;
911 drawtype = (enum NodeDrawType)readU8(is);
912 visual_scale = readF1000(is);
914 throw SerializationError("unsupported tile count");
915 for(u32 i=0; i<6; i++)
916 tiledef[i].deSerialize(is);
917 if(readU8(is) != CF_SPECIAL_COUNT)
918 throw SerializationError("unsupported CF_SPECIAL_COUNT");
919 for(u32 i=0; i<CF_SPECIAL_COUNT; i++)
920 tiledef_special[i].deSerialize(is);
922 post_effect_color.setAlpha(readU8(is));
923 post_effect_color.setRed(readU8(is));
924 post_effect_color.setGreen(readU8(is));
925 post_effect_color.setBlue(readU8(is));
926 param_type = (enum ContentParamType)readU8(is);
927 param_type_2 = (enum ContentParamType2)readU8(is);
928 is_ground_content = readU8(is);
929 light_propagates = readU8(is);
930 sunlight_propagates = readU8(is);
931 walkable = readU8(is);
932 pointable = readU8(is);
933 diggable = readU8(is);
934 climbable = readU8(is);
935 buildable_to = readU8(is);
936 deSerializeString(is); // legacy: used to be metadata_name
937 liquid_type = (enum LiquidType)readU8(is);
938 liquid_alternative_flowing = deSerializeString(is);
939 liquid_alternative_source = deSerializeString(is);
940 liquid_viscosity = readU8(is);
941 light_source = readU8(is);
942 damage_per_second = readU32(is);
943 node_box.deSerialize(is);
944 selection_box.deSerialize(is);
945 legacy_facedir_simple = readU8(is);
946 legacy_wallmounted = readU8(is);
947 deSerializeSimpleSoundSpec(sound_footstep, is);
948 deSerializeSimpleSoundSpec(sound_dig, is);
949 deSerializeSimpleSoundSpec(sound_dug, is);
953 throw SerializationError("unsupported ContentFeatures version");