remove some more looping in enet_host_bandwidth_throttle

This commit is contained in:
lsalzman 2013-05-08 11:02:13 +03:00
parent 30d859f9a4
commit 71d6d63ed8

26
host.c
View file

@ -367,11 +367,6 @@ enet_host_bandwidth_throttle (ENetHost * host)
else
bandwidth = (host -> outgoingBandwidth * elapsedTime) / 1000;
if (dataTotal < bandwidth)
throttle = ENET_PEER_PACKET_THROTTLE_SCALE;
else
throttle = (bandwidth * ENET_PEER_PACKET_THROTTLE_SCALE) / dataTotal;
while (peersRemaining > 0 && needsAdjustment != 0)
{
needsAdjustment = 0;
@ -407,6 +402,9 @@ enet_host_bandwidth_throttle (ENetHost * host)
peer -> outgoingBandwidthThrottleEpoch = timeCurrent;
peer -> incomingDataTotal = 0;
peer -> outgoingDataTotal = 0;
needsAdjustment = 1;
-- peersRemaining;
bandwidth -= peerBandwidth;
@ -415,6 +413,12 @@ enet_host_bandwidth_throttle (ENetHost * host)
}
if (peersRemaining > 0)
{
if (dataTotal < bandwidth)
throttle = ENET_PEER_PACKET_THROTTLE_SCALE;
else
throttle = (bandwidth * ENET_PEER_PACKET_THROTTLE_SCALE) / dataTotal;
for (peer = host -> peers;
peer < & host -> peers [host -> peerCount];
++ peer)
@ -427,6 +431,10 @@ enet_host_bandwidth_throttle (ENetHost * host)
if (peer -> packetThrottle > peer -> packetThrottleLimit)
peer -> packetThrottle = peer -> packetThrottleLimit;
peer -> incomingDataTotal = 0;
peer -> outgoingDataTotal = 0;
}
}
if (host -> recalculateBandwidthLimits)
@ -484,14 +492,6 @@ enet_host_bandwidth_throttle (ENetHost * host)
enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);
}
}
for (peer = host -> peers;
peer < & host -> peers [host -> peerCount];
++ peer)
{
peer -> incomingDataTotal = 0;
peer -> outgoingDataTotal = 0;
}
}
/** @} */