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

46
host.c
View file

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