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(tiledef[j].name);
679 f->tiles[j].alpha = f->alpha;
681 f->tiles[j].material_type = material_type;
683 f->tiles[j].material_flags = 0;
684 if(f->backface_culling)
685 f->tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
686 if(tiledef[j].animation.type == TAT_VERTICAL_FRAMES)
687 f->tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
688 // Animation parameters
689 if(f->tiles[j].material_flags &
690 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
692 // Get raw texture size to determine frame count by
694 video::ITexture *t = tsrc->getTextureRaw(tiledef[j].name);
695 v2u32 size = t->getOriginalSize();
696 int frame_height = (float)size.X /
697 (float)tiledef[j].animation.aspect_w *
698 (float)tiledef[j].animation.aspect_h;
699 int frame_count = size.Y / frame_height;
700 int frame_length_ms = 1000.0 *
701 tiledef[j].animation.length / frame_count;
702 f->tiles[j].animation_frame_count = frame_count;
703 f->tiles[j].animation_frame_length_ms = frame_length_ms;
705 // If there are no frames for an animation, switch
706 // animation off (so that having specified an animation
707 // for something but not using it in the texture pack
708 // gives no overhead)
709 if(frame_count == 1){
710 f->tiles[j].material_flags &=
711 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
715 // Special tiles (fill in f->special_tiles[])
716 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
718 f->special_tiles[j].texture =
719 tsrc->getTexture(f->tiledef_special[j].name);
721 f->special_tiles[j].alpha = f->alpha;
723 f->special_tiles[j].material_type = material_type;
725 f->special_tiles[j].material_flags = 0;
726 if(f->tiledef_special[j].backface_culling)
727 f->special_tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
728 if(f->tiledef_special[j].animation.type == TAT_VERTICAL_FRAMES)
729 f->special_tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
730 // Animation parameters
731 if(f->special_tiles[j].material_flags &
732 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
734 // Get raw texture size to determine frame count by
736 video::ITexture *t = tsrc->getTextureRaw(f->tiledef_special[j].name);
737 v2u32 size = t->getOriginalSize();
738 int frame_height = (float)size.X /
739 (float)f->tiledef_special[j].animation.aspect_w *
740 (float)f->tiledef_special[j].animation.aspect_h;
741 int frame_count = size.Y / frame_height;
742 int frame_length_ms = 1000.0 *
743 f->tiledef_special[j].animation.length / frame_count;
744 f->special_tiles[j].animation_frame_count = frame_count;
745 f->special_tiles[j].animation_frame_length_ms = frame_length_ms;
747 // If there are no frames for an animation, switch
748 // animation off (so that having specified an animation
749 // for something but not using it in the texture pack
750 // gives no overhead)
751 if(frame_count == 1){
752 f->special_tiles[j].material_flags &=
753 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
760 void serialize(std::ostream &os, u16 protocol_version)
762 writeU8(os, 1); // version
764 std::ostringstream os2(std::ios::binary);
765 for(u16 i=0; i<=MAX_CONTENT; i++)
767 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
769 ContentFeatures *f = &m_content_features[i];
773 // Wrap it in a string to allow different lengths without
774 // strict version incompatibilities
775 std::ostringstream wrapper_os(std::ios::binary);
776 f->serialize(wrapper_os, protocol_version);
777 os2<<serializeString(wrapper_os.str());
781 os<<serializeLongString(os2.str());
783 void deSerialize(std::istream &is)
786 int version = readU8(is);
788 throw SerializationError("unsupported NodeDefinitionManager version");
789 u16 count = readU16(is);
790 std::istringstream is2(deSerializeLongString(is), std::ios::binary);
791 for(u16 n=0; n<count; n++){
792 u16 i = readU16(is2);
794 errorstream<<"ContentFeatures::deSerialize(): "
795 <<"Too large content id: "<<i<<std::endl;
798 /*// Do not deserialize special types
799 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
801 ContentFeatures *f = &m_content_features[i];
802 // Read it from the string wrapper
803 std::string wrapper = deSerializeString(is2);
804 std::istringstream wrapper_is(wrapper, std::ios::binary);
805 f->deSerialize(wrapper_is);
806 verbosestream<<"deserialized "<<f->name<<std::endl;
808 addNameIdMapping(i, f->name);
812 void addNameIdMapping(content_t i, std::string name)
814 m_name_id_mapping.set(i, name);
815 m_name_id_mapping_with_aliases.insert(std::make_pair(name, i));
818 // Features indexed by id
819 ContentFeatures m_content_features[MAX_CONTENT+1];
820 // A mapping for fast converting back and forth between names and ids
821 NameIdMapping m_name_id_mapping;
822 // Like m_name_id_mapping, but only from names to ids, and includes
823 // item aliases too. Updated by updateAliases()
824 // Note: Not serialized.
825 std::map<std::string, content_t> m_name_id_mapping_with_aliases;
826 // A mapping from groups to a list of content_ts (and their levels)
827 // that belong to it. Necessary for a direct lookup in getIds().
828 // Note: Not serialized.
829 std::map<std::string, GroupItems> m_group_to_items;
832 IWritableNodeDefManager* createNodeDefManager()
834 return new CNodeDefManager();
838 Serialization of old ContentFeatures formats
841 void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version)
843 if(protocol_version == 13)
845 writeU8(os, 5); // version
846 os<<serializeString(name);
847 writeU16(os, groups.size());
848 for(ItemGroupList::const_iterator
849 i = groups.begin(); i != groups.end(); i++){
850 os<<serializeString(i->first);
851 writeS16(os, i->second);
853 writeU8(os, drawtype);
854 writeF1000(os, visual_scale);
856 for(u32 i=0; i<6; i++)
857 tiledef[i].serialize(os, protocol_version);
858 writeU8(os, CF_SPECIAL_COUNT);
859 for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
860 tiledef_special[i].serialize(os, protocol_version);
863 writeU8(os, post_effect_color.getAlpha());
864 writeU8(os, post_effect_color.getRed());
865 writeU8(os, post_effect_color.getGreen());
866 writeU8(os, post_effect_color.getBlue());
867 writeU8(os, param_type);
868 writeU8(os, param_type_2);
869 writeU8(os, is_ground_content);
870 writeU8(os, light_propagates);
871 writeU8(os, sunlight_propagates);
872 writeU8(os, walkable);
873 writeU8(os, pointable);
874 writeU8(os, diggable);
875 writeU8(os, climbable);
876 writeU8(os, buildable_to);
877 os<<serializeString(""); // legacy: used to be metadata_name
878 writeU8(os, liquid_type);
879 os<<serializeString(liquid_alternative_flowing);
880 os<<serializeString(liquid_alternative_source);
881 writeU8(os, liquid_viscosity);
882 writeU8(os, light_source);
883 writeU32(os, damage_per_second);
884 node_box.serialize(os);
885 selection_box.serialize(os);
886 writeU8(os, legacy_facedir_simple);
887 writeU8(os, legacy_wallmounted);
888 serializeSimpleSoundSpec(sound_footstep, os);
889 serializeSimpleSoundSpec(sound_dig, os);
890 serializeSimpleSoundSpec(sound_dug, os);
894 throw SerializationError("ContentFeatures::serialize(): Unsupported version requested");
898 void ContentFeatures::deSerializeOld(std::istream &is, int version)
900 if(version == 5) // In PROTOCOL_VERSION 13
902 name = deSerializeString(is);
904 u32 groups_size = readU16(is);
905 for(u32 i=0; i<groups_size; i++){
906 std::string name = deSerializeString(is);
907 int value = readS16(is);
908 groups[name] = value;
910 drawtype = (enum NodeDrawType)readU8(is);
911 visual_scale = readF1000(is);
913 throw SerializationError("unsupported tile count");
914 for(u32 i=0; i<6; i++)
915 tiledef[i].deSerialize(is);
916 if(readU8(is) != CF_SPECIAL_COUNT)
917 throw SerializationError("unsupported CF_SPECIAL_COUNT");
918 for(u32 i=0; i<CF_SPECIAL_COUNT; i++)
919 tiledef_special[i].deSerialize(is);
921 post_effect_color.setAlpha(readU8(is));
922 post_effect_color.setRed(readU8(is));
923 post_effect_color.setGreen(readU8(is));
924 post_effect_color.setBlue(readU8(is));
925 param_type = (enum ContentParamType)readU8(is);
926 param_type_2 = (enum ContentParamType2)readU8(is);
927 is_ground_content = readU8(is);
928 light_propagates = readU8(is);
929 sunlight_propagates = readU8(is);
930 walkable = readU8(is);
931 pointable = readU8(is);
932 diggable = readU8(is);
933 climbable = readU8(is);
934 buildable_to = readU8(is);
935 deSerializeString(is); // legacy: used to be metadata_name
936 liquid_type = (enum LiquidType)readU8(is);
937 liquid_alternative_flowing = deSerializeString(is);
938 liquid_alternative_source = deSerializeString(is);
939 liquid_viscosity = readU8(is);
940 light_source = readU8(is);
941 damage_per_second = readU32(is);
942 node_box.deSerialize(is);
943 selection_box.deSerialize(is);
944 legacy_facedir_simple = readU8(is);
945 legacy_wallmounted = readU8(is);
946 deSerializeSimpleSoundSpec(sound_footstep, is);
947 deSerializeSimpleSoundSpec(sound_dig, is);
948 deSerializeSimpleSoundSpec(sound_dug, is);
952 throw SerializationError("unsupported ContentFeatures version");