Node definitions transfer

This commit is contained in:
Perttu Ahola 2011-11-15 20:32:56 +02:00
parent eed727c61b
commit 6da8cb00e2
6 changed files with 80 additions and 2 deletions

View File

@ -1507,7 +1507,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
} }
else if(command == TOCLIENT_TOOLDEF) else if(command == TOCLIENT_TOOLDEF)
{ {
infostream<<"Client: Received tool definitions"<<std::endl; infostream<<"Client: Received tool definitions: packet size: "
<<datasize<<std::endl;
std::string datastring((char*)&data[2], datasize-2); std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary); std::istringstream is(datastring, std::ios_base::binary);
@ -1589,6 +1590,31 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
event.type = CE_TEXTURES_UPDATED; event.type = CE_TEXTURES_UPDATED;
m_client_event_queue.push_back(event); m_client_event_queue.push_back(event);
} }
else if(command == TOCLIENT_NODEDEF)
{
infostream<<"Client: Received node definitions: packet size: "
<<datasize<<std::endl;
std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary);
// Stop threads while updating content definitions
m_mesh_update_thread.stop();
std::istringstream tmp_is(deSerializeLongString(is), std::ios::binary);
m_nodedef->deSerialize(tmp_is, this);
// Update texture atlas
if(g_settings->getBool("enable_texture_atlas"))
m_tsrc->buildMainAtlas(this);
// Update node textures
m_nodedef->updateTextures(m_tsrc);
// Resume threads
m_mesh_update_thread.setRun(true);
m_mesh_update_thread.Start();
}
else else
{ {
infostream<<"Client: Ignoring unknown command " infostream<<"Client: Ignoring unknown command "

View File

@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
PROTOCOL_VERSION 4: PROTOCOL_VERSION 4:
Add TOCLIENT_TOOLDEF Add TOCLIENT_TOOLDEF
Add TOCLIENT_TEXTURES Add TOCLIENT_TEXTURES
Add TOCLIENT_NODEDEF
*/ */
#define PROTOCOL_VERSION 4 #define PROTOCOL_VERSION 4
@ -119,6 +120,8 @@ enum ToClientCommand
u16 time (0-23999) u16 time (0-23999)
*/ */
// (oops, there is some gap here)
TOCLIENT_CHAT_MESSAGE = 0x30, TOCLIENT_CHAT_MESSAGE = 0x30,
/* /*
u16 command u16 command
@ -211,6 +214,13 @@ enum ToClientCommand
} }
*/ */
TOCLIENT_NODEDEF = 0x3a,
/*
u16 command
u32 length of the next item
serialized NodeDefManager
*/
//TOCLIENT_CONTENT_SENDING_MODE = 0x38, //TOCLIENT_CONTENT_SENDING_MODE = 0x38,
/* /*
u16 command u16 command
@ -304,6 +314,8 @@ enum ToServerCommand
TOSERVER_RELEASE = 0x29, // Obsolete TOSERVER_RELEASE = 0x29, // Obsolete
// (oops, there is some gap here)
TOSERVER_SIGNTEXT = 0x30, // Old signs TOSERVER_SIGNTEXT = 0x30, // Old signs
/* /*
u16 command u16 command

View File

@ -451,6 +451,7 @@ public:
} }
void serialize(std::ostream &os) void serialize(std::ostream &os)
{ {
u16 count = 0;
std::ostringstream tmp_os(std::ios::binary); std::ostringstream tmp_os(std::ios::binary);
for(u16 i=0; i<=MAX_CONTENT; i++) for(u16 i=0; i<=MAX_CONTENT; i++)
{ {
@ -459,14 +460,17 @@ public:
continue; continue;
writeU16(tmp_os, i); writeU16(tmp_os, i);
f->serialize(tmp_os); f->serialize(tmp_os);
count++;
} }
writeU16(os, count);
os<<serializeLongString(tmp_os.str()); os<<serializeLongString(tmp_os.str());
} }
void deSerialize(std::istream &is, IGameDef *gamedef) void deSerialize(std::istream &is, IGameDef *gamedef)
{ {
clear(); clear();
u16 count = readU16(is);
std::istringstream tmp_is(deSerializeLongString(is), std::ios::binary); std::istringstream tmp_is(deSerializeLongString(is), std::ios::binary);
while(!tmp_is.eof()){ for(u16 n=0; n<count; n++){
u16 i = readU16(tmp_is); u16 i = readU16(tmp_is);
if(i > MAX_CONTENT){ if(i > MAX_CONTENT){
errorstream<<"ContentFeatures::deSerialize(): " errorstream<<"ContentFeatures::deSerialize(): "

View File

@ -278,6 +278,8 @@ public:
// Get node definition // Get node definition
virtual const ContentFeatures& get(content_t c) const=0; virtual const ContentFeatures& get(content_t c) const=0;
virtual const ContentFeatures& get(const MapNode &n) const=0; virtual const ContentFeatures& get(const MapNode &n) const=0;
virtual void serialize(std::ostream &os)=0;
}; };
class IWritableNodeDefManager : public INodeDefManager class IWritableNodeDefManager : public INodeDefManager

View File

@ -2145,6 +2145,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
// Send tool definitions // Send tool definitions
SendToolDef(m_con, peer_id, m_toolmgr); SendToolDef(m_con, peer_id, m_toolmgr);
// Send node definitions
SendNodeDef(m_con, peer_id, m_nodemgr);
// Send player info to all players // Send player info to all players
SendPlayerInfos(); SendPlayerInfos();
@ -3637,6 +3640,7 @@ void Server::SendToolDef(con::Connection &con, u16 peer_id,
IToolDefManager *tooldef) IToolDefManager *tooldef)
{ {
DSTACK(__FUNCTION_NAME); DSTACK(__FUNCTION_NAME);
infostream<<"Server: Sending tool definitions"<<std::endl;
std::ostringstream os(std::ios_base::binary); std::ostringstream os(std::ios_base::binary);
/* /*
@ -3651,6 +3655,34 @@ void Server::SendToolDef(con::Connection &con, u16 peer_id,
// Make data buffer // Make data buffer
std::string s = os.str(); std::string s = os.str();
infostream<<"Server: Sending tool definitions: data size: "
<<s.size()<<std::endl;
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
// Send as reliable
con.Send(peer_id, 0, data, true);
}
void Server::SendNodeDef(con::Connection &con, u16 peer_id,
INodeDefManager *nodedef)
{
DSTACK(__FUNCTION_NAME);
infostream<<"Server: Sending node definitions"<<std::endl;
std::ostringstream os(std::ios_base::binary);
/*
u16 command
u32 length of the next item
serialized NodeDefManager
*/
writeU16(os, TOCLIENT_NODEDEF);
std::ostringstream tmp_os(std::ios::binary);
nodedef->serialize(tmp_os);
os<<serializeLongString(tmp_os.str());
// Make data buffer
std::string s = os.str();
infostream<<"Server: Sending node definitions: data size: "
<<s.size()<<std::endl;
SharedBuffer<u8> data((u8*)s.c_str(), s.size()); SharedBuffer<u8> data((u8*)s.c_str(), s.size());
// Send as reliable // Send as reliable
con.Send(peer_id, 0, data, true); con.Send(peer_id, 0, data, true);

View File

@ -513,6 +513,8 @@ private:
bool set_camera_point_target, v3f camera_point_target); bool set_camera_point_target, v3f camera_point_target);
static void SendToolDef(con::Connection &con, u16 peer_id, static void SendToolDef(con::Connection &con, u16 peer_id,
IToolDefManager *tooldef); IToolDefManager *tooldef);
static void SendNodeDef(con::Connection &con, u16 peer_id,
INodeDefManager *nodedef);
/* /*
Non-static send methods. Non-static send methods.