aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/camera.cpp4
-rw-r--r--src/camera.h3
-rw-r--r--src/client.cpp28
-rw-r--r--src/client.h38
-rw-r--r--src/clientobject.cpp9
-rw-r--r--src/clientobject.h11
-rw-r--r--src/content_cao.cpp94
-rw-r--r--src/content_cao.h42
-rw-r--r--src/content_craft.cpp112
-rw-r--r--src/content_craft.h7
-rw-r--r--src/content_inventory.cpp33
-rw-r--r--src/content_inventory.h24
-rw-r--r--src/content_mapblock.cpp42
-rw-r--r--src/content_mapblock.h3
-rw-r--r--src/content_mapnode.cpp226
-rw-r--r--src/content_mapnode.h11
-rw-r--r--src/content_nodemeta.cpp58
-rw-r--r--src/content_nodemeta.h24
-rw-r--r--src/content_sao.cpp20
-rw-r--r--src/content_sao.h2
-rw-r--r--src/content_tool.cpp68
-rw-r--r--src/content_tool.h24
-rw-r--r--src/environment.cpp35
-rw-r--r--src/environment.h40
-rw-r--r--src/game.cpp43
-rw-r--r--src/gamedef.h42
-rw-r--r--src/guiInventoryMenu.cpp17
-rw-r--r--src/guiInventoryMenu.h11
-rw-r--r--src/inventory.cpp90
-rw-r--r--src/inventory.h80
-rw-r--r--src/main.cpp33
-rw-r--r--src/main.h4
-rw-r--r--src/map.cpp27
-rw-r--r--src/map.h20
-rw-r--r--src/mapblock.cpp10
-rw-r--r--src/mapblock.h6
-rw-r--r--src/mapblock_mesh.cpp38
-rw-r--r--src/mapblock_mesh.h2
-rw-r--r--src/mapnode.cpp10
-rw-r--r--src/mapnode.h2
-rw-r--r--src/mapnode_contentfeatures.cpp31
-rw-r--r--src/mapnode_contentfeatures.h27
-rw-r--r--src/materials.cpp25
-rw-r--r--src/materials.h5
-rw-r--r--src/mineral.h8
-rw-r--r--src/nodemetadata.cpp11
-rw-r--r--src/nodemetadata.h12
-rw-r--r--src/player.cpp5
-rw-r--r--src/player.h6
-rw-r--r--src/scriptapi.cpp9
-rw-r--r--src/scriptapi.h3
-rw-r--r--src/server.cpp31
-rw-r--r--src/server.h16
-rw-r--r--src/servercommand.cpp1
-rw-r--r--src/servermain.cpp11
-rw-r--r--src/serverobject.cpp3
-rw-r--r--src/serverobject.h3
-rw-r--r--src/tool.cpp128
-rw-r--r--src/tool.h27
60 files changed, 1015 insertions, 741 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cc783855c..550bd1f55 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -94,6 +94,7 @@ configure_file(
)
set(common_SRCS
+ content_tool.cpp
tool.cpp
mapnode_contentfeatures.cpp
luaentity_common.cpp
diff --git a/src/camera.cpp b/src/camera.cpp
index 8188eaf61..d001f8916 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -449,7 +449,7 @@ void Camera::updateSettings()
m_wanted_frametime = 1.0 / wanted_fps;
}
-void Camera::wield(const InventoryItem* item)
+void Camera::wield(const InventoryItem* item, ITextureSource *tsrc)
{
if (item != NULL)
{
@@ -472,7 +472,7 @@ void Camera::wield(const InventoryItem* item)
// 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));
}
diff --git a/src/camera.h b/src/camera.h
index b6349d2c8..29b9fbdaa 100644
--- a/src/camera.h
+++ b/src/camera.h
@@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class LocalPlayer;
class MapDrawControl;
class ExtrudedSpriteSceneNode;
+class ITextureSource;
/*
Client camera class, manages the player and camera scene nodes, the viewing distance
@@ -115,7 +116,7 @@ public:
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
diff --git a/src/client.cpp b/src/client.cpp
index 80d7febe6..876d22e8b 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -160,7 +160,7 @@ void * MeshUpdateThread::Thread()
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;
@@ -185,13 +185,18 @@ Client::Client(
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),
@@ -863,7 +868,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
Update an existing block
*/
//infostream<<"Updating"<<std::endl;
- block->deSerialize(istr, ser_version);
+ block->deSerialize(istr, ser_version, this);
}
else
{
@@ -872,7 +877,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
*/
//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
@@ -1157,7 +1162,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
//t4.stop();
//TimeTaker t1("inventory.deSerialize()", m_device);
- player->inventory.deSerialize(is);
+ player->inventory.deSerialize(is, this);
//t1.stop();
m_inventory_updated = true;
@@ -1464,7 +1469,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
<< 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;
@@ -2041,7 +2047,7 @@ void Client::setTempMod(v3s16 p, NodeMod mod)
i = affected_blocks.getIterator();
i.atEnd() == false; i++)
{
- i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio());
+ i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio(), m_tsrc);
}
}
@@ -2058,7 +2064,7 @@ void Client::clearTempMod(v3s16 p)
i = affected_blocks.getIterator();
i.atEnd() == false; i++)
{
- i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio());
+ i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio(), m_tsrc);
}
}
diff --git a/src/client.h b/src/client.h
index 8585f6d4a..d41603c9d 100644
--- a/src/client.h
+++ b/src/client.h
@@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <ostream>
#include "clientobject.h"
#include "utility.h" // For IntervalLimiter
+#include "gamedef.h"
struct MeshMakeData;
@@ -98,7 +99,8 @@ class MeshUpdateThread : public SimpleThread
{
public:
- MeshUpdateThread()
+ MeshUpdateThread(ITextureSource *tsrc):
+ m_tsrc(tsrc)
{
}
@@ -107,6 +109,8 @@ public:
MeshUpdateQueue m_queue_in;
MutexedQueue<MeshUpdateResult> m_queue_out;
+
+ ITextureSource *m_tsrc;
};
enum ClientEventType
@@ -139,7 +143,7 @@ struct ClientEvent
};
};
-class Client : public con::PeerHandler, public InventoryManager
+class Client : public con::PeerHandler, public InventoryManager, public IGameDef
{
public:
/*
@@ -150,8 +154,10 @@ public:
IrrlichtDevice *device,
const char *playername,
std::string password,
- MapDrawControl &control
- );
+ MapDrawControl &control,
+ ITextureSource *tsrc,
+ IToolDefManager *toolmgr
+ );
~Client();
/*
@@ -303,6 +309,13 @@ public:
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
@@ -325,44 +338,31 @@ private:
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;
};
diff --git a/src/clientobject.cpp b/src/clientobject.cpp
index ee2ad0b9f..7dec1903e 100644
--- a/src/clientobject.cpp
+++ b/src/clientobject.cpp
@@ -26,8 +26,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
ClientActiveObject
*/
-ClientActiveObject::ClientActiveObject(u16 id):
- ActiveObject(id)
+ClientActiveObject::ClientActiveObject(u16 id, IGameDef *gamedef):
+ ActiveObject(id),
+ m_gamedef(gamedef)
{
}
@@ -36,7 +37,7 @@ ClientActiveObject::~ClientActiveObject()
removeFromScene();
}
-ClientActiveObject* ClientActiveObject::create(u8 type)
+ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef)
{
// Find factory function
core::map<u16, Factory>::Node *n;
@@ -50,7 +51,7 @@ ClientActiveObject* ClientActiveObject::create(u8 type)
}
Factory f = n->getValue();
- ClientActiveObject *object = (*f)();
+ ClientActiveObject *object = (*f)(gamedef);
return object;
}
diff --git a/src/clientobject.h b/src/clientobject.h
index 60d293ff4..0b3d8623a 100644
--- a/src/clientobject.h
+++ b/src/clientobject.h
@@ -36,14 +36,16 @@ Some planning
*/
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){}
@@ -68,7 +70,7 @@ public:
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)
@@ -76,8 +78,9 @@ public:
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;
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index e007c5f37..c6ec0761a 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -30,10 +30,10 @@ core::map<u16, ClientActiveObject::Factory> ClientActiveObject::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))
{
@@ -44,12 +44,12 @@ TestCAO::~TestCAO()
{
}
-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;
@@ -146,10 +146,10 @@ void TestCAO::processMessage(const std::string &data)
#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))
@@ -161,12 +161,12 @@ ItemCAO::~ItemCAO()
{
}
-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;
@@ -218,13 +218,13 @@ void ItemCAO::addToScene(scene::ISceneManager *smgr)
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;
}
}
@@ -327,10 +327,10 @@ void ItemCAO::initialize(const std::string &data)
#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)),
@@ -343,12 +343,12 @@ RatCAO::~RatCAO()
{
}
-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;
@@ -473,10 +473,10 @@ void RatCAO::initialize(const std::string &data)
#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)),
@@ -491,12 +491,12 @@ Oerkki1CAO::~Oerkki1CAO()
{
}
-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;
@@ -712,10 +712,10 @@ bool Oerkki1CAO::directReportPunch(const std::string &toolname, v3f dir)
*/
// 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)),
@@ -728,12 +728,12 @@ FireflyCAO::~FireflyCAO()
{
}
-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;
@@ -856,10 +856,10 @@ void FireflyCAO::initialize(const std::string &data)
*/
// 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)),
@@ -888,12 +888,12 @@ MobV2CAO::~MobV2CAO()
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;
@@ -905,7 +905,7 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr)
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);
@@ -1271,10 +1271,10 @@ void MobV2CAO::setLooks(const std::string &looks)
#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),
@@ -1290,12 +1290,12 @@ LuaEntityCAO::~LuaEntityCAO()
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;
@@ -1310,7 +1310,7 @@ void LuaEntityCAO::addToScene(scene::ISceneManager *smgr)
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);
@@ -1389,7 +1389,7 @@ void LuaEntityCAO::addToScene(scene::ISceneManager *smgr)
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;
diff --git a/src/content_cao.h b/src/content_cao.h
index 5310127a6..3a3fbbcda 100644
--- a/src/content_cao.h
+++ b/src/content_cao.h
@@ -115,7 +115,7 @@ struct SmoothTranslator
class TestCAO : public ClientActiveObject
{
public:
- TestCAO();
+ TestCAO(IGameDef *gamedef);
virtual ~TestCAO();
u8 getType() const
@@ -123,9 +123,9 @@ public:
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();
@@ -147,7 +147,7 @@ private:
class ItemCAO : public ClientActiveObject
{
public:
- ItemCAO();
+ ItemCAO(IGameDef *gamedef);
virtual ~ItemCAO();
u8 getType() const
@@ -155,9 +155,9 @@ public:
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();
@@ -188,7 +188,7 @@ private:
class RatCAO : public ClientActiveObject
{
public:
- RatCAO();
+ RatCAO(IGameDef *gamedef);
virtual ~RatCAO();
u8 getType() const
@@ -196,9 +196,9 @@ public:
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();
@@ -231,7 +231,7 @@ private:
class Oerkki1CAO : public ClientActiveObject
{
public:
- Oerkki1CAO();
+ Oerkki1CAO(IGameDef *gamedef);
virtual ~Oerkki1CAO();
u8 getType() const
@@ -239,9 +239,9 @@ public:
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();
@@ -280,7 +280,7 @@ private:
class FireflyCAO : public ClientActiveObject
{
public:
- FireflyCAO();
+ FireflyCAO(IGameDef *gamedef);
virtual ~FireflyCAO();
u8 getType() const
@@ -288,9 +288,9 @@ public:
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();
@@ -322,7 +322,7 @@ private:
class MobV2CAO : public ClientActiveObject
{
public:
- MobV2CAO();
+ MobV2CAO(IGameDef *gamedef);
virtual ~MobV2CAO();
u8 getType() const
@@ -330,9 +330,9 @@ public:
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();
@@ -396,7 +396,7 @@ struct LuaEntityProperties;
class LuaEntityCAO : public ClientActiveObject
{
public:
- LuaEntityCAO();
+ LuaEntityCAO(IGameDef *gamedef);
virtual ~LuaEntityCAO();
u8 getType() const
@@ -404,9 +404,9 @@ public:
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();
diff --git a/src/content_craft.cpp b/src/content_craft.cpp
index 866c1e532..024fc6f09 100644
--- a/src/content_craft.cpp
+++ b/src/content_craft.cpp
@@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
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
{
@@ -35,7 +35,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_WOOD, 4);
+ return new MaterialItem(gamedef, CONTENT_WOOD, 4);
}
}
@@ -45,7 +45,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs))
{
- return new CraftItem("Stick", 4);
+ return new CraftItem(gamedef, "Stick", 4);
}
}
@@ -60,7 +60,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_FENCE, 2);
+ return new MaterialItem(gamedef, CONTENT_FENCE, 2);
}
}
@@ -76,8 +76,8 @@ InventoryItem *craft_get_result(InventoryItem **items)
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);
}
}
@@ -88,7 +88,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_TORCH, 4);
+ return new MaterialItem(gamedef, CONTENT_TORCH, 4);
}
}
@@ -102,7 +102,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("WPick", 0);
+ return new ToolItem(gamedef, "WPick", 0);
}
}
@@ -116,7 +116,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("STPick", 0);
+ return new ToolItem(gamedef, "STPick", 0);
}
}
@@ -130,7 +130,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("SteelPick", 0);
+ return new ToolItem(gamedef, "SteelPick", 0);
}
}
@@ -144,7 +144,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("MesePick", 0);
+ return new ToolItem(gamedef, "MesePick", 0);
}
}
@@ -156,7 +156,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("WShovel", 0);
+ return new ToolItem(gamedef, "WShovel", 0);
}
}
@@ -168,7 +168,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("STShovel", 0);
+ return new ToolItem(gamedef, "STShovel", 0);
}
}
@@ -180,7 +180,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("SteelShovel", 0);
+ return new ToolItem(gamedef, "SteelShovel", 0);
}
}
@@ -194,7 +194,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("WAxe", 0);
+ return new ToolItem(gamedef, "WAxe", 0);
}
}
@@ -208,7 +208,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("STAxe", 0);
+ return new ToolItem(gamedef, "STAxe", 0);
}
}
@@ -222,7 +222,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("SteelAxe", 0);
+ return new ToolItem(gamedef, "SteelAxe", 0);
}
}
@@ -234,7 +234,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("WSword", 0);
+ return new ToolItem(gamedef, "WSword", 0);
}
}
@@ -246,7 +246,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("STSword", 0);
+ return new ToolItem(gamedef, "STSword", 0);
}
}
@@ -258,7 +258,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new ToolItem("SteelSword", 0);
+ return new ToolItem(gamedef, "SteelSword", 0);
}
}
@@ -276,7 +276,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_RAIL, 15);
+ return new MaterialItem(gamedef, CONTENT_RAIL, 15);
}
}
@@ -293,7 +293,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_CHEST, 1);
+ return new MaterialItem(gamedef, CONTENT_CHEST, 1);
}
}
@@ -311,7 +311,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
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);
}
}
@@ -328,7 +328,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_FURNACE, 1);
+ return new MaterialItem(gamedef, CONTENT_FURNACE, 1);
}
}
@@ -346,7 +346,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_STEEL, 1);
+ return new MaterialItem(gamedef, CONTENT_STEEL, 1);
}
}
@@ -359,7 +359,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_SANDSTONE, 1);
+ return new MaterialItem(gamedef, CONTENT_SANDSTONE, 1);
}
}
@@ -372,7 +372,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
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);
}
}
@@ -385,7 +385,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "clay_brick");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_BRICK, 1);
+ return new MaterialItem(gamedef, CONTENT_BRICK, 1);
}
}
@@ -397,7 +397,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
if(checkItemCombination(items, specs))
{
- return new CraftItem("paper", 1);
+ return new CraftItem(gamedef, "paper", 1);
}
}
@@ -409,7 +409,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "paper");
if(checkItemCombination(items, specs))
{
- return new CraftItem("book", 1);
+ return new CraftItem(gamedef, "book", 1);
}
}
@@ -427,7 +427,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_BOOKSHELF, 1);
+ return new MaterialItem(gamedef, CONTENT_BOOKSHELF, 1);
}
}
@@ -443,7 +443,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
- return new MaterialItem(CONTENT_LADDER, 1);
+ return new MaterialItem(gamedef, CONTENT_LADDER, 1);
}
}
@@ -457,35 +457,35 @@ InventoryItem *craft_get_result(InventoryItem **items)
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);
}
@@ -528,7 +528,7 @@ void craft_set_creative_inventory(Player *player)
if(*mip == CONTENT_IGNORE)
break;
- InventoryItem *item = new MaterialItem(*mip, 1);
+ InventoryItem *item = new MaterialItem(gamedef, *mip, 1);
player->inventory.addItem("main", item);
mip++;
@@ -538,7 +538,7 @@ void craft_set_creative_inventory(Player *player)
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
@@ -549,86 +549,86 @@ void craft_set_creative_inventory(Player *player)
|| 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);
}*/
diff --git a/src/content_craft.h b/src/content_craft.h
index 7a8b4659a..9cffbe4aa 100644
--- a/src/content_craft.h
+++ b/src/content_craft.h
@@ -22,17 +22,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
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
diff --git a/src/content_inventory.cpp b/src/content_inventory.cpp
index 51c6f751e..349d47d5b 100644
--- a/src/content_inventory.cpp
+++ b/src/content_inventory.cpp
@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
//#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;
@@ -34,18 +34,20 @@ bool item_material_is_cookable(content_t content)
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";
@@ -103,7 +105,7 @@ ServerActiveObject* item_craft_create_object(const std::string &subname,
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;
@@ -111,7 +113,7 @@ s16 item_craft_get_drop_count(const std::string &subname)
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;
@@ -119,21 +121,22 @@ bool item_craft_is_cookable(const std::string &subname)
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;
@@ -144,7 +147,7 @@ bool item_craft_is_eatable(const std::string &subname)
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
diff --git a/src/content_inventory.h b/src/content_inventory.h
index 9fd4cb03b..0b384f15e 100644
--- a/src/content_inventory.h
+++ b/src/content_inventory.h
@@ -27,18 +27,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
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
diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp
index 4e9c65d41..ebb402475 100644
--- a/src/content_mapblock.cpp
+++ b/src/content_mapblock.cpp
@@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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"
@@ -122,7 +122,7 @@ void makeCuboid(video::SMaterial &material, MeshCollector *collector,
#ifndef SERVER
void mapblock_mesh_generate_special(MeshMakeData *data,
- MeshCollector &collector)
+ MeshCollector &collector, ITextureSource *tsrc)
{
// 0ms
//TimeTaker timer("mapblock_mesh_generate_special()");
@@ -147,8 +147,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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
@@ -157,8 +157,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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
@@ -167,8 +167,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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
@@ -186,8 +186,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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
@@ -196,8 +196,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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);
@@ -207,8 +207,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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);
@@ -218,8 +218,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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++)
@@ -249,7 +249,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
texturename = "torch.png";
}
- AtlasPointer ap = g_texturesource->getTexture(texturename);
+ AtlasPointer ap = tsrc->getTexture(texturename);
// Set material
video::SMaterial material;
@@ -304,7 +304,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
*/
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;
@@ -923,7 +923,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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);
@@ -1110,7 +1110,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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);
@@ -1182,7 +1182,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
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;
diff --git a/src/content_mapblock.h b/src/content_mapblock.h
index 438422014..6eb63af4f 100644
--- a/src/content_mapblock.h
+++ b/src/content_mapblock.h
@@ -23,8 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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
diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp
index 3bc0232e6..eff80f8af 100644
--- a/src/content_mapnode.cpp
+++ b/src/content_mapnode.cpp
@@ -156,16 +156,16 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
}
// 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");
@@ -178,8 +178,8 @@ void content_mapnode_init()
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;
@@ -190,9 +190,9 @@ void content_mapnode_init()
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";
@@ -200,9 +200,9 @@ void content_mapnode_init()
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";
@@ -210,8 +210,8 @@ void content_mapnode_init()
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";
@@ -219,8 +219,8 @@ void content_mapnode_init()
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";
@@ -228,8 +228,8 @@ void content_mapnode_init()
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";
@@ -237,8 +237,8 @@ void content_mapnode_init()
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";
@@ -246,8 +246,8 @@ void content_mapnode_init()
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");
@@ -255,8 +255,8 @@ void content_mapnode_init()
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");
@@ -264,9 +264,9 @@ void content_mapnode_init()
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";
@@ -274,9 +274,9 @@ void content_mapnode_init()
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";
@@ -284,7 +284,7 @@ void content_mapnode_init()
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;
@@ -305,12 +305,12 @@ void content_mapnode_init()
{
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;
@@ -319,10 +319,10 @@ void content_mapnode_init()
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";
@@ -330,7 +330,7 @@ void content_mapnode_init()
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;
@@ -342,12 +342,12 @@ void content_mapnode_init()
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);
@@ -361,8 +361,8 @@ void content_mapnode_init()
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;
@@ -373,13 +373,13 @@ void content_mapnode_init()
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;
@@ -393,7 +393,7 @@ void content_mapnode_init()
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;
@@ -410,30 +410,30 @@ void content_mapnode_init()
// 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";
@@ -451,7 +451,7 @@ void content_mapnode_init()
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
@@ -468,7 +468,7 @@ void content_mapnode_init()
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;
@@ -478,8 +478,8 @@ void content_mapnode_init()
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
@@ -493,8 +493,8 @@ void content_mapnode_init()
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
@@ -504,8 +504,8 @@ void content_mapnode_init()
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;
@@ -530,7 +530,7 @@ void content_mapnode_init()
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;
@@ -539,8 +539,8 @@ void content_mapnode_init()
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;
}
@@ -548,7 +548,7 @@ void content_mapnode_init()
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;
@@ -566,7 +566,7 @@ void content_mapnode_init()
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;
@@ -577,8 +577,8 @@ void content_mapnode_init()
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
@@ -592,7 +592,7 @@ void content_mapnode_init()
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)
{
@@ -603,8 +603,8 @@ void content_mapnode_init()
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;
@@ -627,7 +627,7 @@ void content_mapnode_init()
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;
@@ -637,8 +637,8 @@ void content_mapnode_init()
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;
@@ -647,7 +647,7 @@ void content_mapnode_init()
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;
@@ -672,7 +672,7 @@ void content_mapnode_init()
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;
@@ -683,54 +683,54 @@ void content_mapnode_init()
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";
@@ -738,8 +738,8 @@ void content_mapnode_init()
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";
@@ -747,9 +747,9 @@ void content_mapnode_init()
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";
@@ -758,25 +758,25 @@ void content_mapnode_init()
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;
@@ -787,7 +787,7 @@ void content_mapnode_init()
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;
diff --git a/src/content_mapnode.h b/src/content_mapnode.h
index b58119724..3946c1e4d 100644
--- a/src/content_mapnode.h
+++ b/src/content_mapnode.h
@@ -21,20 +21,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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];
diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp
index e6138a401..adaee33b4 100644
--- a/src/content_nodemeta.cpp
+++ b/src/content_nodemeta.cpp
@@ -27,9 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
// 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);
@@ -38,14 +39,14 @@ u16 SignNodeMetadata::typeId() const
{
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)
{
@@ -61,9 +62,10 @@ std::string SignNodeMetadata::infoText()
*/
// Prototype
-ChestNodeMetadata proto_ChestNodeMetadata;
+ChestNodeMetadata proto_ChestNodeMetadata(NULL);
-ChestNodeMetadata::ChestNodeMetadata()
+ChestNodeMetadata::ChestNodeMetadata(IGameDef *gamedef):
+ NodeMetadata(gamedef)
{
NodeMetadata::registerType(typeId(), create);
@@ -78,15 +80,15 @@ u16 ChestNodeMetadata::typeId() const
{
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;
}
@@ -123,9 +125,10 @@ std::string ChestNodeMetadata::getInventoryDrawSpecString()
*/
// Prototype
-LockingChestNodeMetadata proto_LockingChestNodeMetadata;
+LockingChestNodeMetadata proto_LockingChestNodeMetadata(NULL);
-LockingChestNodeMetadata::LockingChestNodeMetadata()
+LockingChestNodeMetadata::LockingChestNodeMetadata(IGameDef *gamedef):
+ NodeMetadata(gamedef)
{
NodeMetadata::registerType(typeId(), create);
@@ -140,16 +143,16 @@ u16 LockingChestNodeMetadata::typeId() const
{
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;
}
@@ -187,9 +190,10 @@ std::string LockingChestNodeMetadata::getInventoryDrawSpecString()
*/
// Prototype
-FurnaceNodeMetadata proto_FurnaceNodeMetadata;
+FurnaceNodeMetadata proto_FurnaceNodeMetadata(NULL);
-FurnaceNodeMetadata::FurnaceNodeMetadata()
+FurnaceNodeMetadata::FurnaceNodeMetadata(IGameDef *gamedef):
+ NodeMetadata(gamedef)
{
NodeMetadata::registerType(typeId(), create);
@@ -212,17 +216,17 @@ u16 FurnaceNodeMetadata::typeId() const
{
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;
diff --git a/src/content_nodemeta.h b/src/content_nodemeta.h
index da5639e72..86df882ea 100644
--- a/src/content_nodemeta.h
+++ b/src/content_nodemeta.h
@@ -27,12 +27,12 @@ class Inventory;
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();
@@ -47,12 +47,12 @@ private:
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;}
@@ -66,12 +66,12 @@ private:
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;}
@@ -89,12 +89,12 @@ private:
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;}
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 1096ac116..9c48e0707 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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;
@@ -223,7 +224,8 @@ InventoryItem * ItemSAO::createInventoryItem()
{
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;
@@ -448,7 +450,8 @@ std::string RatSAO::getStaticData()
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;
@@ -932,7 +935,8 @@ std::string FireflySAO::getStaticData()
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;
}
@@ -1563,13 +1567,14 @@ LuaEntitySAO::~LuaEntitySAO()
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
@@ -1660,7 +1665,8 @@ std::string LuaEntitySAO::getStaticData()
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;
}
diff --git a/src/content_sao.h b/src/content_sao.h
index 51911fe05..cd7474960 100644
--- a/src/content_sao.h
+++ b/src/content_sao.h
@@ -204,7 +204,7 @@ public:
~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);
diff --git a/src/content_tool.cpp b/src/content_tool.cpp
new file mode 100644
index 000000000..c7c5504f5
--- /dev/null
+++ b/src/content_tool.cpp
@@ -0,0 +1,68 @@
+/*
+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)));
+}
+
diff --git a/src/content_tool.h b/src/content_tool.h
new file mode 100644
index 000000000..66529d3ed
--- /dev/null
+++ b/src/content_tool.h
@@ -0,0 +1,24 @@
+/*
+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);
+
diff --git a/src/environment.cpp b/src/environment.cpp
index d9f24ede9..a7439e7bc 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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<<")"
@@ -270,9 +271,11 @@ void ActiveBlockList::update(core::list<v3s16> &active_positions,
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),
@@ -312,7 +315,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
//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);
@@ -321,7 +324,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
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;
@@ -426,7 +429,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
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);
@@ -435,7 +438,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
- testplayer.deSerialize(is);
+ testplayer.deSerialize(is, m_gamedef);
}
if(!string_allowed(testplayer.getName(), PLAYERNAME_ALLOWED_CHARS))
@@ -454,7 +457,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
if(player == NULL)
{
infostream<<"Is a new player"<<std::endl;
- player = new ServerRemotePlayer();
+ player = new ServerRemotePlayer(this);
newplayer = true;
}
@@ -469,7 +472,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
- player->deSerialize(is);
+ player->deSerialize(is, m_gamedef);
}
if(newplayer)
@@ -1507,7 +1510,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
// 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();
}
@@ -1862,9 +1865,12 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
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);
@@ -2166,9 +2172,9 @@ void ClientEnvironment::step(float dtime)
}
}
-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)
@@ -2242,14 +2248,15 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
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(): "
diff --git a/src/environment.h b/src/environment.h
index 7a4cc3777..754b63979 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
- The map
- Players
- Other objects
- - The current time in the game (actually it only contains the brightness)
+ - The current time in the game
- etc.
*/
@@ -42,6 +42,8 @@ class Server;
class ActiveBlockModifier;
class ServerActiveObject;
typedef struct lua_State lua_State;
+class ITextureSource;
+class IGameDef;
class Environment
{
@@ -127,23 +129,20 @@ private:
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()
{
@@ -218,6 +217,7 @@ public:
/*
ActiveBlockModifiers (TODO)
-------------------------------------------
+ NOTE: Not used currently (TODO: Use or remove)
*/
void addActiveBlockModifier(ActiveBlockModifier *abm);
@@ -277,6 +277,8 @@ private:
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
@@ -302,6 +304,8 @@ private:
These are fed into ServerEnvironment at initialization time;
ServerEnvironment handles deleting them.
+
+ NOTE: Not used currently (TODO: Use or remove)
*/
class ActiveBlockModifier
@@ -353,7 +357,8 @@ struct ClientEnvEvent
class ClientEnvironment : public Environment
{
public:
- ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr);
+ ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
+ ITextureSource *texturesource, IGameDef *gamedef);
~ClientEnvironment();
Map & getMap()
@@ -370,8 +375,9 @@ public:
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)
@@ -382,8 +388,8 @@ public:
if(getDayNightRatio() != old_dr)
{
- dout_client<<DTIME<<"ClientEnvironment: DayNightRatio changed"
- <<" -> expiring meshes"<<std::endl;
+ /*infostream<<"ClientEnvironment: DayNightRatio changed"
+ <<" -> expiring meshes"<<std::endl;*/
expireMeshes(true);
}
}
@@ -429,6 +435,8 @@ public:
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;
diff --git a/src/game.cpp b/src/game.cpp
index bd84593b8..43d09b316 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -46,6 +46,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// 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
@@ -153,6 +157,7 @@ private:
Hotbar draw routine
*/
void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
+ ITextureSource *tsrc,
v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
Inventory *inventory, s32 halfheartcount)
{
@@ -244,7 +249,7 @@ void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
if(item != NULL)
{
- drawInventoryItem(driver, font, item, rect, NULL);
+ drawInventoryItem(driver, font, item, rect, NULL, tsrc);
}
}
@@ -587,6 +592,21 @@ void the_game(
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.
@@ -606,7 +626,8 @@ void the_game(
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);
@@ -883,7 +904,7 @@ void the_game(
/*
Process TextureSource's queue
*/
- ((TextureSource*)g_texturesource)->processQueue();
+ tsrc->processQueue();
/*
Random calculations
@@ -1113,7 +1134,7 @@ void the_game(
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(
@@ -1672,8 +1693,10 @@ void the_game(
// 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;
@@ -1775,7 +1798,7 @@ void the_game(
new GUIInventoryMenu(guienv, guiroot, -1,
&g_menumgr, invsize,
client.getInventoryContext(),
- &client);
+ &client, tsrc);
menu->setDrawSpec(draw_spec);
menu->drop();
}
@@ -2079,7 +2102,7 @@ void the_game(
InventoryItem *item = NULL;
if(mlist != NULL)
item = mlist->getItem(g_selected_item);
- camera.wield(item);
+ camera.wield(item, tsrc);
}
/*
@@ -2202,7 +2225,8 @@ void the_game(
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());
}
@@ -2269,6 +2293,9 @@ void the_game(
driver->endScene();
gui_shuttingdowntext->remove();*/
}
+
+ delete toolmgr;
+ delete tsrc;
}
diff --git a/src/gamedef.h b/src/gamedef.h
new file mode 100644
index 000000000..86fd1e80f
--- /dev/null
+++ b/src/gamedef.h
@@ -0,0 +1,42 @@
+/*
+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
+
diff --git a/src/guiInventoryMenu.cpp b/src/guiInventoryMenu.cpp
index 7d49acaa2..4ed9c857c 100644
--- a/src/guiInventoryMenu.cpp
+++ b/src/guiInventoryMenu.cpp
@@ -32,13 +32,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
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)
{
@@ -89,12 +90,14 @@ GUIInventoryMenu::GUIInventoryMenu(gui::IGUIEnvironment* env,
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;
}
@@ -218,7 +221,7 @@ GUIInventoryMenu::ItemSpec GUIInventoryMenu::getItemAtPos(v2s32 p) const
return ItemSpec("", "", -1);
}
-void GUIInventoryMenu::drawList(const ListDrawSpec &s)
+void GUIInventoryMenu::drawList(const ListDrawSpec &s, ITextureSource *tsrc)
{
video::IVideoDriver* driver = Environment->getVideoDriver();
@@ -269,7 +272,7 @@ void GUIInventoryMenu::drawList(const ListDrawSpec &s)
if(item)
{
drawInventoryItem(driver, font, item,
- rect, &AbsoluteClippingRect);
+ rect, &AbsoluteClippingRect, tsrc);
}
}
@@ -292,7 +295,7 @@ void GUIInventoryMenu::drawMenu()
for(u32 i=0; i<m_draw_spec.size(); i++)
{
ListDrawSpec &s = m_draw_spec[i];
- drawList(s);
+ drawList(s, m_tsrc);
}
/*
diff --git a/src/guiInventoryMenu.h b/src/guiInventoryMenu.h
index 5336cae82..55d18a851 100644
--- a/src/guiInventoryMenu.h
+++ b/src/guiInventoryMenu.h
@@ -26,10 +26,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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
{
@@ -114,7 +117,8 @@ public:
IMenuManager *menumgr,
v2s16 menu_size,
InventoryContext *c,
- InventoryManager *invmgr
+ InventoryManager *invmgr,
+ ITextureSource *tsrc
);
~GUIInventoryMenu();
@@ -130,7 +134,7 @@ public:
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);
@@ -149,6 +153,7 @@ protected:
InventoryContext *m_c;
InventoryManager *m_invmgr;
+ ITextureSource *m_tsrc;
core::array<DrawSpec> m_init_draw_spec;
core::array<ListDrawSpec> m_draw_spec;
diff --git a/src/inventory.cpp b/src/inventory.cpp
index ea5b69636..4ac2453de 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -1,6 +1,6 @@
/*
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
@@ -17,16 +17,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
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"
@@ -35,14 +31,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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()
@@ -61,7 +60,7 @@ content_t content_translate_from_19_to_internal(content_t c_from)
return c_from;
}
-InventoryItem* InventoryItem::deSerialize(std::istream &is)
+InventoryItem* InventoryItem::deSerialize(std::istream &is, IGameDef *gamedef)
{
DSTACK(__FUNCTION_NAME);
@@ -84,7 +83,7 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
}
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")
{
@@ -94,7 +93,7 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
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")
{
@@ -108,7 +107,7 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
std::getline(is, subname, ' ');
u16 count;
is>>count;
- return new CraftItem(subname, count);
+ return new CraftItem(gamedef, subname, count);
}
else if(name == "ToolItem")
{
@@ -116,7 +115,7 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
std::getline(is, toolname, ' ');
u16 wear;
is>>wear;
- return new ToolItem(toolname, wear);
+ return new ToolItem(gamedef, toolname, wear);
}
else
{
@@ -151,7 +150,7 @@ ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f
*/
#ifndef SERVER
-video::ITexture * MaterialItem::getImage() const
+video::ITexture * MaterialItem::getImage(ITextureSource *tsrc) const
{
return content_features(m_content).inventory_texture;
}
@@ -159,12 +158,12 @@ video::ITexture * MaterialItem::getImage() const
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);
}
/*
@@ -173,23 +172,54 @@ InventoryItem *MaterialItem::createCookResult() const
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
@@ -206,7 +236,7 @@ ServerActiveObject* CraftItem::createSAO(ServerEnvironment *env, u16 id, v3f pos
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
@@ -215,21 +245,21 @@ u16 CraftItem::getDropCount() const
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)
@@ -304,7 +334,7 @@ void InventoryList::serialize(std::ostream &os) const
os<<"EndInventoryList\n";
}
-void InventoryList::deSerialize(std::istream &is)
+void InventoryList::deSerialize(std::istream &is, IGameDef *gamedef)
{
//is.imbue(std::locale("C"));
@@ -335,7 +365,7 @@ void InventoryList::deSerialize(std::istream &is)
{
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")
@@ -655,7 +685,7 @@ void Inventory::serialize(std::ostream &os) const
os<<"EndInventory\n";
}
-void Inventory::deSerialize(std::istream &is)
+void Inventory::deSerialize(std::istream &is, IGameDef *gamedef)
{
clear();
@@ -687,7 +717,7 @@ void Inventory::deSerialize(std::istream &is)
iss>>listsize;
InventoryList *list = new InventoryList(listname, listsize);
- list->deSerialize(is);
+ list->deSerialize(is, gamedef);
m_lists.push_back(list);
}
diff --git a/src/inventory.h b/src/inventory.h
index b163fde90..29b97ccad 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -1,6 +1,6 @@
/*
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
@@ -17,10 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-/*
-(c) 2010 Perttu Ahola <celeron55@gmail.com>
-*/
-
#ifndef INVENTORY_HEADER
#define INVENTORY_HEADER
@@ -29,34 +25,37 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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 ""; }
@@ -119,14 +118,15 @@ public:
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;
}
@@ -148,10 +148,10 @@ public:
}
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()
{
@@ -199,8 +199,8 @@ private:
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;
}
@@ -221,10 +221,10 @@ public:
}
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()
{
@@ -275,8 +275,8 @@ private:
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;
@@ -298,41 +298,15 @@ public:
}
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 "";
@@ -390,7 +364,7 @@ public:
~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);
@@ -460,7 +434,7 @@ public:
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);
diff --git a/src/main.cpp b/src/main.cpp
index 6b0cc1f83..63dc94955 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -385,11 +385,11 @@ Doing currently:
*/
#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
@@ -437,9 +437,6 @@ Doing currently:
#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.
@@ -1275,11 +1272,11 @@ int main(int argc, char *argv[])
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();
@@ -1430,9 +1427,6 @@ int main(int argc, char *argv[])
// 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)
*/
@@ -1478,13 +1472,6 @@ int main(int argc, char *argv[])
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
*/
@@ -1657,12 +1644,6 @@ int main(int argc, char *argv[])
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
*/
diff --git a/src/main.h b/src/main.h
index 081029dd5..0e353fce0 100644
--- a/src/main.h
+++ b/src/main.h
@@ -24,10 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
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;
diff --git a/src/map.cpp b/src/map.cpp
index b70b76b71..6b2142dba 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -62,8 +62,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
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();
@@ -1025,7 +1026,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
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);
}
@@ -1906,8 +1907,8 @@ void Map::nodeMetadataStep(float dtime,
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),
@@ -3309,7 +3310,7 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto
}
// Read basic data
- block->deSerialize(is, version);
+ block->deSerialize(is, version, m_gamedef);
// Read extra data stored on disk
block->deSerializeDiskExtra(is, version);
@@ -3379,7 +3380,7 @@ void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool
}
// Read basic data
- block->deSerialize(is, version);
+ block->deSerialize(is, version, m_gamedef);
// Read extra data stored on disk
block->deSerializeDiskExtra(is, version);
@@ -3522,12 +3523,13 @@ void ServerMap::PrintInfo(std::ostream &out)
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),
@@ -4168,14 +4170,15 @@ void ClientMap::expireMeshes(bool only_daynight_diffed)
}
}
-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){}
@@ -4183,21 +4186,21 @@ void ClientMap::updateMeshes(v3s16 blockpos, u32 daynight_ratio)
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){}
diff --git a/src/map.h b/src/map.h
index c9bc81790..6eb208be9 100644
--- a/src/map.h
+++ b/src/map.h
@@ -41,6 +41,7 @@ class ServerMapSector;
class ClientMapSector;
class MapBlock;
class NodeMetadata;
+class IGameDef;
namespace mapgen{
struct BlockMakeData;
@@ -109,7 +110,7 @@ class Map /*: public NodeContainer*/
{
public:
- Map(std::ostream &dout);
+ Map(std::ostream &dout, IGameDef *gamedef);
virtual ~Map();
/*virtual u16 nodeContainerId() const
@@ -289,7 +290,9 @@ public:
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;
@@ -315,7 +318,7 @@ public:
/*
savedir: directory to which map data should be saved
*/
- ServerMap(std::string savedir);
+ ServerMap(std::string savedir, IGameDef *gamedef);
~ServerMap();
s32 mapType() const
@@ -435,9 +438,9 @@ public:
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;
@@ -496,6 +499,7 @@ struct MapDrawControl
};
class Client;
+class ITextureSource;
/*
ClientMap
@@ -508,6 +512,7 @@ class ClientMap : public Map, public scene::ISceneNode
public:
ClientMap(
Client *client,
+ IGameDef *gamedef,
MapDrawControl &control,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
@@ -583,9 +588,10 @@ public:
/*
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);
diff --git a/src/mapblock.cpp b/src/mapblock.cpp
index 012cbd4d1..944d62230 100644
--- a/src/mapblock.cpp
+++ b/src/mapblock.cpp
@@ -138,7 +138,7 @@ MapNode MapBlock::getNodeParentNoEx(v3s16 p)
#ifndef SERVER
#if 1
-void MapBlock::updateMesh(u32 daynight_ratio)
+void MapBlock::updateMesh(u32 daynight_ratio, ITextureSource *tsrc)
{
#if 0
/*
@@ -154,7 +154,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
MeshMakeData data;
data.fill(daynight_ratio, this);
- scene::SMesh *mesh_new = makeMapBlockMesh(&data);
+ scene::SMesh *mesh_new = makeMapBlockMesh(&data, tsrc);
/*
Replace the mesh
@@ -655,7 +655,7 @@ void MapBlock::serialize(std::ostream &os, u8 version)
}
}
-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");
@@ -786,7 +786,7 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
{
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
{
@@ -794,7 +794,7 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
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)
diff --git a/src/mapblock.h b/src/mapblock.h
index 18b679cfc..75e146665 100644
--- a/src/mapblock.h
+++ b/src/mapblock.h
@@ -38,6 +38,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class Map;
class NodeMetadataList;
+class ITextureSource;
+class IGameDef;
#define BLOCK_TIMESTAMP_UNDEFINED 0xffffffff
@@ -407,7 +409,7 @@ public:
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);
@@ -537,7 +539,7 @@ public:
// 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);
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index c81d5adc1..2f9f9ce43 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "profiler.h"
#include "mapnode_contentfeatures.h"
+#include "tile.h"
void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
{
@@ -252,10 +253,10 @@ void makeFastFace(TileSpec tile, u8 li0, u8 li1, u8 li2, u8 li3, v3f p,
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
@@ -272,7 +273,7 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
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)
{
@@ -283,20 +284,20 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
// 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);
}
}
@@ -412,6 +413,7 @@ void getTileInfo(
VoxelManipulator &vmanip,
NodeModMap &temp_mods,
bool smooth_lighting,
+ ITextureSource *tsrc,
// Output:
bool &makes_face,
v3s16 &p_corrected,
@@ -422,8 +424,8 @@ void getTileInfo(
{
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);
@@ -493,7 +495,8 @@ void updateFastFaceRow(
NodeModMap &temp_mods,
VoxelManipulator &vmanip,
v3s16 blockpos_nodes,
- bool smooth_lighting)
+ bool smooth_lighting,
+ ITextureSource *tsrc)
{
v3s16 p = startpos;
@@ -505,7 +508,7 @@ void updateFastFaceRow(
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++)
@@ -528,7 +531,7 @@ void updateFastFaceRow(
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);
@@ -641,7 +644,7 @@ void updateFastFaceRow(
}
}
-scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
+scene::SMesh* makeMapBlockMesh(MeshMakeData *data, ITextureSource *tsrc)
{
// 4-21ms for MAP_BLOCKSIZE=16
// 24-155ms for MAP_BLOCKSIZE=32
@@ -688,7 +691,8 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
data->m_temp_mods,
data->m_vmanip,
blockpos_nodes,
- smooth_lighting);
+ smooth_lighting,
+ tsrc);
}
}
/*
@@ -706,7 +710,8 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
data->m_temp_mods,
data->m_vmanip,
blockpos_nodes,
- smooth_lighting);
+ smooth_lighting,
+ tsrc);
}
}
/*
@@ -724,7 +729,8 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
data->m_temp_mods,
data->m_vmanip,
blockpos_nodes,
- smooth_lighting);
+ smooth_lighting,
+ tsrc);
}
}
}
@@ -789,7 +795,7 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
- whatever
*/
- mapblock_mesh_generate_special(data, collector);
+ mapblock_mesh_generate_special(data, collector, tsrc);
/*
Add stuff from collector to mesh
diff --git a/src/mapblock_mesh.h b/src/mapblock_mesh.h
index d43c19a25..ea6a73122 100644
--- a/src/mapblock_mesh.h
+++ b/src/mapblock_mesh.h
@@ -141,7 +141,7 @@ struct MeshMakeData
};
// This is the highest-level function in here
-scene::SMesh* makeMapBlockMesh(MeshMakeData *data);
+scene::SMesh* makeMapBlockMesh(MeshMakeData *data, ITextureSource *tsrc);
#endif
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index 3e44f5047..829147839 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -220,7 +220,7 @@ u8 MapNode::getLightBanksWithSource()
}
#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);
@@ -253,19 +253,19 @@ TileSpec MapNode::getTile(v3s16 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);
}
}
diff --git a/src/mapnode.h b/src/mapnode.h
index 35920c5a6..62815dad1 100644
--- a/src/mapnode.h
+++ b/src/mapnode.h
@@ -226,7 +226,7 @@ struct MapNode
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
/*
diff --git a/src/mapnode_contentfeatures.cpp b/src/mapnode_contentfeatures.cpp
index aeab713c5..6bafa7338 100644
--- a/src/mapnode_contentfeatures.cpp
+++ b/src/mapnode_contentfeatures.cpp
@@ -19,8 +19,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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];
@@ -29,7 +32,7 @@ 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
/*
@@ -64,7 +67,7 @@ void init_contentfeatures()
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";
}
@@ -83,13 +86,14 @@ ContentFeatures::~ContentFeatures()
}
#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)
@@ -99,23 +103,24 @@ void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha)
}
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, '^', '&');
@@ -129,7 +134,7 @@ void ContentFeatures::setInventoryTextureCube(std::string top,
imgname_full += left;
imgname_full += "{";
imgname_full += right;
- inventory_texture = g_texturesource->getTextureRaw(imgname_full);
+ inventory_texture = tsrc->getTextureRaw(imgname_full);
}
#endif
diff --git a/src/mapnode_contentfeatures.h b/src/mapnode_contentfeatures.h
index 68342c1f8..0f7e35883 100644
--- a/src/mapnode_contentfeatures.h
+++ b/src/mapnode_contentfeatures.h
@@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "tile.h"
#endif
#include "materials.h" // MaterialProperties
+class ITextureSource;
/*
Content feature list
@@ -40,7 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Must be called before accessing the table.
*/
-void init_contentfeatures();
+void init_contentfeatures(ITextureSource *tsrc);
enum ContentParamType
{
@@ -232,21 +233,24 @@ struct ContentFeatures
*/
#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
@@ -265,16 +269,17 @@ struct ContentFeatures
#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
};
diff --git a/src/materials.cpp b/src/materials.cpp
index d905ca291..e990371ee 100644
--- a/src/materials.cpp
+++ b/src/materials.cpp
@@ -3,29 +3,28 @@
#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;
diff --git a/src/materials.h b/src/materials.h
index 39829786d..4f0fd6871 100644
--- a/src/materials.h
+++ b/src/materials.h
@@ -88,8 +88,9 @@ struct DiggingProperties
u16 wear;
};
-// Tool "" is bare hands
-DiggingProperties getDiggingProperties(u16 material, const std::string &tool);
+class ToolDiggingProperties;
+
+DiggingProperties getDiggingProperties(u16 material, ToolDiggingProperties *tp);
#endif
diff --git a/src/mineral.h b/src/mineral.h
index 61776e669..4949fe07e 100644
--- a/src/mineral.h
+++ b/src/mineral.h
@@ -40,12 +40,14 @@ void init_mineral();
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;
}
diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp
index 6fbfc2dba..ef6ea1cd2 100644
--- a/src/nodemetadata.cpp
+++ b/src/nodemetadata.cpp
@@ -32,7 +32,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
core::map<u16, NodeMetadata::Factory> NodeMetadata::m_types;
-NodeMetadata::NodeMetadata()
+NodeMetadata::NodeMetadata(IGameDef *gamedef):
+ m_gamedef(gamedef)
{
}
@@ -40,7 +41,7 @@ NodeMetadata::~NodeMetadata()
{
}
-NodeMetadata* NodeMetadata::deSerialize(std::istream &is)
+NodeMetadata* NodeMetadata::deSerialize(std::istream &is, IGameDef *gamedef)
{
// Read id
u8 buf[2];
@@ -67,7 +68,7 @@ NodeMetadata* NodeMetadata::deSerialize(std::istream &is)
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)
@@ -128,7 +129,7 @@ void NodeMetadataList::serialize(std::ostream &os)
}
}
-void NodeMetadataList::deSerialize(std::istream &is)
+void NodeMetadataList::deSerialize(std::istream &is, IGameDef *gamedef)
{
m_data.clear();
@@ -159,7 +160,7 @@ void NodeMetadataList::deSerialize(std::istream &is)
p16 -= p.Y * MAP_BLOCKSIZE;
p.X += p16;
- NodeMetadata *data = NodeMetadata::deSerialize(is);
+ NodeMetadata *data = NodeMetadata::deSerialize(is, gamedef);
if(data == NULL)
continue;
diff --git a/src/nodemetadata.h b/src/nodemetadata.h
index 5b2f129a1..9eb08678a 100644
--- a/src/nodemetadata.h
+++ b/src/nodemetadata.h
@@ -34,21 +34,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
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;}
@@ -69,6 +70,7 @@ public:
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;
};
@@ -83,7 +85,7 @@ public:
~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);
diff --git a/src/player.cpp b/src/player.cpp
index c8a3816e6..a1edb8299 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef SERVER
#include <ITextSceneNode.h>
#endif
+#include "main.h" // For g_settings
#include "settings.h"
#include "mapnode_contentfeatures.h"
@@ -128,7 +129,7 @@ void Player::serialize(std::ostream &os)
inventory.serialize(os);
}
-void Player::deSerialize(std::istream &is)
+void Player::deSerialize(std::istream &is, IGameDef *gamedef)
{
Settings args;
@@ -162,7 +163,7 @@ void Player::deSerialize(std::istream &is)
hp = 20;
}
- inventory.deSerialize(is);
+ inventory.deSerialize(is, gamedef);
}
/*
diff --git a/src/player.h b/src/player.h
index e6dfb8199..d6147b208 100644
--- a/src/player.h
+++ b/src/player.h
@@ -141,7 +141,7 @@ public:
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
@@ -185,8 +185,8 @@ public:
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_,
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 27f46a8ac..7b9a89f57 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -478,7 +478,11 @@ private:
<<" 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);
@@ -557,7 +561,8 @@ const luaL_reg ObjectRef::methods[] = {
};
// 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);
diff --git a/src/scriptapi.h b/src/scriptapi.h
index de8eb6abe..ecd3d7b81 100644
--- a/src/scriptapi.h
+++ b/src/scriptapi.h
@@ -28,6 +28,7 @@ class ServerEnvironment;
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);
@@ -48,7 +49,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
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);
diff --git a/src/server.cpp b/src/server.cpp
index 95d3f9439..40a5e183b 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -42,6 +42,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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<<")"
@@ -956,7 +958,7 @@ Server::Server(
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),
@@ -982,6 +984,9 @@ Server::Server(
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;
@@ -1001,7 +1006,7 @@ Server::Server(
// 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);
@@ -1100,6 +1105,8 @@ Server::~Server()
// Delete Environment
delete m_env;
+
+ delete m_toolmgr;
// Deinitialize scripting
infostream<<"Server: Deinitializing scripting"<<std::endl;
@@ -2574,8 +2581,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
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)
{
@@ -2600,7 +2609,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
InventoryItem *item = NULL;
if(mineral != MINERAL_NONE)
- item = getDiggedMineralItem(mineral);
+ item = getDiggedMineralItem(mineral, this);
// If not mineral
if(item == NULL)
@@ -2609,7 +2618,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(dug_s != "")
{
std::istringstream is(dug_s, std::ios::binary);
- item = InventoryItem::deSerialize(is);
+ item = InventoryItem::deSerialize(is, this);
}
}
@@ -2626,7 +2635,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
item = NULL;
if(mineral != MINERAL_NONE)
- item = getDiggedMineralItem(mineral);
+ item = getDiggedMineralItem(mineral, this);
// If not mineral
if(item == NULL)
@@ -2637,7 +2646,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
&& myrand() % extra_rarity == 0)
{
std::istringstream is(extra_dug_s, std::ios::binary);
- item = InventoryItem::deSerialize(is);
+ item = InventoryItem::deSerialize(is, this);
}
}
@@ -4108,7 +4117,7 @@ void Server::UpdateCrafting(u16 peer_id)
}
// Get result of crafting grid
- InventoryItem *result = craft_get_result(items);
+ InventoryItem *result = craft_get_result(items, this);
if(result)
rlist->addItem(result);
}
@@ -4272,7 +4281,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
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;
@@ -4326,11 +4335,11 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
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;
diff --git a/src/server.h b/src/server.h
index ab8c31a00..2d0aa8183 100644
--- a/src/server.h
+++ b/src/server.h
@@ -29,8 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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
@@ -361,7 +363,7 @@ private:
};
class Server : public con::PeerHandler, public MapEventReceiver,
- public InventoryManager
+ public InventoryManager, public IGameDef
{
public:
/*
@@ -481,6 +483,13 @@ 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:
@@ -605,6 +614,9 @@ private:
// Scripting
// Envlock and conlock should be locked when using Lua
lua_State *m_lua;
+
+ // Tool definition manager
+ IToolDefManager *m_toolmgr;
/*
Threads
@@ -692,8 +704,6 @@ private:
*/
u16 m_ignore_map_edit_events_peer_id;
- Profiler *m_profiler;
-
friend class EmergeThread;
friend class RemoteClient;
};
diff --git a/src/servercommand.cpp b/src/servercommand.cpp
index 156598940..3c6868e36 100644
--- a/src/servercommand.cpp
+++ b/src/servercommand.cpp
@@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "servercommand.h"
#include "utility.h"
#include "settings.h"
+#include "main.h" // For g_settings
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
diff --git a/src/servermain.cpp b/src/servermain.cpp
index 6bfcf2b75..deae90bba 100644
--- a/src/servermain.cpp
+++ b/src/servermain.cpp
@@ -88,9 +88,6 @@ Settings *g_settings = &main_settings;
Profiler main_profiler;
Profiler *g_profiler = &main_profiler;
-// A dummy thing
-ITextureSource *g_texturesource = NULL;
-
/*
Debug streams
*/
@@ -305,10 +302,10 @@ int main(int argc, char *argv[])
// 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();
diff --git a/src/serverobject.cpp b/src/serverobject.cpp
index 2a007bda5..428ad6484 100644
--- a/src/serverobject.cpp
+++ b/src/serverobject.cpp
@@ -37,9 +37,8 @@ ServerActiveObject::~ServerActiveObject()
{
}
-void ServerActiveObject::addedToEnvironment(u16 id)
+void ServerActiveObject::addedToEnvironment()
{
- setId(id);
}
ServerActiveObject* ServerActiveObject::create(u8 type,
diff --git a/src/serverobject.h b/src/serverobject.h
index 7e767188a..26dce007f 100644
--- a/src/serverobject.h
+++ b/src/serverobject.h
@@ -54,7 +54,8 @@ public:
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,
diff --git a/src/tool.cpp b/src/tool.cpp
index 4a4f0e467..d45556269 100644
--- a/src/tool.cpp
+++ b/src/tool.cpp
@@ -18,76 +18,70 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#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();
}
-
diff --git a/src/tool.h b/src/tool.h
index 49d069aac..a2a94f7fc 100644
--- a/src/tool.h
+++ b/src/tool.h
@@ -51,9 +51,32 @@ struct ToolDiggingProperties
{}
};
-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