Node metadata framework
authorPerttu Ahola <celeron55@gmail.com>
Mon, 4 Apr 2011 00:45:08 +0000 (03:45 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 4 Apr 2011 00:45:08 +0000 (03:45 +0300)
src/client.cpp
src/client.h
src/main.cpp
src/map.cpp
src/map.h
src/mapnode.cpp
src/mapnode.h

index e381fbce3cfe631636710ee6b9448c28814c9d5e..009591c414eea9ef8a0e71a7235d656ed6bb625b 100644 (file)
@@ -1787,10 +1787,9 @@ MapNode Client::getNode(v3s16 p)
        return m_env.getMap().getNode(p);
 }
 
-NodeMetadata* Client::getNodeMetadataClone(v3s16 p)
+NodeMetadata* Client::getNodeMetadata(v3s16 p)
 {
-       //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
-       return m_env.getMap().getNodeMetadataClone(p);
+       return m_env.getMap().getNodeMetadata(p);
 }
 
 v3f Client::getPlayerPosition()
index d46b51a0a8658123b25ebe60749064078639761e..3915282865e0365609550a42a7530f42445d74f3 100644 (file)
@@ -290,7 +290,7 @@ public:
        // Returns InvalidPositionException if not found
        MapNode getNode(v3s16 p);
        // Wrapper to Map
-       NodeMetadata* getNodeMetadataClone(v3s16 p);
+       NodeMetadata* getNodeMetadata(v3s16 p);
 
        v3f getPlayerPosition();
 
index 3ddac369d3954f424b2189c6e9b8185bf1baef89..4b968865fc7de245883fd23e328ac06c3e96d3d5 100644 (file)
@@ -2821,10 +2821,15 @@ int main(int argc, char *argv[])
                        hilightboxes.push_back(nodehilightbox);\r
 \r
                        /*\r
-                               TODO:\r
                                Check information text of node\r
                        */\r
 \r
+                       NodeMetadata *meta = client.getNodeMetadata(nodepos);\r
+                       if(meta)\r
+                       {\r
+                               infotext = narrow_to_wide(meta->infoText());\r
+                       }\r
+\r
                        /*\r
                                Handle digging\r
                        */\r
index 39742a892fcb5a8cb47510f1c818e20ed7683896..d644215be78911de0d56af9825eb684e98d94d3d 100644 (file)
@@ -954,6 +954,17 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
        */
        
        setNode(p, n);
+
+       /*
+               Add intial metadata
+       */
+
+       NodeMetadata *meta_proto = content_features(n.d).initial_metadata;
+       if(meta_proto)
+       {
+               NodeMetadata *meta = meta_proto->clone();
+               setNodeMetadata(p, meta);
+       }
        
        /*
                If node is under sunlight and doesn't let sunlight through,
@@ -1093,6 +1104,12 @@ void Map::removeNodeAndUpdate(v3s16 p,
                                light_sources, modified_blocks);
        }
 
+       /*
+               Remove node metadata
+       */
+
+       removeNodeMetadata(p);
+
        /*
                Remove the node.
                This also clears the lighting.
@@ -1696,17 +1713,49 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
        //dstream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
 }
 
-NodeMetadata* Map::getNodeMetadataClone(v3s16 p)
+NodeMetadata* Map::getNodeMetadata(v3s16 p)
 {
        v3s16 blockpos = getNodeBlockPos(p);
        v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE;
        MapBlock *block = getBlockNoCreateNoEx(blockpos);
        if(block == NULL)
+       {
+               dstream<<"WARNING: Map::setNodeMetadata(): Block not found"
+                               <<std::endl;
                return NULL;
-       NodeMetadata *meta = block->m_node_metadata.getClone(p_rel);
+       }
+       NodeMetadata *meta = block->m_node_metadata.get(p_rel);
        return meta;
 }
 
+void Map::setNodeMetadata(v3s16 p, NodeMetadata *meta)
+{
+       v3s16 blockpos = getNodeBlockPos(p);
+       v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE;
+       MapBlock *block = getBlockNoCreateNoEx(blockpos);
+       if(block == NULL)
+       {
+               dstream<<"WARNING: Map::setNodeMetadata(): Block not found"
+                               <<std::endl;
+               return;
+       }
+       block->m_node_metadata.set(p_rel, meta);
+}
+
+void Map::removeNodeMetadata(v3s16 p)
+{
+       v3s16 blockpos = getNodeBlockPos(p);
+       v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE;
+       MapBlock *block = getBlockNoCreateNoEx(blockpos);
+       if(block == NULL)
+       {
+               dstream<<"WARNING: Map::removeNodeMetadata(): Block not found"
+                               <<std::endl;
+               return;
+       }
+       block->m_node_metadata.remove(p_rel);
+}
+
 /*
        ServerMap
 */
index 2fafcae17e1fef95540be8f4ed56768880cae988..b1b3b9aff42aaf94a229951c07cacca028c42abf 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -282,7 +282,9 @@ public:
                These are basically coordinate wrappers to MapBlock
        */
        
-       NodeMetadata* getNodeMetadataClone(v3s16 p);
+       NodeMetadata* getNodeMetadata(v3s16 p);
+       void setNodeMetadata(v3s16 p, NodeMetadata *meta);
+       void removeNodeMetadata(v3s16 p);
 
        /*
                Variables
index a8c951ab3414c75a6e00dceb669ffbda3744472d..c8a7e504cd20741d1fa7f49120677dc551c5c10a 100644 (file)
@@ -306,6 +306,8 @@ void init_mapnode()
        f->walkable = false;
        f->wall_mounted = true;
        f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
+       if(f->initial_metadata == NULL)
+               f->initial_metadata = new SignNodeMetadata();
        
 }
 
index ba08a37daaeeec8c39f01b1b915def9540aaafcf..0762599c8f9760fcfa81c9c75ae3a849f9e62354 100644 (file)
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "serialization.h"
 #include "tile.h"
 #include "iirrlichtwrapper.h"
+#include "nodemetadata.h"
 
 /*
        Initializes all kind of stuff in here.
@@ -157,6 +158,9 @@ struct ContentFeatures
        // Inventory item string as which the node appears in inventory when dug.
        // Mineral overrides this.
        std::string dug_item;
+       
+       // Initial metadata is cloned from this
+       NodeMetadata *initial_metadata;
 
        //TODO: Move more properties here
 
@@ -176,6 +180,7 @@ struct ContentFeatures
                liquid_type = LIQUID_NONE;
                wall_mounted = false;
                dug_item = "";
+               initial_metadata = NULL;
        }
 
        ~ContentFeatures();