From 45fc45a49e61c61646b9997840e92f25bb8ccde9 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 15 Nov 2011 11:02:47 +0200 Subject: Sending of textures WIP --- src/client.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index 1daeeba36..c89273a80 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodemetadata.h" #include "nodedef.h" #include "tooldef.h" +#include /* QueuedMeshUpdate @@ -1523,6 +1524,62 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) m_mesh_update_thread.setRun(true); m_mesh_update_thread.Start(); } + else if(command == TOCLIENT_TEXTURES) + { + infostream<<"Client: Received textures: packet size: "<getFileSystem(); + video::IVideoDriver *vdrv = m_device->getVideoDriver(); + + 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(); + + /* + u16 command + u32 number of textures + for each texture { + u16 length of name + string name + u32 length of data + data + } + */ + int num_textures = readU32(is); + infostream<<"Client: Received textures: count: "< data_rw(data.c_str(), data.size()); + // Create an irrlicht memory file + io::IReadFile *rfile = irrfs->createMemoryReadFile( + *data_rw, data.size(), "_tempreadfile"); + assert(rfile); + // Read image + video::IImage *img = vdrv->createImageFromFile(rfile); + if(!img){ + errorstream<<"Client: Cannot create image from data of " + <<"received texture \""<drop(); + continue; + } + m_tsrc->insertImage(name, img); + rfile->drop(); + } + + // Update texture atlas + if(g_settings->getBool("enable_texture_atlas")) + m_tsrc->buildMainAtlas(this); + + // Resume threads + m_mesh_update_thread.setRun(true); + m_mesh_update_thread.Start(); + } else { infostream<<"Client: Ignoring unknown command " -- cgit v1.2.3