void deSerialize(std::istream &is) { clear(); int version = readU8(is); if(version != 1) throw SerializationError("unsupported NodeDefinitionManager version"); u16 count = readU16(is); std::istringstream is2(deSerializeLongString(is), std::ios::binary); for(u16 n=0; n<count; n++){ u16 i = readU16(is2); if(i > MAX_CONTENT){ errorstream<<"ContentFeatures::deSerialize(): " <<"Too large content id: "<<i<<std::endl; continue; } /*// Do not deserialize special types if(i == CONTENT_IGNORE || i == CONTENT_AIR) continue;*/ ContentFeatures *f = &m_content_features[i]; // Read it from the string wrapper std::string wrapper = deSerializeString(is2); std::istringstream wrapper_is(wrapper, std::ios::binary); f->deSerialize(wrapper_is); verbosestream<<"deserialized "<<f->name<<std::endl; if(f->name != "") addNameIdMapping(i, f->name); } }
virtual content_t set(const std::string &name, const ContentFeatures &def) { assert(name == def.name); u16 id = CONTENT_IGNORE; bool found = m_name_id_mapping.getId(name, id); // ignore aliases if(!found){ // Determine if full param2 is required bool require_full_param2 = ( def.param_type_2 == CPT2_FULL || def.param_type_2 == CPT2_FLOWINGLIQUID || def.legacy_wallmounted ); // Get some id id = getFreeId(require_full_param2); if(id == CONTENT_IGNORE) return CONTENT_IGNORE; if(name != "") addNameIdMapping(id, name); } set(id, def); return id; }
// IWritableNodeDefManager content_t NodeDefManager::set(const std::string &name, const ContentFeatures &def) { // Pre-conditions assert(name != ""); assert(name != "ignore"); assert(name == def.name); content_t id = CONTENT_IGNORE; if (!m_name_id_mapping.getId(name, id)) { // ignore aliases // Get new id id = allocateId(); if (id == CONTENT_IGNORE) { warningstream << "NodeDefManager: Absolute " "limit reached" << std::endl; return CONTENT_IGNORE; } assert(id != CONTENT_IGNORE); addNameIdMapping(id, name); } m_content_features[id] = def; verbosestream << "NodeDefManager: registering content id \"" << id << "\": name=\"" << def.name << "\""<<std::endl; getNodeBoxUnion(def.selection_box, def, &m_selection_box_union); fixSelectionBoxIntUnion(); // Add this content to the list of all groups it belongs to // FIXME: This should remove a node from groups it no longer // belongs to when a node is re-registered for (const auto &group : def.groups) { const std::string &group_name = group.first; m_group_to_items[group_name].push_back(id); } return id; }
void clear() { m_name_id_mapping.clear(); m_name_id_mapping_with_aliases.clear(); for(u16 i=0; i<=MAX_CONTENT; i++) { ContentFeatures &f = m_content_features[i]; f.reset(); // Reset to defaults } // Set CONTENT_AIR { ContentFeatures f; f.name = "air"; f.drawtype = NDT_AIRLIKE; f.param_type = CPT_LIGHT; f.light_propagates = true; f.sunlight_propagates = true; f.walkable = false; f.pointable = false; f.diggable = false; f.buildable_to = true; // Insert directly into containers content_t c = CONTENT_AIR; m_content_features[c] = f; addNameIdMapping(c, f.name); } // Set CONTENT_IGNORE { ContentFeatures f; f.name = "ignore"; f.drawtype = NDT_AIRLIKE; f.param_type = CPT_NONE; f.light_propagates = false; f.sunlight_propagates = false; f.walkable = false; f.pointable = false; f.diggable = false; // A way to remove accidental CONTENT_IGNOREs f.buildable_to = true; // Insert directly into containers content_t c = CONTENT_IGNORE; m_content_features[c] = f; addNameIdMapping(c, f.name); } }
// IWritableNodeDefManager content_t CNodeDefManager::set(const std::string &name, const ContentFeatures &def) { // Pre-conditions if (name == "") return CONTENT_IGNORE; if (name != def.name) return CONTENT_IGNORE; // Don't allow redefining ignore (but allow air and unknown) if (name == "ignore") { infostream << "NodeDefManager: WARNING: Ignoring " "CONTENT_IGNORE redefinition"<<std::endl; return CONTENT_IGNORE; } content_t id = CONTENT_IGNORE; if (!m_name_id_mapping.getId(name, id)) { // ignore aliases // Get new id id = allocateId(); if (id == CONTENT_IGNORE) { infostream << "NodeDefManager: WARNING: Absolute " "limit reached" << std::endl; return CONTENT_IGNORE; } if (id == CONTENT_IGNORE) return CONTENT_IGNORE; addNameIdMapping(id, name); } m_content_features[id] = def; verbosestream << "NodeDefManager: registering content id \"" << id << "\": name=\"" << def.name << "\""<<std::endl; // Add this content to the list of all groups it belongs to // FIXME: This should remove a node from groups it no longer // belongs to when a node is re-registered for (ItemGroupList::const_iterator i = def.groups.begin(); i != def.groups.end(); ++i) { std::string group_name = i->first; std::map<std::string, GroupItems>::iterator j = m_group_to_items.find(group_name); if (j == m_group_to_items.end()) { m_group_to_items[group_name].push_back( std::make_pair(id, i->second)); } else { GroupItems &items = j->second; items.push_back(std::make_pair(id, i->second)); } } return id; }
void CNodeDefManager::deSerialize(std::istream &is) { clear(); int version = readU8(is); if (version != 1) throw SerializationError("unsupported NodeDefinitionManager version"); u16 count = readU16(is); std::istringstream is2(deSerializeLongString(is), std::ios::binary); ContentFeatures f; for (u16 n = 0; n < count; n++) { u16 i = readU16(is2); // Read it from the string wrapper std::string wrapper = deSerializeString(is2); std::istringstream wrapper_is(wrapper, std::ios::binary); f.deSerialize(wrapper_is); // Check error conditions if (i == CONTENT_IGNORE || i == CONTENT_AIR || i == CONTENT_UNKNOWN) { warningstream << "NodeDefManager::deSerialize(): " "not changing builtin node " << i << std::endl; continue; } if (f.name.empty()) { warningstream << "NodeDefManager::deSerialize(): " "received empty name" << std::endl; continue; } // Ignore aliases u16 existing_id; if (m_name_id_mapping.getId(f.name, existing_id) && i != existing_id) { warningstream << "NodeDefManager::deSerialize(): " "already defined with different ID: " << f.name << std::endl; continue; } // All is ok, add node definition with the requested ID if (i >= m_content_features.size()) m_content_features.resize((u32)(i) + 1); m_content_features[i] = f; addNameIdMapping(i, f.name); verbosestream << "deserialized " << f.name << std::endl; getNodeBoxUnion(f.selection_box, f, &m_selection_box_union); fixSelectionBoxIntUnion(); } }
virtual content_t set(const std::string &name, const ContentFeatures &def) { assert(name == def.name); u16 id = CONTENT_IGNORE; bool found = m_name_id_mapping.getId(name, id); // ignore aliases if(!found){ // Get some id id = getFreeId(); if(id == CONTENT_IGNORE) return CONTENT_IGNORE; if(name != "") addNameIdMapping(id, name); } set(id, def); return id; }
void CNodeDefManager::msgpack_unpack(msgpack::object o) { clear(); std::map<int, ContentFeatures> unpacked_features; o.convert(&unpacked_features); for (std::map<int, ContentFeatures>::iterator it = unpacked_features.begin(); it != unpacked_features.end(); ++it) { unsigned int i = it->first; ContentFeatures f = it->second; if(i == CONTENT_IGNORE || i == CONTENT_AIR || i == CONTENT_UNKNOWN){ infostream<<"NodeDefManager::deSerialize(): WARNING: " <<"not changing builtin node "<<i <<std::endl; continue; } if(f.name == ""){ infostream<<"NodeDefManager::deSerialize(): WARNING: " <<"received empty name"<<std::endl; continue; } u16 existing_id; bool found = m_name_id_mapping.getId(f.name, existing_id); // ignore aliases if(found && i != existing_id){ infostream<<"NodeDefManager::deSerialize(): WARNING: " <<"already defined with different ID: " <<f.name<<std::endl; continue; } // All is ok, add node definition with the requested ID if(i >= m_content_features.size()) m_content_features.resize((u32)(i) + 1); m_content_features[i] = f; addNameIdMapping(i, f.name); verbosestream<<"deserialized "<<f.name<<std::endl; } }
void deSerialize(std::istream &is) { clear(); u16 count = readU16(is); std::istringstream tmp_is(deSerializeLongString(is), std::ios::binary); for(u16 n=0; n<count; n++){ u16 i = readU16(tmp_is); if(i > MAX_CONTENT){ errorstream<<"ContentFeatures::deSerialize(): " <<"Too large content id: "<<i<<std::endl; continue; } /*// Do not deserialize special types if(i == CONTENT_IGNORE || i == CONTENT_AIR) continue;*/ ContentFeatures *f = &m_content_features[i]; f->deSerialize(tmp_is); if(f->name != "") addNameIdMapping(i, f->name); } }
// IWritableNodeDefManager virtual void set(content_t c, const ContentFeatures &def) { verbosestream<<"registerNode: registering content id \""<<c <<"\": name=\""<<def.name<<"\""<<std::endl; assert(c <= MAX_CONTENT); // Don't allow redefining CONTENT_IGNORE (but allow air) if(def.name == "ignore" || c == CONTENT_IGNORE){ infostream<<"registerNode: WARNING: Ignoring " <<"CONTENT_IGNORE redefinition"<<std::endl; return; } // Check that the special contents are not redefined as different id // because it would mess up everything if((def.name == "ignore" && c != CONTENT_IGNORE) || (def.name == "air" && c != CONTENT_AIR)){ errorstream<<"registerNode: IGNORING ERROR: " <<"trying to register built-in type \"" <<def.name<<"\" as different id"<<std::endl; return; } m_content_features[c] = def; if(def.name != "") addNameIdMapping(c, def.name); // Add this content to the list of all groups it belongs to for (ItemGroupList::const_iterator i = def.groups.begin(); i != def.groups.end(); ++i) { std::string group_name = i->first; std::map<std::string, GroupItems>::iterator j = m_group_to_items.find(group_name); if (j == m_group_to_items.end()) { m_group_to_items[group_name].push_back(std::make_pair(c, i->second)); } else { GroupItems &items = j->second; items.push_back(std::make_pair(c, i->second)); } } }
// IWritableNodeDefManager virtual void set(content_t c, const ContentFeatures &def) { verbosestream<<"registerNode: registering content id \""<<c <<"\": name=\""<<def.name<<"\""<<std::endl; assert(c <= MAX_CONTENT); // Don't allow redefining CONTENT_IGNORE (but allow air) if(def.name == "ignore" || c == CONTENT_IGNORE){ infostream<<"registerNode: WARNING: Ignoring " <<"CONTENT_IGNORE redefinition"<<std::endl; return; } // Check that the special contents are not redefined as different id // because it would mess up everything if((def.name == "ignore" && c != CONTENT_IGNORE) || (def.name == "air" && c != CONTENT_AIR)){ errorstream<<"registerNode: IGNORING ERROR: " <<"trying to register built-in type \"" <<def.name<<"\" as different id"<<std::endl; return; } m_content_features[c] = def; if(def.name != "") addNameIdMapping(c, def.name); }
void clear() { m_content_features.clear(); m_name_id_mapping.clear(); m_name_id_mapping_with_aliases.clear(); m_group_to_items.clear(); m_next_id = 0; u32 initial_length = 0; initial_length = MYMAX(initial_length, CONTENT_UNKNOWN + 1); initial_length = MYMAX(initial_length, CONTENT_AIR + 1); initial_length = MYMAX(initial_length, CONTENT_IGNORE + 1); m_content_features.resize(initial_length); // Set CONTENT_UNKNOWN { ContentFeatures f; f.name = "unknown"; // Insert directly into containers content_t c = CONTENT_UNKNOWN; m_content_features[c] = f; addNameIdMapping(c, f.name); } // Set CONTENT_AIR { ContentFeatures f; f.name = "air"; f.drawtype = NDT_AIRLIKE; f.param_type = CPT_LIGHT; f.light_propagates = true; f.sunlight_propagates = true; f.walkable = false; f.pointable = false; f.diggable = false; f.buildable_to = true; // Insert directly into containers content_t c = CONTENT_AIR; m_content_features[c] = f; addNameIdMapping(c, f.name); } // Set CONTENT_IGNORE { ContentFeatures f; f.name = "ignore"; f.drawtype = NDT_AIRLIKE; f.param_type = CPT_NONE; f.light_propagates = false; f.sunlight_propagates = false; f.walkable = false; f.pointable = false; f.diggable = false; // A way to remove accidental CONTENT_IGNOREs f.buildable_to = true; // Insert directly into containers content_t c = CONTENT_IGNORE; m_content_features[c] = f; addNameIdMapping(c, f.name); } }
void CNodeDefManager::clear() { m_content_features.clear(); m_name_id_mapping.clear(); m_name_id_mapping_with_aliases.clear(); m_group_to_items.clear(); m_next_id = 0; resetNodeResolveState(); u32 initial_length = 0; initial_length = MYMAX(initial_length, CONTENT_UNKNOWN + 1); initial_length = MYMAX(initial_length, CONTENT_AIR + 1); initial_length = MYMAX(initial_length, CONTENT_IGNORE + 1); m_content_features.resize(initial_length); // Set CONTENT_UNKNOWN { ContentFeatures f; f.name = "unknown"; // Insert directly into containers content_t c = CONTENT_UNKNOWN; m_content_features[c] = f; addNameIdMapping(c, f.name); } // Set CONTENT_AIR { ContentFeatures f; f.name = "air"; f.drawtype = NDT_AIRLIKE; f.param_type = CPT_LIGHT; f.light_propagates = true; f.sunlight_propagates = true; f.walkable = false; f.pointable = false; f.diggable = false; f.buildable_to = true; f.is_ground_content = true; #ifndef SERVER f.minimap_color = video::SColor(0,255,255,255); #endif // Insert directly into containers content_t c = CONTENT_AIR; m_content_features[c] = f; addNameIdMapping(c, f.name); } // Set CONTENT_IGNORE { ContentFeatures f; f.name = "ignore"; f.drawtype = NDT_AIRLIKE; f.param_type = CPT_NONE; f.light_propagates = false; f.sunlight_propagates = false; f.walkable = false; f.pointable = false; f.diggable = false; f.buildable_to = true; // A way to remove accidental CONTENT_IGNOREs f.is_ground_content = true; #ifndef SERVER f.minimap_color = video::SColor(0,255,255,255); #endif // Insert directly into containers content_t c = CONTENT_IGNORE; m_content_features[c] = f; addNameIdMapping(c, f.name); // mtproto: 0 must be ignore always if (c) m_content_features[0] = f; } }