diff options
author | sfan5 <sfan5@live.de> | 2020-05-22 15:25:47 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2020-05-23 22:52:21 +0200 |
commit | 10c3002aea784b5f0075f3f3e3ec824b6ba546ba (patch) | |
tree | b5e432e25a3c00b31d413f8f41afdf0af431065e | |
parent | 9d6e7e48d6fb1daff8fedcb2f111164bef61f1e7 (diff) | |
download | minetest-10c3002aea784b5f0075f3f3e3ec824b6ba546ba.tar.gz minetest-10c3002aea784b5f0075f3f3e3ec824b6ba546ba.tar.bz2 minetest-10c3002aea784b5f0075f3f3e3ec824b6ba546ba.zip |
Optimize particlespawner sending by not sending to distant players
-rw-r--r-- | src/server.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/server.cpp b/src/server.cpp index d6e545498..8c62584c8 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1549,12 +1549,30 @@ void Server::SendSpawnParticle(session_t peer_id, u16 protocol_version, void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version, const ParticleSpawnerParameters &p, u16 attached_id, u32 id) { + static thread_local const float radius = + g_settings->getS16("max_block_send_distance") * MAP_BLOCKSIZE * BS; + if (peer_id == PEER_ID_INEXISTENT) { std::vector<session_t> clients = m_clients.getClientIDs(); + const v3f pos = (p.minpos + p.maxpos) / 2.0f * BS; + const float radius_sq = radius * radius; + /* Don't send short-lived spawners to distant players. + * This could be replaced with proper tracking at some point. */ + const bool distance_check = !attached_id && p.time <= 1.0f; + for (const session_t client_id : clients) { RemotePlayer *player = m_env->getPlayer(client_id); if (!player) continue; + + if (distance_check) { + PlayerSAO *sao = player->getPlayerSAO(); + if (!sao) + continue; + if (sao->getBasePosition().getDistanceFromSQ(pos) > radius_sq) + continue; + } + SendAddParticleSpawner(client_id, player->protocol_version, p, attached_id, id); } |