Node metadata framework

This commit is contained in:
Perttu Ahola 2011-04-04 03:45:08 +03:00
parent 2f466726e6
commit fa08294d09
7 changed files with 70 additions and 8 deletions

View File

@ -1787,10 +1787,9 @@ MapNode Client::getNode(v3s16 p)
return m_env.getMap().getNode(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().getNodeMetadata(p);
return m_env.getMap().getNodeMetadataClone(p);
} }
v3f Client::getPlayerPosition() v3f Client::getPlayerPosition()

View File

@ -290,7 +290,7 @@ public:
// Returns InvalidPositionException if not found // Returns InvalidPositionException if not found
MapNode getNode(v3s16 p); MapNode getNode(v3s16 p);
// Wrapper to Map // Wrapper to Map
NodeMetadata* getNodeMetadataClone(v3s16 p); NodeMetadata* getNodeMetadata(v3s16 p);
v3f getPlayerPosition(); v3f getPlayerPosition();

View File

@ -2821,10 +2821,15 @@ int main(int argc, char *argv[])
hilightboxes.push_back(nodehilightbox); hilightboxes.push_back(nodehilightbox);
/* /*
TODO:
Check information text of node Check information text of node
*/ */
NodeMetadata *meta = client.getNodeMetadata(nodepos);
if(meta)
{
infotext = narrow_to_wide(meta->infoText());
}
/* /*
Handle digging Handle digging
*/ */

View File

@ -955,6 +955,17 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
setNode(p, 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, If node is under sunlight and doesn't let sunlight through,
take all sunlighted nodes under it and clear light from them take all sunlighted nodes under it and clear light from them
@ -1093,6 +1104,12 @@ void Map::removeNodeAndUpdate(v3s16 p,
light_sources, modified_blocks); light_sources, modified_blocks);
} }
/*
Remove node metadata
*/
removeNodeMetadata(p);
/* /*
Remove the node. Remove the node.
This also clears the lighting. 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; //dstream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
} }
NodeMetadata* Map::getNodeMetadataClone(v3s16 p) NodeMetadata* Map::getNodeMetadata(v3s16 p)
{ {
v3s16 blockpos = getNodeBlockPos(p); v3s16 blockpos = getNodeBlockPos(p);
v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE; v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE;
MapBlock *block = getBlockNoCreateNoEx(blockpos); MapBlock *block = getBlockNoCreateNoEx(blockpos);
if(block == NULL) if(block == NULL)
{
dstream<<"WARNING: Map::setNodeMetadata(): Block not found"
<<std::endl;
return NULL; return NULL;
NodeMetadata *meta = block->m_node_metadata.getClone(p_rel); }
NodeMetadata *meta = block->m_node_metadata.get(p_rel);
return meta; 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 ServerMap
*/ */

View File

@ -282,7 +282,9 @@ public:
These are basically coordinate wrappers to MapBlock 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 Variables

View File

@ -306,6 +306,8 @@ void init_mapnode()
f->walkable = false; f->walkable = false;
f->wall_mounted = true; f->wall_mounted = true;
f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
if(f->initial_metadata == NULL)
f->initial_metadata = new SignNodeMetadata();
} }

View File

@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serialization.h" #include "serialization.h"
#include "tile.h" #include "tile.h"
#include "iirrlichtwrapper.h" #include "iirrlichtwrapper.h"
#include "nodemetadata.h"
/* /*
Initializes all kind of stuff in here. Initializes all kind of stuff in here.
@ -158,6 +159,9 @@ struct ContentFeatures
// Mineral overrides this. // Mineral overrides this.
std::string dug_item; std::string dug_item;
// Initial metadata is cloned from this
NodeMetadata *initial_metadata;
//TODO: Move more properties here //TODO: Move more properties here
ContentFeatures() ContentFeatures()
@ -176,6 +180,7 @@ struct ContentFeatures
liquid_type = LIQUID_NONE; liquid_type = LIQUID_NONE;
wall_mounted = false; wall_mounted = false;
dug_item = ""; dug_item = "";
initial_metadata = NULL;
} }
~ContentFeatures(); ~ContentFeatures();