From aa474e4501f460ba853dc70ff4d97cbd061e6704 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 5 Mar 2015 11:39:05 +0100 Subject: [PATCH] Server.cpp Use std::list instead of std::vector for playSound, fillMediaCache, sendRequestedMedia, sendMediaAnnouncement and related functions --- src/network/packethandlers/server.cpp | 2 +- src/server.cpp | 84 +++++++++++++-------------- src/server.h | 2 +- 3 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/network/packethandlers/server.cpp b/src/network/packethandlers/server.cpp index 62ce7eb55..a11e8dc2f 100644 --- a/src/network/packethandlers/server.cpp +++ b/src/network/packethandlers/server.cpp @@ -419,7 +419,7 @@ void Server::handleCommand_Init2(NetworkPacket* pkt) void Server::handleCommand_RequestMedia(NetworkPacket* pkt) { - std::list tosend; + std::vector tosend; u16 numfiles; *pkt >> numfiles; diff --git a/src/server.cpp b/src/server.cpp index 51832181a..09884f1bc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1913,7 +1913,7 @@ s32 Server::playSound(const SimpleSoundSpec &spec, return -1; // Filter destination clients - std::list dst_clients; + std::vector dst_clients; if(params.to_player != "") { Player *player = m_env->getPlayer(params.to_player.c_str()); @@ -1929,8 +1929,7 @@ s32 Server::playSound(const SimpleSoundSpec &spec, } dst_clients.push_back(player->peer_id); } - else - { + else { std::vector clients = m_clients.getClientIDs(); for(std::vector::iterator @@ -1957,16 +1956,14 @@ s32 Server::playSound(const SimpleSoundSpec &spec, m_playing_sounds[id] = ServerPlayingSound(); ServerPlayingSound &psound = m_playing_sounds[id]; psound.params = params; - for(std::list::iterator i = dst_clients.begin(); - i != dst_clients.end(); i++) - psound.clients.insert(*i); NetworkPacket* pkt = new NetworkPacket(TOCLIENT_PLAY_SOUND, 0); *pkt << id << spec.name << (float) (spec.gain * params.gain) << (u8) params.type << pos << params.object << params.loop; - for(std::list::iterator i = dst_clients.begin(); + + for(std::vector::iterator i = dst_clients.begin(); i != dst_clients.end(); i++) { - // Send as reliable + psound.clients.insert(*i); m_clients.send(*i, 0, pkt, true, false); } delete pkt; @@ -2183,9 +2180,9 @@ void Server::fillMediaCache() infostream<<"Server: Calculating media file checksums"< paths; + std::vector paths; for(std::vector::iterator i = m_mods.begin(); - i != m_mods.end(); i++){ + i != m_mods.end(); i++) { const ModSpec &mod = *i; paths.push_back(mod.path + DIR_DELIM + "textures"); paths.push_back(mod.path + DIR_DELIM + "sounds"); @@ -2195,19 +2192,18 @@ void Server::fillMediaCache() paths.push_back(porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server"); // Collect media file information from paths into cache - for(std::list::iterator i = paths.begin(); - i != paths.end(); i++) - { + for(std::vector::iterator i = paths.begin(); + i != paths.end(); i++) { std::string mediapath = *i; std::vector dirlist = fs::GetDirListing(mediapath); - for(u32 j=0; jm_media[filename] = MediaInfo(filepath, sha1_base64); - verbosestream<<"Server: "< file_announcements; + std::vector file_announcements; - for(std::map::iterator i = m_media.begin(); + for (std::map::iterator i = m_media.begin(); i != m_media.end(); i++){ // Put in list file_announcements.push_back( @@ -2316,7 +2313,7 @@ void Server::sendMediaAnnouncement(u16 peer_id) NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ANNOUNCE_MEDIA, 0, peer_id); *pkt << (u16) file_announcements.size(); - for(std::list::iterator + for (std::vector::iterator j = file_announcements.begin(); j != file_announcements.end(); ++j) { *pkt << j->name << j->sha1_digest; @@ -2341,7 +2338,7 @@ struct SendableMedia }; void Server::sendRequestedMedia(u16 peer_id, - const std::list &tosend) + const std::vector &tosend) { DSTACK(__FUNCTION_NAME); @@ -2353,14 +2350,13 @@ void Server::sendRequestedMedia(u16 peer_id, // Put 5kB in one bunch (this is not accurate) u32 bytes_per_bunch = 5000; - std::vector< std::list > file_bunches; - file_bunches.push_back(std::list()); + std::vector< std::vector > file_bunches; + file_bunches.push_back(std::vector()); u32 file_size_bunch_total = 0; - for(std::list::const_iterator i = tosend.begin(); - i != tosend.end(); ++i) - { + for(std::vector::const_iterator i = tosend.begin(); + i != tosend.end(); ++i) { const std::string &name = *i; if(m_media.find(name) == m_media.end()) { @@ -2407,7 +2403,7 @@ void Server::sendRequestedMedia(u16 peer_id, // Start next bunch if got enough data if(file_size_bunch_total >= bytes_per_bunch) { - file_bunches.push_back(std::list()); + file_bunches.push_back(std::vector()); file_size_bunch_total = 0; } @@ -2433,7 +2429,7 @@ void Server::sendRequestedMedia(u16 peer_id, NetworkPacket* pkt = new NetworkPacket(TOCLIENT_MEDIA, 0, peer_id); *pkt << num_bunches << i << (u32) file_bunches[i].size(); - for(std::list::iterator + for(std::vector::iterator j = file_bunches[i].begin(); j != file_bunches[i].end(); ++j) { *pkt << j->name; diff --git a/src/server.h b/src/server.h index eefac0be6..ba6c37faa 100644 --- a/src/server.h +++ b/src/server.h @@ -437,7 +437,7 @@ private: void fillMediaCache(); void sendMediaAnnouncement(u16 peer_id); void sendRequestedMedia(u16 peer_id, - const std::list &tosend); + const std::vector &tosend); void sendDetachedInventory(const std::string &name, u16 peer_id); void sendDetachedInventories(u16 peer_id); -- 2.25.1