diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index 3a4a4652a..a6bf0a82d 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -167,69 +167,3 @@ void content_mapnode_get_name_id_mapping(NameIdMapping *nimap) nimap->set(CONTENT_AIR, "air"); } -class NewNameGetter -{ -public: - NewNameGetter() - { - old_to_new["CONTENT_STONE"] = "default:stone"; - old_to_new["CONTENT_WATER"] = "default:water_flowing"; - old_to_new["CONTENT_TORCH"] = "default:torch"; - old_to_new["CONTENT_WATERSOURCE"] = "default:water_source"; - old_to_new["CONTENT_SIGN_WALL"] = "default:sign_wall"; - old_to_new["CONTENT_CHEST"] = "default:chest"; - old_to_new["CONTENT_FURNACE"] = "default:furnace"; - old_to_new["CONTENT_LOCKABLE_CHEST"] = "default:locked_chest"; - old_to_new["CONTENT_FENCE"] = "default:wooden_fence"; - old_to_new["CONTENT_RAIL"] = "default:rail"; - old_to_new["CONTENT_LADDER"] = "default:ladder"; - old_to_new["CONTENT_LAVA"] = "default:lava_flowing"; - old_to_new["CONTENT_LAVASOURCE"] = "default:lava_source"; - old_to_new["CONTENT_GRASS"] = "default:dirt_with_grass"; - old_to_new["CONTENT_TREE"] = "default:tree"; - old_to_new["CONTENT_LEAVES"] = "default:leaves"; - old_to_new["CONTENT_GRASS_FOOTSTEPS"] = "default:dirt_with_grass_footsteps"; - old_to_new["CONTENT_MESE"] = "default:mese"; - old_to_new["CONTENT_MUD"] = "default:dirt"; - old_to_new["CONTENT_CLOUD"] = "default:cloud"; - old_to_new["CONTENT_COALSTONE"] = "default:coalstone"; - old_to_new["CONTENT_WOOD"] = "default:wood"; - old_to_new["CONTENT_SAND"] = "default:sand"; - old_to_new["CONTENT_COBBLE"] = "default:cobble"; - old_to_new["CONTENT_STEEL"] = "default:steel"; - old_to_new["CONTENT_GLASS"] = "default:glass"; - old_to_new["CONTENT_MOSSYCOBBLE"] = "default:mossycobble"; - old_to_new["CONTENT_GRAVEL"] = "default:gravel"; - old_to_new["CONTENT_SANDSTONE"] = "default:sandstone"; - old_to_new["CONTENT_CACTUS"] = "default:cactus"; - old_to_new["CONTENT_BRICK"] = "default:brick"; - old_to_new["CONTENT_CLAY"] = "default:clay"; - old_to_new["CONTENT_PAPYRUS"] = "default:papyrus"; - old_to_new["CONTENT_BOOKSHELF"] = "default:bookshelf"; - old_to_new["CONTENT_JUNGLETREE"] = "default:jungletree"; - old_to_new["CONTENT_JUNGLEGRASS"] = "default:junglegrass"; - old_to_new["CONTENT_NC"] = "default:nyancat"; - old_to_new["CONTENT_NC_RB"] = "default:nyancat_rainbow"; - old_to_new["CONTENT_APPLE"] = "default:apple"; - old_to_new["CONTENT_SAPLING"] = "default:sapling"; - // Just in case - old_to_new["CONTENT_IGNORE"] = "ignore"; - old_to_new["CONTENT_AIR"] = "air"; - } - std::string get(const std::string &old) - { - StringMap::const_iterator it = old_to_new.find(old); - if (it == old_to_new.end()) - return ""; - return it->second; - } -private: - StringMap old_to_new; -}; - -NewNameGetter newnamegetter; - -std::string content_mapnode_get_new_name(const std::string &oldname) -{ - return newnamegetter.get(oldname); -} diff --git a/src/content_mapnode.h b/src/content_mapnode.h index 5d68afe59..9fa4e6d13 100644 --- a/src/content_mapnode.h +++ b/src/content_mapnode.h @@ -34,8 +34,4 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version); class NameIdMapping; void content_mapnode_get_name_id_mapping(NameIdMapping *nimap); -// Convert "CONTENT_STONE"-style names to dynamic ids -std::string content_mapnode_get_new_name(const std::string &oldname); -class INodeDefManager; - #endif diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index f504924f9..dd5f8e6b5 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -79,7 +79,7 @@ static bool content_nodemeta_deserialize_legacy_body( inv->getList("0")->setName("main"); } assert(inv->getList("main") && !inv->getList("0")); - + meta->setString("formspec","size[8,9]" "list[current_name;main;0,0;8,4;]" "list[current_player;main;0,5;8,4;]"); @@ -96,7 +96,7 @@ static bool content_nodemeta_deserialize_legacy_body( inv->getList("0")->setName("main"); } assert(inv->getList("main") && !inv->getList("0")); - + meta->setString("formspec","size[8,9]" "list[current_name;main;0,0;8,4;]" "list[current_player;main;0,5;8,4;]"); @@ -145,7 +145,7 @@ static bool content_nodemeta_deserialize_legacy_meta( void content_nodemeta_deserialize_legacy(std::istream &is, NodeMetadataList *meta, NodeTimerList *timers, - IGameDef *gamedef) + IItemDefManager *item_def_mgr) { meta->clear(); timers->clear(); @@ -181,7 +181,7 @@ void content_nodemeta_deserialize_legacy(std::istream &is, continue; } - NodeMetadata *data = new NodeMetadata(gamedef); + NodeMetadata *data = new NodeMetadata(item_def_mgr); bool need_timer = content_nodemeta_deserialize_legacy_meta(is, data); meta->set(p, data); diff --git a/src/content_nodemeta.h b/src/content_nodemeta.h index 0b08bc6a1..ebc01d9a8 100644 --- a/src/content_nodemeta.h +++ b/src/content_nodemeta.h @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class NodeMetadataList; class NodeTimerList; -class IGameDef; +class IItemDefManager; /* Legacy nodemeta definitions @@ -32,7 +32,7 @@ class IGameDef; void content_nodemeta_deserialize_legacy(std::istream &is, NodeMetadataList *meta, NodeTimerList *timers, - IGameDef *gamedef); + IItemDefManager *item_def_mgr); void content_nodemeta_serialize_legacy(std::ostream &os, NodeMetadataList *meta); diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 11c4c125b..942457407 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -696,19 +696,17 @@ void MapBlock::deSerialize(std::istream &is, u8 version, bool disk) TRACESTREAM(<<"MapBlock::deSerialize "<= 23) - m_node_metadata.deSerialize(iss, m_gamedef); + if (version >= 23) + m_node_metadata.deSerialize(iss, m_gamedef->idef()); else content_nodemeta_deserialize_legacy(iss, - &m_node_metadata, &m_node_timers, - m_gamedef); - } - catch(SerializationError &e) - { + &m_node_metadata, &m_node_timers, + m_gamedef->idef()); + } catch(SerializationError &e) { errorstream<<"WARNING: MapBlock::deSerialize(): Ignoring an error" <<" while deserializing node metadata at (" < databuf_nodelist(nodecount * ser_length); // These have no compression - if(version <= 3 || version == 5 || version == 6) - { + if (version <= 3 || version == 5 || version == 6) { char tmp; is.read(&tmp, 1); - if(is.gcount() != 1) - throw SerializationError - ("MapBlock::deSerialize: no enough input data"); + if (is.gcount() != 1) + throw SerializationError(std::string(__FUNCTION_NAME) + + ": no enough input data"); is_underground = tmp; - is.read((char*)*databuf_nodelist, nodecount * ser_length); - if((u32)is.gcount() != nodecount * ser_length) - throw SerializationError - ("MapBlock::deSerialize: no enough input data"); - } - else if(version <= 10) - { + is.read((char *)*databuf_nodelist, nodecount * ser_length); + if ((u32)is.gcount() != nodecount * ser_length) + throw SerializationError(std::string(__FUNCTION_NAME) + + ": no enough input data"); + } else if (version <= 10) { u8 t8; - is.read((char*)&t8, 1); + is.read((char *)&t8, 1); is_underground = t8; { @@ -818,11 +813,10 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk) std::ostringstream os(std::ios_base::binary); decompress(is, os, version); std::string s = os.str(); - if(s.size() != nodecount) - throw SerializationError - ("MapBlock::deSerialize: invalid format"); - for(u32 i=0; i= 10) - { + if (version >= 10) { // Uncompress and set param2 data std::ostringstream os(std::ios_base::binary); decompress(is, os, version); std::string s = os.str(); - if(s.size() != nodecount) - throw SerializationError - ("MapBlock::deSerialize: invalid format"); - for(u32 i=0; i= 14) - { + if (version >= 14) { // Ignore errors - try{ - if(version <= 15) - { + try { + if (version <= 15) { std::string data = deSerializeString(is); std::istringstream iss(data, std::ios_base::binary); content_nodemeta_deserialize_legacy(iss, - &m_node_metadata, &m_node_timers, - m_gamedef); - } - else - { + &m_node_metadata, &m_node_timers, + m_gamedef->idef()); + } else { //std::string data = deSerializeLongString(is); std::ostringstream oss(std::ios_base::binary); decompressZlib(is, oss); std::istringstream iss(oss.str(), std::ios_base::binary); content_nodemeta_deserialize_legacy(iss, - &m_node_metadata, &m_node_timers, - m_gamedef); + &m_node_metadata, &m_node_timers, + m_gamedef->idef()); } - } - catch(SerializationError &e) - { + } catch(SerializationError &e) { errorstream<<"WARNING: MapBlock::deSerialize(): Ignoring an error" <<" while deserializing node metadata"<= 9){ + if (version >= 9) { u16 count = readU16(is); // Not supported and length not known if count is not 0 if(count != 0){ @@ -941,11 +919,11 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk) /* Versions up from 15 have static objects. */ - if(version >= 15) + if (version >= 15) m_static_objects.deSerialize(is); // Timestamp - if(version >= 17){ + if (version >= 17) { setTimestamp(readU32(is)); m_disk_timestamp = m_timestamp; } else { @@ -955,7 +933,7 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk) // Dynamically re-set ids based on node names NameIdMapping nimap; // If supported, read node definition id mapping - if(version >= 21){ + if (version >= 21) { nimap.deSerialize(is); // Else set the legacy mapping } else { diff --git a/src/mapgen.cpp b/src/mapgen.cpp index f8e9477c5..31d394fa4 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -29,7 +29,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_sao.h" #include "nodedef.h" #include "emerge.h" -#include "content_mapnode.h" // For content_mapnode_get_new_name #include "voxelalgorithms.h" #include "porting.h" #include "profiler.h" diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index 5e9219816..8492adfd9 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., //#include "serverobject.h" #include "content_sao.h" #include "nodedef.h" -#include "content_mapnode.h" // For content_mapnode_get_new_name #include "voxelalgorithms.h" //#include "profiler.h" // For TimeTaker #include "settings.h" // For g_settings diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index 2a9131be0..d63dac696 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -30,9 +30,9 @@ with this program; if not, write to the Free Software Foundation, Inc., NodeMetadata */ -NodeMetadata::NodeMetadata(IGameDef *gamedef): +NodeMetadata::NodeMetadata(IItemDefManager *item_def_mgr): m_stringvars(), - m_inventory(new Inventory(gamedef->idef())) + m_inventory(new Inventory(item_def_mgr)) { } @@ -101,34 +101,34 @@ void NodeMetadataList::serialize(std::ostream &os) const v3s16 p = i->first; NodeMetadata *data = i->second; - u16 p16 = p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X; + u16 p16 = p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE + p.Y * MAP_BLOCKSIZE + p.X; writeU16(os, p16); data->serialize(os); } } -void NodeMetadataList::deSerialize(std::istream &is, IGameDef *gamedef) +void NodeMetadataList::deSerialize(std::istream &is, IItemDefManager *item_def_mgr) { clear(); u8 version = readU8(is); - if(version == 0){ + if (version == 0) { // Nothing return; } - if(version != 1){ - infostream<<__FUNCTION_NAME<<": version "<deSerialize(is); m_data[p] = data; } diff --git a/src/nodemetadata.h b/src/nodemetadata.h index 8e84e5af3..8d1298212 100644 --- a/src/nodemetadata.h +++ b/src/nodemetadata.h @@ -35,12 +35,12 @@ with this program; if not, write to the Free Software Foundation, Inc., */ class Inventory; -class IGameDef; +class IItemDefManager; class NodeMetadata { public: - NodeMetadata(IGameDef *gamedef); + NodeMetadata(IItemDefManager *item_def_mgr); ~NodeMetadata(); void serialize(std::ostream &os) const; @@ -80,7 +80,7 @@ public: ~NodeMetadataList(); void serialize(std::ostream &os) const; - void deSerialize(std::istream &is, IGameDef *gamedef); + void deSerialize(std::istream &is, IItemDefManager *item_def_mgr); // Add all keys in this list to the vector keys std::vector getAllKeys(); diff --git a/src/rollback_interface.cpp b/src/rollback_interface.cpp index b3f457029..bffe0a82c 100644 --- a/src/rollback_interface.cpp +++ b/src/rollback_interface.cpp @@ -155,7 +155,7 @@ bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gam } else { NodeMetadata *meta = map->getNodeMetadata(p); if (!meta) { - meta = new NodeMetadata(gamedef); + meta = new NodeMetadata(gamedef->idef()); if (!map->setNodeMetadata(p, meta)) { delete meta; infostream << "RollbackAction::applyRevert(): " diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 6cdbe5c68..d8de9a412 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_content.h" #include "environment.h" #include "map.h" +#include "gamedef.h" #include "nodemetadata.h" @@ -43,7 +44,7 @@ NodeMetadata* NodeMetaRef::getmeta(NodeMetaRef *ref, bool auto_create) { NodeMetadata *meta = ref->m_env->getMap().getNodeMetadata(ref->m_p); if(meta == NULL && auto_create) { - meta = new NodeMetadata(ref->m_env->getGameDef()); + meta = new NodeMetadata(ref->m_env->getGameDef()->idef()); if(!ref->m_env->getMap().setNodeMetadata(ref->m_p, meta)) { delete meta; return NULL;