aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorParamat <paramat@users.noreply.github.com>2017-05-17 09:37:28 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-05-17 10:37:28 +0200
commit0443620c5e699b02f8521ff8da7cff2e89ce4c5a (patch)
tree27da0fdda024e33d5bad19d2d25fd48c73ac6aa5 /src
parent287605ca8151f68224c919f45e2ae425cf6849a9 (diff)
downloadminetest-0443620c5e699b02f8521ff8da7cff2e89ce4c5a.tar.gz
minetest-0443620c5e699b02f8521ff8da7cff2e89ce4c5a.tar.bz2
minetest-0443620c5e699b02f8521ff8da7cff2e89ce4c5a.zip
Particles: Do not send single particles to distant clients (#5760)
Previously, every individual particle on a server is sent to, and rendered by (even if not actually visible), every client regardless of distance. This significantly reduces client FPS and creates unnecessary network traffic. Maximum distance is set by 'max block send distance' as this determines how far a client is able to see.
Diffstat (limited to 'src')
-rw-r--r--src/server.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/server.cpp b/src/server.cpp
index bf01fb7eb..5400dd595 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1707,13 +1707,25 @@ void Server::SendSpawnParticle(u16 peer_id, u16 protocol_version,
const struct TileAnimationParams &animation, u8 glow)
{
DSTACK(FUNCTION_NAME);
+ static const float radius =
+ g_settings->getS16("max_block_send_distance") * MAP_BLOCKSIZE * BS;
+
if (peer_id == PEER_ID_INEXISTENT) {
- // This sucks and should be replaced by a better solution in a refactor:
std::vector<u16> clients = m_clients.getClientIDs();
+
for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) {
RemotePlayer *player = m_env->getPlayer(*i);
if (!player)
continue;
+
+ PlayerSAO *sao = player->getPlayerSAO();
+ if (!sao)
+ continue;
+
+ // Do not send to distant clients
+ if (sao->getBasePosition().getDistanceFrom(pos * BS) > radius)
+ continue;
+
SendSpawnParticle(*i, player->protocol_version,
pos, velocity, acceleration,
expirationtime, size, collisiondetection,