Browse Source

Add parameter to control packet throttle threshold

NX 6 years ago
parent
commit
999f4bab1f
2 changed files with 10 additions and 8 deletions
  1. 4 4
      Source/Managed/ENet.cs
  2. 6 4
      Source/Native/enet.h

+ 4 - 4
Source/Managed/ENet.cs

@@ -776,10 +776,10 @@ namespace ENet {
 				throw new InvalidOperationException("Peer not created");
 				throw new InvalidOperationException("Peer not created");
 		}
 		}
 
 
-		public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration) {
+		public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration, uint threshold) {
 			CheckCreated();
 			CheckCreated();
 
 
-			Native.enet_peer_throttle_configure(nativePeer, interval, acceleration, deceleration);
+			Native.enet_peer_throttle_configure(nativePeer, interval, acceleration, deceleration, threshold);
 		}
 		}
 
 
 		public bool Send(byte channelID, ref Packet packet) {
 		public bool Send(byte channelID, ref Packet packet) {
@@ -1011,7 +1011,7 @@ namespace ENet {
 		internal static extern void enet_host_prevent_connections(IntPtr host, byte state);
 		internal static extern void enet_host_prevent_connections(IntPtr host, byte state);
 
 
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_peer_throttle_configure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
+		internal static extern void enet_peer_throttle_configure(IntPtr peer, uint interval, uint acceleration, uint deceleration, uint threshold);
 
 
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern uint enet_peer_get_id(IntPtr peer);
 		internal static extern uint enet_peer_get_id(IntPtr peer);
@@ -1082,4 +1082,4 @@ namespace ENet {
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_reset(IntPtr peer);
 		internal static extern void enet_peer_reset(IntPtr peer);
 	}
 	}
-}
+}

+ 6 - 4
Source/Native/enet.h

@@ -600,6 +600,7 @@ extern "C" {
 		enet_uint32 packetLoss;
 		enet_uint32 packetLoss;
 		enet_uint32 packetLossVariance;
 		enet_uint32 packetLossVariance;
 		enet_uint32 packetThrottle;
 		enet_uint32 packetThrottle;
+		enet_uint32 packetThrottleThreshold;
 		enet_uint32 packetThrottleLimit;
 		enet_uint32 packetThrottleLimit;
 		enet_uint32 packetThrottleCounter;
 		enet_uint32 packetThrottleCounter;
 		enet_uint32 packetThrottleEpoch;
 		enet_uint32 packetThrottleEpoch;
@@ -760,7 +761,7 @@ extern "C" {
 	ENET_API void enet_peer_disconnect(ENetPeer*, enet_uint32);
 	ENET_API void enet_peer_disconnect(ENetPeer*, enet_uint32);
 	ENET_API void enet_peer_disconnect_now(ENetPeer*, enet_uint32);
 	ENET_API void enet_peer_disconnect_now(ENetPeer*, enet_uint32);
 	ENET_API void enet_peer_disconnect_later(ENetPeer*, enet_uint32);
 	ENET_API void enet_peer_disconnect_later(ENetPeer*, enet_uint32);
-	ENET_API void enet_peer_throttle_configure(ENetPeer*, enet_uint32, enet_uint32, enet_uint32);
+	ENET_API void enet_peer_throttle_configure(ENetPeer*, enet_uint32, enet_uint32, enet_uint32, enet_uint32);
 
 
 	/* Extended API for easier binding in other programming languages */
 	/* Extended API for easier binding in other programming languages */
 	ENET_API void* enet_packet_get_data(const ENetPacket*);
 	ENET_API void* enet_packet_get_data(const ENetPacket*);
@@ -2976,8 +2977,9 @@ extern "C" {
 // !
 // !
 // =======================================================================//
 // =======================================================================//
 
 
-	void enet_peer_throttle_configure(ENetPeer* peer, enet_uint32 interval, enet_uint32 acceleration, enet_uint32 deceleration) {
+	void enet_peer_throttle_configure(ENetPeer* peer, enet_uint32 interval, enet_uint32 acceleration, enet_uint32 deceleration, enet_uint32 threshold) {
 		ENetProtocol command;
 		ENetProtocol command;
+		peer->packetThrottleThreshold = threshold;
 		peer->packetThrottleInterval = interval;
 		peer->packetThrottleInterval = interval;
 		peer->packetThrottleAcceleration = acceleration;
 		peer->packetThrottleAcceleration = acceleration;
 		peer->packetThrottleDeceleration = deceleration;
 		peer->packetThrottleDeceleration = deceleration;
@@ -3000,7 +3002,7 @@ extern "C" {
 				peer->packetThrottle = peer->packetThrottleLimit;
 				peer->packetThrottle = peer->packetThrottleLimit;
 
 
 			return 1;
 			return 1;
-		} else if (rtt > peer->lastRoundTripTime + 2 * peer->lastRoundTripTimeVariance) {
+		} else if (rtt > peer->lastRoundTripTime + peer->packetThrottleThreshold + 2 * peer->lastRoundTripTimeVariance) {
 			if (peer->packetThrottle > peer->packetThrottleDeceleration)
 			if (peer->packetThrottle > peer->packetThrottleDeceleration)
 				peer->packetThrottle -= peer->packetThrottleDeceleration;
 				peer->packetThrottle -= peer->packetThrottleDeceleration;
 			else
 			else
@@ -5117,4 +5119,4 @@ extern "C" {
 }
 }
 #endif
 #endif
 #endif
 #endif
-#endif
+#endif