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/numeric.h"
31 #include "util/serialize.h"
32 //#include "profiler.h" // For TimeTaker
40 type = NODEBOX_REGULAR;
43 // default is sign/ladder-like
44 wall_top = aabb3f(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2);
45 wall_bottom = aabb3f(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2);
46 wall_side = aabb3f(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2);
49 void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
51 int version = protocol_version >= 21 ? 2 : 1;
54 if (version == 1 && type == NODEBOX_LEVELED)
55 writeU8(os, NODEBOX_FIXED);
59 if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED)
61 writeU16(os, fixed.size());
62 for(std::vector<aabb3f>::const_iterator
64 i != fixed.end(); i++)
66 writeV3F1000(os, i->MinEdge);
67 writeV3F1000(os, i->MaxEdge);
70 else if(type == NODEBOX_WALLMOUNTED)
72 writeV3F1000(os, wall_top.MinEdge);
73 writeV3F1000(os, wall_top.MaxEdge);
74 writeV3F1000(os, wall_bottom.MinEdge);
75 writeV3F1000(os, wall_bottom.MaxEdge);
76 writeV3F1000(os, wall_side.MinEdge);
77 writeV3F1000(os, wall_side.MaxEdge);
81 void NodeBox::deSerialize(std::istream &is)
83 int version = readU8(is);
84 if(version < 1 || version > 2)
85 throw SerializationError("unsupported NodeBox version");
89 type = (enum NodeBoxType)readU8(is);
91 if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED)
93 u16 fixed_count = readU16(is);
97 box.MinEdge = readV3F1000(is);
98 box.MaxEdge = readV3F1000(is);
102 else if(type == NODEBOX_WALLMOUNTED)
104 wall_top.MinEdge = readV3F1000(is);
105 wall_top.MaxEdge = readV3F1000(is);
106 wall_bottom.MinEdge = readV3F1000(is);
107 wall_bottom.MaxEdge = readV3F1000(is);
108 wall_side.MinEdge = readV3F1000(is);
109 wall_side.MaxEdge = readV3F1000(is);
117 void TileDef::serialize(std::ostream &os, u16 protocol_version) const
119 if(protocol_version >= 17)
123 os<<serializeString(name);
124 writeU8(os, animation.type);
125 writeU16(os, animation.aspect_w);
126 writeU16(os, animation.aspect_h);
127 writeF1000(os, animation.length);
128 if(protocol_version >= 17)
129 writeU8(os, backface_culling);
132 void TileDef::deSerialize(std::istream &is)
134 int version = readU8(is);
135 name = deSerializeString(is);
136 animation.type = (TileAnimationType)readU8(is);
137 animation.aspect_w = readU16(is);
138 animation.aspect_h = readU16(is);
139 animation.length = readF1000(is);
141 backface_culling = readU8(is);
145 SimpleSoundSpec serialization
148 static void serializeSimpleSoundSpec(const SimpleSoundSpec &ss,
151 os<<serializeString(ss.name);
152 writeF1000(os, ss.gain);
154 static void deSerializeSimpleSoundSpec(SimpleSoundSpec &ss, std::istream &is)
156 ss.name = deSerializeString(is);
157 ss.gain = readF1000(is);
164 ContentFeatures::ContentFeatures()
169 ContentFeatures::~ContentFeatures()
173 void ContentFeatures::reset()
180 visual_solidness = 0;
181 backface_culling = true;
183 has_on_construct = false;
184 has_on_destruct = false;
185 has_after_destruct = false;
189 NOTE: Most of this is always overridden by the default values given
194 // Unknown nodes can be dug
195 groups["dig_immediate"] = 2;
196 drawtype = NDT_NORMAL;
198 for(u32 i=0; i<6; i++)
199 tiledef[i] = TileDef();
200 for(u16 j=0; j<CF_SPECIAL_COUNT; j++)
201 tiledef_special[j] = TileDef();
203 post_effect_color = video::SColor(0, 0, 0, 0);
204 param_type = CPT_NONE;
205 param_type_2 = CPT2_NONE;
206 is_ground_content = false;
207 light_propagates = false;
208 sunlight_propagates = false;
213 buildable_to = false;
214 rightclickable = true;
216 liquid_type = LIQUID_NONE;
217 liquid_alternative_flowing = "";
218 liquid_alternative_source = "";
219 liquid_viscosity = 0;
220 liquid_renewable = true;
222 liquid_range = LIQUID_LEVEL_MAX+1;
225 damage_per_second = 0;
226 node_box = NodeBox();
227 selection_box = NodeBox();
228 legacy_facedir_simple = false;
229 legacy_wallmounted = false;
230 sound_footstep = SimpleSoundSpec();
231 sound_dig = SimpleSoundSpec("__group");
232 sound_dug = SimpleSoundSpec();
235 void ContentFeatures::serialize(std::ostream &os, u16 protocol_version)
237 if(protocol_version < 14){
238 serializeOld(os, protocol_version);
242 writeU8(os, 6); // version
243 os<<serializeString(name);
244 writeU16(os, groups.size());
245 for(ItemGroupList::const_iterator
246 i = groups.begin(); i != groups.end(); i++){
247 os<<serializeString(i->first);
248 writeS16(os, i->second);
250 writeU8(os, drawtype);
251 writeF1000(os, visual_scale);
253 for(u32 i=0; i<6; i++)
254 tiledef[i].serialize(os, protocol_version);
255 writeU8(os, CF_SPECIAL_COUNT);
256 for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
257 tiledef_special[i].serialize(os, protocol_version);
260 writeU8(os, post_effect_color.getAlpha());
261 writeU8(os, post_effect_color.getRed());
262 writeU8(os, post_effect_color.getGreen());
263 writeU8(os, post_effect_color.getBlue());
264 writeU8(os, param_type);
265 writeU8(os, param_type_2);
266 writeU8(os, is_ground_content);
267 writeU8(os, light_propagates);
268 writeU8(os, sunlight_propagates);
269 writeU8(os, walkable);
270 writeU8(os, pointable);
271 writeU8(os, diggable);
272 writeU8(os, climbable);
273 writeU8(os, buildable_to);
274 os<<serializeString(""); // legacy: used to be metadata_name
275 writeU8(os, liquid_type);
276 os<<serializeString(liquid_alternative_flowing);
277 os<<serializeString(liquid_alternative_source);
278 writeU8(os, liquid_viscosity);
279 writeU8(os, liquid_renewable);
280 writeU8(os, light_source);
281 writeU32(os, damage_per_second);
282 node_box.serialize(os, protocol_version);
283 selection_box.serialize(os, protocol_version);
284 writeU8(os, legacy_facedir_simple);
285 writeU8(os, legacy_wallmounted);
286 serializeSimpleSoundSpec(sound_footstep, os);
287 serializeSimpleSoundSpec(sound_dig, os);
288 serializeSimpleSoundSpec(sound_dug, os);
289 writeU8(os, rightclickable);
290 writeU8(os, drowning);
291 writeU8(os, leveled);
292 writeU8(os, liquid_range);
293 // Stuff below should be moved to correct place in a version that otherwise changes
294 // the protocol version
297 void ContentFeatures::deSerialize(std::istream &is)
299 int version = readU8(is);
301 deSerializeOld(is, version);
305 name = deSerializeString(is);
307 u32 groups_size = readU16(is);
308 for(u32 i=0; i<groups_size; i++){
309 std::string name = deSerializeString(is);
310 int value = readS16(is);
311 groups[name] = value;
313 drawtype = (enum NodeDrawType)readU8(is);
314 visual_scale = readF1000(is);
316 throw SerializationError("unsupported tile count");
317 for(u32 i=0; i<6; i++)
318 tiledef[i].deSerialize(is);
319 if(readU8(is) != CF_SPECIAL_COUNT)
320 throw SerializationError("unsupported CF_SPECIAL_COUNT");
321 for(u32 i=0; i<CF_SPECIAL_COUNT; i++)
322 tiledef_special[i].deSerialize(is);
324 post_effect_color.setAlpha(readU8(is));
325 post_effect_color.setRed(readU8(is));
326 post_effect_color.setGreen(readU8(is));
327 post_effect_color.setBlue(readU8(is));
328 param_type = (enum ContentParamType)readU8(is);
329 param_type_2 = (enum ContentParamType2)readU8(is);
330 is_ground_content = readU8(is);
331 light_propagates = readU8(is);
332 sunlight_propagates = readU8(is);
333 walkable = readU8(is);
334 pointable = readU8(is);
335 diggable = readU8(is);
336 climbable = readU8(is);
337 buildable_to = readU8(is);
338 deSerializeString(is); // legacy: used to be metadata_name
339 liquid_type = (enum LiquidType)readU8(is);
340 liquid_alternative_flowing = deSerializeString(is);
341 liquid_alternative_source = deSerializeString(is);
342 liquid_viscosity = readU8(is);
343 liquid_renewable = readU8(is);
344 light_source = readU8(is);
345 damage_per_second = readU32(is);
346 node_box.deSerialize(is);
347 selection_box.deSerialize(is);
348 legacy_facedir_simple = readU8(is);
349 legacy_wallmounted = readU8(is);
350 deSerializeSimpleSoundSpec(sound_footstep, is);
351 deSerializeSimpleSoundSpec(sound_dig, is);
352 deSerializeSimpleSoundSpec(sound_dug, is);
353 rightclickable = readU8(is);
354 drowning = readU8(is);
355 leveled = readU8(is);
356 liquid_range = readU8(is);
357 // If you add anything here, insert it primarily inside the try-catch
358 // block to not need to increase the version.
360 // Stuff below should be moved to correct place in a version that
361 // otherwise changes the protocol version
362 }catch(SerializationError &e) {};
369 class CNodeDefManager: public IWritableNodeDefManager
374 m_content_features.clear();
375 m_name_id_mapping.clear();
376 m_name_id_mapping_with_aliases.clear();
377 m_group_to_items.clear();
380 u32 initial_length = 0;
381 initial_length = MYMAX(initial_length, CONTENT_UNKNOWN + 1);
382 initial_length = MYMAX(initial_length, CONTENT_AIR + 1);
383 initial_length = MYMAX(initial_length, CONTENT_IGNORE + 1);
384 m_content_features.resize(initial_length);
386 // Set CONTENT_UNKNOWN
390 // Insert directly into containers
391 content_t c = CONTENT_UNKNOWN;
392 m_content_features[c] = f;
393 addNameIdMapping(c, f.name);
400 f.drawtype = NDT_AIRLIKE;
401 f.param_type = CPT_LIGHT;
402 f.light_propagates = true;
403 f.sunlight_propagates = true;
407 f.buildable_to = true;
408 f.is_ground_content = true;
409 // Insert directly into containers
410 content_t c = CONTENT_AIR;
411 m_content_features[c] = f;
412 addNameIdMapping(c, f.name);
415 // Set CONTENT_IGNORE
419 f.drawtype = NDT_AIRLIKE;
420 f.param_type = CPT_NONE;
421 f.light_propagates = false;
422 f.sunlight_propagates = false;
426 f.buildable_to = true; // A way to remove accidental CONTENT_IGNOREs
427 f.is_ground_content = true;
428 // Insert directly into containers
429 content_t c = CONTENT_IGNORE;
430 m_content_features[c] = f;
431 addNameIdMapping(c, f.name);
438 virtual ~CNodeDefManager()
441 virtual IWritableNodeDefManager* clone()
443 CNodeDefManager *mgr = new CNodeDefManager();
447 virtual const ContentFeatures& get(content_t c) const
449 if(c < m_content_features.size())
450 return m_content_features[c];
452 return m_content_features[CONTENT_UNKNOWN];
454 virtual const ContentFeatures& get(const MapNode &n) const
456 return get(n.getContent());
458 virtual bool getId(const std::string &name, content_t &result) const
460 std::map<std::string, content_t>::const_iterator
461 i = m_name_id_mapping_with_aliases.find(name);
462 if(i == m_name_id_mapping_with_aliases.end())
467 virtual content_t getId(const std::string &name) const
469 content_t id = CONTENT_IGNORE;
473 virtual void getIds(const std::string &name, std::set<content_t> &result)
476 //TimeTaker t("getIds", NULL, PRECISION_MICRO);
477 if(name.substr(0,6) != "group:"){
478 content_t id = CONTENT_IGNORE;
483 std::string group = name.substr(6);
485 std::map<std::string, GroupItems>::const_iterator
486 i = m_group_to_items.find(group);
487 if (i == m_group_to_items.end())
490 const GroupItems &items = i->second;
491 for (GroupItems::const_iterator j = items.begin();
492 j != items.end(); ++j) {
493 if ((*j).second != 0)
494 result.insert((*j).first);
496 //printf("getIds: %dus\n", t.stop());
498 virtual const ContentFeatures& get(const std::string &name) const
500 content_t id = CONTENT_UNKNOWN;
504 // returns CONTENT_IGNORE if no free ID found
505 content_t allocateId()
507 for(content_t id = m_next_id;
508 id >= m_next_id; // overflow?
510 while(id >= m_content_features.size()){
511 m_content_features.push_back(ContentFeatures());
513 const ContentFeatures &f = m_content_features[id];
519 // If we arrive here, an overflow occurred in id.
520 // That means no ID was found
521 return CONTENT_IGNORE;
523 // IWritableNodeDefManager
524 virtual content_t set(const std::string &name,
525 const ContentFeatures &def)
528 assert(name == def.name);
530 // Don't allow redefining ignore (but allow air and unknown)
531 if(name == "ignore"){
532 infostream<<"NodeDefManager: WARNING: Ignoring "
533 <<"CONTENT_IGNORE redefinition"<<std::endl;
534 return CONTENT_IGNORE;
537 content_t id = CONTENT_IGNORE;
538 bool found = m_name_id_mapping.getId(name, id); // ignore aliases
542 if(id == CONTENT_IGNORE){
543 infostream<<"NodeDefManager: WARNING: Absolute "
544 <<"limit reached"<<std::endl;
545 return CONTENT_IGNORE;
547 assert(id != CONTENT_IGNORE);
548 addNameIdMapping(id, name);
550 m_content_features[id] = def;
551 verbosestream<<"NodeDefManager: registering content id \""<<id
552 <<"\": name=\""<<def.name<<"\""<<std::endl;
554 // Add this content to the list of all groups it belongs to
555 // FIXME: This should remove a node from groups it no longer
556 // belongs to when a node is re-registered
557 for (ItemGroupList::const_iterator i = def.groups.begin();
558 i != def.groups.end(); ++i) {
559 std::string group_name = i->first;
561 std::map<std::string, GroupItems>::iterator
562 j = m_group_to_items.find(group_name);
563 if (j == m_group_to_items.end()) {
564 m_group_to_items[group_name].push_back(
565 std::make_pair(id, i->second));
567 GroupItems &items = j->second;
568 items.push_back(std::make_pair(id, i->second));
573 virtual content_t allocateDummy(const std::string &name)
580 virtual void updateAliases(IItemDefManager *idef)
582 std::set<std::string> all = idef->getAll();
583 m_name_id_mapping_with_aliases.clear();
584 for(std::set<std::string>::iterator
585 i = all.begin(); i != all.end(); i++)
587 std::string name = *i;
588 std::string convert_to = idef->getAlias(name);
590 if(m_name_id_mapping.getId(convert_to, id))
592 m_name_id_mapping_with_aliases.insert(
593 std::make_pair(name, id));
597 virtual void updateTextures(ITextureSource *tsrc)
600 infostream<<"CNodeDefManager::updateTextures(): Updating "
601 <<"textures in node definitions"<<std::endl;
603 bool new_style_water = g_settings->getBool("new_style_water");
604 bool new_style_leaves = g_settings->getBool("new_style_leaves");
605 bool opaque_water = g_settings->getBool("opaque_water");
607 for(u32 i=0; i<m_content_features.size(); i++)
609 ContentFeatures *f = &m_content_features[i];
611 // Figure out the actual tiles to use
613 for(u32 j=0; j<6; j++)
615 tiledef[j] = f->tiledef[j];
616 if(tiledef[j].name == "")
617 tiledef[j].name = "unknown_node.png";
620 bool is_liquid = false;
630 assert(f->liquid_type == LIQUID_SOURCE);
637 f->backface_culling = false;
641 case NDT_FLOWINGLIQUID:
642 assert(f->liquid_type == LIQUID_FLOWING);
650 f->visual_solidness = 1;
652 case NDT_GLASSLIKE_FRAMED:
654 f->visual_solidness = 1;
658 f->visual_solidness = 1;
660 case NDT_ALLFACES_OPTIONAL:
661 if(new_style_leaves){
662 f->drawtype = NDT_ALLFACES;
664 f->visual_solidness = 1;
666 f->drawtype = NDT_NORMAL;
668 for(u32 i=0; i<6; i++){
669 tiledef[i].name += std::string("^[noalpha");
675 f->backface_culling = false;
688 material_type = (f->alpha == 255) ? TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT;
690 material_type = (f->alpha == 255) ? TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA;
692 // Tiles (fill in f->tiles[])
693 for(u16 j=0; j<6; j++){
695 f->tiles[j].texture = tsrc->getTexture(
697 &f->tiles[j].texture_id);
699 f->tiles[j].alpha = f->alpha;
701 f->tiles[j].material_type = material_type;
703 f->tiles[j].material_flags = 0;
704 if(f->backface_culling)
705 f->tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
706 if(tiledef[j].animation.type == TAT_VERTICAL_FRAMES)
707 f->tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
708 // Animation parameters
709 if(f->tiles[j].material_flags &
710 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
712 // Get texture size to determine frame count by
714 v2u32 size = f->tiles[j].texture->getOriginalSize();
715 int frame_height = (float)size.X /
716 (float)tiledef[j].animation.aspect_w *
717 (float)tiledef[j].animation.aspect_h;
718 int frame_count = size.Y / frame_height;
719 int frame_length_ms = 1000.0 *
720 tiledef[j].animation.length / frame_count;
721 f->tiles[j].animation_frame_count = frame_count;
722 f->tiles[j].animation_frame_length_ms = frame_length_ms;
724 // If there are no frames for an animation, switch
725 // animation off (so that having specified an animation
726 // for something but not using it in the texture pack
727 // gives no overhead)
728 if(frame_count == 1){
729 f->tiles[j].material_flags &=
730 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
734 // Special tiles (fill in f->special_tiles[])
735 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
737 f->special_tiles[j].texture = tsrc->getTexture(
738 f->tiledef_special[j].name,
739 &f->special_tiles[j].texture_id);
741 f->special_tiles[j].alpha = f->alpha;
743 f->special_tiles[j].material_type = material_type;
745 f->special_tiles[j].material_flags = 0;
746 if(f->tiledef_special[j].backface_culling)
747 f->special_tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
748 if(f->tiledef_special[j].animation.type == TAT_VERTICAL_FRAMES)
749 f->special_tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
750 // Animation parameters
751 if(f->special_tiles[j].material_flags &
752 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
754 // Get texture size to determine frame count by
756 v2u32 size = f->special_tiles[j].texture->getOriginalSize();
757 int frame_height = (float)size.X /
758 (float)f->tiledef_special[j].animation.aspect_w *
759 (float)f->tiledef_special[j].animation.aspect_h;
760 int frame_count = size.Y / frame_height;
761 int frame_length_ms = 1000.0 *
762 f->tiledef_special[j].animation.length / frame_count;
763 f->special_tiles[j].animation_frame_count = frame_count;
764 f->special_tiles[j].animation_frame_length_ms = frame_length_ms;
766 // If there are no frames for an animation, switch
767 // animation off (so that having specified an animation
768 // for something but not using it in the texture pack
769 // gives no overhead)
770 if(frame_count == 1){
771 f->special_tiles[j].material_flags &=
772 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
779 void serialize(std::ostream &os, u16 protocol_version)
781 writeU8(os, 1); // version
783 std::ostringstream os2(std::ios::binary);
784 for(u32 i=0; i<m_content_features.size(); i++)
786 if(i == CONTENT_IGNORE || i == CONTENT_AIR
787 || i == CONTENT_UNKNOWN)
789 ContentFeatures *f = &m_content_features[i];
793 // Wrap it in a string to allow different lengths without
794 // strict version incompatibilities
795 std::ostringstream wrapper_os(std::ios::binary);
796 f->serialize(wrapper_os, protocol_version);
797 os2<<serializeString(wrapper_os.str());
799 assert(count + 1 > count); // must not overflow
803 os<<serializeLongString(os2.str());
805 void deSerialize(std::istream &is)
808 int version = readU8(is);
810 throw SerializationError("unsupported NodeDefinitionManager version");
811 u16 count = readU16(is);
812 std::istringstream is2(deSerializeLongString(is), std::ios::binary);
814 for(u16 n=0; n<count; n++){
815 u16 i = readU16(is2);
817 // Read it from the string wrapper
818 std::string wrapper = deSerializeString(is2);
819 std::istringstream wrapper_is(wrapper, std::ios::binary);
820 f.deSerialize(wrapper_is);
822 // Check error conditions
823 if(i == CONTENT_IGNORE || i == CONTENT_AIR
824 || i == CONTENT_UNKNOWN){
825 infostream<<"NodeDefManager::deSerialize(): WARNING: "
826 <<"not changing builtin node "<<i
831 infostream<<"NodeDefManager::deSerialize(): WARNING: "
832 <<"received empty name"<<std::endl;
836 bool found = m_name_id_mapping.getId(f.name, existing_id); // ignore aliases
837 if(found && i != existing_id){
838 infostream<<"NodeDefManager::deSerialize(): WARNING: "
839 <<"already defined with different ID: "
844 // All is ok, add node definition with the requested ID
845 if(i >= m_content_features.size())
846 m_content_features.resize((u32)(i) + 1);
847 m_content_features[i] = f;
848 addNameIdMapping(i, f.name);
849 verbosestream<<"deserialized "<<f.name<<std::endl;
853 void addNameIdMapping(content_t i, std::string name)
855 m_name_id_mapping.set(i, name);
856 m_name_id_mapping_with_aliases.insert(std::make_pair(name, i));
859 // Features indexed by id
860 std::vector<ContentFeatures> m_content_features;
861 // A mapping for fast converting back and forth between names and ids
862 NameIdMapping m_name_id_mapping;
863 // Like m_name_id_mapping, but only from names to ids, and includes
864 // item aliases too. Updated by updateAliases()
865 // Note: Not serialized.
866 std::map<std::string, content_t> m_name_id_mapping_with_aliases;
867 // A mapping from groups to a list of content_ts (and their levels)
868 // that belong to it. Necessary for a direct lookup in getIds().
869 // Note: Not serialized.
870 std::map<std::string, GroupItems> m_group_to_items;
871 // Next possibly free id
875 IWritableNodeDefManager* createNodeDefManager()
877 return new CNodeDefManager();
881 Serialization of old ContentFeatures formats
884 void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version)
886 if(protocol_version == 13)
888 writeU8(os, 5); // version
889 os<<serializeString(name);
890 writeU16(os, groups.size());
891 for(ItemGroupList::const_iterator
892 i = groups.begin(); i != groups.end(); i++){
893 os<<serializeString(i->first);
894 writeS16(os, i->second);
896 writeU8(os, drawtype);
897 writeF1000(os, visual_scale);
899 for(u32 i=0; i<6; i++)
900 tiledef[i].serialize(os, protocol_version);
901 writeU8(os, CF_SPECIAL_COUNT);
902 for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
903 tiledef_special[i].serialize(os, protocol_version);
906 writeU8(os, post_effect_color.getAlpha());
907 writeU8(os, post_effect_color.getRed());
908 writeU8(os, post_effect_color.getGreen());
909 writeU8(os, post_effect_color.getBlue());
910 writeU8(os, param_type);
911 writeU8(os, param_type_2);
912 writeU8(os, is_ground_content);
913 writeU8(os, light_propagates);
914 writeU8(os, sunlight_propagates);
915 writeU8(os, walkable);
916 writeU8(os, pointable);
917 writeU8(os, diggable);
918 writeU8(os, climbable);
919 writeU8(os, buildable_to);
920 os<<serializeString(""); // legacy: used to be metadata_name
921 writeU8(os, liquid_type);
922 os<<serializeString(liquid_alternative_flowing);
923 os<<serializeString(liquid_alternative_source);
924 writeU8(os, liquid_viscosity);
925 writeU8(os, light_source);
926 writeU32(os, damage_per_second);
927 node_box.serialize(os, protocol_version);
928 selection_box.serialize(os, protocol_version);
929 writeU8(os, legacy_facedir_simple);
930 writeU8(os, legacy_wallmounted);
931 serializeSimpleSoundSpec(sound_footstep, os);
932 serializeSimpleSoundSpec(sound_dig, os);
933 serializeSimpleSoundSpec(sound_dug, os);
937 throw SerializationError("ContentFeatures::serialize(): Unsupported version requested");
941 void ContentFeatures::deSerializeOld(std::istream &is, int version)
943 if(version == 5) // In PROTOCOL_VERSION 13
945 name = deSerializeString(is);
947 u32 groups_size = readU16(is);
948 for(u32 i=0; i<groups_size; i++){
949 std::string name = deSerializeString(is);
950 int value = readS16(is);
951 groups[name] = value;
953 drawtype = (enum NodeDrawType)readU8(is);
954 visual_scale = readF1000(is);
956 throw SerializationError("unsupported tile count");
957 for(u32 i=0; i<6; i++)
958 tiledef[i].deSerialize(is);
959 if(readU8(is) != CF_SPECIAL_COUNT)
960 throw SerializationError("unsupported CF_SPECIAL_COUNT");
961 for(u32 i=0; i<CF_SPECIAL_COUNT; i++)
962 tiledef_special[i].deSerialize(is);
964 post_effect_color.setAlpha(readU8(is));
965 post_effect_color.setRed(readU8(is));
966 post_effect_color.setGreen(readU8(is));
967 post_effect_color.setBlue(readU8(is));
968 param_type = (enum ContentParamType)readU8(is);
969 param_type_2 = (enum ContentParamType2)readU8(is);
970 is_ground_content = readU8(is);
971 light_propagates = readU8(is);
972 sunlight_propagates = readU8(is);
973 walkable = readU8(is);
974 pointable = readU8(is);
975 diggable = readU8(is);
976 climbable = readU8(is);
977 buildable_to = readU8(is);
978 deSerializeString(is); // legacy: used to be metadata_name
979 liquid_type = (enum LiquidType)readU8(is);
980 liquid_alternative_flowing = deSerializeString(is);
981 liquid_alternative_source = deSerializeString(is);
982 liquid_viscosity = readU8(is);
983 light_source = readU8(is);
984 damage_per_second = readU32(is);
985 node_box.deSerialize(is);
986 selection_box.deSerialize(is);
987 legacy_facedir_simple = readU8(is);
988 legacy_wallmounted = readU8(is);
989 deSerializeSimpleSoundSpec(sound_footstep, is);
990 deSerializeSimpleSoundSpec(sound_dig, is);
991 deSerializeSimpleSoundSpec(sound_dug, is);
995 throw SerializationError("unsupported ContentFeatures version");