From 613797a3048907275ceebe29582b9fc2761b1f25 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 5 Oct 2016 09:03:55 +0200 Subject: Replace various std::map with UNORDERED_MAP + various cleanups This is part 2 for 5f084cd98d7b3326b51320455364337539710efd Other improvements: * Use the defined ItemGroupList when used * make Client::checkPrivilege const * inline some trivial functions * Add ActiveObjectMap typedef * Add SettingsEntries typedef --- src/clientiface.cpp | 55 +++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index a3a17d435..e7ad39579 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -605,11 +605,8 @@ ClientInterface::~ClientInterface() { MutexAutoLock clientslock(m_clients_mutex); - for(std::map::iterator - i = m_clients.begin(); - i != m_clients.end(); ++i) - { - + for (UNORDERED_MAP::iterator i = m_clients.begin(); + i != m_clients.end(); ++i) { // Delete client delete i->second; } @@ -621,10 +618,8 @@ std::vector ClientInterface::getClientIDs(ClientState min_state) std::vector reply; MutexAutoLock clientslock(m_clients_mutex); - for(std::map::iterator - i = m_clients.begin(); - i != m_clients.end(); ++i) - { + for(UNORDERED_MAP::iterator i = m_clients.begin(); + i != m_clients.end(); ++i) { if (i->second->getState() >= min_state) reply.push_back(i->second->peer_id); } @@ -691,8 +686,7 @@ void ClientInterface::sendToAll(u16 channelnum, NetworkPacket* pkt, bool reliable) { MutexAutoLock clientslock(m_clients_mutex); - for(std::map::iterator - i = m_clients.begin(); + for(UNORDERED_MAP::iterator i = m_clients.begin(); i != m_clients.end(); ++i) { RemoteClient *client = i->second; @@ -705,11 +699,10 @@ void ClientInterface::sendToAll(u16 channelnum, RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min) { MutexAutoLock clientslock(m_clients_mutex); - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return NULL; if (n->second->getState() >= state_min) @@ -720,11 +713,10 @@ RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min) RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min) { - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return NULL; if (n->second->getState() >= state_min) @@ -736,11 +728,10 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState stat ClientState ClientInterface::getClientState(u16 peer_id) { MutexAutoLock clientslock(m_clients_mutex); - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return CS_Invalid; return n->second->getState(); @@ -749,11 +740,10 @@ ClientState ClientInterface::getClientState(u16 peer_id) void ClientInterface::setPlayerName(u16 peer_id,std::string name) { MutexAutoLock clientslock(m_clients_mutex); - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n != m_clients.end()) + if (n != m_clients.end()) n->second->setName(name); } @@ -762,11 +752,10 @@ void ClientInterface::DeleteClient(u16 peer_id) MutexAutoLock conlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return; /* @@ -797,10 +786,9 @@ void ClientInterface::CreateClient(u16 peer_id) MutexAutoLock conlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client shouldn't already exist - if(n != m_clients.end()) return; + if (n != m_clients.end()) return; // Create client RemoteClient *client = new RemoteClient(); @@ -814,8 +802,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event) MutexAutoLock clientlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // No client to deliver event if (n == m_clients.end()) @@ -836,8 +823,7 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id) MutexAutoLock conlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // No client to get version if (n == m_clients.end()) @@ -851,8 +837,7 @@ void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch MutexAutoLock conlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // No client to set versions if (n == m_clients.end()) -- cgit v1.2.3 From fd5a130b86c08f0b3190c3d81affd4869c139fb7 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 8 Oct 2016 16:31:22 +0200 Subject: More code cleanup (UNORDERED + RemotePlayer/LocalPlayer) * ClientEnvironment now uses UNORDERED MAP for active objects * Use RemotePlayer and LocalPlayer everywhere it's possible * Minor code style fixes * Drop Client::getBreath() unused function --- src/clientiface.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index e7ad39579..e55c07cb6 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -77,9 +77,9 @@ void RemoteClient::GetNextBlocks ( if(m_nothing_to_send_pause_timer >= 0) return; - Player *player = env->getPlayer(peer_id); + RemotePlayer *player = env->getPlayer(peer_id); // This can happen sometimes; clients and players are not in perfect sync. - if(player == NULL) + if (player == NULL) return; // Won't send anything if already sending @@ -645,8 +645,7 @@ void ClientInterface::step(float dtime) void ClientInterface::UpdatePlayerList() { - if (m_env != NULL) - { + if (m_env != NULL) { std::vector clients = getClientIDs(); m_clients_names.clear(); @@ -654,10 +653,8 @@ void ClientInterface::UpdatePlayerList() if(!clients.empty()) infostream<<"Players:"<::iterator - i = clients.begin(); - i != clients.end(); ++i) { - Player *player = m_env->getPlayer(*i); + for (std::vector::iterator i = clients.begin(); i != clients.end(); ++i) { + RemotePlayer *player = m_env->getPlayer(*i); if (player == NULL) continue; -- cgit v1.2.3 From edba6e50d9c9c0a7120c251bed36a87b51f4c826 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 8 Oct 2016 16:42:09 +0200 Subject: Optimize ClientIface::getPlayerNames(): return const ref instead a copy of all names --- src/clientiface.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index e55c07cb6..fbfc16770 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -627,12 +627,6 @@ std::vector ClientInterface::getClientIDs(ClientState min_state) return reply; } -std::vector ClientInterface::getPlayerNames() -{ - return m_clients_names; -} - - void ClientInterface::step(float dtime) { m_print_info_timer += dtime; -- cgit v1.2.3 From 569b89b36fff058390cb90458da4285552a9c97e Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 8 Oct 2016 19:08:23 +0200 Subject: Move RemotePlayer code to its own cpp/header --- src/clientiface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index fbfc16770..d78cf1c53 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "clientiface.h" #include "util/numeric.h" #include "util/mathconstants.h" -#include "player.h" +#include "remoteplayer.h" #include "settings.h" #include "mapblock.h" #include "network/connection.h" -- cgit v1.2.3 From 9d25242c5c1411d692254cf910345d51c9a24fa3 Mon Sep 17 00:00:00 2001 From: Ner'zhul Date: Sun, 30 Oct 2016 14:53:26 +0100 Subject: PlayerSAO/LocalPlayer refactor: (#4612) * Create UnitSAO, a common part between PlayerSAO & LuaEntitySAO * Move breath to PlayerSAO & LocalPlayer * Migrate m_yaw from (Remote)Player & LuaEntitySAO to UnitSAO * Migrate m_yaw from Player to LocalPlayer for client * Move some functions outside of player class to PlayerSAO/RemotePlayer or LocalPlayer depending on which class needs it * Move pitch to LocalPlayer & PlayerSAO * Move m_position from Player to LocalPlayer * Move camera_barely_in_ceiling to LocalPlayer as it's used only there * use PlayerSAO::m_base_position for Server side positions * remove a unused variable * ServerActiveObject::setPos now uses const ref * use ServerEnv::loadPlayer unconditionnaly as it creates RemotePlayer only if it's not already loaded * Move hp from Player to LocalPlayer * Move m_hp from LuaEntitySAO to UnitSAO * Use m_hp from PlayerSAO/UnitSAO instead of RemotePlayer --- src/clientiface.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index d78cf1c53..d2e3a6da0 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "environment.h" #include "map.h" #include "emerge.h" -#include "serverobject.h" // TODO this is used for cleanup of only +#include "content_sao.h" // TODO this is used for cleanup of only #include "log.h" #include "util/srp.h" @@ -82,6 +82,10 @@ void RemoteClient::GetNextBlocks ( if (player == NULL) return; + PlayerSAO *sao = player->getPlayerSAO(); + if (sao == NULL) + return; + // Won't send anything if already sending if(m_blocks_sending.size() >= g_settings->getU16 ("max_simultaneous_block_sends_per_client")) @@ -90,7 +94,7 @@ void RemoteClient::GetNextBlocks ( return; } - v3f playerpos = player->getPosition(); + v3f playerpos = sao->getBasePosition(); v3f playerspeed = player->getSpeed(); v3f playerspeeddir(0,0,0); if(playerspeed.getLength() > 1.0*BS) @@ -103,10 +107,10 @@ void RemoteClient::GetNextBlocks ( v3s16 center = getNodeBlockPos(center_nodepos); // Camera position and direction - v3f camera_pos = player->getEyePosition(); + v3f camera_pos = sao->getEyePosition(); v3f camera_dir = v3f(0,0,1); - camera_dir.rotateYZBy(player->getPitch()); - camera_dir.rotateXZBy(player->getYaw()); + camera_dir.rotateYZBy(sao->getPitch()); + camera_dir.rotateXZBy(sao->getYaw()); /*infostream<<"camera_dir=("< Date: Sun, 30 Oct 2016 20:35:55 -0700 Subject: Optionally disable optimization that causes underwater and cave rendering glitches. (#4686) --- src/clientiface.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index d2e3a6da0..7dce77cd7 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -174,6 +174,8 @@ void RemoteClient::GetNextBlocks ( s32 new_nearest_unsent_d = -1; const s16 full_d_max = g_settings->getS16("max_block_send_distance"); + const s16 d_opt = g_settings->getS16("block_send_optimize_distance"); + s16 d_max = full_d_max; s16 d_max_gen = g_settings->getS16("max_block_generate_distance"); @@ -300,7 +302,7 @@ void RemoteClient::GetNextBlocks ( Block is near ground level if night-time mesh differs from day-time mesh. */ - if(d >= 4) + if(d >= d_opt) { if(block->getDayNightDiff() == false) continue; -- cgit v1.2.3 From 45eab340b90e54134a6f1cde3314c10cce08820b Mon Sep 17 00:00:00 2001 From: Lars Hofhansl Date: Sun, 6 Nov 2016 21:30:49 -0800 Subject: Don't use reduced vertical limits for mapblock send and generation --- src/clientiface.cpp | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 7dce77cd7..4b9efcb49 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -235,16 +235,6 @@ void RemoteClient::GetNextBlocks ( // If this is true, inexistent block will be made from scratch bool generate = d <= d_max_gen; - { - /*// Limit the generating area vertically to 2/3 - if(abs(p.Y - center.Y) > d_max_gen - d_max_gen / 3) - generate = false;*/ - - // Limit the send area vertically to 1/2 - if (abs(p.Y - center.Y) > full_d_max / 2) - continue; - } - /* Don't generate or send if not in sight FIXME This only works if the client uses a small enough -- cgit v1.2.3 From e7c62edec90c476b54ea7cf7c44354f1609e4575 Mon Sep 17 00:00:00 2001 From: Lars Hofhansl Date: Fri, 4 Nov 2016 00:14:07 -0700 Subject: Retrieve mapblocks from the server in a sphere, not a cube Use unused range argument in 'isBlockInSight()' to limit mapblock sends to a sphere of radius 'max block send distance'. --- src/clientiface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 4b9efcb49..7e75c69a4 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -175,6 +175,7 @@ void RemoteClient::GetNextBlocks ( const s16 full_d_max = g_settings->getS16("max_block_send_distance"); const s16 d_opt = g_settings->getS16("block_send_optimize_distance"); + const s16 d_blocks_in_sight = (full_d_max + 1) * BS * MAP_BLOCKSIZE; s16 d_max = full_d_max; s16 d_max_gen = g_settings->getS16("max_block_generate_distance"); @@ -242,7 +243,7 @@ void RemoteClient::GetNextBlocks ( */ float camera_fov = (72.0*M_PI/180) * 4./3.; - if(isBlockInSight(p, camera_pos, camera_dir, camera_fov, 10000*BS) == false) + if(isBlockInSight(p, camera_pos, camera_dir, camera_fov, d_blocks_in_sight) == false) { continue; } -- cgit v1.2.3 From b98f98b367f2c55d5a0bff4bafaaa183b3746403 Mon Sep 17 00:00:00 2001 From: Rogier-5 Date: Fri, 11 Nov 2016 09:30:37 +0100 Subject: Fix incorrect distance computation for visible blocks (#4765) The client would not compute the distance from the camera to to a mapblock correctly. The result was that blocks that were in view (i.e. not beyond the fog limit) would not be rendered. With the improved distance computation, a range adjustment that existed in clientiface.cpp is no longer required. --- src/clientiface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 7e75c69a4..bdc16f31c 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -175,7 +175,7 @@ void RemoteClient::GetNextBlocks ( const s16 full_d_max = g_settings->getS16("max_block_send_distance"); const s16 d_opt = g_settings->getS16("block_send_optimize_distance"); - const s16 d_blocks_in_sight = (full_d_max + 1) * BS * MAP_BLOCKSIZE; + const s16 d_blocks_in_sight = full_d_max * BS * MAP_BLOCKSIZE; s16 d_max = full_d_max; s16 d_max_gen = g_settings->getS16("max_block_generate_distance"); -- cgit v1.2.3 From 5dc61988788e44bc87e8c57c0beded97d4efdf05 Mon Sep 17 00:00:00 2001 From: lhofhansl Date: Wed, 30 Nov 2016 00:13:14 -0800 Subject: Optimize/adjust blocks/ActiveObjects sent at the server based on client settings. (#4811) Optimize/adjust blocks and active blocks sent at the server based on client settings. --- src/clientiface.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index bdc16f31c..abe878ecc 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -173,12 +173,20 @@ void RemoteClient::GetNextBlocks ( */ s32 new_nearest_unsent_d = -1; - const s16 full_d_max = g_settings->getS16("max_block_send_distance"); - const s16 d_opt = g_settings->getS16("block_send_optimize_distance"); + // get view range and camera fov from the client + s16 wanted_range = sao->getWantedRange(); + float camera_fov = sao->getFov(); + // if FOV, wanted_range are not available (old client), fall back to old default + if (wanted_range <= 0) wanted_range = 1000; + if (camera_fov <= 0) camera_fov = (72.0*M_PI/180) * 4./3.; + + const s16 full_d_max = MYMIN(g_settings->getS16("max_block_send_distance"), wanted_range); + const s16 d_opt = MYMIN(g_settings->getS16("block_send_optimize_distance"), wanted_range); const s16 d_blocks_in_sight = full_d_max * BS * MAP_BLOCKSIZE; + //infostream << "Fov from client " << camera_fov << " full_d_max " << full_d_max << std::endl; s16 d_max = full_d_max; - s16 d_max_gen = g_settings->getS16("max_block_generate_distance"); + s16 d_max_gen = MYMIN(g_settings->getS16("max_block_generate_distance"), wanted_range); // Don't loop very much at a time s16 max_d_increment_at_time = 2; @@ -242,7 +250,6 @@ void RemoteClient::GetNextBlocks ( FOV setting. The default of 72 degrees is fine. */ - float camera_fov = (72.0*M_PI/180) * 4./3.; if(isBlockInSight(p, camera_pos, camera_dir, camera_fov, d_blocks_in_sight) == false) { continue; -- cgit v1.2.3 From 8a7dc838a8c1f8f2a5e9b710a8ee27d4d00715f9 Mon Sep 17 00:00:00 2001 From: Lars Hofhansl Date: Wed, 30 Nov 2016 21:42:22 -0800 Subject: Optimize block sent: Fix rendering issue --- src/clientiface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/clientiface.cpp') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index abe878ecc..0390cf0ff 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -357,7 +357,7 @@ queue_full_break: } else if(nearest_emergefull_d != -1){ new_nearest_unsent_d = nearest_emergefull_d; } else { - if(d > g_settings->getS16("max_block_send_distance")){ + if(d > full_d_max){ new_nearest_unsent_d = 0; m_nothing_to_send_pause_timer = 2.0; } else { -- cgit v1.2.3