From: Daniel Karbach Date: Fri, 9 Oct 2015 07:55:31 +0000 (+0200) Subject: transmit chunks in growing sphere order X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=9711e8f340be713d9c4949cc92e680b2c3349bc4;p=blank.git transmit chunks in growing sphere order --- diff --git a/src/server/net.cpp b/src/server/net.cpp index 1e60ff6..27643ee 100644 --- a/src/server/net.cpp +++ b/src/server/net.cpp @@ -9,6 +9,7 @@ #include "../world/Entity.hpp" #include "../world/World.hpp" +#include #include #include #include @@ -352,6 +353,23 @@ void ClientConnection::CheckPlayerFix() { } } +namespace { + +struct QueueCompare { + explicit QueueCompare(const glm::ivec3 &base) + : base(base) { } + bool operator ()(const glm::ivec3 &left, const glm::ivec3 &right) const noexcept { + const glm::ivec3 ld(left - base); + const glm::ivec3 rd(right - base); + return + ld.x * ld.x + ld.y * ld.y + ld.z * ld.z < + rd.x * rd.x + rd.y * rd.y + rd.z * rd.z; + } + const glm::ivec3 &base; +}; + +} + void ClientConnection::CheckChunkQueue() { if (PlayerChunks().Base() != old_base) { Chunk::Pos begin = PlayerChunks().CoordsBegin(); @@ -366,6 +384,7 @@ void ClientConnection::CheckChunkQueue() { } } old_base = PlayerChunks().Base(); + sort(chunk_queue.begin(), chunk_queue.end(), QueueCompare(old_base)); } if (transmitter.Transmitting()) { transmitter.Transmit(); @@ -406,6 +425,7 @@ void ClientConnection::AttachPlayer(Player &player) { } } } + sort(chunk_queue.begin(), chunk_queue.end(), QueueCompare(old_base)); // TODO: should the server do this? if (HasPlayerModel()) { GetPlayerModel().Instantiate(PlayerEntity().GetModel());