From d0508e5155bddfb5a3ed3b6118b8125e6a87a9ae Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 11 Aug 2021 21:05:37 +0200 Subject: [PATCH] Enable range coder compression by default in NetworkedMultiplayerENet From empirical testing, this seems to provide the best compression compared to other compression algorithms when used in the Multiplayer Bomber demo. Other algorithms may provide better compression ratios for more complex games, but some compression is probably better than no compression. Zstandard was also not very efficient in my testing, so I added a note in the documentation. --- modules/enet/doc_classes/NetworkedMultiplayerENet.xml | 9 +++++---- modules/enet/networked_multiplayer_enet.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml index ef245a952b6e..ac368c62550f 100644 --- a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml +++ b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml @@ -115,8 +115,9 @@ The number of channels to be used by ENet. Channels are used to separate different kinds of data. In reliable or ordered mode, for example, the packet delivery order is ensured on a per-channel basis. This is done to combat latency and reduces ordering restrictions on packets. The delivery status of a packet in one channel won't stall the delivery of other packets in another channel. - + The compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all. + [b]Note:[/b] Most games' network design involve sending many small packets frequently (smaller than 4 KB each). If in doubt, it is recommended to keep the default compression algorithm as it works best on these small packets. The hostname used for DTLS verification, to be compared against the "CN" value in the certificate provided by the server. @@ -140,16 +141,16 @@ - No compression. This uses the most bandwidth, but has the upside of requiring the fewest CPU resources. + No compression. This uses the most bandwidth, but has the upside of requiring the fewest CPU resources. This option may also be used to make network debugging using tools like Wireshark easier. - ENet's built-in range encoding. + ENet's built-in range encoding. Works well on small packets, but is not the most efficient algorithm on packets larger than 4 KB. [url=http://fastlz.org/]FastLZ[/url] compression. This option uses less CPU resources compared to [constant COMPRESS_ZLIB], at the expense of using more bandwidth. - [url=https://www.zlib.net/]Zlib[/url] compression. This option uses less bandwidth compared to [constant COMPRESS_FASTLZ], at the expense of using more CPU resources. + [url=https://www.zlib.net/]Zlib[/url] compression. This option uses less bandwidth compared to [constant COMPRESS_FASTLZ], at the expense of using more CPU resources. Note that this algorithm is not very efficient on packets smaller than 4 KB. Therefore, it's recommended to use other compression algorithms in most cases. [url=https://facebook.github.io/zstd/]Zstandard[/url] compression. diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 9e06f4fb0897..2383fae386b9 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -897,7 +897,7 @@ NetworkedMultiplayerENet::NetworkedMultiplayerENet() { transfer_channel = -1; always_ordered = false; connection_status = CONNECTION_DISCONNECTED; - compression_mode = COMPRESS_NONE; + compression_mode = COMPRESS_RANGE_CODER; enet_compressor.context = this; enet_compressor.compress = enet_compress; enet_compressor.decompress = enet_decompress;