From 280e1a2512c71ef0d38643d8b245c40b285879ae Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 31 Mar 2012 12:30:11 +0300 Subject: Allow group:groupname in ABM definition and implement minetest.hash_node_position() --- src/environment.cpp | 33 ++++++++++++++++++--------------- src/nodedef.cpp | 19 +++++++++++++++++++ src/nodedef.h | 6 ++++++ 3 files changed, 43 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/environment.cpp b/src/environment.cpp index 0c6d829f5..001b53a40 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -646,27 +646,30 @@ public: = abm->getRequiredNeighbors(); for(std::set::iterator i = required_neighbors_s.begin(); - i != required_neighbors_s.end(); i++){ - content_t c = ndef->getId(*i); - if(c == CONTENT_IGNORE) - continue; - aabm.required_neighbors.insert(c); + i != required_neighbors_s.end(); i++) + { + ndef->getIds(*i, aabm.required_neighbors); } // Trigger contents std::set contents_s = abm->getTriggerContents(); for(std::set::iterator - i = contents_s.begin(); i != contents_s.end(); i++){ - content_t c = ndef->getId(*i); - if(c == CONTENT_IGNORE) - continue; - std::map >::iterator j; - j = m_aabms.find(c); - if(j == m_aabms.end()){ - std::list aabmlist; - m_aabms[c] = aabmlist; + i = contents_s.begin(); i != contents_s.end(); i++) + { + std::set ids; + ndef->getIds(*i, ids); + for(std::set::const_iterator k = ids.begin(); + k != ids.end(); k++) + { + content_t c = *k; + std::map >::iterator j; j = m_aabms.find(c); + if(j == m_aabms.end()){ + std::list aabmlist; + m_aabms[c] = aabmlist; + j = m_aabms.find(c); + } + j->second.push_back(aabm); } - j->second.push_back(aabm); } } } diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 4b0c4b288..da74c8ce5 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -380,6 +380,25 @@ public: getId(name, id); return id; } + virtual void getIds(const std::string &name, std::set &result) + const + { + if(name.substr(0,6) != "group:"){ + content_t id = CONTENT_IGNORE; + if(getId(name, id)) + result.insert(id); + return; + } + std::string group = name.substr(6); + for(u16 id=0; id<=MAX_CONTENT; id++) + { + const ContentFeatures &f = m_content_features[id]; + if(f.name == "") // Quickly discard undefined nodes + continue; + if(itemgroup_get(f.groups, group) != 0) + result.insert(id); + } + } virtual const ContentFeatures& get(const std::string &name) const { content_t id = CONTENT_IGNORE; diff --git a/src/nodedef.h b/src/nodedef.h index a7ffa5a2e..753bea0ed 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -238,6 +238,9 @@ public: virtual const ContentFeatures& get(const MapNode &n) const=0; virtual bool getId(const std::string &name, content_t &result) const=0; virtual content_t getId(const std::string &name) const=0; + // Allows "group:name" in addition to regular node names + virtual void getIds(const std::string &name, std::set &result) + const=0; virtual const ContentFeatures& get(const std::string &name) const=0; virtual void serialize(std::ostream &os)=0; @@ -254,6 +257,9 @@ public: virtual const ContentFeatures& get(const MapNode &n) const=0; virtual bool getId(const std::string &name, content_t &result) const=0; virtual content_t getId(const std::string &name) const=0; + // Allows "group:name" in addition to regular node names + virtual void getIds(const std::string &name, std::set &result) + const=0; // If not found, returns the features of CONTENT_IGNORE virtual const ContentFeatures& get(const std::string &name) const=0; -- cgit v1.2.3