some prep to metadata to allow for node swapping or something similar

master
darkrose 2014-02-15 13:35:24 +10:00
parent 64873ede4f
commit da4dc1187d
7 changed files with 20 additions and 18 deletions

View File

@ -404,7 +404,7 @@ void FurnaceNodeMetadata::inventoryModified()
{
infostream<<"Furnace inventory modification callback"<<std::endl;
}
bool FurnaceNodeMetadata::step(float dtime)
bool FurnaceNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
{
if(dtime > 60.0)
infostream<<"Furnace stepping a long time ("<<dtime<<")"<<std::endl;
@ -633,7 +633,7 @@ void LockingFurnaceNodeMetadata::inventoryModified()
{
infostream<<"LockingFurnace inventory modification callback"<<std::endl;
}
bool LockingFurnaceNodeMetadata::step(float dtime)
bool LockingFurnaceNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
{
if(dtime > 60.0)
infostream<<"LockingFurnace stepping a long time ("<<dtime<<")"<<std::endl;
@ -787,7 +787,7 @@ NodeMetadata* TNTNodeMetadata::clone()
TNTNodeMetadata *d = new TNTNodeMetadata();
return d;
}
bool TNTNodeMetadata::step(float dtime)
bool TNTNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
{
if (!m_armed)
return false;
@ -966,7 +966,7 @@ void CraftGuideNodeMetadata::inventoryModified()
{
infostream<<"CraftGuide inventory modification callback"<<std::endl;
}
bool CraftGuideNodeMetadata::step(float dtime)
bool CraftGuideNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
{
InventoryList *l = m_inventory->getList("result");
InventoryItem *t = l->getItem(0);

View File

@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodemetadata.h"
class ServerEnvironment;
class Inventory;
class SignNodeMetadata : public NodeMetadata
@ -163,7 +164,7 @@ public:
virtual std::string infoText();
virtual Inventory* getInventory() {return m_inventory;}
virtual void inventoryModified();
virtual bool step(float dtime);
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
virtual bool nodeRemovalDisabled();
virtual std::string getInventoryDrawSpecString();
@ -189,7 +190,7 @@ public:
virtual std::string infoText();
virtual Inventory* getInventory() {return m_inventory;}
virtual void inventoryModified();
virtual bool step(float dtime);
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
virtual bool nodeRemovalDisabled();
virtual std::string getInventoryDrawSpecString();
@ -221,7 +222,7 @@ public:
virtual NodeMetadata* clone();
virtual void serializeBody(std::ostream &os);
virtual std::string infoText();
virtual bool step(float dtime);
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
virtual bool energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos)
{
@ -279,7 +280,7 @@ public:
virtual Inventory* getInventory() {return m_inventory;}
virtual bool nodeRemovalDisabled();
virtual void inventoryModified();
virtual bool step(float dtime);
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
virtual std::string getInventoryDrawSpecString();
private:

View File

@ -608,7 +608,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
activateObjects(block);
// Run node metadata
bool changed = block->m_node_metadata.step((float)dtime_s);
bool changed = block->m_node_metadata.step((float)dtime_s,this);
if(changed)
{
MapEditEvent event;
@ -918,7 +918,7 @@ void ServerEnvironment::step(float dtime)
block->setTimestampNoChangedFlag(m_game_time);
// Run node metadata
bool changed = block->m_node_metadata.step(dtime);
bool changed = block->m_node_metadata.step(dtime,this);
if(changed)
{
MapEditEvent event;

View File

@ -1876,8 +1876,7 @@ void Map::removeNodeMetadata(v3s16 p)
block->m_node_metadata.remove(p_rel);
}
void Map::nodeMetadataStep(float dtime,
core::map<v3s16, MapBlock*> &changed_blocks)
void Map::nodeMetadataStep(float dtime, core::map<v3s16, MapBlock*> &changed_blocks, ServerEnvironment *env)
{
/*
NOTE:
@ -1898,7 +1897,7 @@ void Map::nodeMetadataStep(float dtime,
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
{
MapBlock *block = *i;
bool changed = block->m_node_metadata.step(dtime);
bool changed = block->m_node_metadata.step(dtime,env);
if(changed)
changed_blocks[block->getPos()] = block;
}

View File

@ -43,6 +43,7 @@ class ServerMapSector;
class ClientMapSector;
class MapBlock;
class NodeMetadata;
class ServerEnvironment;
namespace mapgen{
struct BlockMakeData;
@ -278,7 +279,7 @@ public:
void setNodeMetadata(v3s16 p, NodeMetadata *meta);
void removeNodeMetadata(v3s16 p);
void nodeMetadataStep(float dtime,
core::map<v3s16, MapBlock*> &changed_blocks);
core::map<v3s16, MapBlock*> &changed_blocks, ServerEnvironment *env);
/*
Misc.

View File

@ -213,7 +213,7 @@ void NodeMetadataList::set(v3s16 p, NodeMetadata *d)
m_data.insert(p, d);
}
bool NodeMetadataList::step(float dtime)
bool NodeMetadataList::step(float dtime, ServerEnvironment *env)
{
bool something_changed = false;
for(core::map<v3s16, NodeMetadata*>::Iterator
@ -222,7 +222,7 @@ bool NodeMetadataList::step(float dtime)
{
v3s16 p = i.getNode()->getKey();
NodeMetadata *meta = i.getNode()->getValue();
bool changed = meta->step(dtime);
bool changed = meta->step(dtime, p, env);
if(changed)
something_changed = true;
}

View File

@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
class Inventory;
class ServerEnvironment;
class NodeMetadata
{
@ -62,7 +63,7 @@ public:
// the changes are copied elsewhere
virtual void inventoryModified(){}
// A step in time. Returns true if metadata changed.
virtual bool step(float dtime) {return false;}
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env) {return false;}
virtual bool nodeRemovalDisabled(){return false;}
// Used to make custom inventory menus.
// See format in guiInventoryMenu.cpp.
@ -120,7 +121,7 @@ public:
void set(v3s16 p, NodeMetadata *d);
// A step in time. Returns true if something changed.
bool step(float dtime);
bool step(float dtime, ServerEnvironment *env);
private:
core::map<v3s16, NodeMetadata*> m_data;