Browse Source

[Net] ENet now sends fragmented packets unreliably too.

It used to always send them reliably when transfer mode was unreliable
or ordered if the packet size was more then the enet host MTU (1400
bytes by default).

This commit also adds a warning when debug is enabled to explain the
effects of sending fragmented packets unreliably.
Jordan Schidlowsky 4 năm trước cách đây
mục cha
commit
25636f8db7
1 tập tin đã thay đổi với 8 bổ sung1 xóa
  1. 8 1
      modules/enet/networked_multiplayer_enet.cpp

+ 8 - 1
modules/enet/networked_multiplayer_enet.cpp

@@ -546,9 +546,10 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer
 				packet_flags = ENET_PACKET_FLAG_UNSEQUENCED;
 			}
 			channel = SYSCH_UNRELIABLE;
+			packet_flags |= ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT;
 		} break;
 		case TRANSFER_MODE_UNRELIABLE_ORDERED: {
-			packet_flags = 0;
+			packet_flags = ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT;
 			channel = SYSCH_UNRELIABLE;
 		} break;
 		case TRANSFER_MODE_RELIABLE: {
@@ -561,6 +562,12 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer
 		channel = transfer_channel;
 	}
 
+#ifdef DEBUG_ENABLED
+	if ((packet_flags & ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT) && p_buffer_size + 8 > ENET_HOST_DEFAULT_MTU) {
+		WARN_PRINT_ONCE(vformat("Sending %d bytes unrealiably which is above the MTU (%d), this will result in higher packet loss", p_buffer_size + 8, host->mtu));
+	}
+#endif
+
 	Map<int, ENetPeer *>::Element *E = nullptr;
 
 	if (target_peer != 0) {