From fa08294d09a46b603e9ff5e034010c0a7986c61a Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 4 Apr 2011 03:45:08 +0300 Subject: [PATCH] Node metadata framework --- src/client.cpp | 5 ++--- src/client.h | 2 +- src/main.cpp | 7 ++++++- src/map.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++-- src/map.h | 4 +++- src/mapnode.cpp | 2 ++ src/mapnode.h | 5 +++++ 7 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index e381fbce..009591c4 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -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() diff --git a/src/client.h b/src/client.h index d46b51a0..39152828 100644 --- a/src/client.h +++ b/src/client.h @@ -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(); diff --git a/src/main.cpp b/src/main.cpp index 3ddac369..4b968865 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2821,10 +2821,15 @@ int main(int argc, char *argv[]) hilightboxes.push_back(nodehilightbox); /* - TODO: Check information text of node */ + NodeMetadata *meta = client.getNodeMetadata(nodepos); + if(meta) + { + infotext = narrow_to_wide(meta->infoText()); + } + /* Handle digging */ diff --git a/src/map.cpp b/src/map.cpp index 39742a89..d644215b 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -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 & modified_blocks) //dstream<<"Map::transformLiquids(): loopcount="<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" + <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" + <m_node_metadata.remove(p_rel); +} + /* ServerMap */ diff --git a/src/map.h b/src/map.h index 2fafcae1..b1b3b9af 100644 --- 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 diff --git a/src/mapnode.cpp b/src/mapnode.cpp index a8c951ab..c8a7e504 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -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(); } diff --git a/src/mapnode.h b/src/mapnode.h index ba08a37d..0762599c 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -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(); -- 2.30.2