From 7696a385433f815d8af8c905b45e2d7656299329 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 15 Nov 2011 23:58:56 +0200 Subject: Improve loading screen and protocol --- src/server.cpp | 88 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 32 deletions(-) (limited to 'src/server.cpp') diff --git a/src/server.cpp b/src/server.cpp index 45630d301..2a9aac32b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2139,15 +2139,15 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) Send some initialization data */ - // Send textures - SendTextures(peer_id); - // Send tool definitions SendToolDef(m_con, peer_id, m_toolmgr); // Send node definitions SendNodeDef(m_con, peer_id, m_nodemgr); + // Send textures + SendTextures(peer_id); + // Send player info to all players SendPlayerInfos(); @@ -4160,7 +4160,13 @@ void Server::SendTextures(u16 peer_id) /* Read textures */ - core::list textures; + // Put 5kB in one bunch (this is not accurate) + u32 bytes_per_bunch = 5000; + + core::array< core::list > texture_bunches; + texture_bunches.push_back(core::list()); + + u32 texture_size_bunch_total = 0; core::list mods = getMods(m_modspaths); for(core::list::Iterator i = mods.begin(); i != mods.end(); i++){ @@ -4186,6 +4192,7 @@ void Server::SendTextures(u16 peer_id) fis.read(buf, 1024); std::streamsize len = fis.gcount(); tmp_os.write(buf, len); + texture_size_bunch_total += len; if(fis.eof()) break; if(!fis.good()){ @@ -4201,40 +4208,57 @@ void Server::SendTextures(u16 peer_id) errorstream<<"Server::SendTextures(): Loaded \"" <= bytes_per_bunch){ + texture_bunches.push_back(core::list()); + texture_size_bunch_total = 0; + } } } - /* Create and send packet */ + /* Create and send packets */ + + u32 num_bunches = texture_bunches.size(); + for(u32 i=0; i::Iterator + j = texture_bunches[i].begin(); + j != texture_bunches[i].end(); j++){ + os<name); + os<data); } - */ - std::ostringstream os(std::ios_base::binary); - - writeU16(os, TOCLIENT_TEXTURES); - writeU32(os, textures.size()); - - for(core::list::Iterator i = textures.begin(); - i != textures.end(); i++){ - os<name); - os<data); + + // Make data buffer + std::string s = os.str(); + infostream<<"Server::SendTextures(): number of textures in bunch[" + < data((u8*)s.c_str(), s.size()); + // Send as reliable + m_con.Send(peer_id, 0, data, true); } - - // Make data buffer - std::string s = os.str(); - infostream<<"Server::SendTextures(): number of textures: " - < data((u8*)s.c_str(), s.size()); - // Send as reliable - m_con.Send(peer_id, 0, data, true); } /* -- cgit v1.2.3