Skip to content

Commit

Permalink
Create framework for getting rid of global definitions of node/tool/i…
Browse files Browse the repository at this point in the history
…tem/whatever types
  • Loading branch information
celeron55 committed Nov 29, 2011
1 parent 5fc791a commit abceeee
Show file tree
Hide file tree
Showing 60 changed files with 1,015 additions and 741 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ configure_file(
)

set(common_SRCS
content_tool.cpp
tool.cpp
mapnode_contentfeatures.cpp
luaentity_common.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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));
}

Expand Down
3 changes: 2 additions & 1 deletion src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -115,7 +116,7 @@ class Camera
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
Expand Down
28 changes: 17 additions & 11 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
38 changes: 19 additions & 19 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -98,7 +99,8 @@ class MeshUpdateThread : public SimpleThread
{
public:

MeshUpdateThread()
MeshUpdateThread(ITextureSource *tsrc):
m_tsrc(tsrc)
{
}

Expand All @@ -107,6 +109,8 @@ class MeshUpdateThread : public SimpleThread
MeshUpdateQueue m_queue_in;

MutexedQueue<MeshUpdateResult> m_queue_out;

ITextureSource *m_tsrc;
};

enum ClientEventType
Expand Down Expand Up @@ -139,7 +143,7 @@ struct ClientEvent
};
};

class Client : public con::PeerHandler, public InventoryManager
class Client : public con::PeerHandler, public InventoryManager, public IGameDef
{
public:
/*
Expand All @@ -150,8 +154,10 @@ class Client : public con::PeerHandler, public InventoryManager
IrrlichtDevice *device,
const char *playername,
std::string password,
MapDrawControl &control
);
MapDrawControl &control,
ITextureSource *tsrc,
IToolDefManager *toolmgr
);

~Client();
/*
Expand Down Expand Up @@ -303,6 +309,13 @@ class Client : public con::PeerHandler, public InventoryManager

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
Expand All @@ -325,44 +338,31 @@ class Client : public con::PeerHandler, public InventoryManager
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;
};

Expand Down
9 changes: 5 additions & 4 deletions src/clientobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -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;
Expand All @@ -50,7 +51,7 @@ ClientActiveObject* ClientActiveObject::create(u8 type)
}

Factory f = n->getValue();
ClientActiveObject *object = (*f)();
ClientActiveObject *object = (*f)(gamedef);
return object;
}

Expand Down
11 changes: 7 additions & 4 deletions src/clientobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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){}
Expand All @@ -68,16 +70,17 @@ class ClientActiveObject : public ActiveObject
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)
{ return false; }

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;
Expand Down
Loading

0 comments on commit abceeee

Please sign in to comment.