)
set(common_SRCS
+ content_tool.cpp
tool.cpp
mapnode_contentfeatures.cpp
luaentity_common.cpp
m_wanted_frametime = 1.0 / wanted_fps;
}
-void Camera::wield(const InventoryItem* item)
+void Camera::wield(const InventoryItem* item, ITextureSource *tsrc)
{
if (item != NULL)
{
// If that failed, make an extruded sprite.
if (!isCube)
{
- m_wieldnode->setSprite(item->getImageRaw());
+ m_wieldnode->setSprite(item->getImageRaw(tsrc));
m_wieldnode->setScale(v3f(40));
}
class LocalPlayer;
class MapDrawControl;
class ExtrudedSpriteSceneNode;
+class ITextureSource;
/*
Client camera class, manages the player and camera scene nodes, the viewing distance
void updateSettings();
// Replace the wielded item mesh
- void wield(const InventoryItem* item);
+ void wield(const InventoryItem* item, ITextureSource *tsrc);
// Start digging animation
// Pass 0 for left click, 1 for right click
ScopeProfiler sp(g_profiler, "Client: Mesh making");
scene::SMesh *mesh_new = NULL;
- mesh_new = makeMapBlockMesh(q->data);
+ mesh_new = makeMapBlockMesh(q->data, m_tsrc);
MeshUpdateResult r;
r.p = q->p;
IrrlichtDevice *device,
const char *playername,
std::string password,
- MapDrawControl &control):
- m_mesh_update_thread(),
+ MapDrawControl &control,
+ ITextureSource *tsrc,
+ IToolDefManager *toolmgr):
+ m_tsrc(tsrc),
+ m_toolmgr(toolmgr),
+ m_mesh_update_thread(tsrc),
m_env(
- new ClientMap(this, control,
+ new ClientMap(this, this, control,
device->getSceneManager()->getRootSceneNode(),
device->getSceneManager(), 666),
- device->getSceneManager()
+ device->getSceneManager(),
+ tsrc, this
),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_device(device),
Update an existing block
*/
//infostream<<"Updating"<<std::endl;
- block->deSerialize(istr, ser_version);
+ block->deSerialize(istr, ser_version, this);
}
else
{
*/
//infostream<<"Creating new"<<std::endl;
block = new MapBlock(&m_env.getMap(), p);
- block->deSerialize(istr, ser_version);
+ block->deSerialize(istr, ser_version, this);
sector->insertBlock(block);
//DEBUG
//t4.stop();
//TimeTaker t1("inventory.deSerialize()", m_device);
- player->inventory.deSerialize(is);
+ player->inventory.deSerialize(is, this);
//t1.stop();
m_inventory_updated = true;
<< peer_id << std::endl;
} else {
std::istringstream iss(itemstring);
- delete inv->changeItem(0, InventoryItem::deSerialize(iss));
+ delete inv->changeItem(0,
+ InventoryItem::deSerialize(iss, this));
infostream<<"Client: player item for peer " << peer_id << ": ";
player->getWieldItem()->serialize(infostream);
infostream<<std::endl;
i = affected_blocks.getIterator();
i.atEnd() == false; i++)
{
- i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio());
+ i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio(), m_tsrc);
}
}
i = affected_blocks.getIterator();
i.atEnd() == false; i++)
{
- i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio());
+ i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio(), m_tsrc);
}
}
#include <ostream>
#include "clientobject.h"
#include "utility.h" // For IntervalLimiter
+#include "gamedef.h"
struct MeshMakeData;
{
public:
- MeshUpdateThread()
+ MeshUpdateThread(ITextureSource *tsrc):
+ m_tsrc(tsrc)
{
}
MeshUpdateQueue m_queue_in;
MutexedQueue<MeshUpdateResult> m_queue_out;
+
+ ITextureSource *m_tsrc;
};
enum ClientEventType
};
};
-class Client : public con::PeerHandler, public InventoryManager
+class Client : public con::PeerHandler, public InventoryManager, public IGameDef
{
public:
/*
IrrlichtDevice *device,
const char *playername,
std::string password,
- MapDrawControl &control
- );
+ MapDrawControl &control,
+ ITextureSource *tsrc,
+ IToolDefManager *toolmgr
+ );
~Client();
/*
float getRTT(void);
+ // IGameDef interface
+ // Under envlock
+ virtual IToolDefManager* getToolDefManager()
+ { return m_toolmgr; }
+ virtual INodeDefManager* getNodeDefManager()
+ { assert(0); return NULL; } // TODO
+
private:
// Virtual methods from con::PeerHandler
float m_ignore_damage_timer; // Used after server moves player
IntervalLimiter m_map_timer_and_unload_interval;
+ ITextureSource *m_tsrc;
+ IToolDefManager *m_toolmgr;
MeshUpdateThread m_mesh_update_thread;
-
ClientEnvironment m_env;
-
con::Connection m_con;
-
IrrlichtDevice *m_device;
-
// Server serialization version
u8 m_server_ser_ver;
-
// This is behind m_env_mutex.
bool m_inventory_updated;
-
core::map<v3s16, bool> m_active_blocks;
-
PacketCounter m_packetcounter;
-
// Received from the server. 0-23999
u32 m_time_of_day;
-
// 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT
//s32 m_daynight_i;
//u32 m_daynight_ratio;
-
Queue<std::wstring> m_chat_queue;
-
// The seed returned by the server in TOCLIENT_INIT is stored here
u64 m_map_seed;
-
std::string m_password;
bool m_access_denied;
std::wstring m_access_denied_reason;
-
InventoryContext m_inventory_context;
-
Queue<ClientEvent> m_client_event_queue;
-
friend class FarMesh;
};
ClientActiveObject
*/
-ClientActiveObject::ClientActiveObject(u16 id):
- ActiveObject(id)
+ClientActiveObject::ClientActiveObject(u16 id, IGameDef *gamedef):
+ ActiveObject(id),
+ m_gamedef(gamedef)
{
}
removeFromScene();
}
-ClientActiveObject* ClientActiveObject::create(u8 type)
+ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef)
{
// Find factory function
core::map<u16, Factory>::Node *n;
}
Factory f = n->getValue();
- ClientActiveObject *object = (*f)();
+ ClientActiveObject *object = (*f)(gamedef);
return object;
}
*/
class ClientEnvironment;
+class ITextureSource;
+class IGameDef;
class ClientActiveObject : public ActiveObject
{
public:
- ClientActiveObject(u16 id);
+ ClientActiveObject(u16 id, IGameDef *gamedef);
virtual ~ClientActiveObject();
- virtual void addToScene(scene::ISceneManager *smgr){}
+ virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc){}
virtual void removeFromScene(){}
// 0 <= light_at_pos <= LIGHT_SUN
virtual void updateLight(u8 light_at_pos){}
virtual void initialize(const std::string &data){}
// Create a certain type of ClientActiveObject
- static ClientActiveObject* create(u8 type);
+ static ClientActiveObject* create(u8 type, IGameDef *gamedef);
// If returns true, punch will not be sent to the server
virtual bool directReportPunch(const std::string &toolname, v3f dir)
protected:
// Used for creating objects based on type
- typedef ClientActiveObject* (*Factory)();
+ typedef ClientActiveObject* (*Factory)(IGameDef *gamedef);
static void registerType(u16 type, Factory f);
+ IGameDef *m_gamedef;
private:
// Used for creating objects based on type
static core::map<u16, Factory> m_types;
*/
// Prototype
-TestCAO proto_TestCAO;
+TestCAO proto_TestCAO(NULL);
-TestCAO::TestCAO():
- ClientActiveObject(0),
+TestCAO::TestCAO(IGameDef *gamedef):
+ ClientActiveObject(0, gamedef),
m_node(NULL),
m_position(v3f(0,10*BS,0))
{
{
}
-ClientActiveObject* TestCAO::create()
+ClientActiveObject* TestCAO::create(IGameDef *gamedef)
{
- return new TestCAO();
+ return new TestCAO(gamedef);
}
-void TestCAO::addToScene(scene::ISceneManager *smgr)
+void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{
if(m_node != NULL)
return;
#include "inventory.h"
// Prototype
-ItemCAO proto_ItemCAO;
+ItemCAO proto_ItemCAO(NULL);
-ItemCAO::ItemCAO():
- ClientActiveObject(0),
+ItemCAO::ItemCAO(IGameDef *gamedef):
+ ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.),
m_node(NULL),
m_position(v3f(0,10*BS,0))
{
}
-ClientActiveObject* ItemCAO::create()
+ClientActiveObject* ItemCAO::create(IGameDef *gamedef)
{
- return new ItemCAO();
+ return new ItemCAO(gamedef);
}
-void ItemCAO::addToScene(scene::ISceneManager *smgr)
+void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{
if(m_node != NULL)
return;
video::ITexture *texture = NULL;
try{
InventoryItem *item = NULL;
- item = InventoryItem::deSerialize(is);
+ item = InventoryItem::deSerialize(is, m_gamedef);
infostream<<__FUNCTION_NAME<<": m_inventorystring=\""
<<m_inventorystring<<"\" -> item="<<item
<<std::endl;
if(item)
{
- texture = item->getImage();
+ texture = item->getImage(tsrc);
delete item;
}
}
#include "inventory.h"
// Prototype
-RatCAO proto_RatCAO;
+RatCAO proto_RatCAO(NULL);
-RatCAO::RatCAO():
- ClientActiveObject(0),
+RatCAO::RatCAO(IGameDef *gamedef):
+ ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS/2.,BS/3.),
m_node(NULL),
m_position(v3f(0,10*BS,0)),
{
}
-ClientActiveObject* RatCAO::create()
+ClientActiveObject* RatCAO::create(IGameDef *gamedef)
{
- return new RatCAO();
+ return new RatCAO(gamedef);
}
-void RatCAO::addToScene(scene::ISceneManager *smgr)
+void RatCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{
if(m_node != NULL)
return;
#include "inventory.h"
// Prototype
-Oerkki1CAO proto_Oerkki1CAO;
+Oerkki1CAO proto_Oerkki1CAO(NULL);
-Oerkki1CAO::Oerkki1CAO():
- ClientActiveObject(0),
+Oerkki1CAO::Oerkki1CAO(IGameDef *gamedef):
+ ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2.,BS/3.),
m_node(NULL),
m_position(v3f(0,10*BS,0)),
{
}
-ClientActiveObject* Oerkki1CAO::create()
+ClientActiveObject* Oerkki1CAO::create(IGameDef *gamedef)
{
- return new Oerkki1CAO();
+ return new Oerkki1CAO(gamedef);
}
-void Oerkki1CAO::addToScene(scene::ISceneManager *smgr)
+void Oerkki1CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{
if(m_node != NULL)
return;
*/
// Prototype
-FireflyCAO proto_FireflyCAO;
+FireflyCAO proto_FireflyCAO(NULL);
-FireflyCAO::FireflyCAO():
- ClientActiveObject(0),
+FireflyCAO::FireflyCAO(IGameDef *gamedef):
+ ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS/2.,BS/3.),
m_node(NULL),
m_position(v3f(0,10*BS,0)),
{
}
-ClientActiveObject* FireflyCAO::create()
+ClientActiveObject* FireflyCAO::create(IGameDef *gamedef)
{
- return new FireflyCAO();
+ return new FireflyCAO(gamedef);
}
-void FireflyCAO::addToScene(scene::ISceneManager *smgr)
+void FireflyCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{
if(m_node != NULL)
return;
*/
// Prototype
-MobV2CAO proto_MobV2CAO;
+MobV2CAO proto_MobV2CAO(NULL);
-MobV2CAO::MobV2CAO():
- ClientActiveObject(0),
+MobV2CAO::MobV2CAO(IGameDef *gamedef):
+ ClientActiveObject(0, gamedef),
m_selection_box(-0.4*BS,-0.4*BS,-0.4*BS, 0.4*BS,0.8*BS,0.4*BS),
m_node(NULL),
m_position(v3f(0,10*BS,0)),
delete m_properties;
}
-ClientActiveObject* MobV2CAO::create()
+ClientActiveObject* MobV2CAO::create(IGameDef *gamedef)
{
- return new MobV2CAO();
+ return new MobV2CAO(gamedef);
}
-void MobV2CAO::addToScene(scene::ISceneManager *smgr)
+void MobV2CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{
if(m_node != NULL)
return;
scene::MyBillboardSceneNode *bill = new scene::MyBillboardSceneNode(
smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1));
- bill->setMaterialTexture(0, g_texturesource->getTextureRaw(texture_string));
+ bill->setMaterialTexture(0, tsrc->getTextureRaw(texture_string));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
#include "luaentity_common.h"
// Prototype
-LuaEntityCAO proto_LuaEntityCAO;
+LuaEntityCAO proto_LuaEntityCAO(NULL);
-LuaEntityCAO::LuaEntityCAO():
- ClientActiveObject(0),
+LuaEntityCAO::LuaEntityCAO(IGameDef *gamedef):
+ ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.),
m_meshnode(NULL),
m_spritenode(NULL),
delete m_prop;
}
-ClientActiveObject* LuaEntityCAO::create()
+ClientActiveObject* LuaEntityCAO::create(IGameDef *gamedef)
{
- return new LuaEntityCAO();
+ return new LuaEntityCAO(gamedef);
}
-void LuaEntityCAO::addToScene(scene::ISceneManager *smgr)
+void LuaEntityCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{
if(m_meshnode != NULL || m_spritenode != NULL)
return;
if(m_prop->textures.size() >= 1)
texturestring = m_prop->textures[0];
m_spritenode->setMaterialTexture(0,
- g_texturesource->getTextureRaw(texturestring));
+ tsrc->getTextureRaw(texturestring));
m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false);
m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
std::string texturestring = "unknown_block.png";
if(m_prop->textures.size() > i)
texturestring = m_prop->textures[i];
- AtlasPointer ap = g_texturesource->getTexture(texturestring);
+ AtlasPointer ap = tsrc->getTexture(texturestring);
// Get the tile texture and atlas transformation
video::ITexture* atlas = ap.atlas;
class TestCAO : public ClientActiveObject
{
public:
- TestCAO();
+ TestCAO(IGameDef *gamedef);
virtual ~TestCAO();
u8 getType() const
return ACTIVEOBJECT_TYPE_TEST;
}
- static ClientActiveObject* create();
+ static ClientActiveObject* create(IGameDef *gamedef);
- void addToScene(scene::ISceneManager *smgr);
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene();
void updateLight(u8 light_at_pos);
v3s16 getLightPosition();
class ItemCAO : public ClientActiveObject
{
public:
- ItemCAO();
+ ItemCAO(IGameDef *gamedef);
virtual ~ItemCAO();
u8 getType() const
return ACTIVEOBJECT_TYPE_ITEM;
}
- static ClientActiveObject* create();
+ static ClientActiveObject* create(IGameDef *gamedef);
- void addToScene(scene::ISceneManager *smgr);
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene();
void updateLight(u8 light_at_pos);
v3s16 getLightPosition();
class RatCAO : public ClientActiveObject
{
public:
- RatCAO();
+ RatCAO(IGameDef *gamedef);
virtual ~RatCAO();
u8 getType() const
return ACTIVEOBJECT_TYPE_RAT;
}
- static ClientActiveObject* create();
+ static ClientActiveObject* create(IGameDef *gamedef);
- void addToScene(scene::ISceneManager *smgr);
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene();
void updateLight(u8 light_at_pos);
v3s16 getLightPosition();
class Oerkki1CAO : public ClientActiveObject
{
public:
- Oerkki1CAO();
+ Oerkki1CAO(IGameDef *gamedef);
virtual ~Oerkki1CAO();
u8 getType() const
return ACTIVEOBJECT_TYPE_OERKKI1;
}
- static ClientActiveObject* create();
+ static ClientActiveObject* create(IGameDef *gamedef);
- void addToScene(scene::ISceneManager *smgr);
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene();
void updateLight(u8 light_at_pos);
v3s16 getLightPosition();
class FireflyCAO : public ClientActiveObject
{
public:
- FireflyCAO();
+ FireflyCAO(IGameDef *gamedef);
virtual ~FireflyCAO();
u8 getType() const
return ACTIVEOBJECT_TYPE_FIREFLY;
}
- static ClientActiveObject* create();
+ static ClientActiveObject* create(IGameDef *gamedef);
- void addToScene(scene::ISceneManager *smgr);
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene();
void updateLight(u8 light_at_pos);
v3s16 getLightPosition();
class MobV2CAO : public ClientActiveObject
{
public:
- MobV2CAO();
+ MobV2CAO(IGameDef *gamedef);
virtual ~MobV2CAO();
u8 getType() const
return ACTIVEOBJECT_TYPE_MOBV2;
}
- static ClientActiveObject* create();
+ static ClientActiveObject* create(IGameDef *gamedef);
- void addToScene(scene::ISceneManager *smgr);
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene();
void updateLight(u8 light_at_pos);
v3s16 getLightPosition();
class LuaEntityCAO : public ClientActiveObject
{
public:
- LuaEntityCAO();
+ LuaEntityCAO(IGameDef *gamedef);
virtual ~LuaEntityCAO();
u8 getType() const
return ACTIVEOBJECT_TYPE_LUAENTITY;
}
- static ClientActiveObject* create();
+ static ClientActiveObject* create(IGameDef *gamedef);
- void addToScene(scene::ISceneManager *smgr);
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene();
void updateLight(u8 light_at_pos);
v3s16 getLightPosition();
items: actually *items[9]
return value: allocates a new item, or returns NULL.
*/
-InventoryItem *craft_get_result(InventoryItem **items)
+InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef)
{
// Wood
{
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_WOOD, 4);
+ return new MaterialItem(gamedef, CONTENT_WOOD, 4);
}
}
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs))
{
- return new CraftItem("Stick", 4);
+ return new CraftItem(gamedef, "Stick", 4);
}
}
specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_FENCE, 2);
+ return new MaterialItem(gamedef, CONTENT_FENCE, 2);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- //return new MapBlockObjectItem("Sign");
- return new MaterialItem(CONTENT_SIGN_WALL, 1);
+ //return new MapBlockObjectItem(gamedef, "Sign");
+ return new MaterialItem(gamedef, CONTENT_SIGN_WALL, 1);
}
}
specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_TORCH, 4);
+ return new MaterialItem(gamedef, CONTENT_TORCH, 4);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("WPick", 0);
+ return new ToolItem(gamedef, "WPick", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("STPick", 0);
+ return new ToolItem(gamedef, "STPick", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("SteelPick", 0);
+ return new ToolItem(gamedef, "SteelPick", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("MesePick", 0);
+ return new ToolItem(gamedef, "MesePick", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("WShovel", 0);
+ return new ToolItem(gamedef, "WShovel", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("STShovel", 0);
+ return new ToolItem(gamedef, "STShovel", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("SteelShovel", 0);
+ return new ToolItem(gamedef, "SteelShovel", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("WAxe", 0);
+ return new ToolItem(gamedef, "WAxe", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("STAxe", 0);
+ return new ToolItem(gamedef, "STAxe", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("SteelAxe", 0);
+ return new ToolItem(gamedef, "SteelAxe", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("WSword", 0);
+ return new ToolItem(gamedef, "WSword", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("STSword", 0);
+ return new ToolItem(gamedef, "STSword", 0);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("SteelSword", 0);
+ return new ToolItem(gamedef, "SteelSword", 0);
}
}
specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_RAIL, 15);
+ return new MaterialItem(gamedef, CONTENT_RAIL, 15);
}
}
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_CHEST, 1);
+ return new MaterialItem(gamedef, CONTENT_CHEST, 1);
}
}
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_LOCKABLE_CHEST, 1);
+ return new MaterialItem(gamedef, CONTENT_LOCKABLE_CHEST, 1);
}
}
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_FURNACE, 1);
+ return new MaterialItem(gamedef, CONTENT_FURNACE, 1);
}
}
specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_STEEL, 1);
+ return new MaterialItem(gamedef, CONTENT_STEEL, 1);
}
}
specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_SANDSTONE, 1);
+ return new MaterialItem(gamedef, CONTENT_SANDSTONE, 1);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_CLAY, 1);
+ return new MaterialItem(gamedef, CONTENT_CLAY, 1);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "clay_brick");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_BRICK, 1);
+ return new MaterialItem(gamedef, CONTENT_BRICK, 1);
}
}
specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
if(checkItemCombination(items, specs))
{
- return new CraftItem("paper", 1);
+ return new CraftItem(gamedef, "paper", 1);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "paper");
if(checkItemCombination(items, specs))
{
- return new CraftItem("book", 1);
+ return new CraftItem(gamedef, "book", 1);
}
}
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_BOOKSHELF, 1);
+ return new MaterialItem(gamedef, CONTENT_BOOKSHELF, 1);
}
}
specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_LADDER, 1);
+ return new MaterialItem(gamedef, CONTENT_LADDER, 1);
}
}
specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot");
if(checkItemCombination(items, specs))
{
- return new CraftItem("apple_iron", 1);
+ return new CraftItem(gamedef, "apple_iron", 1);
}
}
return NULL;
}
-void craft_set_creative_inventory(Player *player)
+void craft_set_creative_inventory(Player *player, IGameDef *gamedef)
{
player->resetInventory();
// Give some good tools
{
- InventoryItem *item = new ToolItem("MesePick", 0);
+ InventoryItem *item = new ToolItem(gamedef, "MesePick", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new ToolItem("SteelPick", 0);
+ InventoryItem *item = new ToolItem(gamedef, "SteelPick", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new ToolItem("SteelAxe", 0);
+ InventoryItem *item = new ToolItem(gamedef, "SteelAxe", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new ToolItem("SteelShovel", 0);
+ InventoryItem *item = new ToolItem(gamedef, "SteelShovel", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
if(*mip == CONTENT_IGNORE)
break;
- InventoryItem *item = new MaterialItem(*mip, 1);
+ InventoryItem *item = new MaterialItem(gamedef, *mip, 1);
player->inventory.addItem("main", item);
mip++;
assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
// add torch first
- InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1);
+ InventoryItem *item = new MaterialItem(gamedef, CONTENT_TORCH, 1);
player->inventory.addItem("main", item);
// Then others
|| i == CONTENT_COALSTONE)
continue;
- InventoryItem *item = new MaterialItem(i, 1);
+ InventoryItem *item = new MaterialItem(gamedef, i, 1);
player->inventory.addItem("main", item);
}
#endif
/*// Sign
{
- InventoryItem *item = new MapBlockObjectItem("Sign Example text");
+ InventoryItem *item = new MapBlockObjectItem(gamedef, "Sign Example text");
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}*/
}
-void craft_give_initial_stuff(Player *player)
+void craft_give_initial_stuff(Player *player, IGameDef *gamedef)
{
{
- InventoryItem *item = new ToolItem("SteelPick", 0);
+ InventoryItem *item = new ToolItem(gamedef, "SteelPick", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new MaterialItem(CONTENT_TORCH, 99);
+ InventoryItem *item = new MaterialItem(gamedef, CONTENT_TORCH, 99);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new ToolItem("SteelAxe", 0);
+ InventoryItem *item = new ToolItem(gamedef, "SteelAxe", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new ToolItem("SteelShovel", 0);
+ InventoryItem *item = new ToolItem(gamedef, "SteelShovel", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new MaterialItem(CONTENT_COBBLE, 99);
+ InventoryItem *item = new MaterialItem(gamedef, CONTENT_COBBLE, 99);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
/*{
- InventoryItem *item = new MaterialItem(CONTENT_MESE, 6);
+ InventoryItem *item = new MaterialItem(gamedef, CONTENT_MESE, 6);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6);
+ InventoryItem *item = new MaterialItem(gamedef, CONTENT_COALSTONE, 6);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6);
+ InventoryItem *item = new MaterialItem(gamedef, CONTENT_WOOD, 6);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new CraftItem("Stick", 4);
+ InventoryItem *item = new CraftItem(gamedef, "Stick", 4);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new ToolItem("WPick", 32000);
+ InventoryItem *item = new ToolItem(gamedef, "WPick", 32000);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
- InventoryItem *item = new ToolItem("STPick", 32000);
+ InventoryItem *item = new ToolItem(gamedef, "STPick", 32000);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}*/
/*// and some signs
for(u16 i=0; i<4; i++)
{
- InventoryItem *item = new MapBlockObjectItem("Sign Example text");
+ InventoryItem *item = new MapBlockObjectItem(gamedef, "Sign Example text");
bool r = player->inventory.addItem("main", item);
assert(r == true);
}*/
/*// Give some other stuff
{
- InventoryItem *item = new MaterialItem(CONTENT_TREE, 999);
+ InventoryItem *item = new MaterialItem(gamedef, CONTENT_TREE, 999);
bool r = player->inventory.addItem("main", item);
assert(r == true);
}*/
class InventoryItem;
class Player;
+class IGameDef;
/*
items: actually *items[9]
return value: allocates a new item, or returns NULL.
*/
-InventoryItem *craft_get_result(InventoryItem **items);
+InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef);
-void craft_set_creative_inventory(Player *player);
+void craft_set_creative_inventory(Player *player, IGameDef *gamedef);
// Called when give_initial_stuff setting is used
-void craft_give_initial_stuff(Player *player);
+void craft_give_initial_stuff(Player *player, IGameDef *gamedef);
#endif
//#include "serverobject.h"
#include "content_sao.h"
-bool item_material_is_cookable(content_t content)
+bool item_material_is_cookable(content_t content, IGameDef *gamedef)
{
if(content == CONTENT_TREE)
return true;
return false;
}
-InventoryItem* item_material_create_cook_result(content_t content)
+InventoryItem* item_material_create_cook_result(content_t content,
+ IGameDef *gamedef)
{
if(content == CONTENT_TREE)
- return new CraftItem("lump_of_coal", 1);
+ return new CraftItem(gamedef, "lump_of_coal", 1);
else if(content == CONTENT_COBBLE)
- return new MaterialItem(CONTENT_STONE, 1);
+ return new MaterialItem(gamedef, CONTENT_STONE, 1);
else if(content == CONTENT_SAND)
- return new MaterialItem(CONTENT_GLASS, 1);
+ return new MaterialItem(gamedef, CONTENT_GLASS, 1);
return NULL;
}
-std::string item_craft_get_image_name(const std::string &subname)
+std::string item_craft_get_image_name(const std::string &subname,
+ IGameDef *gamedef)
{
if(subname == "Stick")
return "stick.png";
return NULL;
}
-s16 item_craft_get_drop_count(const std::string &subname)
+s16 item_craft_get_drop_count(const std::string &subname, IGameDef *gamedef)
{
if(subname == "rat" || subname == "firefly" || subname == "testobject1")
return 1;
return -1;
}
-bool item_craft_is_cookable(const std::string &subname)
+bool item_craft_is_cookable(const std::string &subname, IGameDef *gamedef)
{
if(subname == "lump_of_iron" || subname == "lump_of_clay" || subname == "rat" || subname == "cooked_rat")
return true;
return false;
}
-InventoryItem* item_craft_create_cook_result(const std::string &subname)
+InventoryItem* item_craft_create_cook_result(const std::string &subname,
+ IGameDef *gamedef)
{
if(subname == "lump_of_iron")
- return new CraftItem("steel_ingot", 1);
+ return new CraftItem(gamedef, "steel_ingot", 1);
else if(subname == "lump_of_clay")
- return new CraftItem("clay_brick", 1);
+ return new CraftItem(gamedef, "clay_brick", 1);
else if(subname == "rat")
- return new CraftItem("cooked_rat", 1);
+ return new CraftItem(gamedef, "cooked_rat", 1);
else if(subname == "cooked_rat")
- return new CraftItem("scorched_stuff", 1);
+ return new CraftItem(gamedef, "scorched_stuff", 1);
return NULL;
}
-bool item_craft_is_eatable(const std::string &subname)
+bool item_craft_is_eatable(const std::string &subname, IGameDef *gamedef)
{
if(subname == "cooked_rat")
return true;
return false;
}
-s16 item_craft_eat_hp_change(const std::string &subname)
+s16 item_craft_eat_hp_change(const std::string &subname, IGameDef *gamedef)
{
if(subname == "cooked_rat")
return 6; // 3 hearts
class InventoryItem;
class ServerActiveObject;
class ServerEnvironment;
+class IGameDef;
-bool item_material_is_cookable(content_t content);
-InventoryItem* item_material_create_cook_result(content_t content);
+bool item_material_is_cookable(content_t content, IGameDef *gamedef);
+InventoryItem* item_material_create_cook_result(content_t content,
+ IGameDef *gamedef);
-std::string item_craft_get_image_name(const std::string &subname);
+std::string item_craft_get_image_name(const std::string &subname,
+ IGameDef *gamedef);
ServerActiveObject* item_craft_create_object(const std::string &subname,
ServerEnvironment *env, v3f pos);
-s16 item_craft_get_drop_count(const std::string &subname);
-bool item_craft_is_cookable(const std::string &subname);
-InventoryItem* item_craft_create_cook_result(const std::string &subname);
-bool item_craft_is_eatable(const std::string &subname);
-s16 item_craft_eat_hp_change(const std::string &subname);
+s16 item_craft_get_drop_count(const std::string &subname,
+ IGameDef *gamedef);
+bool item_craft_is_cookable(const std::string &subname,
+ IGameDef *gamedef);
+InventoryItem* item_craft_create_cook_result(const std::string &subname,
+ IGameDef *gamedef);
+bool item_craft_is_eatable(const std::string &subname,
+ IGameDef *gamedef);
+s16 item_craft_eat_hp_change(const std::string &subname,
+ IGameDef *gamedef);
#endif
#include "content_mapblock.h"
#include "content_mapnode.h"
-#include "main.h" // For g_settings and g_texturesource
+#include "main.h" // For g_settings
#include "mineral.h"
#include "mapblock_mesh.h" // For MapBlock_LightColor()
#include "settings.h"
#ifndef SERVER
void mapblock_mesh_generate_special(MeshMakeData *data,
- MeshCollector &collector)
+ MeshCollector &collector, ITextureSource *tsrc)
{
// 0ms
//TimeTaker timer("mapblock_mesh_generate_special()");
material_leaves1.setFlag(video::EMF_BILINEAR_FILTER, false);
material_leaves1.setFlag(video::EMF_FOG_ENABLE, true);
material_leaves1.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
- AtlasPointer pa_leaves1 = g_texturesource->getTexture(
- g_texturesource->getTextureId("leaves.png"));
+ AtlasPointer pa_leaves1 = tsrc->getTexture(
+ tsrc->getTextureId("leaves.png"));
material_leaves1.setTexture(0, pa_leaves1.atlas);
// Glass material
material_glass.setFlag(video::EMF_BILINEAR_FILTER, false);
material_glass.setFlag(video::EMF_FOG_ENABLE, true);
material_glass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
- AtlasPointer pa_glass = g_texturesource->getTexture(
- g_texturesource->getTextureId("glass.png"));
+ AtlasPointer pa_glass = tsrc->getTexture(
+ tsrc->getTextureId("glass.png"));
material_glass.setTexture(0, pa_glass.atlas);
// Wood material
material_wood.setFlag(video::EMF_BILINEAR_FILTER, false);
material_wood.setFlag(video::EMF_FOG_ENABLE, true);
material_wood.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
- AtlasPointer pa_wood = g_texturesource->getTexture(
- g_texturesource->getTextureId("wood.png"));
+ AtlasPointer pa_wood = tsrc->getTexture(
+ tsrc->getTextureId("wood.png"));
material_wood.setTexture(0, pa_wood.atlas);
// General ground material for special output
material_papyrus.setFlag(video::EMF_BILINEAR_FILTER, false);
material_papyrus.setFlag(video::EMF_FOG_ENABLE, true);
material_papyrus.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
- AtlasPointer pa_papyrus = g_texturesource->getTexture(
- g_texturesource->getTextureId("papyrus.png"));
+ AtlasPointer pa_papyrus = tsrc->getTexture(
+ tsrc->getTextureId("papyrus.png"));
material_papyrus.setTexture(0, pa_papyrus.atlas);
// Apple material
material_apple.setFlag(video::EMF_BILINEAR_FILTER, false);
material_apple.setFlag(video::EMF_FOG_ENABLE, true);
material_apple.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
- AtlasPointer pa_apple = g_texturesource->getTexture(
- g_texturesource->getTextureId("apple.png"));
+ AtlasPointer pa_apple = tsrc->getTexture(
+ tsrc->getTextureId("apple.png"));
material_apple.setTexture(0, pa_apple.atlas);
material_sapling.setFlag(video::EMF_BILINEAR_FILTER, false);
material_sapling.setFlag(video::EMF_FOG_ENABLE, true);
material_sapling.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
- AtlasPointer pa_sapling = g_texturesource->getTexture(
- g_texturesource->getTextureId("sapling.png"));
+ AtlasPointer pa_sapling = tsrc->getTexture(
+ tsrc->getTextureId("sapling.png"));
material_sapling.setTexture(0, pa_sapling.atlas);
material_junglegrass.setFlag(video::EMF_BILINEAR_FILTER, false);
material_junglegrass.setFlag(video::EMF_FOG_ENABLE, true);
material_junglegrass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
- AtlasPointer pa_junglegrass = g_texturesource->getTexture(
- g_texturesource->getTextureId("junglegrass.png"));
+ AtlasPointer pa_junglegrass = tsrc->getTexture(
+ tsrc->getTextureId("junglegrass.png"));
material_junglegrass.setTexture(0, pa_junglegrass.atlas);
for(s16 z=0; z<MAP_BLOCKSIZE; z++)
texturename = "torch.png";
}
- AtlasPointer ap = g_texturesource->getTexture(texturename);
+ AtlasPointer ap = tsrc->getTexture(texturename);
// Set material
video::SMaterial material;
*/
else if(n.getContent() == CONTENT_SIGN_WALL)
{
- AtlasPointer ap = g_texturesource->getTexture("sign_wall.png");
+ AtlasPointer ap = tsrc->getTexture("sign_wall.png");
// Set material
video::SMaterial material;
video::SColor c = MapBlock_LightColor(255, l);
// Get the right texture
- TileSpec ts = n.getTile(dir);
+ TileSpec ts = n.getTile(dir, tsrc);
AtlasPointer ap = ts.texture;
material_general.setTexture(0, ap.atlas);
else if(adjacencies == 4)
texturename = "rail_crossing.png";
- AtlasPointer ap = g_texturesource->getTexture(texturename);
+ AtlasPointer ap = tsrc->getTexture(texturename);
video::SMaterial material_rail;
material_rail.setFlag(video::EMF_LIGHTING, false);
collector.append(material_rail, vertices, 4, indices, 6);
}
else if (n.getContent() == CONTENT_LADDER) {
- AtlasPointer ap = g_texturesource->getTexture("ladder.png");
+ AtlasPointer ap = tsrc->getTexture("ladder.png");
// Set material
video::SMaterial material_ladder;
#ifndef SERVER
#include "mapblock_mesh.h"
#include "utility.h"
+class ITextureSource;
void mapblock_mesh_generate_special(MeshMakeData *data,
- MeshCollector &collector);
+ MeshCollector &collector, ITextureSource *tsrc);
#endif
#endif
}
// See header for description
-void content_mapnode_init()
+void content_mapnode_init(ITextureSource *tsrc)
{
- if(g_texturesource == NULL)
+ if(tsrc == NULL)
dstream<<"INFO: Initial run of content_mapnode_init with "
- "g_texturesource=NULL. If this segfaults, "
+ "tsrc=NULL. If this segfaults, "
"there is a bug with something not checking for "
"the NULL value."<<std::endl;
else
dstream<<"INFO: Full run of content_mapnode_init with "
- "g_texturesource!=NULL"<<std::endl;
+ "tsrc!=NULL"<<std::endl;
// Read some settings
bool new_style_water = g_settings->getBool("new_style_water");
i = CONTENT_STONE;
f = &content_features(i);
- f->setAllTextures("stone.png");
- f->setInventoryTextureCube("stone.png", "stone.png", "stone.png");
+ f->setAllTextures(tsrc, "stone.png");
+ f->setInventoryTextureCube("stone.png", "stone.png", "stone.png", tsrc);
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->often_contains_mineral = true;
i = CONTENT_GRASS;
f = &content_features(i);
- f->setAllTextures("mud.png^grass_side.png");
- f->setTexture(0, "grass.png");
- f->setTexture(1, "mud.png");
+ f->setAllTextures(tsrc, "mud.png^grass_side.png");
+ f->setTexture(tsrc, 0, "grass.png");
+ f->setTexture(tsrc, 1, "mud.png");
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_MUD)+" 1";
i = CONTENT_GRASS_FOOTSTEPS;
f = &content_features(i);
- f->setAllTextures("mud.png^grass_side.png");
- f->setTexture(0, "grass_footsteps.png");
- f->setTexture(1, "mud.png");
+ f->setAllTextures(tsrc, "mud.png^grass_side.png");
+ f->setTexture(tsrc, 0, "grass_footsteps.png");
+ f->setTexture(tsrc, 1, "mud.png");
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_MUD)+" 1";
i = CONTENT_MUD;
f = &content_features(i);
- f->setAllTextures("mud.png");
- f->setInventoryTextureCube("mud.png", "mud.png", "mud.png");
+ f->setAllTextures(tsrc, "mud.png");
+ f->setInventoryTextureCube("mud.png", "mud.png", "mud.png", tsrc);
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_SAND;
f = &content_features(i);
- f->setAllTextures("sand.png");
- f->setInventoryTextureCube("sand.png", "sand.png", "sand.png");
+ f->setAllTextures(tsrc, "sand.png");
+ f->setInventoryTextureCube("sand.png", "sand.png", "sand.png", tsrc);
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_GRAVEL;
f = &content_features(i);
- f->setAllTextures("gravel.png");
- f->setInventoryTextureCube("gravel.png", "gravel.png", "gravel.png");
+ f->setAllTextures(tsrc, "gravel.png");
+ f->setInventoryTextureCube("gravel.png", "gravel.png", "gravel.png", tsrc);
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_SANDSTONE;
f = &content_features(i);
- f->setAllTextures("sandstone.png");
- f->setInventoryTextureCube("sandstone.png", "sandstone.png", "sandstone.png");
+ f->setAllTextures(tsrc, "sandstone.png");
+ f->setInventoryTextureCube("sandstone.png", "sandstone.png", "sandstone.png", tsrc);
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_SAND)+" 1";
i = CONTENT_CLAY;
f = &content_features(i);
- f->setAllTextures("clay.png");
- f->setInventoryTextureCube("clay.png", "clay.png", "clay.png");
+ f->setAllTextures(tsrc, "clay.png");
+ f->setInventoryTextureCube("clay.png", "clay.png", "clay.png", tsrc);
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("CraftItem lump_of_clay 4");
i = CONTENT_BRICK;
f = &content_features(i);
- f->setAllTextures("brick.png");
- f->setInventoryTextureCube("brick.png", "brick.png", "brick.png");
+ f->setAllTextures(tsrc, "brick.png");
+ f->setInventoryTextureCube("brick.png", "brick.png", "brick.png", tsrc);
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("CraftItem clay_brick 4");
i = CONTENT_TREE;
f = &content_features(i);
- f->setAllTextures("tree.png");
- f->setTexture(0, "tree_top.png");
- f->setTexture(1, "tree_top.png");
+ f->setAllTextures(tsrc, "tree.png");
+ f->setTexture(tsrc, 0, "tree_top.png");
+ f->setTexture(tsrc, 1, "tree_top.png");
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_JUNGLETREE;
f = &content_features(i);
- f->setAllTextures("jungletree.png");
- f->setTexture(0, "jungletree_top.png");
- f->setTexture(1, "jungletree_top.png");
+ f->setAllTextures(tsrc, "jungletree.png");
+ f->setTexture(tsrc, 0, "jungletree_top.png");
+ f->setTexture(tsrc, 1, "jungletree_top.png");
f->param_type = CPT_MINERAL;
//f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_JUNGLEGRASS;
f = &content_features(i);
- f->setInventoryTexture("junglegrass.png");
+ f->setInventoryTexture("junglegrass.png", tsrc);
f->used_texturenames["junglegrass.png"] = true;
f->light_propagates = true;
f->param_type = CPT_LIGHT;
{
f->solidness = 0; // drawn separately, makes no faces
f->visual_solidness = 1;
- f->setAllTextures("leaves.png");
- f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
+ f->setAllTextures(tsrc, "leaves.png");
+ f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png", tsrc);
}
else
{
- f->setAllTextures("[noalpha:leaves.png");
+ f->setAllTextures(tsrc, "[noalpha:leaves.png");
}
f->extra_dug_item = std::string("MaterialItem2 ")+itos(CONTENT_SAPLING)+" 1";
f->extra_dug_item_rarity = 20;
i = CONTENT_CACTUS;
f = &content_features(i);
- f->setAllTextures("cactus_side.png");
- f->setTexture(0, "cactus_top.png");
- f->setTexture(1, "cactus_top.png");
- f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png");
+ f->setAllTextures(tsrc, "cactus_side.png");
+ f->setTexture(tsrc, 0, "cactus_top.png");
+ f->setTexture(tsrc, 1, "cactus_top.png");
+ f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png", tsrc);
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_PAPYRUS;
f = &content_features(i);
- f->setInventoryTexture("papyrus.png");
+ f->setInventoryTexture("papyrus.png", tsrc);
f->used_texturenames["papyrus.png"] = true;
f->light_propagates = true;
f->param_type = CPT_LIGHT;
i = CONTENT_BOOKSHELF;
f = &content_features(i);
- f->setAllTextures("bookshelf.png");
- f->setTexture(0, "wood.png");
- f->setTexture(1, "wood.png");
+ f->setAllTextures(tsrc, "bookshelf.png");
+ f->setTexture(tsrc, 0, "wood.png");
+ f->setTexture(tsrc, 1, "wood.png");
// FIXME: setInventoryTextureCube() only cares for the first texture
- f->setInventoryTextureCube("bookshelf.png", "bookshelf.png", "bookshelf.png");
- //f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png");
+ f->setInventoryTextureCube("bookshelf.png", "bookshelf.png", "bookshelf.png", tsrc);
+ //f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png", tsrc);
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
setWoodLikeMaterialProperties(f->material, 0.75);
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->solidness = 0; // drawn separately, makes no faces
f->visual_solidness = 1;
- f->setAllTextures("glass.png");
- f->setInventoryTextureCube("glass.png", "glass.png", "glass.png");
+ f->setAllTextures(tsrc, "glass.png");
+ f->setInventoryTextureCube("glass.png", "glass.png", "glass.png", tsrc);
setGlassLikeMaterialProperties(f->material, 1.0);
i = CONTENT_FENCE;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->solidness = 0; // drawn separately, makes no faces
f->air_equivalent = true; // grass grows underneath
- f->setInventoryTexture("fence.png");
+ f->setInventoryTexture("fence.png", tsrc);
f->used_texturenames["fence.png"] = true;
setWoodLikeMaterialProperties(f->material, 0.75);
i = CONTENT_RAIL;
f = &content_features(i);
- f->setInventoryTexture("rail.png");
+ f->setInventoryTexture("rail.png", tsrc);
f->used_texturenames["rail.png"] = true;
f->light_propagates = true;
f->param_type = CPT_LIGHT;
i = CONTENT_LADDER;
f = &content_features(i);
- f->setInventoryTexture("ladder.png");
+ f->setInventoryTexture("ladder.png", tsrc);
f->used_texturenames["ladder.png"] = true;
f->light_propagates = true;
f->param_type = CPT_LIGHT;
// Deprecated
i = CONTENT_COALSTONE;
f = &content_features(i);
- f->setAllTextures("stone.png^mineral_coal.png");
+ f->setAllTextures(tsrc, "stone.png^mineral_coal.png");
f->is_ground_content = true;
setStoneLikeMaterialProperties(f->material, 1.5);
i = CONTENT_WOOD;
f = &content_features(i);
- f->setAllTextures("wood.png");
- f->setInventoryTextureCube("wood.png", "wood.png", "wood.png");
+ f->setAllTextures(tsrc, "wood.png");
+ f->setInventoryTextureCube("wood.png", "wood.png", "wood.png", tsrc);
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
setWoodLikeMaterialProperties(f->material, 0.75);
i = CONTENT_MESE;
f = &content_features(i);
- f->setAllTextures("mese.png");
- f->setInventoryTextureCube("mese.png", "mese.png", "mese.png");
+ f->setAllTextures(tsrc, "mese.png");
+ f->setInventoryTextureCube("mese.png", "mese.png", "mese.png", tsrc);
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
setStoneLikeMaterialProperties(f->material, 0.5);
i = CONTENT_CLOUD;
f = &content_features(i);
- f->setAllTextures("cloud.png");
- f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png");
+ f->setAllTextures(tsrc, "cloud.png");
+ f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png", tsrc);
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_WATER;
f = &content_features(i);
- f->setInventoryTextureCube("water.png", "water.png", "water.png");
+ f->setInventoryTextureCube("water.png", "water.png", "water.png", tsrc);
f->param_type = CPT_LIGHT;
f->light_propagates = true;
f->solidness = 0; // Drawn separately, makes no faces
if(!opaque_water)
f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200);
- if(f->special_material == NULL && g_texturesource)
+ if(f->special_material == NULL && tsrc)
{
// Flowing water material
f->special_material = new video::SMaterial;
f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
if(!opaque_water)
f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
- AtlasPointer *pa_water1 = new AtlasPointer(g_texturesource->getTexture(
- g_texturesource->getTextureId("water.png")));
+ AtlasPointer *pa_water1 = new AtlasPointer(tsrc->getTexture(
+ tsrc->getTextureId("water.png")));
f->special_material->setTexture(0, pa_water1->atlas);
// Flowing water material, backface culled
i = CONTENT_WATERSOURCE;
f = &content_features(i);
- //f->setInventoryTexture("water.png");
- f->setInventoryTextureCube("water.png", "water.png", "water.png");
+ //f->setInventoryTexture("water.png", tsrc);
+ f->setInventoryTextureCube("water.png", "water.png", "water.png", tsrc);
if(new_style_water)
{
f->solidness = 0; // drawn separately, makes no faces
f->solidness = 1;
#ifndef SERVER
TileSpec t;
- if(g_texturesource)
- t.texture = g_texturesource->getTexture("water.png");
+ if(tsrc)
+ t.texture = tsrc->getTexture("water.png");
if(!opaque_water){
t.alpha = WATER_ALPHA;
if(!opaque_water)
f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200);
- if(f->special_material == NULL && g_texturesource)
+ if(f->special_material == NULL && tsrc)
{
// New-style water source material (mostly unused)
f->special_material = new video::SMaterial;
f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
- AtlasPointer *pa_water1 = new AtlasPointer(g_texturesource->getTexture(
- g_texturesource->getTextureId("water.png")));
+ AtlasPointer *pa_water1 = new AtlasPointer(tsrc->getTexture(
+ tsrc->getTextureId("water.png")));
f->special_material->setTexture(0, pa_water1->atlas);
f->special_atlas = pa_water1;
}
i = CONTENT_LAVA;
f = &content_features(i);
- f->setInventoryTextureCube("lava.png", "lava.png", "lava.png");
+ f->setInventoryTextureCube("lava.png", "lava.png", "lava.png", tsrc);
f->used_texturenames["lava.png"] = true;
f->param_type = CPT_LIGHT;
f->light_propagates = false;
f->damage_per_second = 4*2;
#ifndef SERVER
f->post_effect_color = video::SColor(192, 255, 64, 0);
- if(f->special_material == NULL && g_texturesource)
+ if(f->special_material == NULL && tsrc)
{
// Flowing lava material
f->special_material = new video::SMaterial;
f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer *pa_lava1 = new AtlasPointer(
- g_texturesource->getTexture(
- g_texturesource->getTextureId("lava.png")));
+ tsrc->getTexture(
+ tsrc->getTextureId("lava.png")));
f->special_material->setTexture(0, pa_lava1->atlas);
// Flowing lava material, backface culled
i = CONTENT_LAVASOURCE;
f = &content_features(i);
- f->setInventoryTextureCube("lava.png", "lava.png", "lava.png");
+ f->setInventoryTextureCube("lava.png", "lava.png", "lava.png", tsrc);
f->used_texturenames["ladder.png"] = true;
if(new_style_water)
{
f->solidness = 2;
#ifndef SERVER
TileSpec t;
- if(g_texturesource)
- t.texture = g_texturesource->getTexture("lava.png");
+ if(tsrc)
+ t.texture = tsrc->getTexture("lava.png");
//t.alpha = 255;
//t.material_type = MATERIAL_ALPHA_VERTEX;
f->damage_per_second = 4*2;
#ifndef SERVER
f->post_effect_color = video::SColor(192, 255, 64, 0);
- if(f->special_material == NULL && g_texturesource)
+ if(f->special_material == NULL && tsrc)
{
// New-style lava source material (mostly unused)
f->special_material = new video::SMaterial;
f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer *pa_lava1 = new AtlasPointer(
- g_texturesource->getTexture(
- g_texturesource->getTextureId("lava.png")));
+ tsrc->getTexture(
+ tsrc->getTextureId("lava.png")));
f->special_material->setTexture(0, pa_lava1->atlas);
f->special_atlas = pa_lava1;
i = CONTENT_TORCH;
f = &content_features(i);
- f->setInventoryTexture("torch_on_floor.png");
+ f->setInventoryTexture("torch_on_floor.png", tsrc);
f->used_texturenames["torch_on_floor.png"] = true;
f->used_texturenames["torch_on_ceiling.png"] = true;
f->used_texturenames["torch_on_floor.png"] = true;
i = CONTENT_SIGN_WALL;
f = &content_features(i);
- f->setInventoryTexture("sign_wall.png");
+ f->setInventoryTexture("sign_wall.png", tsrc);
f->used_texturenames["sign_wall.png"] = true;
f->param_type = CPT_LIGHT;
f->light_propagates = true;
f->air_equivalent = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
if(f->initial_metadata == NULL)
- f->initial_metadata = new SignNodeMetadata("Some sign");
+ f->initial_metadata = new SignNodeMetadata(NULL, "Some sign");
setConstantMaterialProperties(f->material, 0.5);
f->selection_box.type = NODEBOX_WALLMOUNTED;
i = CONTENT_CHEST;
f = &content_features(i);
f->param_type = CPT_FACEDIR_SIMPLE;
- f->setAllTextures("chest_side.png");
- f->setTexture(0, "chest_top.png");
- f->setTexture(1, "chest_top.png");
- f->setTexture(5, "chest_front.png"); // Z-
- f->setInventoryTexture("chest_top.png");
- //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
+ f->setAllTextures(tsrc, "chest_side.png");
+ f->setTexture(tsrc, 0, "chest_top.png");
+ f->setTexture(tsrc, 1, "chest_top.png");
+ f->setTexture(tsrc, 5, "chest_front.png"); // Z-
+ f->setInventoryTexture("chest_top.png", tsrc);
+ //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png", tsrc);
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
if(f->initial_metadata == NULL)
- f->initial_metadata = new ChestNodeMetadata();
+ f->initial_metadata = new ChestNodeMetadata(NULL);
setWoodLikeMaterialProperties(f->material, 1.0);
i = CONTENT_LOCKABLE_CHEST;
f = &content_features(i);
f->param_type = CPT_FACEDIR_SIMPLE;
- f->setAllTextures("chest_side.png");
- f->setTexture(0, "chest_top.png");
- f->setTexture(1, "chest_top.png");
- f->setTexture(5, "chest_lock.png"); // Z-
- f->setInventoryTexture("chest_lock.png");
- //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
+ f->setAllTextures(tsrc, "chest_side.png");
+ f->setTexture(tsrc, 0, "chest_top.png");
+ f->setTexture(tsrc, 1, "chest_top.png");
+ f->setTexture(tsrc, 5, "chest_lock.png"); // Z-
+ f->setInventoryTexture("chest_lock.png", tsrc);
+ //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png", tsrc);
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
if(f->initial_metadata == NULL)
- f->initial_metadata = new LockingChestNodeMetadata();
+ f->initial_metadata = new LockingChestNodeMetadata(NULL);
setWoodLikeMaterialProperties(f->material, 1.0);
i = CONTENT_FURNACE;
f = &content_features(i);
f->param_type = CPT_FACEDIR_SIMPLE;
- f->setAllTextures("furnace_side.png");
- f->setTexture(5, "furnace_front.png"); // Z-
- f->setInventoryTexture("furnace_front.png");
+ f->setAllTextures(tsrc, "furnace_side.png");
+ f->setTexture(tsrc, 5, "furnace_front.png"); // Z-
+ f->setInventoryTexture("furnace_front.png", tsrc);
//f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_COBBLE)+" 6";
if(f->initial_metadata == NULL)
- f->initial_metadata = new FurnaceNodeMetadata();
+ f->initial_metadata = new FurnaceNodeMetadata(NULL);
setStoneLikeMaterialProperties(f->material, 3.0);
i = CONTENT_COBBLE;
f = &content_features(i);
- f->setAllTextures("cobble.png");
- f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png");
+ f->setAllTextures(tsrc, "cobble.png");
+ f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png", tsrc);
f->param_type = CPT_NONE;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_MOSSYCOBBLE;
f = &content_features(i);
- f->setAllTextures("mossycobble.png");
- f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png");
+ f->setAllTextures(tsrc, "mossycobble.png");
+ f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png", tsrc);
f->param_type = CPT_NONE;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_STEEL;
f = &content_features(i);
- f->setAllTextures("steel_block.png");
+ f->setAllTextures(tsrc, "steel_block.png");
f->setInventoryTextureCube("steel_block.png", "steel_block.png",
- "steel_block.png");
+ "steel_block.png", tsrc);
f->param_type = CPT_NONE;
f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
i = CONTENT_NC;
f = &content_features(i);
f->param_type = CPT_FACEDIR_SIMPLE;
- f->setAllTextures("nc_side.png");
- f->setTexture(5, "nc_front.png"); // Z-
- f->setTexture(4, "nc_back.png"); // Z+
- f->setInventoryTexture("nc_front.png");
+ f->setAllTextures(tsrc, "nc_side.png");
+ f->setTexture(tsrc, 5, "nc_front.png"); // Z-
+ f->setTexture(tsrc, 4, "nc_back.png"); // Z+
+ f->setInventoryTexture("nc_front.png", tsrc);
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
setStoneLikeMaterialProperties(f->material, 3.0);
i = CONTENT_NC_RB;
f = &content_features(i);
- f->setAllTextures("nc_rb.png");
- f->setInventoryTexture("nc_rb.png");
+ f->setAllTextures(tsrc, "nc_rb.png");
+ f->setInventoryTexture("nc_rb.png", tsrc);
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
setStoneLikeMaterialProperties(f->material, 3.0);
i = CONTENT_SAPLING;
f = &content_features(i);
f->param_type = CPT_LIGHT;
- f->setAllTextures("sapling.png");
- f->setInventoryTexture("sapling.png");
+ f->setAllTextures(tsrc, "sapling.png");
+ f->setInventoryTexture("sapling.png", tsrc);
f->used_texturenames["sapling.png"] = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->light_propagates = true;
i = CONTENT_APPLE;
f = &content_features(i);
- f->setInventoryTexture("apple.png");
+ f->setInventoryTexture("apple.png", tsrc);
f->used_texturenames["apple.png"] = true;
f->param_type = CPT_LIGHT;
f->light_propagates = true;
#define CONTENT_MAPNODE_HEADER
#include "mapnode.h"
+class ITextureSource;
/*
Fills stuff to the global ContentFeatures lookup table.
- This accesses g_texturesource; if it is non-NULL, textures are set
+ This accesses tsrc; if it is non-NULL, textures are set
for the nodes.
- Client first calls this with g_texturesource=NULL to run some
- unit tests and stuff, then it runs this again with g_texturesource
+ Client first calls this with tsrc=NULL to run some
+ unit tests and stuff, then it runs this again with tsrc
defined to get the textures.
- Server only calls this once with g_texturesource=NULL.
+ Server only calls this once with tsrc=NULL.
*/
-void content_mapnode_init();
+void content_mapnode_init(ITextureSource *tsrc);
// Backwards compatibility for non-extended content types in v19
extern content_t trans_table_19[21][2];
*/
// Prototype
-SignNodeMetadata proto_SignNodeMetadata("");
+SignNodeMetadata proto_SignNodeMetadata(NULL, "");
-SignNodeMetadata::SignNodeMetadata(std::string text):
+SignNodeMetadata::SignNodeMetadata(IGameDef *gamedef, std::string text):
+ NodeMetadata(gamedef),
m_text(text)
{
NodeMetadata::registerType(typeId(), create);
{
return CONTENT_SIGN_WALL;
}
-NodeMetadata* SignNodeMetadata::create(std::istream &is)
+NodeMetadata* SignNodeMetadata::create(std::istream &is, IGameDef *gamedef)
{
std::string text = deSerializeString(is);
- return new SignNodeMetadata(text);
+ return new SignNodeMetadata(gamedef, text);
}
-NodeMetadata* SignNodeMetadata::clone()
+NodeMetadata* SignNodeMetadata::clone(IGameDef *gamedef)
{
- return new SignNodeMetadata(m_text);
+ return new SignNodeMetadata(gamedef, m_text);
}
void SignNodeMetadata::serializeBody(std::ostream &os)
{
*/
// Prototype
-ChestNodeMetadata proto_ChestNodeMetadata;
+ChestNodeMetadata proto_ChestNodeMetadata(NULL);
-ChestNodeMetadata::ChestNodeMetadata()
+ChestNodeMetadata::ChestNodeMetadata(IGameDef *gamedef):
+ NodeMetadata(gamedef)
{
NodeMetadata::registerType(typeId(), create);
{
return CONTENT_CHEST;
}
-NodeMetadata* ChestNodeMetadata::create(std::istream &is)
+NodeMetadata* ChestNodeMetadata::create(std::istream &is, IGameDef *gamedef)
{
- ChestNodeMetadata *d = new ChestNodeMetadata();
- d->m_inventory->deSerialize(is);
+ ChestNodeMetadata *d = new ChestNodeMetadata(gamedef);
+ d->m_inventory->deSerialize(is, gamedef);
return d;
}
-NodeMetadata* ChestNodeMetadata::clone()
+NodeMetadata* ChestNodeMetadata::clone(IGameDef *gamedef)
{
- ChestNodeMetadata *d = new ChestNodeMetadata();
+ ChestNodeMetadata *d = new ChestNodeMetadata(gamedef);
*d->m_inventory = *m_inventory;
return d;
}
*/
// Prototype
-LockingChestNodeMetadata proto_LockingChestNodeMetadata;
+LockingChestNodeMetadata proto_LockingChestNodeMetadata(NULL);
-LockingChestNodeMetadata::LockingChestNodeMetadata()
+LockingChestNodeMetadata::LockingChestNodeMetadata(IGameDef *gamedef):
+ NodeMetadata(gamedef)
{
NodeMetadata::registerType(typeId(), create);
{
return CONTENT_LOCKABLE_CHEST;
}
-NodeMetadata* LockingChestNodeMetadata::create(std::istream &is)
+NodeMetadata* LockingChestNodeMetadata::create(std::istream &is, IGameDef *gamedef)
{
- LockingChestNodeMetadata *d = new LockingChestNodeMetadata();
+ LockingChestNodeMetadata *d = new LockingChestNodeMetadata(gamedef);
d->setOwner(deSerializeString(is));
- d->m_inventory->deSerialize(is);
+ d->m_inventory->deSerialize(is, gamedef);
return d;
}
-NodeMetadata* LockingChestNodeMetadata::clone()
+NodeMetadata* LockingChestNodeMetadata::clone(IGameDef *gamedef)
{
- LockingChestNodeMetadata *d = new LockingChestNodeMetadata();
+ LockingChestNodeMetadata *d = new LockingChestNodeMetadata(gamedef);
*d->m_inventory = *m_inventory;
return d;
}
*/
// Prototype
-FurnaceNodeMetadata proto_FurnaceNodeMetadata;
+FurnaceNodeMetadata proto_FurnaceNodeMetadata(NULL);
-FurnaceNodeMetadata::FurnaceNodeMetadata()
+FurnaceNodeMetadata::FurnaceNodeMetadata(IGameDef *gamedef):
+ NodeMetadata(gamedef)
{
NodeMetadata::registerType(typeId(), create);
{
return CONTENT_FURNACE;
}
-NodeMetadata* FurnaceNodeMetadata::clone()
+NodeMetadata* FurnaceNodeMetadata::clone(IGameDef *gamedef)
{
- FurnaceNodeMetadata *d = new FurnaceNodeMetadata();
+ FurnaceNodeMetadata *d = new FurnaceNodeMetadata(m_gamedef);
*d->m_inventory = *m_inventory;
return d;
}
-NodeMetadata* FurnaceNodeMetadata::create(std::istream &is)
+NodeMetadata* FurnaceNodeMetadata::create(std::istream &is, IGameDef *gamedef)
{
- FurnaceNodeMetadata *d = new FurnaceNodeMetadata();
+ FurnaceNodeMetadata *d = new FurnaceNodeMetadata(gamedef);
- d->m_inventory->deSerialize(is);
+ d->m_inventory->deSerialize(is, gamedef);
int temp;
is>>temp;
class SignNodeMetadata : public NodeMetadata
{
public:
- SignNodeMetadata(std::string text);
+ SignNodeMetadata(IGameDef *gamedef, std::string text);
//~SignNodeMetadata();
virtual u16 typeId() const;
- static NodeMetadata* create(std::istream &is);
- virtual NodeMetadata* clone();
+ static NodeMetadata* create(std::istream &is, IGameDef *gamedef);
+ virtual NodeMetadata* clone(IGameDef *gamedef);
virtual void serializeBody(std::ostream &os);
virtual std::string infoText();
class ChestNodeMetadata : public NodeMetadata
{
public:
- ChestNodeMetadata();
+ ChestNodeMetadata(IGameDef *gamedef);
~ChestNodeMetadata();
virtual u16 typeId() const;
- static NodeMetadata* create(std::istream &is);
- virtual NodeMetadata* clone();
+ static NodeMetadata* create(std::istream &is, IGameDef *gamedef);
+ virtual NodeMetadata* clone(IGameDef *gamedef);
virtual void serializeBody(std::ostream &os);
virtual std::string infoText();
virtual Inventory* getInventory() {return m_inventory;}
class LockingChestNodeMetadata : public NodeMetadata
{
public:
- LockingChestNodeMetadata();
+ LockingChestNodeMetadata(IGameDef *gamedef);
~LockingChestNodeMetadata();
virtual u16 typeId() const;
- static NodeMetadata* create(std::istream &is);
- virtual NodeMetadata* clone();
+ static NodeMetadata* create(std::istream &is, IGameDef *gamedef);
+ virtual NodeMetadata* clone(IGameDef *gamedef);
virtual void serializeBody(std::ostream &os);
virtual std::string infoText();
virtual Inventory* getInventory() {return m_inventory;}
class FurnaceNodeMetadata : public NodeMetadata
{
public:
- FurnaceNodeMetadata();
+ FurnaceNodeMetadata(IGameDef *gamedef);
~FurnaceNodeMetadata();
virtual u16 typeId() const;
- virtual NodeMetadata* clone();
- static NodeMetadata* create(std::istream &is);
+ virtual NodeMetadata* clone(IGameDef *gamedef);
+ static NodeMetadata* create(std::istream &is, IGameDef *gamedef);
virtual void serializeBody(std::ostream &os);
virtual std::string infoText();
virtual Inventory* getInventory() {return m_inventory;}
#include "collision.h"
#include "environment.h"
#include "settings.h"
+#include "main.h" // For g_profiler
#include "profiler.h"
core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
{
try{
std::istringstream is(m_inventorystring, std::ios_base::binary);
- InventoryItem *item = InventoryItem::deSerialize(is);
+ IGameDef *gamedef = m_env->getGameDef();
+ InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
infostream<<__FUNCTION_NAME<<": m_inventorystring=\""
<<m_inventorystring<<"\" -> item="<<item
<<std::endl;
void RatSAO::punch(ServerActiveObject *puncher)
{
std::istringstream is("CraftItem rat 1", std::ios_base::binary);
- InventoryItem *item = InventoryItem::deSerialize(is);
+ IGameDef *gamedef = m_env->getGameDef();
+ InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
bool fits = puncher->addToInventory(item);
if(fits)
m_removed = true;
InventoryItem* FireflySAO::createPickedUpItem()
{
std::istringstream is("CraftItem firefly 1", std::ios_base::binary);
- InventoryItem *item = InventoryItem::deSerialize(is);
+ IGameDef *gamedef = m_env->getGameDef();
+ InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
return item;
}
delete m_prop;
}
-void LuaEntitySAO::addedToEnvironment(u16 id)
+void LuaEntitySAO::addedToEnvironment()
{
- ServerActiveObject::addedToEnvironment(id);
+ ServerActiveObject::addedToEnvironment();
// Create entity from name and state
lua_State *L = m_env->getLua();
- m_registered = scriptapi_luaentity_add(L, id, m_init_name.c_str(), m_init_state.c_str());
+ m_registered = scriptapi_luaentity_add(L, m_id, m_init_name.c_str(),
+ m_init_state.c_str());
if(m_registered){
// Get properties
InventoryItem* LuaEntitySAO::createPickedUpItem()
{
std::istringstream is("CraftItem testobject1 1", std::ios_base::binary);
- InventoryItem *item = InventoryItem::deSerialize(is);
+ IGameDef *gamedef = m_env->getGameDef();
+ InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
return item;
}
~LuaEntitySAO();
u8 getType() const
{return ACTIVEOBJECT_TYPE_LUAENTITY;}
- virtual void addedToEnvironment(u16 id);
+ virtual void addedToEnvironment();
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data);
void step(float dtime, bool send_recommended);
--- /dev/null
+/*
+Minetest-c55
+Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "content_tool.h"
+#include "tool.h"
+
+void content_tool_init(IToolDefManager *mgr)
+{
+ mgr->registerTool("WPick",
+ ToolDefinition("tool_woodpick.png",
+ ToolDiggingProperties(2.0, 0,-1,2,0, 50, 0,0,0,0)));
+ mgr->registerTool("STPick",
+ ToolDefinition("tool_stonepick.png",
+ ToolDiggingProperties(1.5, 0,-1,2,0, 100, 0,0,0,0)));
+ mgr->registerTool("SteelPick",
+ ToolDefinition("tool_steelpick.png",
+ ToolDiggingProperties(1.0, 0,-1,2,0, 300, 0,0,0,0)));
+ mgr->registerTool("MesePick",
+ ToolDefinition("tool_mesepick.png",
+ ToolDiggingProperties(0, 0,0,0,0, 1337, 0,0,0,0)));
+ mgr->registerTool("WShovel",
+ ToolDefinition("tool_woodshovel.png",
+ ToolDiggingProperties(2.0, 0.5,2,-1.5,0.3, 50, 0,0,0,0)));
+ mgr->registerTool("STShovel",
+ ToolDefinition("tool_stoneshovel.png",
+ ToolDiggingProperties(1.5, 0.5,2,-1.5,0.1, 100, 0,0,0,0)));
+ mgr->registerTool("SteelShovel",
+ ToolDefinition("tool_steelshovel.png",
+ ToolDiggingProperties(1.0, 0.5,2,-1.5,0.0, 300, 0,0,0,0)));
+ mgr->registerTool("WAxe",
+ ToolDefinition("tool_woodaxe.png",
+ ToolDiggingProperties(2.0, 0.5,-0.2,1,-0.5, 50, 0,0,0,0)));
+ mgr->registerTool("STAxe",
+ ToolDefinition("tool_stoneaxe.png",
+ ToolDiggingProperties(1.5, 0.5,-0.2,1,-0.5, 100, 0,0,0,0)));
+ mgr->registerTool("SteelAxe",
+ ToolDefinition("tool_steelaxe.png",
+ ToolDiggingProperties(1.0, 0.5,-0.2,1,-0.5, 300, 0,0,0,0)));
+ mgr->registerTool("WSword",
+ ToolDefinition("tool_woodsword.png",
+ ToolDiggingProperties(3.0, 3,0,1,-1, 50, 0,0,0,0)));
+ mgr->registerTool("STSword",
+ ToolDefinition("tool_stonesword.png",
+ ToolDiggingProperties(2.5, 3,0,1,-1, 100, 0,0,0,0)));
+ mgr->registerTool("SteelSword",
+ ToolDefinition("tool_steelsword.png",
+ ToolDiggingProperties(2.0, 3,0,1,-1, 300, 0,0,0,0)));
+ mgr->registerTool("",
+ ToolDefinition("tool_hand.png",
+ ToolDiggingProperties(0.5, 1,0,-1,0, 50, 0,0,0,0)));
+}
+
--- /dev/null
+/*
+Minetest-c55
+Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+class IToolDefManager;
+
+// Add default tools to manager
+void content_tool_init(IToolDefManager *mgr);
+
#include "scriptapi.h"
#include "mapnode_contentfeatures.h"
#include "nodemetadata.h"
+#include "main.h" // For g_settings, g_profiler
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
ServerEnvironment
*/
-ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L):
+ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L,
+ IGameDef *gamedef):
m_map(map),
m_lua(L),
+ m_gamedef(gamedef),
m_random_spawn_timer(3),
m_send_recommended_timer(0),
m_game_time(0),
//infostream<<"Checking player file "<<path<<std::endl;
// Load player to see what is its name
- ServerRemotePlayer testplayer;
+ ServerRemotePlayer testplayer(this);
{
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
- testplayer.deSerialize(is);
+ testplayer.deSerialize(is, m_gamedef);
}
//infostream<<"Loaded test player with name "<<testplayer.getName()<<std::endl;
infostream<<"Checking player file "<<path<<std::endl;
// Load player to see what is its name
- ServerRemotePlayer testplayer;
+ ServerRemotePlayer testplayer(this);
{
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
- testplayer.deSerialize(is);
+ testplayer.deSerialize(is, m_gamedef);
}
if(!string_allowed(testplayer.getName(), PLAYERNAME_ALLOWED_CHARS))
if(player == NULL)
{
infostream<<"Is a new player"<<std::endl;
- player = new ServerRemotePlayer();
+ player = new ServerRemotePlayer(this);
newplayer = true;
}
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
- player->deSerialize(is);
+ player->deSerialize(is, m_gamedef);
}
if(newplayer)
// Register reference in scripting api (must be done before post-init)
scriptapi_add_object_reference(m_lua, object);
// Post-initialize object
- object->addedToEnvironment(object->getId());
+ object->addedToEnvironment();
return object->getId();
}
ClientEnvironment
*/
-ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr):
+ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
+ ITextureSource *texturesource, IGameDef *gamedef):
m_map(map),
- m_smgr(smgr)
+ m_smgr(smgr),
+ m_texturesource(texturesource),
+ m_gamedef(gamedef)
{
assert(m_map);
assert(m_smgr);
}
}
-void ClientEnvironment::updateMeshes(v3s16 blockpos)
+void ClientEnvironment::updateMeshes(v3s16 blockpos, ITextureSource *tsrc)
{
- m_map->updateMeshes(blockpos, getDayNightRatio());
+ m_map->updateMeshes(blockpos, getDayNightRatio(), tsrc);
}
void ClientEnvironment::expireMeshes(bool only_daynight_diffed)
infostream<<"ClientEnvironment::addActiveObject(): "
<<"added (id="<<object->getId()<<")"<<std::endl;
m_active_objects.insert(object->getId(), object);
- object->addToScene(m_smgr);
+ // TODO: Make g_texturesource non-global
+ object->addToScene(m_smgr, m_texturesource);
return object->getId();
}
void ClientEnvironment::addActiveObject(u16 id, u8 type,
const std::string &init_data)
{
- ClientActiveObject* obj = ClientActiveObject::create(type);
+ ClientActiveObject* obj = ClientActiveObject::create(type, m_gamedef);
if(obj == NULL)
{
infostream<<"ClientEnvironment::addActiveObject(): "
- The map
- Players
- Other objects
- - The current time in the game (actually it only contains the brightness)
+ - The current time in the game
- etc.
*/
class ActiveBlockModifier;
class ServerActiveObject;
typedef struct lua_State lua_State;
+class ITextureSource;
+class IGameDef;
class Environment
{
class ServerEnvironment : public Environment
{
public:
- ServerEnvironment(ServerMap *map, lua_State *L);
+ ServerEnvironment(ServerMap *map, lua_State *L, IGameDef *gamedef);
~ServerEnvironment();
Map & getMap()
- {
- return *m_map;
- }
+ { return *m_map; }
ServerMap & getServerMap()
- {
- return *m_map;
- }
+ { return *m_map; }
lua_State* getLua()
- {
- return m_lua;
- }
+ { return m_lua; }
+
+ IGameDef *getGameDef()
+ { return m_gamedef; }
float getSendRecommendedInterval()
{
/*
ActiveBlockModifiers (TODO)
-------------------------------------------
+ NOTE: Not used currently (TODO: Use or remove)
*/
void addActiveBlockModifier(ActiveBlockModifier *abm);
ServerMap *m_map;
// Lua state
lua_State *m_lua;
+ // Game definition
+ IGameDef *m_gamedef;
// Active object list
core::map<u16, ServerActiveObject*> m_active_objects;
// Outgoing network message buffer for active objects
These are fed into ServerEnvironment at initialization time;
ServerEnvironment handles deleting them.
+
+ NOTE: Not used currently (TODO: Use or remove)
*/
class ActiveBlockModifier
class ClientEnvironment : public Environment
{
public:
- ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr);
+ ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
+ ITextureSource *texturesource, IGameDef *gamedef);
~ClientEnvironment();
Map & getMap()
virtual void addPlayer(Player *player);
LocalPlayer * getLocalPlayer();
-
- void updateMeshes(v3s16 blockpos);
+
+ // Slightly deprecated
+ void updateMeshes(v3s16 blockpos, ITextureSource *tsrc);
void expireMeshes(bool only_daynight_diffed);
void setTimeOfDay(u32 time)
if(getDayNightRatio() != old_dr)
{
- dout_client<<DTIME<<"ClientEnvironment: DayNightRatio changed"
- <<" -> expiring meshes"<<std::endl;
+ /*infostream<<"ClientEnvironment: DayNightRatio changed"
+ <<" -> expiring meshes"<<std::endl;*/
expireMeshes(true);
}
}
private:
ClientMap *m_map;
scene::ISceneManager *m_smgr;
+ ITextureSource *m_texturesource;
+ IGameDef *m_gamedef;
core::map<u16, ClientActiveObject*> m_active_objects;
Queue<ClientEnvEvent> m_client_event_queue;
IntervalLimiter m_active_object_light_update_interval;
// Needed for determining pointing to nodes
#include "mapnode_contentfeatures.h"
#include "nodemetadata.h"
+#include "main.h" // For g_settings
+#include "content_mapnode.h" // For content_mapnode_init
+#include "tool.h"
+#include "content_tool.h" // For content_tool_init
/*
Setting this to 1 enables a special camera mode that forces
Hotbar draw routine
*/
void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
+ ITextureSource *tsrc,
v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
Inventory *inventory, s32 halfheartcount)
{
if(item != NULL)
{
- drawInventoryItem(driver, font, item, rect, NULL);
+ drawInventoryItem(driver, font, item, rect, NULL, tsrc);
}
}
draw_load_screen(L"Loading...", driver, font);
+ // Create tool manager
+ IToolDefManager *toolmgr = createToolDefManager();
+
+ // Create texture source
+ TextureSource *tsrc = new TextureSource(device);
+
+ // Initialize mapnode again to enable changed graphics settings
+ // Initialize content feature table with textures
+ init_contentfeatures(tsrc);
+ // Fill content feature table with default definitions
+ content_mapnode_init(tsrc);
+
+ // Initialize default tool definitions
+ content_tool_init(toolmgr);
+
/*
Create server.
SharedPtr will delete it when it goes out of scope.
draw_load_screen(L"Creating client...", driver, font);
infostream<<"Creating client"<<std::endl;
MapDrawControl draw_control;
- Client client(device, playername.c_str(), password, draw_control);
+ Client client(device, playername.c_str(), password, draw_control,
+ tsrc, toolmgr);
draw_load_screen(L"Resolving address...", driver, font);
Address connect_address(0,0,0,0, port);
/*
Process TextureSource's queue
*/
- ((TextureSource*)g_texturesource)->processQueue();
+ tsrc->processQueue();
/*
Random calculations
new GUIInventoryMenu(guienv, guiroot, -1,
&g_menumgr, v2s16(8,7),
client.getInventoryContext(),
- &client);
+ &client, tsrc);
core::array<GUIInventoryMenu::DrawSpec> draw_spec;
draw_spec.push_back(GUIInventoryMenu::DrawSpec(
// Get digging properties for material and tool
content_t material = n.getContent();
+ ToolDiggingProperties tp =
+ toolmgr->getDiggingProperties(toolname);
DiggingProperties prop =
- getDiggingProperties(material, toolname);
+ getDiggingProperties(material, &tp);
float dig_time_complete = 0.0;
new GUIInventoryMenu(guienv, guiroot, -1,
&g_menumgr, invsize,
client.getInventoryContext(),
- &client);
+ &client, tsrc);
menu->setDrawSpec(draw_spec);
menu->drop();
}
InventoryItem *item = NULL;
if(mlist != NULL)
item = mlist->getItem(g_selected_item);
- camera.wield(item);
+ camera.wield(item, tsrc);
}
/*
Draw hotbar
*/
{
- draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),
+ draw_hotbar(driver, font, tsrc,
+ v2s32(displaycenter.X, screensize.Y),
hotbar_imagesize, hotbar_itemcount, &local_inventory,
client.getHP());
}
driver->endScene();
gui_shuttingdowntext->remove();*/
}
+
+ delete toolmgr;
+ delete tsrc;
}
--- /dev/null
+/*
+Minetest-c55
+Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef GAMEDEF_HEADER
+#define GAMEDEF_HEADER
+
+class IToolDefManager;
+class INodeDefManager; //TODO
+//class IItemDefManager; //TODO
+// Mineral too?
+
+/*
+ An interface for fetching game-global definitions like tool and
+ mapnode properties
+*/
+
+class IGameDef
+{
+public:
+ virtual IToolDefManager* getToolDefManager()=0;
+ virtual INodeDefManager* getNodeDefManager()=0;
+ //virtual IItemDefManager* getItemDefManager()=0;
+};
+
+#endif
+
void drawInventoryItem(video::IVideoDriver *driver,
gui::IGUIFont *font,
InventoryItem *item, core::rect<s32> rect,
- const core::rect<s32> *clip)
+ const core::rect<s32> *clip,
+ ITextureSource *tsrc)
{
if(item == NULL)
return;
video::ITexture *texture = NULL;
- texture = item->getImage();
+ texture = item->getImage(tsrc);
if(texture != NULL)
{
IMenuManager *menumgr,
v2s16 menu_size,
InventoryContext *c,
- InventoryManager *invmgr
+ InventoryManager *invmgr,
+ ITextureSource *tsrc
):
GUIModalMenu(env, parent, id, menumgr),
m_menu_size(menu_size),
m_c(c),
- m_invmgr(invmgr)
+ m_invmgr(invmgr),
+ m_tsrc(tsrc)
{
m_selected_item = NULL;
}
return ItemSpec("", "", -1);
}
-void GUIInventoryMenu::drawList(const ListDrawSpec &s)
+void GUIInventoryMenu::drawList(const ListDrawSpec &s, ITextureSource *tsrc)
{
video::IVideoDriver* driver = Environment->getVideoDriver();
if(item)
{
drawInventoryItem(driver, font, item,
- rect, &AbsoluteClippingRect);
+ rect, &AbsoluteClippingRect, tsrc);
}
}
for(u32 i=0; i<m_draw_spec.size(); i++)
{
ListDrawSpec &s = m_draw_spec[i];
- drawList(s);
+ drawList(s, m_tsrc);
}
/*
#include "utility.h"
#include "modalMenu.h"
+class ITextureSource;
+
void drawInventoryItem(video::IVideoDriver *driver,
gui::IGUIFont *font,
InventoryItem *item, core::rect<s32> rect,
- const core::rect<s32> *clip);
+ const core::rect<s32> *clip,
+ ITextureSource *tsrc);
class GUIInventoryMenu : public GUIModalMenu
{
IMenuManager *menumgr,
v2s16 menu_size,
InventoryContext *c,
- InventoryManager *invmgr
+ InventoryManager *invmgr,
+ ITextureSource *tsrc
);
~GUIInventoryMenu();
void regenerateGui(v2u32 screensize);
ItemSpec getItemAtPos(v2s32 p) const;
- void drawList(const ListDrawSpec &s);
+ void drawList(const ListDrawSpec &s, ITextureSource *tsrc);
void drawMenu();
bool OnEvent(const SEvent& event);
InventoryContext *m_c;
InventoryManager *m_invmgr;
+ ITextureSource *m_tsrc;
core::array<DrawSpec> m_init_draw_spec;
core::array<ListDrawSpec> m_draw_spec;
/*
Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-/*
-(c) 2010 Perttu Ahola <celeron55@gmail.com>
-*/
-
#include "inventory.h"
#include "serialization.h"
#include "utility.h"
#include "debug.h"
#include <sstream>
-#include "main.h"
+#include "main.h" // For tsrc, g_toolmanager
#include "serverobject.h"
#include "content_mapnode.h"
#include "content_inventory.h"
#include "log.h"
#include "mapnode_contentfeatures.h"
#include "tool.h"
+#include "gamedef.h"
/*
InventoryItem
*/
-InventoryItem::InventoryItem(u16 count)
+InventoryItem::InventoryItem(IGameDef *gamedef, u16 count):
+ m_gamedef(gamedef),
+ m_count(count)
{
- m_count = count;
+ assert(m_gamedef);
}
InventoryItem::~InventoryItem()
return c_from;
}
-InventoryItem* InventoryItem::deSerialize(std::istream &is)
+InventoryItem* InventoryItem::deSerialize(std::istream &is, IGameDef *gamedef)
{
DSTACK(__FUNCTION_NAME);
}
if(material > MAX_CONTENT)
throw SerializationError("Too large material number");
- return new MaterialItem(material, count);
+ return new MaterialItem(gamedef, material, count);
}
else if(name == "MaterialItem2")
{
is>>count;
if(material > MAX_CONTENT)
throw SerializationError("Too large material number");
- return new MaterialItem(material, count);
+ return new MaterialItem(gamedef, material, count);
}
else if(name == "MBOItem")
{
std::getline(is, subname, ' ');
u16 count;
is>>count;
- return new CraftItem(subname, count);
+ return new CraftItem(gamedef, subname, count);
}
else if(name == "ToolItem")
{
std::getline(is, toolname, ' ');
u16 wear;
is>>wear;
- return new ToolItem(toolname, wear);
+ return new ToolItem(gamedef, toolname, wear);
}
else
{
*/
#ifndef SERVER
-video::ITexture * MaterialItem::getImage() const
+video::ITexture * MaterialItem::getImage(ITextureSource *tsrc) const
{
return content_features(m_content).inventory_texture;
}
bool MaterialItem::isCookable() const
{
- return item_material_is_cookable(m_content);
+ return item_material_is_cookable(m_content, m_gamedef);
}
InventoryItem *MaterialItem::createCookResult() const
{
- return item_material_create_cook_result(m_content);
+ return item_material_create_cook_result(m_content, m_gamedef);
}
/*
std::string ToolItem::getImageBasename() const
{
- return tool_get_imagename(m_toolname);
+ return m_gamedef->getToolDefManager()->getImagename(m_toolname);
+}
+
+#ifndef SERVER
+video::ITexture * ToolItem::getImage(ITextureSource *tsrc) const
+{
+ if(tsrc == NULL)
+ return NULL;
+
+ std::string basename = getImageBasename();
+
+ /*
+ Calculate a progress value with sane amount of
+ maximum states
+ */
+ u32 maxprogress = 30;
+ u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
+
+ float value_f = (float)toolprogress / (float)maxprogress;
+ std::ostringstream os;
+ os<<basename<<"^[progressbar"<<value_f;
+
+ return tsrc->getTextureRaw(os.str());
+}
+
+video::ITexture * ToolItem::getImageRaw(ITextureSource *tsrc) const
+{
+ if(tsrc == NULL)
+ return NULL;
+
+ return tsrc->getTextureRaw(getImageBasename());
}
+#endif
/*
CraftItem
*/
#ifndef SERVER
-video::ITexture * CraftItem::getImage() const
+video::ITexture * CraftItem::getImage(ITextureSource *tsrc) const
{
- if(g_texturesource == NULL)
+ if(tsrc == NULL)
return NULL;
- std::string name = item_craft_get_image_name(m_subname);
+ std::string name = item_craft_get_image_name(m_subname, m_gamedef);
// Get such a texture
- return g_texturesource->getTextureRaw(name);
+ return tsrc->getTextureRaw(name);
}
#endif
u16 CraftItem::getDropCount() const
{
// Special cases
- s16 dc = item_craft_get_drop_count(m_subname);
+ s16 dc = item_craft_get_drop_count(m_subname, m_gamedef);
if(dc != -1)
return dc;
// Default
bool CraftItem::isCookable() const
{
- return item_craft_is_cookable(m_subname);
+ return item_craft_is_cookable(m_subname, m_gamedef);
}
InventoryItem *CraftItem::createCookResult() const
{
- return item_craft_create_cook_result(m_subname);
+ return item_craft_create_cook_result(m_subname, m_gamedef);
}
bool CraftItem::use(ServerEnvironment *env, ServerActiveObject *user)
{
- if(!item_craft_is_eatable(m_subname))
+ if(!item_craft_is_eatable(m_subname, m_gamedef))
return false;
u16 result_count = getCount() - 1; // Eat one at a time
- s16 hp_change = item_craft_eat_hp_change(m_subname);
+ s16 hp_change = item_craft_eat_hp_change(m_subname, m_gamedef);
s16 hp = user->getHP();
hp += hp_change;
if(hp < 0)
os<<"EndInventoryList\n";
}
-void InventoryList::deSerialize(std::istream &is)
+void InventoryList::deSerialize(std::istream &is, IGameDef *gamedef)
{
//is.imbue(std::locale("C"));
{
if(item_i > getSize() - 1)
throw SerializationError("too many items");
- InventoryItem *item = InventoryItem::deSerialize(iss);
+ InventoryItem *item = InventoryItem::deSerialize(iss, gamedef);
m_items[item_i++] = item;
}
else if(name == "Empty")
os<<"EndInventory\n";
}
-void Inventory::deSerialize(std::istream &is)
+void Inventory::deSerialize(std::istream &is, IGameDef *gamedef)
{
clear();
iss>>listsize;
InventoryList *list = new InventoryList(listname, listsize);
- list->deSerialize(is);
+ list->deSerialize(is, gamedef);
m_lists.push_back(list);
}
/*
Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-/*
-(c) 2010 Perttu Ahola <celeron55@gmail.com>
-*/
-
#ifndef INVENTORY_HEADER
#define INVENTORY_HEADER
#include <string>
#include "common_irrlicht.h"
#include "debug.h"
-#include "main.h" // For g_materials
#include "mapnode.h" // For content_t
#define QUANTITY_ITEM_MAX_COUNT 99
class ServerActiveObject;
class ServerEnvironment;
+class ITextureSource;
+class IGameDef;
class InventoryItem
{
public:
- InventoryItem(u16 count);
+ InventoryItem(IGameDef *gamedef, u16 count);
virtual ~InventoryItem();
- static InventoryItem* deSerialize(std::istream &is);
+ static InventoryItem* deSerialize(std::istream &is, IGameDef *gamedef);
virtual const char* getName() const = 0;
// Shall write the name and the parameters
virtual void serialize(std::ostream &os) const = 0;
// Shall make an exact clone of the item
virtual InventoryItem* clone() = 0;
-#ifndef SERVER
// Return the name of the image for this item
virtual std::string getImageBasename() const { return ""; }
+#ifndef SERVER
// Shall return an image of the item (or NULL)
- virtual video::ITexture * getImage() const { return NULL; }
+ virtual video::ITexture * getImage(ITextureSource *tsrc) const
+ { return NULL; }
// Shall return an image of the item without embellishments (or NULL)
- virtual video::ITexture * getImageRaw() const { return getImage(); }
+ virtual video::ITexture * getImageRaw(ITextureSource *tsrc) const
+ { return getImage(tsrc); }
#endif
// Shall return a text to show in the GUI
virtual std::string getText() { return ""; }
ServerActiveObject *user){return false;}
protected:
+ IGameDef *m_gamedef;
u16 m_count;
};
class MaterialItem : public InventoryItem
{
public:
- MaterialItem(content_t content, u16 count):
- InventoryItem(count)
+ MaterialItem(IGameDef *gamedef, content_t content, u16 count):
+ InventoryItem(gamedef, count)
{
m_content = content;
}
}
virtual InventoryItem* clone()
{
- return new MaterialItem(m_content, m_count);
+ return new MaterialItem(m_gamedef, m_content, m_count);
}
#ifndef SERVER
- video::ITexture * getImage() const;
+ video::ITexture * getImage(ITextureSource *tsrc) const;
#endif
std::string getText()
{
class CraftItem : public InventoryItem
{
public:
- CraftItem(std::string subname, u16 count):
- InventoryItem(count)
+ CraftItem(IGameDef *gamedef, std::string subname, u16 count):
+ InventoryItem(gamedef, count)
{
m_subname = subname;
}
}
virtual InventoryItem* clone()
{
- return new CraftItem(m_subname, m_count);
+ return new CraftItem(m_gamedef, m_subname, m_count);
}
#ifndef SERVER
- video::ITexture * getImage() const;
+ video::ITexture * getImage(ITextureSource *tsrc) const;
#endif
std::string getText()
{
class ToolItem : public InventoryItem
{
public:
- ToolItem(std::string toolname, u16 wear):
- InventoryItem(1)
+ ToolItem(IGameDef *gamedef, std::string toolname, u16 wear):
+ InventoryItem(gamedef, 1)
{
m_toolname = toolname;
m_wear = wear;
}
virtual InventoryItem* clone()
{
- return new ToolItem(m_toolname, m_wear);
+ return new ToolItem(m_gamedef, m_toolname, m_wear);
}
std::string getImageBasename() const;
-
#ifndef SERVER
- video::ITexture * getImage() const
- {
- if(g_texturesource == NULL)
- return NULL;
-
- std::string basename = getImageBasename();
-
- /*
- Calculate a progress value with sane amount of
- maximum states
- */
- u32 maxprogress = 30;
- u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
-
- float value_f = (float)toolprogress / (float)maxprogress;
- std::ostringstream os;
- os<<basename<<"^[progressbar"<<value_f;
-
- return g_texturesource->getTextureRaw(os.str());
- }
-
- video::ITexture * getImageRaw() const
- {
- if(g_texturesource == NULL)
- return NULL;
-
- return g_texturesource->getTextureRaw(getImageBasename());
- }
+ video::ITexture * getImage(ITextureSource *tsrc) const;
+ video::ITexture * getImageRaw(ITextureSource *tsrc) const;
#endif
+
std::string getText()
{
return "";
~InventoryList();
void clearItems();
void serialize(std::ostream &os) const;
- void deSerialize(std::istream &is);
+ void deSerialize(std::istream &is, IGameDef *gamedef);
InventoryList(const InventoryList &other);
InventoryList & operator = (const InventoryList &other);
Inventory & operator = (const Inventory &other);
void serialize(std::ostream &os) const;
- void deSerialize(std::istream &is);
+ void deSerialize(std::istream &is, IGameDef *gamedef);
InventoryList * addList(const std::string &name, u32 size);
InventoryList * getList(const std::string &name);
*/
#ifdef NDEBUG
- #ifdef _WIN32
+ /*#ifdef _WIN32
#pragma message ("Disabling unit tests")
#else
#warning "Disabling unit tests"
- #endif
+ #endif*/
// Disable unit tests
#define ENABLE_TESTS 0
#else
#include "mapnode_contentfeatures.h" // For init_contentfeatures
#include "content_mapnode.h" // For content_mapnode_init
-// This makes textures
-ITextureSource *g_texturesource = NULL;
-
/*
Settings.
These are loaded from the config file.
These are needed for unit tests at least.
*/
- // Initialize content feature table
- init_contentfeatures();
- // Initialize mapnode content without textures (with g_texturesource=NULL)
- content_mapnode_init();
- // Must be called before g_texturesource is created
+ // Initialize content feature table without textures
+ init_contentfeatures(NULL);
+ // Initialize mapnode content without textures
+ content_mapnode_init(NULL);
+ // Must be called before texturesource is created
// (for texture atlas making)
init_mineral();
// Create game callback for menus
g_gamecallback = new MainGameCallback(device);
- // Create texture source
- g_texturesource = new TextureSource(device);
-
/*
Speed tests (done after irrlicht is loaded to get timer)
*/
skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0));
skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));
- /*
- Preload some textures and stuff
- */
-
- // Initialize mapnode content with textures (with g_texturesource!=NULL)
- content_mapnode_init();
-
/*
GUI stuff
*/
if(device->run() == false)
break;
- // Initialize mapnode again to enable changed graphics settings
- // Initialize content feature table
- init_contentfeatures();
- // Initialize mapnode content with textures (with g_texturesource!=NULL)
- content_mapnode_init();
-
/*
Run game
*/
class Settings;
extern Settings *g_settings;
-// This makes and maps textures
-class ITextureSource;
-extern ITextureSource *g_texturesource;
-
// Global profiler
class Profiler;
extern Profiler *g_profiler;
Map
*/
-Map::Map(std::ostream &dout):
+Map::Map(std::ostream &dout, IGameDef *gamedef):
m_dout(dout),
+ m_gamedef(gamedef),
m_sector_cache(NULL)
{
/*m_sector_mutex.Init();
NodeMetadata *meta_proto = content_features(n).initial_metadata;
if(meta_proto)
{
- NodeMetadata *meta = meta_proto->clone();
+ NodeMetadata *meta = meta_proto->clone(m_gamedef);
meta->setOwner(player_name);
setNodeMetadata(p, meta);
}
ServerMap
*/
-ServerMap::ServerMap(std::string savedir):
- Map(dout_server),
+ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
+ Map(dout_server, gamedef),
m_seed(0),
m_map_metadata_changed(true),
m_database(NULL),
}
// Read basic data
- block->deSerialize(is, version);
+ block->deSerialize(is, version, m_gamedef);
// Read extra data stored on disk
block->deSerializeDiskExtra(is, version);
}
// Read basic data
- block->deSerialize(is, version);
+ block->deSerialize(is, version, m_gamedef);
// Read extra data stored on disk
block->deSerializeDiskExtra(is, version);
ClientMap::ClientMap(
Client *client,
+ IGameDef *gamedef,
MapDrawControl &control,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id
):
- Map(dout_client),
+ Map(dout_client, gamedef),
scene::ISceneNode(parent, mgr, id),
m_client(client),
m_control(control),
}
}
-void ClientMap::updateMeshes(v3s16 blockpos, u32 daynight_ratio)
+void ClientMap::updateMeshes(v3s16 blockpos, u32 daynight_ratio,
+ ITextureSource *tsrc)
{
assert(mapType() == MAPTYPE_CLIENT);
try{
v3s16 p = blockpos + v3s16(0,0,0);
MapBlock *b = getBlockNoCreate(p);
- b->updateMesh(daynight_ratio);
+ b->updateMesh(daynight_ratio, tsrc);
//b->setMeshExpired(true);
}
catch(InvalidPositionException &e){}
try{
v3s16 p = blockpos + v3s16(-1,0,0);
MapBlock *b = getBlockNoCreate(p);
- b->updateMesh(daynight_ratio);
+ b->updateMesh(daynight_ratio, tsrc);
//b->setMeshExpired(true);
}
catch(InvalidPositionException &e){}
try{
v3s16 p = blockpos + v3s16(0,-1,0);
MapBlock *b = getBlockNoCreate(p);
- b->updateMesh(daynight_ratio);
+ b->updateMesh(daynight_ratio, tsrc);
//b->setMeshExpired(true);
}
catch(InvalidPositionException &e){}
try{
v3s16 p = blockpos + v3s16(0,0,-1);
MapBlock *b = getBlockNoCreate(p);
- b->updateMesh(daynight_ratio);
+ b->updateMesh(daynight_ratio, tsrc);
//b->setMeshExpired(true);
}
catch(InvalidPositionException &e){}
class ClientMapSector;
class MapBlock;
class NodeMetadata;
+class IGameDef;
namespace mapgen{
struct BlockMakeData;
{
public:
- Map(std::ostream &dout);
+ Map(std::ostream &dout, IGameDef *gamedef);
virtual ~Map();
/*virtual u16 nodeContainerId() const
protected:
- std::ostream &m_dout;
+ std::ostream &m_dout; // A bit deprecated, could be removed
+
+ IGameDef *m_gamedef;
core::map<MapEventReceiver*, bool> m_event_receivers;
/*
savedir: directory to which map data should be saved
*/
- ServerMap(std::string savedir);
+ ServerMap(std::string savedir, IGameDef *gamedef);
~ServerMap();
s32 mapType() const
u64 getSeed(){ return m_seed; }
private:
- // Seed used for all kinds of randomness
+ // Seed used for all kinds of randomness in generation
u64 m_seed;
-
+
std::string m_savedir;
bool m_map_saving_enabled;
};
class Client;
+class ITextureSource;
/*
ClientMap
public:
ClientMap(
Client *client,
+ IGameDef *gamedef,
MapDrawControl &control,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
/*
Update the faces of the given block and blocks on the
- leading edge.
+ leading edge, without threading. Rarely used.
*/
- void updateMeshes(v3s16 blockpos, u32 daynight_ratio);
+ void updateMeshes(v3s16 blockpos, u32 daynight_ratio,
+ ITextureSource *tsrc);
// Update meshes that touch the node
//void updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio);
#ifndef SERVER
#if 1
-void MapBlock::updateMesh(u32 daynight_ratio)
+void MapBlock::updateMesh(u32 daynight_ratio, ITextureSource *tsrc)
{
#if 0
/*
MeshMakeData data;
data.fill(daynight_ratio, this);
- scene::SMesh *mesh_new = makeMapBlockMesh(&data);
+ scene::SMesh *mesh_new = makeMapBlockMesh(&data, tsrc);
/*
Replace the mesh
}
}
-void MapBlock::deSerialize(std::istream &is, u8 version)
+void MapBlock::deSerialize(std::istream &is, u8 version, IGameDef *gamedef)
{
if(!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapBlock format not supported");
{
std::string data = deSerializeString(is);
std::istringstream iss(data, std::ios_base::binary);
- m_node_metadata->deSerialize(iss);
+ m_node_metadata->deSerialize(iss, gamedef);
}
else
{
std::ostringstream oss(std::ios_base::binary);
decompressZlib(is, oss);
std::istringstream iss(oss.str(), std::ios_base::binary);
- m_node_metadata->deSerialize(iss);
+ m_node_metadata->deSerialize(iss, gamedef);
}
}
catch(SerializationError &e)
class Map;
class NodeMetadataList;
+class ITextureSource;
+class IGameDef;
#define BLOCK_TIMESTAMP_UNDEFINED 0xffffffff
NOTE: Prefer generating the mesh separately and then using
replaceMesh().
*/
- void updateMesh(u32 daynight_ratio);
+ void updateMesh(u32 daynight_ratio, ITextureSource *tsrc);
#endif
// Replace the mesh with a new one
void replaceMesh(scene::SMesh *mesh_new);
// These don't write or read version by itself
void serialize(std::ostream &os, u8 version);
- void deSerialize(std::istream &is, u8 version);
+ void deSerialize(std::istream &is, u8 version, IGameDef *gamedef);
// Used after the basic ones when writing on disk (serverside)
void serializeDiskExtra(std::ostream &os, u8 version);
void deSerializeDiskExtra(std::istream &is, u8 version);
#include "settings.h"
#include "profiler.h"
#include "mapnode_contentfeatures.h"
+#include "tile.h"
void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
{
Returns TILE_NODE if doesn't exist or should not be drawn.
*/
TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
- NodeModMap &temp_mods)
+ NodeModMap &temp_mods, ITextureSource *tsrc)
{
TileSpec spec;
- spec = mn.getTile(face_dir);
+ spec = mn.getTile(face_dir, tsrc);
/*
Check temporary modifications on this node
if(mod.type == NODEMOD_CHANGECONTENT)
{
MapNode mn2(mod.param);
- spec = mn2.getTile(face_dir);
+ spec = mn2.getTile(face_dir, tsrc);
}
if(mod.type == NODEMOD_CRACK)
{
// Get original texture name
u32 orig_id = spec.texture.id;
- std::string orig_name = g_texturesource->getTextureName(orig_id);
+ std::string orig_name = tsrc->getTextureName(orig_id);
// Create new texture name
std::ostringstream os;
os<<orig_name<<"^[crack"<<mod.param;
// Get new texture
- u32 new_id = g_texturesource->getTextureId(os.str());
+ u32 new_id = tsrc->getTextureId(os.str());
/*dstream<<"MapBlock::getNodeTile(): Switching from "
<<orig_name<<" to "<<os.str()<<" ("
<<orig_id<<" to "<<new_id<<")"<<std::endl;*/
- spec.texture = g_texturesource->getTexture(new_id);
+ spec.texture = tsrc->getTexture(new_id);
}
}
VoxelManipulator &vmanip,
NodeModMap &temp_mods,
bool smooth_lighting,
+ ITextureSource *tsrc,
// Output:
bool &makes_face,
v3s16 &p_corrected,
{
MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p);
MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir);
- TileSpec tile0 = getNodeTile(n0, p, face_dir, temp_mods);
- TileSpec tile1 = getNodeTile(n1, p + face_dir, -face_dir, temp_mods);
+ TileSpec tile0 = getNodeTile(n0, p, face_dir, temp_mods, tsrc);
+ TileSpec tile1 = getNodeTile(n1, p + face_dir, -face_dir, temp_mods, tsrc);
// This is hackish
content_t content0 = getNodeContent(p, n0, temp_mods);
NodeModMap &temp_mods,
VoxelManipulator &vmanip,
v3s16 blockpos_nodes,
- bool smooth_lighting)
+ bool smooth_lighting,
+ ITextureSource *tsrc)
{
v3s16 p = startpos;
u8 lights[4] = {0,0,0,0};
TileSpec tile;
getTileInfo(blockpos_nodes, p, face_dir, daynight_ratio,
- vmanip, temp_mods, smooth_lighting,
+ vmanip, temp_mods, smooth_lighting, tsrc,
makes_face, p_corrected, face_dir_corrected, lights, tile);
for(u16 j=0; j<length; j++)
p_next = p + translate_dir;
getTileInfo(blockpos_nodes, p_next, face_dir, daynight_ratio,
- vmanip, temp_mods, smooth_lighting,
+ vmanip, temp_mods, smooth_lighting, tsrc,
next_makes_face, next_p_corrected,
next_face_dir_corrected, next_lights,
next_tile);
}
}
-scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
+scene::SMesh* makeMapBlockMesh(MeshMakeData *data, ITextureSource *tsrc)
{
// 4-21ms for MAP_BLOCKSIZE=16
// 24-155ms for MAP_BLOCKSIZE=32
data->m_temp_mods,
data->m_vmanip,
blockpos_nodes,
- smooth_lighting);
+ smooth_lighting,
+ tsrc);
}
}
/*
data->m_temp_mods,
data->m_vmanip,
blockpos_nodes,
- smooth_lighting);
+ smooth_lighting,
+ tsrc);
}
}
/*
data->m_temp_mods,
data->m_vmanip,
blockpos_nodes,
- smooth_lighting);
+ smooth_lighting,
+ tsrc);
}
}
}
- whatever
*/
- mapblock_mesh_generate_special(data, collector);
+ mapblock_mesh_generate_special(data, collector, tsrc);
/*
Add stuff from collector to mesh
};
// This is the highest-level function in here
-scene::SMesh* makeMapBlockMesh(MeshMakeData *data);
+scene::SMesh* makeMapBlockMesh(MeshMakeData *data, ITextureSource *tsrc);
#endif
}
#ifndef SERVER
-TileSpec MapNode::getTile(v3s16 dir)
+TileSpec MapNode::getTile(v3s16 dir, ITextureSource *tsrc)
{
if(content_features(*this).param_type == CPT_FACEDIR_SIMPLE)
dir = facedir_rotate(param1, dir);
/*
If it contains some mineral, change texture id
*/
- if(content_features(*this).param_type == CPT_MINERAL && g_texturesource)
+ if(content_features(*this).param_type == CPT_MINERAL && tsrc)
{
u8 mineral = getMineral();
std::string mineral_texture_name = mineral_block_texture(mineral);
if(mineral_texture_name != "")
{
u32 orig_id = spec.texture.id;
- std::string texture_name = g_texturesource->getTextureName(orig_id);
+ std::string texture_name = tsrc->getTextureName(orig_id);
//texture_name += "^blit:";
texture_name += "^";
texture_name += mineral_texture_name;
- u32 new_id = g_texturesource->getTextureId(texture_name);
- spec.texture = g_texturesource->getTexture(new_id);
+ u32 new_id = tsrc->getTextureId(texture_name);
+ spec.texture = tsrc->getTexture(new_id);
}
}
Returns: TileSpec. Can contain miscellaneous texture coordinates,
which must be obeyed so that the texture atlas can be used.
*/
- TileSpec getTile(v3s16 dir);
+ TileSpec getTile(v3s16 dir, ITextureSource *tsrc);
#endif
/*
#include "mapnode_contentfeatures.h"
-#include "main.h" // For g_settings and g_texturesource
+#include "main.h" // For g_settings
#include "nodemetadata.h"
+#ifndef SERVER
+#include "tile.h"
+#endif
struct ContentFeatures g_content_features[MAX_CONTENT+1];
Must be called before accessing the table.
*/
-void init_contentfeatures()
+void init_contentfeatures(ITextureSource *tsrc)
{
#ifndef SERVER
/*
if(i == CONTENT_IGNORE || i == CONTENT_AIR)
continue;
ContentFeatures *f = &g_content_features[i];
- f->setAllTextures("unknown_block.png");
+ f->setAllTextures(tsrc, "unknown_block.png");
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
}
}
#ifndef SERVER
-void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha)
+void ContentFeatures::setTexture(ITextureSource *tsrc,
+ u16 i, std::string name, u8 alpha)
{
used_texturenames[name] = true;
- if(g_texturesource)
+ if(tsrc)
{
- tiles[i].texture = g_texturesource->getTexture(name);
+ tiles[i].texture = tsrc->getTexture(name);
}
if(alpha != 255)
}
if(inventory_texture == NULL)
- setInventoryTexture(name);
+ setInventoryTexture(name, tsrc);
}
-void ContentFeatures::setInventoryTexture(std::string imgname)
+void ContentFeatures::setInventoryTexture(std::string imgname,
+ ITextureSource *tsrc)
{
- if(g_texturesource == NULL)
+ if(tsrc == NULL)
return;
imgname += "^[forcesingle";
- inventory_texture = g_texturesource->getTextureRaw(imgname);
+ inventory_texture = tsrc->getTextureRaw(imgname);
}
void ContentFeatures::setInventoryTextureCube(std::string top,
- std::string left, std::string right)
+ std::string left, std::string right, ITextureSource *tsrc)
{
- if(g_texturesource == NULL)
+ if(tsrc == NULL)
return;
str_replace_char(top, '^', '&');
imgname_full += left;
imgname_full += "{";
imgname_full += right;
- inventory_texture = g_texturesource->getTextureRaw(imgname_full);
+ inventory_texture = tsrc->getTextureRaw(imgname_full);
}
#endif
#include "tile.h"
#endif
#include "materials.h" // MaterialProperties
+class ITextureSource;
/*
Content feature list
Must be called before accessing the table.
*/
-void init_contentfeatures();
+void init_contentfeatures(ITextureSource *tsrc);
enum ContentParamType
{
*/
#ifdef SERVER
- void setTexture(u16 i, std::string name, u8 alpha=255)
+ void setTexture(ITextureSource *tsrc, u16 i, std::string name,
+ u8 alpha=255)
{}
- void setAllTextures(std::string name, u8 alpha=255)
+ void setAllTextures(ITextureSource *tsrc, std::string name, u8 alpha=255)
{}
#else
- void setTexture(u16 i, std::string name, u8 alpha=255);
+ void setTexture(ITextureSource *tsrc,
+ u16 i, std::string name, u8 alpha=255);
- void setAllTextures(std::string name, u8 alpha=255)
+ void setAllTextures(ITextureSource *tsrc,
+ std::string name, u8 alpha=255)
{
for(u16 i=0; i<6; i++)
{
- setTexture(i, name, alpha);
+ setTexture(tsrc, i, name, alpha);
}
// Force inventory texture too
- setInventoryTexture(name);
+ setInventoryTexture(name, tsrc);
}
#endif
#endif
#ifdef SERVER
- void setInventoryTexture(std::string imgname)
+ void setInventoryTexture(std::string imgname,
+ ITextureSource *tsrc)
{}
void setInventoryTextureCube(std::string top,
- std::string left, std::string right)
+ std::string left, std::string right, ITextureSource *tsrc)
{}
#else
- void setInventoryTexture(std::string imgname);
+ void setInventoryTexture(std::string imgname, ITextureSource *tsrc);
void setInventoryTextureCube(std::string top,
- std::string left, std::string right);
+ std::string left, std::string right, ITextureSource *tsrc);
#endif
};
#include "mapnode_contentfeatures.h"
#include "tool.h"
-DiggingProperties getDiggingProperties(u16 material, const std::string &tool)
+DiggingProperties getDiggingProperties(u16 material, ToolDiggingProperties *tp)
{
+ assert(tp);
MaterialProperties &mp = content_features(material).material;
if(mp.diggability == DIGGABLE_NOT)
return DiggingProperties(false, 0, 0);
if(mp.diggability == DIGGABLE_CONSTANT)
return DiggingProperties(true, mp.constant_time, 0);
- ToolDiggingProperties tp = tool_get_digging_properties(tool);
-
- float time = tp.basetime;
- time += tp.dt_weight * mp.weight;
- time += tp.dt_crackiness * mp.crackiness;
- time += tp.dt_crumbliness * mp.crumbliness;
- time += tp.dt_cuttability * mp.cuttability;
+ float time = tp->basetime;
+ time += tp->dt_weight * mp.weight;
+ time += tp->dt_crackiness * mp.crackiness;
+ time += tp->dt_crumbliness * mp.crumbliness;
+ time += tp->dt_cuttability * mp.cuttability;
if(time < 0.2)
time = 0.2;
- float durability = tp.basedurability;
- durability += tp.dd_weight * mp.weight;
- durability += tp.dd_crackiness * mp.crackiness;
- durability += tp.dd_crumbliness * mp.crumbliness;
- durability += tp.dd_cuttability * mp.cuttability;
+ float durability = tp->basedurability;
+ durability += tp->dd_weight * mp.weight;
+ durability += tp->dd_crackiness * mp.crackiness;
+ durability += tp->dd_crumbliness * mp.crumbliness;
+ durability += tp->dd_cuttability * mp.cuttability;
if(durability < 1)
durability = 1;
u16 wear;
};
-// Tool "" is bare hands
-DiggingProperties getDiggingProperties(u16 material, const std::string &tool);
+class ToolDiggingProperties;
+
+DiggingProperties getDiggingProperties(u16 material, ToolDiggingProperties *tp);
#endif
std::string mineral_block_texture(u8 mineral);
-inline CraftItem * getDiggedMineralItem(u8 mineral)
+class IGameDef;
+
+inline CraftItem * getDiggedMineralItem(u8 mineral, IGameDef *gamedef)
{
if(mineral == MINERAL_COAL)
- return new CraftItem("lump_of_coal", 1);
+ return new CraftItem(gamedef, "lump_of_coal", 1);
else if(mineral == MINERAL_IRON)
- return new CraftItem("lump_of_iron", 1);
+ return new CraftItem(gamedef, "lump_of_iron", 1);
return NULL;
}
core::map<u16, NodeMetadata::Factory> NodeMetadata::m_types;
-NodeMetadata::NodeMetadata()
+NodeMetadata::NodeMetadata(IGameDef *gamedef):
+ m_gamedef(gamedef)
{
}
{
}
-NodeMetadata* NodeMetadata::deSerialize(std::istream &is)
+NodeMetadata* NodeMetadata::deSerialize(std::istream &is, IGameDef *gamedef)
{
// Read id
u8 buf[2];
std::istringstream iss(data, std::ios_base::binary);
Factory f = n->getValue();
- NodeMetadata *meta = (*f)(iss);
+ NodeMetadata *meta = (*f)(iss, gamedef);
return meta;
}
catch(SerializationError &e)
}
}
-void NodeMetadataList::deSerialize(std::istream &is)
+void NodeMetadataList::deSerialize(std::istream &is, IGameDef *gamedef)
{
m_data.clear();
p16 -= p.Y * MAP_BLOCKSIZE;
p.X += p16;
- NodeMetadata *data = NodeMetadata::deSerialize(is);
+ NodeMetadata *data = NodeMetadata::deSerialize(is, gamedef);
if(data == NULL)
continue;
*/
class Inventory;
+class IGameDef;
class NodeMetadata
{
public:
- typedef NodeMetadata* (*Factory)(std::istream&);
+ typedef NodeMetadata* (*Factory)(std::istream&, IGameDef *gamedef);
- NodeMetadata();
+ NodeMetadata(IGameDef *gamedef);
virtual ~NodeMetadata();
- static NodeMetadata* deSerialize(std::istream &is);
+ static NodeMetadata* deSerialize(std::istream &is, IGameDef *gamedef);
void serialize(std::ostream &os);
// This usually is the CONTENT_ value
virtual u16 typeId() const = 0;
- virtual NodeMetadata* clone() = 0;
+ virtual NodeMetadata* clone(IGameDef *gamedef) = 0;
virtual void serializeBody(std::ostream &os) = 0;
virtual std::string infoText() {return "";}
virtual Inventory* getInventory() {return NULL;}
virtual void setText(const std::string &t){}
protected:
static void registerType(u16 id, Factory f);
+ IGameDef *m_gamedef;
private:
static core::map<u16, Factory> m_types;
};
~NodeMetadataList();
void serialize(std::ostream &os);
- void deSerialize(std::istream &is);
+ void deSerialize(std::istream &is, IGameDef *gamedef);
// Get pointer to data
NodeMetadata* get(v3s16 p);
#ifndef SERVER
#include <ITextSceneNode.h>
#endif
+#include "main.h" // For g_settings
#include "settings.h"
#include "mapnode_contentfeatures.h"
inventory.serialize(os);
}
-void Player::deSerialize(std::istream &is)
+void Player::deSerialize(std::istream &is, IGameDef *gamedef)
{
Settings args;
hp = 20;
}
- inventory.deSerialize(is);
+ inventory.deSerialize(is, gamedef);
}
/*
deSerialize stops reading exactly at the right point.
*/
void serialize(std::ostream &os);
- void deSerialize(std::istream &is);
+ void deSerialize(std::istream &is, IGameDef *gamedef);
bool touching_ground;
// This oscillates so that the player jumps a bit above the surface
class ServerRemotePlayer : public Player, public ServerActiveObject
{
public:
- ServerRemotePlayer():
- ServerActiveObject(NULL, v3f(0,0,0))
+ ServerRemotePlayer(ServerEnvironment *env):
+ ServerActiveObject(env, v3f(0,0,0))
{
}
ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 peer_id_,
<<" itemstring=\""<<itemstring<<"\""<<std::endl;
// Do it
std::istringstream is(itemstring, std::ios::binary);
- InventoryItem *item = InventoryItem::deSerialize(is);
+ ServerEnvironment *env = co->getEnv();
+ assert(env);
+ IGameDef *gamedef = env->getGameDef();
+ InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
+ infostream<<"item="<<env<<std::endl;
bool fits = co->addToInventory(item);
// Return
lua_pushboolean(L, fits);
};
// Creates a new anonymous reference if id=0
-static void objectref_get_or_create(lua_State *L, ServerActiveObject *cobj)
+static void objectref_get_or_create(lua_State *L,
+ ServerActiveObject *cobj)
{
if(cobj->getId() == 0){
ObjectRef::create(L, cobj);
class ServerActiveObject;
typedef struct lua_State lua_State;
struct LuaEntityProperties;
+//class IGameDef;
void scriptapi_export(lua_State *L, Server *server);
void scriptapi_add_environment(lua_State *L, ServerEnvironment *env);
LuaEntityProperties *prop);
void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime);
void scriptapi_luaentity_punch(lua_State *L, u16 id,
- ServerActiveObject *clicker);
+ ServerActiveObject *puncher);
void scriptapi_luaentity_rightclick(lua_State *L, u16 id,
ServerActiveObject *clicker);
#include "script.h"
#include "scriptapi.h"
#include "mapnode_contentfeatures.h"
+#include "tool.h"
+#include "content_tool.h" // For content_tool_init
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
m_authmanager(mapsavedir+DIR_DELIM+"auth.txt"),
m_banmanager(mapsavedir+DIR_DELIM+"ipban.txt"),
m_lua(NULL),
- //m_scriptapi(NULL),
+ m_toolmgr(createToolDefManager()),
m_thread(this),
m_emergethread(this),
m_time_counter(0),
JMutexAutoLock envlock(m_env_mutex);
JMutexAutoLock conlock(m_con_mutex);
+ // Initialize default tool definitions
+ content_tool_init(m_toolmgr);
+
// Initialize scripting
infostream<<"Server: Initializing scripting"<<std::endl;
// Initialize Environment
- m_env = new ServerEnvironment(new ServerMap(mapsavedir), m_lua);
+ m_env = new ServerEnvironment(new ServerMap(mapsavedir, this), m_lua, this);
// Give environment reference to scripting api
scriptapi_add_environment(m_lua, m_env);
// Delete Environment
delete m_env;
+
+ delete m_toolmgr;
// Deinitialize scripting
infostream<<"Server: Deinitializing scripting"<<std::endl;
std::string toolname = titem->getToolName();
// Get digging properties for material and tool
+ ToolDiggingProperties tp =
+ m_toolmgr->getDiggingProperties(toolname);
DiggingProperties prop =
- getDiggingProperties(material, toolname);
+ getDiggingProperties(material, &tp);
if(prop.diggable == false)
{
InventoryItem *item = NULL;
if(mineral != MINERAL_NONE)
- item = getDiggedMineralItem(mineral);
+ item = getDiggedMineralItem(mineral, this);
// If not mineral
if(item == NULL)
if(dug_s != "")
{
std::istringstream is(dug_s, std::ios::binary);
- item = InventoryItem::deSerialize(is);
+ item = InventoryItem::deSerialize(is, this);
}
}
item = NULL;
if(mineral != MINERAL_NONE)
- item = getDiggedMineralItem(mineral);
+ item = getDiggedMineralItem(mineral, this);
// If not mineral
if(item == NULL)
&& myrand() % extra_rarity == 0)
{
std::istringstream is(extra_dug_s, std::ios::binary);
- item = InventoryItem::deSerialize(is);
+ item = InventoryItem::deSerialize(is, this);
}
}
}
// Get result of crafting grid
- InventoryItem *result = craft_get_result(items);
+ InventoryItem *result = craft_get_result(items, this);
if(result)
rlist->addItem(result);
}
player->inventory_backup = new Inventory();
*(player->inventory_backup) = player->inventory;
// Set creative inventory
- craft_set_creative_inventory(player);
+ craft_set_creative_inventory(player, this);
}
return player;
player->inventory_backup = new Inventory();
*(player->inventory_backup) = player->inventory;
// Set creative inventory
- craft_set_creative_inventory(player);
+ craft_set_creative_inventory(player, this);
}
else if(g_settings->getBool("give_initial_stuff"))
{
- craft_give_initial_stuff(player);
+ craft_give_initial_stuff(player, this);
}
return player;
#include "inventory.h"
#include "auth.h"
#include "ban.h"
+#include "gamedef.h"
struct LuaState;
typedef struct lua_State lua_State;
+class IToolDefManager;
/*
Some random functions
};
class Server : public con::PeerHandler, public MapEventReceiver,
- public InventoryManager
+ public InventoryManager, public IGameDef
{
public:
/*
// Envlock and conlock should be locked when using Lua
lua_State *getLua(){ return m_lua; }
+
+ // IGameDef interface
+ // Under envlock
+ virtual IToolDefManager* getToolDefManager()
+ { return m_toolmgr; }
+ virtual INodeDefManager* getNodeDefManager()
+ { assert(0); return NULL; } // TODO
private:
// Scripting
// Envlock and conlock should be locked when using Lua
lua_State *m_lua;
+
+ // Tool definition manager
+ IToolDefManager *m_toolmgr;
/*
Threads
*/
u16 m_ignore_map_edit_events_peer_id;
- Profiler *m_profiler;
-
friend class EmergeThread;
friend class RemoteClient;
};
#include "servercommand.h"
#include "utility.h"
#include "settings.h"
+#include "main.h" // For g_settings
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
Profiler main_profiler;
Profiler *g_profiler = &main_profiler;
-// A dummy thing
-ITextureSource *g_texturesource = NULL;
-
/*
Debug streams
*/
// Initialize stuff
- // Initialize content feature table
- init_contentfeatures();
- // Initialize mapnode content without textures (with g_texturesource=NULL)
- content_mapnode_init();
+ // Initialize content feature table without textures
+ init_contentfeatures(NULL);
+ // Initialize mapnode content without textures
+ content_mapnode_init(NULL);
init_mineral();
{
}
-void ServerActiveObject::addedToEnvironment(u16 id)
+void ServerActiveObject::addedToEnvironment()
{
- setId(id);
}
ServerActiveObject* ServerActiveObject::create(u8 type,
ServerActiveObject(ServerEnvironment *env, v3f pos);
virtual ~ServerActiveObject();
- virtual void addedToEnvironment(u16 id);
+ // Call after id has been set and has been inserted in environment
+ virtual void addedToEnvironment();
// Create a certain type of ServerActiveObject
static ServerActiveObject* create(u8 type,
*/
#include "tool.h"
+#include "irrlichttypes.h"
+#include "log.h"
+#include <ostream>
-std::string tool_get_imagename(const std::string &toolname)
+class CToolDefManager: public IToolDefManager
{
- if(toolname == "WPick")
- return "tool_woodpick.png";
- else if(toolname == "STPick")
- return "tool_stonepick.png";
- else if(toolname == "SteelPick")
- return "tool_steelpick.png";
- else if(toolname == "MesePick")
- return "tool_mesepick.png";
- else if(toolname == "WShovel")
- return "tool_woodshovel.png";
- else if(toolname == "STShovel")
- return "tool_stoneshovel.png";
- else if(toolname == "SteelShovel")
- return "tool_steelshovel.png";
- else if(toolname == "WAxe")
- return "tool_woodaxe.png";
- else if(toolname == "STAxe")
- return "tool_stoneaxe.png";
- else if(toolname == "SteelAxe")
- return "tool_steelaxe.png";
- else if(toolname == "WSword")
- return "tool_woodsword.png";
- else if(toolname == "STSword")
- return "tool_stonesword.png";
- else if(toolname == "SteelSword")
- return "tool_steelsword.png";
- else
- return "cloud.png";
-}
+public:
+ virtual ~CToolDefManager()
+ {
+ for(core::map<std::string, ToolDefinition*>::Iterator
+ i = m_tool_definitions.getIterator();
+ i.atEnd() == false; i++){
+ delete i.getNode()->getValue();
+ }
+ }
+ virtual bool registerTool(std::string toolname, const ToolDefinition &def)
+ {
+ infostream<<"registerTool: registering tool \""<<toolname<<"\""<<std::endl;
+ core::map<std::string, ToolDefinition*>::Node *n;
+ n = m_tool_definitions.find(toolname);
+ if(n != NULL){
+ errorstream<<"registerTool: registering tool \""<<toolname
+ <<"\" failed: name is already registered"<<std::endl;
+ return false;
+ }
+ m_tool_definitions[toolname] = new ToolDefinition(def);
+ return true;
+ }
+ virtual ToolDefinition* getToolDefinition(const std::string &toolname)
+ {
+ core::map<std::string, ToolDefinition*>::Node *n;
+ n = m_tool_definitions.find(toolname);
+ if(n == NULL)
+ return NULL;
+ return n->getValue();
+ }
+ virtual std::string getImagename(const std::string &toolname)
+ {
+ ToolDefinition *def = getToolDefinition(toolname);
+ if(def == NULL)
+ return "";
+ return def->imagename;
+ }
+ virtual ToolDiggingProperties getDiggingProperties(
+ const std::string &toolname)
+ {
+ ToolDefinition *def = getToolDefinition(toolname);
+ // If tool does not exist, just return an impossible
+ if(def == NULL){
+ // If tool does not exist, try empty name
+ ToolDefinition *def = getToolDefinition("");
+ if(def == NULL) // If that doesn't exist either, return default
+ return ToolDiggingProperties();
+ return def->properties;
+ }
+ return def->properties;
+ }
+private:
+ // Key is name
+ core::map<std::string, ToolDefinition*> m_tool_definitions;
+};
-ToolDiggingProperties tool_get_digging_properties(const std::string &toolname)
+IToolDefManager* createToolDefManager()
{
- // weight, crackiness, crumbleness, cuttability
- if(toolname == "WPick")
- return ToolDiggingProperties(2.0, 0,-1,2,0, 50, 0,0,0,0);
- else if(toolname == "STPick")
- return ToolDiggingProperties(1.5, 0,-1,2,0, 100, 0,0,0,0);
- else if(toolname == "SteelPick")
- return ToolDiggingProperties(1.0, 0,-1,2,0, 300, 0,0,0,0);
-
- else if(toolname == "MesePick")
- return ToolDiggingProperties(0, 0,0,0,0, 1337, 0,0,0,0);
-
- else if(toolname == "WShovel")
- return ToolDiggingProperties(2.0, 0.5,2,-1.5,0.3, 50, 0,0,0,0);
- else if(toolname == "STShovel")
- return ToolDiggingProperties(1.5, 0.5,2,-1.5,0.1, 100, 0,0,0,0);
- else if(toolname == "SteelShovel")
- return ToolDiggingProperties(1.0, 0.5,2,-1.5,0.0, 300, 0,0,0,0);
-
- // weight, crackiness, crumbleness, cuttability
- else if(toolname == "WAxe")
- return ToolDiggingProperties(2.0, 0.5,-0.2,1,-0.5, 50, 0,0,0,0);
- else if(toolname == "STAxe")
- return ToolDiggingProperties(1.5, 0.5,-0.2,1,-0.5, 100, 0,0,0,0);
- else if(toolname == "SteelAxe")
- return ToolDiggingProperties(1.0, 0.5,-0.2,1,-0.5, 300, 0,0,0,0);
-
- else if(toolname == "WSword")
- return ToolDiggingProperties(3.0, 3,0,1,-1, 50, 0,0,0,0);
- else if(toolname == "STSword")
- return ToolDiggingProperties(2.5, 3,0,1,-1, 100, 0,0,0,0);
- else if(toolname == "SteelSword")
- return ToolDiggingProperties(2.0, 3,0,1,-1, 300, 0,0,0,0);
-
- // Properties of hand
- return ToolDiggingProperties(0.5, 1,0,-1,0, 50, 0,0,0,0);
+ return new CToolDefManager();
}
-
{}
};
-std::string tool_get_imagename(const std::string &toolname);
+struct ToolDefinition
+{
+ std::string imagename;
+ ToolDiggingProperties properties;
+
+ ToolDefinition(){}
+ ToolDefinition(const std::string &imagename_,
+ ToolDiggingProperties properties_):
+ imagename(imagename_),
+ properties(properties_)
+ {}
+};
+
+class IToolDefManager
+{
+public:
+ IToolDefManager(){}
+ virtual ~IToolDefManager(){}
+ virtual bool registerTool(std::string toolname, const ToolDefinition &def)=0;
+ virtual ToolDefinition* getToolDefinition(const std::string &toolname)=0;
+ virtual std::string getImagename(const std::string &toolname)=0;
+ virtual ToolDiggingProperties getDiggingProperties(
+ const std::string &toolname)=0;
+};
-ToolDiggingProperties tool_get_digging_properties(const std::string &toolname);
+IToolDefManager* createToolDefManager();
#endif