From c0f6395cf09f658eb95365c60f67b8a89104cb23 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 16 Nov 2011 13:03:28 +0200 Subject: Node definition names --- src/nodedef.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 14 deletions(-) (limited to 'src/nodedef.cpp') diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 166d9cba0..baaaa1048 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif #include "log.h" #include "settings.h" +#include "nameidmapping.h" /* NodeBox @@ -318,20 +319,63 @@ class CNodeDefManager: public IWritableNodeDefManager public: void clear() { + m_name_id_mapping.clear(); for(u16 i=0; i<=MAX_CONTENT; i++) { - ContentFeatures *f = &m_content_features[i]; - f->reset(); // Reset to defaults - if(i == CONTENT_IGNORE || i == CONTENT_AIR){ - f->drawtype = NDT_AIRLIKE; - continue; + ContentFeatures &f = m_content_features[i]; + f.reset(); // Reset to defaults + f.setAllTextures("unknown_block.png"); + } + + // 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.air_equivalent = true; + set(CONTENT_AIR, f); + } + // Set CONTENT_IGNORE + { + ContentFeatures f; + f.name = "ignore"; + 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.air_equivalent = true; + set(CONTENT_AIR, f); + } + } + // CONTENT_IGNORE = not found + content_t getFreeId(bool require_full_param2) + { + // If allowed, first search in the large 4-byte-param2 pool + if(!require_full_param2){ + for(u16 i=0x800; i<=0xfff; i++){ + const ContentFeatures &f = m_content_features[i]; + if(f.name == "") + return i; } - f->setAllTextures("unknown_block.png"); } -#ifndef SERVER - // Make CONTENT_IGNORE to not block the view when occlusion culling - m_content_features[CONTENT_IGNORE].solidness = 0; -#endif + // Then search from the small 8-byte-param2 pool + for(u16 i=0; i<=125; i++){ + const ContentFeatures &f = m_content_features[i]; + if(f.name == "") + return i; + } + return CONTENT_IGNORE; } CNodeDefManager() { @@ -358,18 +402,54 @@ public: { return get(n.getContent()); } - // Writable + virtual bool getId(const std::string &name, content_t &result) const + { + return m_name_id_mapping.getId(name, result); + } + // IWritableNodeDefManager virtual void set(content_t c, const ContentFeatures &def) { infostream<<"registerNode: registering content id \""<name == "") continue; @@ -523,10 +605,13 @@ public: } ContentFeatures *f = &m_content_features[i]; f->deSerialize(tmp_is, gamedef); + if(f->name != "") + m_name_id_mapping.set(i, f->name); } } private: ContentFeatures m_content_features[MAX_CONTENT+1]; + NameIdMapping m_name_id_mapping; }; IWritableNodeDefManager* createNodeDefManager() -- cgit v1.2.3