Navigation Menu

Skip to content

Commit

Permalink
Particles: Do not send single particles to distant clients (#5760)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paramat authored and nerzhul committed May 17, 2017
1 parent 287605c commit 0443620
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/server.cpp
Expand Up @@ -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,
Expand Down

0 comments on commit 0443620

Please sign in to comment.