X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fserver%2Fnet.cpp;h=aa1bdeb89448c46c757f6a4f47eb283c730ce581;hb=c58e8bce2b5eb61dea7bd78e98da8e1dcceb2d29;hp=f7c874f665fb1fbc4f38e190e045b5ae4f96a255;hpb=10a310869c61cc52046e165f36ac9639fe9d0c69;p=blank.git diff --git a/src/server/net.cpp b/src/server/net.cpp index f7c874f..aa1bdeb 100644 --- a/src/server/net.cpp +++ b/src/server/net.cpp @@ -180,6 +180,7 @@ ClientConnection::ClientConnection(Server &server, const IPaddress &addr) , spawns() , confirm_wait(0) , entity_updates() +, entity_updates_skipped(0) , player_update_state() , player_update_pack(0) , player_update_timer(1500) @@ -211,7 +212,7 @@ void ClientConnection::Update(int dt) { // they're the same if (CanDespawn(*global_iter)) { SendDespawn(*local_iter); - } else { + } else if (SendingUpdates()) { // update QueueUpdate(*local_iter); } @@ -308,6 +309,10 @@ void ClientConnection::SendDespawn(SpawnStatus &status) { ++confirm_wait; } +bool ClientConnection::SendingUpdates() const noexcept { + return entity_updates_skipped >= NetStat().SuggestedPacketSkip(); +} + void ClientConnection::QueueUpdate(SpawnStatus &status) { // don't send updates while spawn not ack'd or despawn sent if (status.spawn_pack == -1 && status.despawn_pack == -1) { @@ -316,6 +321,11 @@ void ClientConnection::QueueUpdate(SpawnStatus &status) { } void ClientConnection::SendUpdates() { + if (!SendingUpdates()) { + entity_updates.clear(); + ++entity_updates_skipped; + return; + } auto base = PlayerChunks().Base(); auto pack = Prepare(); pack.WriteChunkBase(base); @@ -335,6 +345,7 @@ void ClientConnection::SendUpdates() { Send(Packet::EntityUpdate::GetSize(entity_pos)); } entity_updates.clear(); + entity_updates_skipped = 0; } void ClientConnection::CheckPlayerFix() { @@ -387,6 +398,11 @@ void ClientConnection::CheckChunkQueue() { old_base = PlayerChunks().Base(); sort(chunk_queue.begin(), chunk_queue.end(), QueueCompare(old_base)); } + // if we have packet skip enabled and just pushed an entity + // update, don't also send chunk data + if (NetStat().SuggestedPacketSkip() > 0 && entity_updates_skipped == 0) { + return; + } if (transmitter.Transmitting()) { transmitter.Transmit(); return;