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) const
51 writeU8(os, 1); // version
54 if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED)
56 writeU16(os, fixed.size());
57 for(std::vector<aabb3f>::const_iterator
59 i != fixed.end(); i++)
61 writeV3F1000(os, i->MinEdge);
62 writeV3F1000(os, i->MaxEdge);
65 else if(type == NODEBOX_WALLMOUNTED)
67 writeV3F1000(os, wall_top.MinEdge);
68 writeV3F1000(os, wall_top.MaxEdge);
69 writeV3F1000(os, wall_bottom.MinEdge);
70 writeV3F1000(os, wall_bottom.MaxEdge);
71 writeV3F1000(os, wall_side.MinEdge);
72 writeV3F1000(os, wall_side.MaxEdge);
76 void NodeBox::deSerialize(std::istream &is)
78 int version = readU8(is);
80 throw SerializationError("unsupported NodeBox version");
84 type = (enum NodeBoxType)readU8(is);
86 if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED)
88 u16 fixed_count = readU16(is);
92 box.MinEdge = readV3F1000(is);
93 box.MaxEdge = readV3F1000(is);
97 else if(type == NODEBOX_WALLMOUNTED)
99 wall_top.MinEdge = readV3F1000(is);
100 wall_top.MaxEdge = readV3F1000(is);
101 wall_bottom.MinEdge = readV3F1000(is);
102 wall_bottom.MaxEdge = readV3F1000(is);
103 wall_side.MinEdge = readV3F1000(is);
104 wall_side.MaxEdge = readV3F1000(is);
112 void TileDef::serialize(std::ostream &os, u16 protocol_version) const
114 if(protocol_version >= 17)
118 os<<serializeString(name);
119 writeU8(os, animation.type);
120 writeU16(os, animation.aspect_w);
121 writeU16(os, animation.aspect_h);
122 writeF1000(os, animation.length);
123 if(protocol_version >= 17)
124 writeU8(os, backface_culling);
127 void TileDef::deSerialize(std::istream &is)
129 int version = readU8(is);
130 name = deSerializeString(is);
131 animation.type = (TileAnimationType)readU8(is);
132 animation.aspect_w = readU16(is);
133 animation.aspect_h = readU16(is);
134 animation.length = readF1000(is);
136 backface_culling = readU8(is);
140 SimpleSoundSpec serialization
143 static void serializeSimpleSoundSpec(const SimpleSoundSpec &ss,
146 os<<serializeString(ss.name);
147 writeF1000(os, ss.gain);
149 static void deSerializeSimpleSoundSpec(SimpleSoundSpec &ss, std::istream &is)
151 ss.name = deSerializeString(is);
152 ss.gain = readF1000(is);
159 ContentFeatures::ContentFeatures()
164 ContentFeatures::~ContentFeatures()
168 void ContentFeatures::reset()
175 visual_solidness = 0;
176 backface_culling = true;
178 has_on_construct = false;
179 has_on_destruct = false;
180 has_after_destruct = false;
184 NOTE: Most of this is always overridden by the default values given
189 // Unknown nodes can be dug
190 groups["dig_immediate"] = 2;
191 drawtype = NDT_NORMAL;
193 for(u32 i=0; i<6; i++)
194 tiledef[i] = TileDef();
195 for(u16 j=0; j<CF_SPECIAL_COUNT; j++)
196 tiledef_special[j] = TileDef();
198 post_effect_color = video::SColor(0, 0, 0, 0);
199 param_type = CPT_NONE;
200 param_type_2 = CPT2_NONE;
201 is_ground_content = false;
202 light_propagates = false;
203 sunlight_propagates = false;
208 buildable_to = false;
209 rightclickable = true;
211 liquid_type = LIQUID_NONE;
212 liquid_alternative_flowing = "";
213 liquid_alternative_source = "";
214 liquid_viscosity = 0;
215 liquid_renewable = true;
216 liquid_range = LIQUID_LEVEL_MAX+1;
219 damage_per_second = 0;
220 node_box = NodeBox();
221 selection_box = NodeBox();
222 legacy_facedir_simple = false;
223 legacy_wallmounted = false;
224 sound_footstep = SimpleSoundSpec();
225 sound_dig = SimpleSoundSpec("__group");
226 sound_dug = SimpleSoundSpec();
229 void ContentFeatures::serialize(std::ostream &os, u16 protocol_version)
231 if(protocol_version < 14){
232 serializeOld(os, protocol_version);
236 writeU8(os, 6); // version
237 os<<serializeString(name);
238 writeU16(os, groups.size());
239 for(ItemGroupList::const_iterator
240 i = groups.begin(); i != groups.end(); i++){
241 os<<serializeString(i->first);
242 writeS16(os, i->second);
244 writeU8(os, drawtype);
245 writeF1000(os, visual_scale);
247 for(u32 i=0; i<6; i++)
248 tiledef[i].serialize(os, protocol_version);
249 writeU8(os, CF_SPECIAL_COUNT);
250 for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
251 tiledef_special[i].serialize(os, protocol_version);
254 writeU8(os, post_effect_color.getAlpha());
255 writeU8(os, post_effect_color.getRed());
256 writeU8(os, post_effect_color.getGreen());
257 writeU8(os, post_effect_color.getBlue());
258 writeU8(os, param_type);
259 writeU8(os, param_type_2);
260 writeU8(os, is_ground_content);
261 writeU8(os, light_propagates);
262 writeU8(os, sunlight_propagates);
263 writeU8(os, walkable);
264 writeU8(os, pointable);
265 writeU8(os, diggable);
266 writeU8(os, climbable);
267 writeU8(os, buildable_to);
268 os<<serializeString(""); // legacy: used to be metadata_name
269 writeU8(os, liquid_type);
270 os<<serializeString(liquid_alternative_flowing);
271 os<<serializeString(liquid_alternative_source);
272 writeU8(os, liquid_viscosity);
273 writeU8(os, liquid_renewable);
274 writeU8(os, light_source);
275 writeU32(os, damage_per_second);
276 node_box.serialize(os);
277 selection_box.serialize(os);
278 writeU8(os, legacy_facedir_simple);
279 writeU8(os, legacy_wallmounted);
280 serializeSimpleSoundSpec(sound_footstep, os);
281 serializeSimpleSoundSpec(sound_dig, os);
282 serializeSimpleSoundSpec(sound_dug, os);
283 writeU8(os, rightclickable);
284 // Stuff below should be moved to correct place in a version that otherwise changes
285 // the protocol version
286 writeU8(os, drowning);
287 writeU8(os, leveled);
288 writeU8(os, liquid_range);
291 void ContentFeatures::deSerialize(std::istream &is)
293 int version = readU8(is);
295 deSerializeOld(is, version);
299 name = deSerializeString(is);
301 u32 groups_size = readU16(is);
302 for(u32 i=0; i<groups_size; i++){
303 std::string name = deSerializeString(is);
304 int value = readS16(is);
305 groups[name] = value;
307 drawtype = (enum NodeDrawType)readU8(is);
308 visual_scale = readF1000(is);
310 throw SerializationError("unsupported tile count");
311 for(u32 i=0; i<6; i++)
312 tiledef[i].deSerialize(is);
313 if(readU8(is) != CF_SPECIAL_COUNT)
314 throw SerializationError("unsupported CF_SPECIAL_COUNT");
315 for(u32 i=0; i<CF_SPECIAL_COUNT; i++)
316 tiledef_special[i].deSerialize(is);
318 post_effect_color.setAlpha(readU8(is));
319 post_effect_color.setRed(readU8(is));
320 post_effect_color.setGreen(readU8(is));
321 post_effect_color.setBlue(readU8(is));
322 param_type = (enum ContentParamType)readU8(is);
323 param_type_2 = (enum ContentParamType2)readU8(is);
324 is_ground_content = readU8(is);
325 light_propagates = readU8(is);
326 sunlight_propagates = readU8(is);
327 walkable = readU8(is);
328 pointable = readU8(is);
329 diggable = readU8(is);
330 climbable = readU8(is);
331 buildable_to = readU8(is);
332 deSerializeString(is); // legacy: used to be metadata_name
333 liquid_type = (enum LiquidType)readU8(is);
334 liquid_alternative_flowing = deSerializeString(is);
335 liquid_alternative_source = deSerializeString(is);
336 liquid_viscosity = readU8(is);
337 liquid_renewable = readU8(is);
338 light_source = readU8(is);
339 damage_per_second = readU32(is);
340 node_box.deSerialize(is);
341 selection_box.deSerialize(is);
342 legacy_facedir_simple = readU8(is);
343 legacy_wallmounted = readU8(is);
344 deSerializeSimpleSoundSpec(sound_footstep, is);
345 deSerializeSimpleSoundSpec(sound_dig, is);
346 deSerializeSimpleSoundSpec(sound_dug, is);
347 rightclickable = readU8(is);
348 // If you add anything here, insert it primarily inside the try-catch
349 // block to not need to increase the version.
351 // Stuff below should be moved to correct place in a version that
352 // otherwise changes the protocol version
353 drowning = readU8(is);
354 leveled = readU8(is);
355 liquid_range = readU8(is);
356 }catch(SerializationError &e) {};
363 class CNodeDefManager: public IWritableNodeDefManager
368 m_content_features.clear();
369 m_name_id_mapping.clear();
370 m_name_id_mapping_with_aliases.clear();
371 m_group_to_items.clear();
374 u32 initial_length = 0;
375 initial_length = MYMAX(initial_length, CONTENT_UNKNOWN + 1);
376 initial_length = MYMAX(initial_length, CONTENT_AIR + 1);
377 initial_length = MYMAX(initial_length, CONTENT_IGNORE + 1);
378 m_content_features.resize(initial_length);
380 // Set CONTENT_UNKNOWN
384 // Insert directly into containers
385 content_t c = CONTENT_UNKNOWN;
386 m_content_features[c] = f;
387 addNameIdMapping(c, f.name);
394 f.drawtype = NDT_AIRLIKE;
395 f.param_type = CPT_LIGHT;
396 f.light_propagates = true;
397 f.sunlight_propagates = true;
401 f.buildable_to = true;
402 // Insert directly into containers
403 content_t c = CONTENT_AIR;
404 m_content_features[c] = f;
405 addNameIdMapping(c, f.name);
408 // Set CONTENT_IGNORE
412 f.drawtype = NDT_AIRLIKE;
413 f.param_type = CPT_NONE;
414 f.light_propagates = false;
415 f.sunlight_propagates = false;
419 // A way to remove accidental CONTENT_IGNOREs
420 f.buildable_to = true;
421 // Insert directly into containers
422 content_t c = CONTENT_IGNORE;
423 m_content_features[c] = f;
424 addNameIdMapping(c, f.name);
431 virtual ~CNodeDefManager()
434 virtual IWritableNodeDefManager* clone()
436 CNodeDefManager *mgr = new CNodeDefManager();
440 virtual const ContentFeatures& get(content_t c) const
442 if(c < m_content_features.size())
443 return m_content_features[c];
445 return m_content_features[CONTENT_UNKNOWN];
447 virtual const ContentFeatures& get(const MapNode &n) const
449 return get(n.getContent());
451 virtual bool getId(const std::string &name, content_t &result) const
453 std::map<std::string, content_t>::const_iterator
454 i = m_name_id_mapping_with_aliases.find(name);
455 if(i == m_name_id_mapping_with_aliases.end())
460 virtual content_t getId(const std::string &name) const
462 content_t id = CONTENT_IGNORE;
466 virtual void getIds(const std::string &name, std::set<content_t> &result)
469 //TimeTaker t("getIds", NULL, PRECISION_MICRO);
470 if(name.substr(0,6) != "group:"){
471 content_t id = CONTENT_IGNORE;
476 std::string group = name.substr(6);
478 std::map<std::string, GroupItems>::const_iterator
479 i = m_group_to_items.find(group);
480 if (i == m_group_to_items.end())
483 const GroupItems &items = i->second;
484 for (GroupItems::const_iterator j = items.begin();
485 j != items.end(); ++j) {
486 if ((*j).second != 0)
487 result.insert((*j).first);
489 //printf("getIds: %dus\n", t.stop());
491 virtual const ContentFeatures& get(const std::string &name) const
493 content_t id = CONTENT_UNKNOWN;
497 // returns CONTENT_IGNORE if no free ID found
498 content_t allocateId()
500 for(content_t id = m_next_id;
501 id >= m_next_id; // overflow?
503 while(id >= m_content_features.size()){
504 m_content_features.push_back(ContentFeatures());
506 const ContentFeatures &f = m_content_features[id];
512 // If we arrive here, an overflow occurred in id.
513 // That means no ID was found
514 return CONTENT_IGNORE;
516 // IWritableNodeDefManager
517 virtual content_t set(const std::string &name,
518 const ContentFeatures &def)
521 assert(name == def.name);
523 // Don't allow redefining ignore (but allow air and unknown)
524 if(name == "ignore"){
525 infostream<<"NodeDefManager: WARNING: Ignoring "
526 <<"CONTENT_IGNORE redefinition"<<std::endl;
527 return CONTENT_IGNORE;
530 content_t id = CONTENT_IGNORE;
531 bool found = m_name_id_mapping.getId(name, id); // ignore aliases
535 if(id == CONTENT_IGNORE){
536 infostream<<"NodeDefManager: WARNING: Absolute "
537 <<"limit reached"<<std::endl;
538 return CONTENT_IGNORE;
540 assert(id != CONTENT_IGNORE);
541 addNameIdMapping(id, name);
543 m_content_features[id] = def;
544 verbosestream<<"NodeDefManager: registering content id \""<<id
545 <<"\": name=\""<<def.name<<"\""<<std::endl;
547 // Add this content to the list of all groups it belongs to
548 // FIXME: This should remove a node from groups it no longer
549 // belongs to when a node is re-registered
550 for (ItemGroupList::const_iterator i = def.groups.begin();
551 i != def.groups.end(); ++i) {
552 std::string group_name = i->first;
554 std::map<std::string, GroupItems>::iterator
555 j = m_group_to_items.find(group_name);
556 if (j == m_group_to_items.end()) {
557 m_group_to_items[group_name].push_back(
558 std::make_pair(id, i->second));
560 GroupItems &items = j->second;
561 items.push_back(std::make_pair(id, i->second));
566 virtual content_t allocateDummy(const std::string &name)
573 virtual void updateAliases(IItemDefManager *idef)
575 std::set<std::string> all = idef->getAll();
576 m_name_id_mapping_with_aliases.clear();
577 for(std::set<std::string>::iterator
578 i = all.begin(); i != all.end(); i++)
580 std::string name = *i;
581 std::string convert_to = idef->getAlias(name);
583 if(m_name_id_mapping.getId(convert_to, id))
585 m_name_id_mapping_with_aliases.insert(
586 std::make_pair(name, id));
590 virtual void updateTextures(ITextureSource *tsrc)
593 infostream<<"CNodeDefManager::updateTextures(): Updating "
594 <<"textures in node definitions"<<std::endl;
596 bool new_style_water = g_settings->getBool("new_style_water");
597 bool new_style_leaves = g_settings->getBool("new_style_leaves");
598 bool opaque_water = g_settings->getBool("opaque_water");
600 for(u32 i=0; i<m_content_features.size(); i++)
602 ContentFeatures *f = &m_content_features[i];
604 // Figure out the actual tiles to use
606 for(u32 j=0; j<6; j++)
608 tiledef[j] = f->tiledef[j];
609 if(tiledef[j].name == "")
610 tiledef[j].name = "unknown_node.png";
613 bool is_liquid = false;
623 assert(f->liquid_type == LIQUID_SOURCE);
630 f->backface_culling = false;
634 case NDT_FLOWINGLIQUID:
635 assert(f->liquid_type == LIQUID_FLOWING);
643 f->visual_solidness = 1;
645 case NDT_GLASSLIKE_FRAMED:
647 f->visual_solidness = 1;
651 f->visual_solidness = 1;
653 case NDT_ALLFACES_OPTIONAL:
654 if(new_style_leaves){
655 f->drawtype = NDT_ALLFACES;
657 f->visual_solidness = 1;
659 f->drawtype = NDT_NORMAL;
661 for(u32 i=0; i<6; i++){
662 tiledef[i].name += std::string("^[noalpha");
668 f->backface_culling = false;
681 material_type = (f->alpha == 255) ? TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT;
683 material_type = (f->alpha == 255) ? TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA;
685 // Tiles (fill in f->tiles[])
686 for(u16 j=0; j<6; j++){
688 f->tiles[j].texture = tsrc->getTexture(
690 &f->tiles[j].texture_id);
692 f->tiles[j].alpha = f->alpha;
694 f->tiles[j].material_type = material_type;
696 f->tiles[j].material_flags = 0;
697 if(f->backface_culling)
698 f->tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
699 if(tiledef[j].animation.type == TAT_VERTICAL_FRAMES)
700 f->tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
701 // Animation parameters
702 if(f->tiles[j].material_flags &
703 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
705 // Get texture size to determine frame count by
707 v2u32 size = f->tiles[j].texture->getOriginalSize();
708 int frame_height = (float)size.X /
709 (float)tiledef[j].animation.aspect_w *
710 (float)tiledef[j].animation.aspect_h;
711 int frame_count = size.Y / frame_height;
712 int frame_length_ms = 1000.0 *
713 tiledef[j].animation.length / frame_count;
714 f->tiles[j].animation_frame_count = frame_count;
715 f->tiles[j].animation_frame_length_ms = frame_length_ms;
717 // If there are no frames for an animation, switch
718 // animation off (so that having specified an animation
719 // for something but not using it in the texture pack
720 // gives no overhead)
721 if(frame_count == 1){
722 f->tiles[j].material_flags &=
723 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
727 // Special tiles (fill in f->special_tiles[])
728 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
730 f->special_tiles[j].texture = tsrc->getTexture(
731 f->tiledef_special[j].name,
732 &f->special_tiles[j].texture_id);
734 f->special_tiles[j].alpha = f->alpha;
736 f->special_tiles[j].material_type = material_type;
738 f->special_tiles[j].material_flags = 0;
739 if(f->tiledef_special[j].backface_culling)
740 f->special_tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
741 if(f->tiledef_special[j].animation.type == TAT_VERTICAL_FRAMES)
742 f->special_tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
743 // Animation parameters
744 if(f->special_tiles[j].material_flags &
745 MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
747 // Get texture size to determine frame count by
749 v2u32 size = f->special_tiles[j].texture->getOriginalSize();
750 int frame_height = (float)size.X /
751 (float)f->tiledef_special[j].animation.aspect_w *
752 (float)f->tiledef_special[j].animation.aspect_h;
753 int frame_count = size.Y / frame_height;
754 int frame_length_ms = 1000.0 *
755 f->tiledef_special[j].animation.length / frame_count;
756 f->special_tiles[j].animation_frame_count = frame_count;
757 f->special_tiles[j].animation_frame_length_ms = frame_length_ms;
759 // If there are no frames for an animation, switch
760 // animation off (so that having specified an animation
761 // for something but not using it in the texture pack
762 // gives no overhead)
763 if(frame_count == 1){
764 f->special_tiles[j].material_flags &=
765 ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
772 void serialize(std::ostream &os, u16 protocol_version)
774 writeU8(os, 1); // version
776 std::ostringstream os2(std::ios::binary);
777 for(u32 i=0; i<m_content_features.size(); i++)
779 if(i == CONTENT_IGNORE || i == CONTENT_AIR
780 || i == CONTENT_UNKNOWN)
782 ContentFeatures *f = &m_content_features[i];
786 // Wrap it in a string to allow different lengths without
787 // strict version incompatibilities
788 std::ostringstream wrapper_os(std::ios::binary);
789 f->serialize(wrapper_os, protocol_version);
790 os2<<serializeString(wrapper_os.str());
792 assert(count + 1 > count); // must not overflow
796 os<<serializeLongString(os2.str());
798 void deSerialize(std::istream &is)
801 int version = readU8(is);
803 throw SerializationError("unsupported NodeDefinitionManager version");
804 u16 count = readU16(is);
805 std::istringstream is2(deSerializeLongString(is), std::ios::binary);
807 for(u16 n=0; n<count; n++){
808 u16 i = readU16(is2);
810 // Read it from the string wrapper
811 std::string wrapper = deSerializeString(is2);
812 std::istringstream wrapper_is(wrapper, std::ios::binary);
813 f.deSerialize(wrapper_is);
815 // Check error conditions
816 if(i == CONTENT_IGNORE || i == CONTENT_AIR
817 || i == CONTENT_UNKNOWN){
818 infostream<<"NodeDefManager::deSerialize(): WARNING: "
819 <<"not changing builtin node "<<i
824 infostream<<"NodeDefManager::deSerialize(): WARNING: "
825 <<"received empty name"<<std::endl;
829 bool found = m_name_id_mapping.getId(f.name, existing_id); // ignore aliases
830 if(found && i != existing_id){
831 infostream<<"NodeDefManager::deSerialize(): WARNING: "
832 <<"already defined with different ID: "
837 // All is ok, add node definition with the requested ID
838 if(i >= m_content_features.size())
839 m_content_features.resize((u32)(i) + 1);
840 m_content_features[i] = f;
841 addNameIdMapping(i, f.name);
842 verbosestream<<"deserialized "<<f.name<<std::endl;
846 void addNameIdMapping(content_t i, std::string name)
848 m_name_id_mapping.set(i, name);
849 m_name_id_mapping_with_aliases.insert(std::make_pair(name, i));
852 // Features indexed by id
853 std::vector<ContentFeatures> m_content_features;
854 // A mapping for fast converting back and forth between names and ids
855 NameIdMapping m_name_id_mapping;
856 // Like m_name_id_mapping, but only from names to ids, and includes
857 // item aliases too. Updated by updateAliases()
858 // Note: Not serialized.
859 std::map<std::string, content_t> m_name_id_mapping_with_aliases;
860 // A mapping from groups to a list of content_ts (and their levels)
861 // that belong to it. Necessary for a direct lookup in getIds().
862 // Note: Not serialized.
863 std::map<std::string, GroupItems> m_group_to_items;
864 // Next possibly free id
868 IWritableNodeDefManager* createNodeDefManager()
870 return new CNodeDefManager();
874 Serialization of old ContentFeatures formats
877 void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version)
879 if(protocol_version == 13)
881 writeU8(os, 5); // version
882 os<<serializeString(name);
883 writeU16(os, groups.size());
884 for(ItemGroupList::const_iterator
885 i = groups.begin(); i != groups.end(); i++){
886 os<<serializeString(i->first);
887 writeS16(os, i->second);
889 writeU8(os, drawtype);
890 writeF1000(os, visual_scale);
892 for(u32 i=0; i<6; i++)
893 tiledef[i].serialize(os, protocol_version);
894 writeU8(os, CF_SPECIAL_COUNT);
895 for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
896 tiledef_special[i].serialize(os, protocol_version);
899 writeU8(os, post_effect_color.getAlpha());
900 writeU8(os, post_effect_color.getRed());
901 writeU8(os, post_effect_color.getGreen());
902 writeU8(os, post_effect_color.getBlue());
903 writeU8(os, param_type);
904 writeU8(os, param_type_2);
905 writeU8(os, is_ground_content);
906 writeU8(os, light_propagates);
907 writeU8(os, sunlight_propagates);
908 writeU8(os, walkable);
909 writeU8(os, pointable);
910 writeU8(os, diggable);
911 writeU8(os, climbable);
912 writeU8(os, buildable_to);
913 os<<serializeString(""); // legacy: used to be metadata_name
914 writeU8(os, liquid_type);
915 os<<serializeString(liquid_alternative_flowing);
916 os<<serializeString(liquid_alternative_source);
917 writeU8(os, liquid_viscosity);
918 writeU8(os, light_source);
919 writeU32(os, damage_per_second);
920 node_box.serialize(os);
921 selection_box.serialize(os);
922 writeU8(os, legacy_facedir_simple);
923 writeU8(os, legacy_wallmounted);
924 serializeSimpleSoundSpec(sound_footstep, os);
925 serializeSimpleSoundSpec(sound_dig, os);
926 serializeSimpleSoundSpec(sound_dug, os);
930 throw SerializationError("ContentFeatures::serialize(): Unsupported version requested");
934 void ContentFeatures::deSerializeOld(std::istream &is, int version)
936 if(version == 5) // In PROTOCOL_VERSION 13
938 name = deSerializeString(is);
940 u32 groups_size = readU16(is);
941 for(u32 i=0; i<groups_size; i++){
942 std::string name = deSerializeString(is);
943 int value = readS16(is);
944 groups[name] = value;
946 drawtype = (enum NodeDrawType)readU8(is);
947 visual_scale = readF1000(is);
949 throw SerializationError("unsupported tile count");
950 for(u32 i=0; i<6; i++)
951 tiledef[i].deSerialize(is);
952 if(readU8(is) != CF_SPECIAL_COUNT)
953 throw SerializationError("unsupported CF_SPECIAL_COUNT");
954 for(u32 i=0; i<CF_SPECIAL_COUNT; i++)
955 tiledef_special[i].deSerialize(is);
957 post_effect_color.setAlpha(readU8(is));
958 post_effect_color.setRed(readU8(is));
959 post_effect_color.setGreen(readU8(is));
960 post_effect_color.setBlue(readU8(is));
961 param_type = (enum ContentParamType)readU8(is);
962 param_type_2 = (enum ContentParamType2)readU8(is);
963 is_ground_content = readU8(is);
964 light_propagates = readU8(is);
965 sunlight_propagates = readU8(is);
966 walkable = readU8(is);
967 pointable = readU8(is);
968 diggable = readU8(is);
969 climbable = readU8(is);
970 buildable_to = readU8(is);
971 deSerializeString(is); // legacy: used to be metadata_name
972 liquid_type = (enum LiquidType)readU8(is);
973 liquid_alternative_flowing = deSerializeString(is);
974 liquid_alternative_source = deSerializeString(is);
975 liquid_viscosity = readU8(is);
976 light_source = readU8(is);
977 damage_per_second = readU32(is);
978 node_box.deSerialize(is);
979 selection_box.deSerialize(is);
980 legacy_facedir_simple = readU8(is);
981 legacy_wallmounted = readU8(is);
982 deSerializeSimpleSoundSpec(sound_footstep, is);
983 deSerializeSimpleSoundSpec(sound_dig, is);
984 deSerializeSimpleSoundSpec(sound_dug, is);
988 throw SerializationError("unsupported ContentFeatures version");