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;
215 damage_per_second = 0;
216 node_box = NodeBox();
217 selection_box = NodeBox();
218 legacy_facedir_simple = false;
219 legacy_wallmounted = false;
220 sound_footstep = SimpleSoundSpec();
221 sound_dig = SimpleSoundSpec("__group");
222 sound_dug = SimpleSoundSpec();
225 void ContentFeatures::serialize(std::ostream &os, u16 protocol_version)
227 if(protocol_version < 14){
228 serializeOld(os, protocol_version);
232 writeU8(os, 6); // version
233 os<<serializeString(name);
234 writeU16(os, groups.size());
235 for(ItemGroupList::const_iterator
236 i = groups.begin(); i != groups.end(); i++){
237 os<<serializeString(i->first);
238 writeS16(os, i->second);
240 writeU8(os, drawtype);
241 writeF1000(os, visual_scale);
243 for(u32 i=0; i<6; i++)
244 tiledef[i].serialize(os, protocol_version);
245 writeU8(os, CF_SPECIAL_COUNT);
246 for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
247 tiledef_special[i].serialize(os, protocol_version);
250 writeU8(os, post_effect_color.getAlpha());
251 writeU8(os, post_effect_color.getRed());
252 writeU8(os, post_effect_color.getGreen());
253 writeU8(os, post_effect_color.getBlue());
254 writeU8(os, param_type);
255 writeU8(os, param_type_2);
256 writeU8(os, is_ground_content);
257 writeU8(os, light_propagates);
258 writeU8(os, sunlight_propagates);
259 writeU8(os, walkable);
260 writeU8(os, pointable);
261 writeU8(os, diggable);
262 writeU8(os, climbable);
263 writeU8(os, buildable_to);
264 os<<serializeString(""); // legacy: used to be metadata_name
265 writeU8(os, liquid_type);
266 os<<serializeString(liquid_alternative_flowing);
267 os<<serializeString(liquid_alternative_source);
268 writeU8(os, liquid_viscosity);
269 writeU8(os, liquid_renewable);
270 writeU8(os, light_source);
271 writeU32(os, damage_per_second);
272 node_box.serialize(os);
273 selection_box.serialize(os);
274 writeU8(os, legacy_facedir_simple);
275 writeU8(os, legacy_wallmounted);
276 serializeSimpleSoundSpec(sound_footstep, os);
277 serializeSimpleSoundSpec(sound_dig, os);
278 serializeSimpleSoundSpec(sound_dug, os);
279 writeU8(os, rightclickable);
280 // Stuff below should be moved to correct place in a version that otherwise changes
281 // the protocol version
284 void ContentFeatures::deSerialize(std::istream &is)
286 int version = readU8(is);
288 deSerializeOld(is, version);
292 name = deSerializeString(is);
294 u32 groups_size = readU16(is);
295 for(u32 i=0; i<groups_size; i++){
296 std::string name = deSerializeString(is);
297 int value = readS16(is);
298 groups[name] = value;
300 drawtype = (enum NodeDrawType)readU8(is);
301 visual_scale = readF1000(is);
303 throw SerializationError("unsupported tile count");
304 for(u32 i=0; i<6; i++)
305 tiledef[i].deSerialize(is);
306 if(readU8(is) != CF_SPECIAL_COUNT)
307 throw SerializationError("unsupported CF_SPECIAL_COUNT");
308 for(u32 i=0; i<CF_SPECIAL_COUNT; i++)
309 tiledef_special[i].deSerialize(is);
311 post_effect_color.setAlpha(readU8(is));
312 post_effect_color.setRed(readU8(is));
313 post_effect_color.setGreen(readU8(is));
314 post_effect_color.setBlue(readU8(is));
315 param_type = (enum ContentParamType)readU8(is);
316 param_type_2 = (enum ContentParamType2)readU8(is);
317 is_ground_content = readU8(is);
318 light_propagates = readU8(is);
319 sunlight_propagates = readU8(is);
320 walkable = readU8(is);
321 pointable = readU8(is);
322 diggable = readU8(is);
323 climbable = readU8(is);
324 buildable_to = readU8(is);
325 deSerializeString(is); // legacy: used to be metadata_name
326 liquid_type = (enum LiquidType)readU8(is);
327 liquid_alternative_flowing = deSerializeString(is);
328 liquid_alternative_source = deSerializeString(is);
329 liquid_viscosity = readU8(is);
330 liquid_renewable = readU8(is);
331 light_source = readU8(is);
332 damage_per_second = readU32(is);
333 node_box.deSerialize(is);
334 selection_box.deSerialize(is);
335 legacy_facedir_simple = readU8(is);
336 legacy_wallmounted = readU8(is);
337 deSerializeSimpleSoundSpec(sound_footstep, is);
338 deSerializeSimpleSoundSpec(sound_dig, is);
339 deSerializeSimpleSoundSpec(sound_dug, is);
340 rightclickable = readU8(is);
341 // If you add anything here, insert it primarily inside the try-catch
342 // block to not need to increase the version.
344 // Stuff below should be moved to correct place in a version that
345 // otherwise changes the protocol version
346 }catch(SerializationError &e) {};
353 class CNodeDefManager: public IWritableNodeDefManager
358 m_name_id_mapping.clear();
359 m_name_id_mapping_with_aliases.clear();
361 for(u16 i=0; i<=MAX_CONTENT; i++)
363 ContentFeatures &f = m_content_features[i];
364 f.reset(); // Reset to defaults
371 f.drawtype = NDT_AIRLIKE;
372 f.param_type = CPT_LIGHT;
373 f.light_propagates = true;
374 f.sunlight_propagates = true;
378 f.buildable_to = true;
379 // Insert directly into containers
380 content_t c = CONTENT_AIR;
381 m_content_features[c] = f;
382 addNameIdMapping(c, f.name);
384 // Set CONTENT_IGNORE
388 f.drawtype = NDT_AIRLIKE;
389 f.param_type = CPT_NONE;
390 f.light_propagates = false;
391 f.sunlight_propagates = false;
395 // A way to remove accidental CONTENT_IGNOREs
396 f.buildable_to = true;
397 // Insert directly into containers
398 content_t c = CONTENT_IGNORE;
399 m_content_features[c] = f;
400 addNameIdMapping(c, f.name);
403 // CONTENT_IGNORE = not found
404 content_t getFreeId()
406 for(u32 i=0; i<=0xffff; i++){
407 const ContentFeatures &f = m_content_features[i];
411 return CONTENT_IGNORE;
417 virtual ~CNodeDefManager()
420 virtual IWritableNodeDefManager* clone()
422 CNodeDefManager *mgr = new CNodeDefManager();
423 for(u16 i=0; i<=MAX_CONTENT; i++)
429 virtual const ContentFeatures& get(content_t c) const
431 assert(c <= MAX_CONTENT);
432 return m_content_features[c];
434 virtual const ContentFeatures& get(const MapNode &n) const
436 return get(n.getContent());
438 virtual bool getId(const std::string &name, content_t &result) const
440 std::map<std::string, content_t>::const_iterator
441 i = m_name_id_mapping_with_aliases.find(name);
442 if(i == m_name_id_mapping_with_aliases.end())
447 virtual content_t getId(const std::string &name) const
449 content_t id = CONTENT_IGNORE;
453 virtual void getIds(const std::string &name, std::set<content_t> &result)
456 //TimeTaker t("getIds", NULL, PRECISION_MICRO);
457 if(name.substr(0,6) != "group:"){
458 content_t id = CONTENT_IGNORE;
463 std::string group = name.substr(6);
465 #if 1 // Optimized version, takes less than 1 microsecond at -O1
466 std::map<std::string, GroupItems>::const_iterator
467 i = m_group_to_items.find(group);
468 if (i == m_group_to_items.end())
471 const GroupItems &items = i->second;
472 for (GroupItems::const_iterator j = items.begin();
473 j != items.end(); ++j) {
474 if ((*j).second != 0)
475 result.insert((*j).first);
477 #else // Old version, takes about ~150-200us at -O1
478 for(u16 id=0; id<=MAX_CONTENT; id++)
480 const ContentFeatures &f = m_content_features[id];
481 if(f.name == "") // Quickly discard undefined nodes
483 if(itemgroup_get(f.groups, group) != 0)
487 //printf("getIds: %dus\n", t.stop());
489 virtual const ContentFeatures& get(const std::string &name) const
491 content_t id = CONTENT_IGNORE;
495 // IWritableNodeDefManager
496 virtual void set(content_t c, const ContentFeatures &def)
498 verbosestream<<"registerNode: registering content id \""<<c
499 <<"\": name=\""<<def.name<<"\""<<std::endl;
500 assert(c <= MAX_CONTENT);
501 // Don't allow redefining CONTENT_IGNORE (but allow air)
502 if(def.name == "ignore" || c == CONTENT_IGNORE){
503 infostream<<"registerNode: WARNING: Ignoring "
504 <<"CONTENT_IGNORE redefinition"<<std::endl;
507 // Check that the special contents are not redefined as different id
508 // because it would mess up everything
509 if((def.name == "ignore" && c != CONTENT_IGNORE) ||
510 (def.name == "air" && c != CONTENT_AIR)){
511 errorstream<<"registerNode: IGNORING ERROR: "
512 <<"trying to register built-in type \""
513 <<def.name<<"\" as different id"<<std::endl;
516 m_content_features[c] = def;
518 addNameIdMapping(c, def.name);
520 // Add this content to the list of all groups it belongs to
521 for (ItemGroupList::const_iterator i = def.groups.begin();
522 i != def.groups.end(); ++i) {
523 std::string group_name = i->first;
525 std::map<std::string, GroupItems>::iterator
526 j = m_group_to_items.find(group_name);
527 if (j == m_group_to_items.end()) {
528 m_group_to_items[group_name].push_back(std::make_pair(c, i->second));
530 GroupItems &items = j->second;
531 items.push_back(std::make_pair(c, i->second));
535 virtual content_t set(const std::string &name,
536 const ContentFeatures &def)
538 assert(name == def.name);
539 u16 id = CONTENT_IGNORE;
540 bool found = m_name_id_mapping.getId(name, id); // ignore aliases
544 if(id == CONTENT_IGNORE)
545 return CONTENT_IGNORE;
547 addNameIdMapping(id, name);
552 virtual content_t allocateDummy(const std::string &name)
559 virtual void updateAliases(IItemDefManager *idef)
561 std::set<std::string> all = idef->getAll();
562 m_name_id_mapping_with_aliases.clear();
563 for(std::set<std::string>::iterator
564 i = all.begin(); i != all.end(); i++)
566 std::string name = *i;
567 std::string convert_to = idef->getAlias(name);
569 if(m_name_id_mapping.getId(convert_to, id))
571 m_name_id_mapping_with_aliases.insert(
572 std::make_pair(name, id));
576 virtual void updateTextures(ITextureSource *tsrc)
579 infostream<<"CNodeDefManager::updateTextures(): Updating "
580 <<"textures in node definitions"<<std::endl;
582 bool new_style_water = g_settings->getBool("new_style_water");
583 bool new_style_leaves = g_settings->getBool("new_style_leaves");
584 bool opaque_water = g_settings->getBool("opaque_water");
586 for(u16 i=0; i<=MAX_CONTENT; i++)
588 ContentFeatures *f = &m_content_features[i];
590 // Figure out the actual tiles to use
592 for(u32 j=0; j<6; j++)
594 tiledef[j] = f->tiledef[j];
595 if(tiledef[j].name == "")
596 tiledef[j].name = "unknown_node.png";
599 bool is_liquid = false;
609 assert(f->liquid_type == LIQUID_SOURCE);
616 f->backface_culling = false;
620 case NDT_FLOWINGLIQUID:
621 assert(f->liquid_type == LIQUID_FLOWING);
629 f->visual_solidness = 1;
633 f->visual_solidness = 1;
635 case NDT_ALLFACES_OPTIONAL:
636 if(new_style_leaves){
637 f->drawtype = NDT_ALLFACES;
639 f->visual_solidness = 1;
641 f->drawtype = NDT_NORMAL;
643 for(u32 i=0; i<6; i++){
644 tiledef[i].name += std::string("^[noalpha");
650 f->backface_culling = false;
663 material_type = (f->alpha == 255) ? TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT;
665 material_type = (f->alpha == 255) ? TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA;
667 // Tiles (fill in f->tiles[])
668 for(u16 j=0; j<6; j++){
670 f->tiles[j].texture = tsrc->getTexture(tiledef[j].name);
672 f->tiles[j].alpha = f->alpha;
674 f->tiles[j].material_type = material_type;
676 f->tiles[j].material_flags = 0;
677 if(f->backface_culling)
678 f->tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
679 if(tiledef[j].animation.type == TAT_VERTICAL_FRAMES)
680 f->tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
681 // Animation parameters
682 if(f->tiles[j].material_flags &
683 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
685 // Get raw texture size to determine frame count by
687 video::ITexture *t = tsrc->getTextureRaw(tiledef[j].name);
688 v2u32 size = t->getOriginalSize();
689 int frame_height = (float)size.X /
690 (float)tiledef[j].animation.aspect_w *
691 (float)tiledef[j].animation.aspect_h;
692 int frame_count = size.Y / frame_height;
693 int frame_length_ms = 1000.0 *
694 tiledef[j].animation.length / frame_count;
695 f->tiles[j].animation_frame_count = frame_count;
696 f->tiles[j].animation_frame_length_ms = frame_length_ms;
698 // If there are no frames for an animation, switch
699 // animation off (so that having specified an animation
700 // for something but not using it in the texture pack
701 // gives no overhead)
702 if(frame_count == 1){
703 f->tiles[j].material_flags &=
704 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
708 // Special tiles (fill in f->special_tiles[])
709 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
711 f->special_tiles[j].texture =
712 tsrc->getTexture(f->tiledef_special[j].name);
714 f->special_tiles[j].alpha = f->alpha;
716 f->special_tiles[j].material_type = material_type;
718 f->special_tiles[j].material_flags = 0;
719 if(f->tiledef_special[j].backface_culling)
720 f->special_tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
721 if(f->tiledef_special[j].animation.type == TAT_VERTICAL_FRAMES)
722 f->special_tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
723 // Animation parameters
724 if(f->special_tiles[j].material_flags &
725 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
727 // Get raw texture size to determine frame count by
729 video::ITexture *t = tsrc->getTextureRaw(f->tiledef_special[j].name);
730 v2u32 size = t->getOriginalSize();
731 int frame_height = (float)size.X /
732 (float)f->tiledef_special[j].animation.aspect_w *
733 (float)f->tiledef_special[j].animation.aspect_h;
734 int frame_count = size.Y / frame_height;
735 int frame_length_ms = 1000.0 *
736 f->tiledef_special[j].animation.length / frame_count;
737 f->special_tiles[j].animation_frame_count = frame_count;
738 f->special_tiles[j].animation_frame_length_ms = frame_length_ms;
740 // If there are no frames for an animation, switch
741 // animation off (so that having specified an animation
742 // for something but not using it in the texture pack
743 // gives no overhead)
744 if(frame_count == 1){
745 f->special_tiles[j].material_flags &=
746 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
753 void serialize(std::ostream &os, u16 protocol_version)
755 writeU8(os, 1); // version
757 std::ostringstream os2(std::ios::binary);
758 for(u16 i=0; i<=MAX_CONTENT; i++)
760 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
762 ContentFeatures *f = &m_content_features[i];
766 // Wrap it in a string to allow different lengths without
767 // strict version incompatibilities
768 std::ostringstream wrapper_os(std::ios::binary);
769 f->serialize(wrapper_os, protocol_version);
770 os2<<serializeString(wrapper_os.str());
774 os<<serializeLongString(os2.str());
776 void deSerialize(std::istream &is)
779 int version = readU8(is);
781 throw SerializationError("unsupported NodeDefinitionManager version");
782 u16 count = readU16(is);
783 std::istringstream is2(deSerializeLongString(is), std::ios::binary);
784 for(u16 n=0; n<count; n++){
785 u16 i = readU16(is2);
787 errorstream<<"ContentFeatures::deSerialize(): "
788 <<"Too large content id: "<<i<<std::endl;
791 /*// Do not deserialize special types
792 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
794 ContentFeatures *f = &m_content_features[i];
795 // Read it from the string wrapper
796 std::string wrapper = deSerializeString(is2);
797 std::istringstream wrapper_is(wrapper, std::ios::binary);
798 f->deSerialize(wrapper_is);
799 verbosestream<<"deserialized "<<f->name<<std::endl;
801 addNameIdMapping(i, f->name);
805 void addNameIdMapping(content_t i, std::string name)
807 m_name_id_mapping.set(i, name);
808 m_name_id_mapping_with_aliases.insert(std::make_pair(name, i));
811 // Features indexed by id
812 ContentFeatures m_content_features[MAX_CONTENT+1];
813 // A mapping for fast converting back and forth between names and ids
814 NameIdMapping m_name_id_mapping;
815 // Like m_name_id_mapping, but only from names to ids, and includes
816 // item aliases too. Updated by updateAliases()
817 // Note: Not serialized.
818 std::map<std::string, content_t> m_name_id_mapping_with_aliases;
819 // A mapping from groups to a list of content_ts (and their levels)
820 // that belong to it. Necessary for a direct lookup in getIds().
821 // Note: Not serialized.
822 std::map<std::string, GroupItems> m_group_to_items;
825 IWritableNodeDefManager* createNodeDefManager()
827 return new CNodeDefManager();
831 Serialization of old ContentFeatures formats
834 void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version)
836 if(protocol_version == 13)
838 writeU8(os, 5); // version
839 os<<serializeString(name);
840 writeU16(os, groups.size());
841 for(ItemGroupList::const_iterator
842 i = groups.begin(); i != groups.end(); i++){
843 os<<serializeString(i->first);
844 writeS16(os, i->second);
846 writeU8(os, drawtype);
847 writeF1000(os, visual_scale);
849 for(u32 i=0; i<6; i++)
850 tiledef[i].serialize(os, protocol_version);
851 writeU8(os, CF_SPECIAL_COUNT);
852 for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
853 tiledef_special[i].serialize(os, protocol_version);
856 writeU8(os, post_effect_color.getAlpha());
857 writeU8(os, post_effect_color.getRed());
858 writeU8(os, post_effect_color.getGreen());
859 writeU8(os, post_effect_color.getBlue());
860 writeU8(os, param_type);
861 writeU8(os, param_type_2);
862 writeU8(os, is_ground_content);
863 writeU8(os, light_propagates);
864 writeU8(os, sunlight_propagates);
865 writeU8(os, walkable);
866 writeU8(os, pointable);
867 writeU8(os, diggable);
868 writeU8(os, climbable);
869 writeU8(os, buildable_to);
870 os<<serializeString(""); // legacy: used to be metadata_name
871 writeU8(os, liquid_type);
872 os<<serializeString(liquid_alternative_flowing);
873 os<<serializeString(liquid_alternative_source);
874 writeU8(os, liquid_viscosity);
875 writeU8(os, light_source);
876 writeU32(os, damage_per_second);
877 node_box.serialize(os);
878 selection_box.serialize(os);
879 writeU8(os, legacy_facedir_simple);
880 writeU8(os, legacy_wallmounted);
881 serializeSimpleSoundSpec(sound_footstep, os);
882 serializeSimpleSoundSpec(sound_dig, os);
883 serializeSimpleSoundSpec(sound_dug, os);
887 throw SerializationError("ContentFeatures::serialize(): Unsupported version requested");
891 void ContentFeatures::deSerializeOld(std::istream &is, int version)
893 if(version == 5) // In PROTOCOL_VERSION 13
895 name = deSerializeString(is);
897 u32 groups_size = readU16(is);
898 for(u32 i=0; i<groups_size; i++){
899 std::string name = deSerializeString(is);
900 int value = readS16(is);
901 groups[name] = value;
903 drawtype = (enum NodeDrawType)readU8(is);
904 visual_scale = readF1000(is);
906 throw SerializationError("unsupported tile count");
907 for(u32 i=0; i<6; i++)
908 tiledef[i].deSerialize(is);
909 if(readU8(is) != CF_SPECIAL_COUNT)
910 throw SerializationError("unsupported CF_SPECIAL_COUNT");
911 for(u32 i=0; i<CF_SPECIAL_COUNT; i++)
912 tiledef_special[i].deSerialize(is);
914 post_effect_color.setAlpha(readU8(is));
915 post_effect_color.setRed(readU8(is));
916 post_effect_color.setGreen(readU8(is));
917 post_effect_color.setBlue(readU8(is));
918 param_type = (enum ContentParamType)readU8(is);
919 param_type_2 = (enum ContentParamType2)readU8(is);
920 is_ground_content = readU8(is);
921 light_propagates = readU8(is);
922 sunlight_propagates = readU8(is);
923 walkable = readU8(is);
924 pointable = readU8(is);
925 diggable = readU8(is);
926 climbable = readU8(is);
927 buildable_to = readU8(is);
928 deSerializeString(is); // legacy: used to be metadata_name
929 liquid_type = (enum LiquidType)readU8(is);
930 liquid_alternative_flowing = deSerializeString(is);
931 liquid_alternative_source = deSerializeString(is);
932 liquid_viscosity = readU8(is);
933 light_source = readU8(is);
934 damage_per_second = readU32(is);
935 node_box.deSerialize(is);
936 selection_box.deSerialize(is);
937 legacy_facedir_simple = readU8(is);
938 legacy_wallmounted = readU8(is);
939 deSerializeSimpleSoundSpec(sound_footstep, is);
940 deSerializeSimpleSoundSpec(sound_dig, is);
941 deSerializeSimpleSoundSpec(sound_dug, is);
945 throw SerializationError("unsupported ContentFeatures version");