diff --git a/Lidgren.Network/NetConnection.cs b/Lidgren.Network/NetConnection.cs index 29601f6..72ce6a9 100644 --- a/Lidgren.Network/NetConnection.cs +++ b/Lidgren.Network/NetConnection.cs @@ -182,7 +182,8 @@ namespace Lidgren.Network m_lastSentUnsentMessages = now; } - int mtu = m_peerConfiguration.MaximumTransmissionUnit; + int mtu = m_peerConfiguration.m_maximumTransmissionUnit; + bool useCoalescing = m_peerConfiguration.m_useMessageCoalescing; float throttleThreshold = m_peerConfiguration.m_throttlePeakBytes; if (m_throttleDebt < throttleThreshold) @@ -204,7 +205,7 @@ namespace Lidgren.Network int msgPayloadLength = msg.LengthBytes; msg.m_lastSentTime = now; - if (ptr > 0 && (ptr + NetPeer.kMaxPacketHeaderSize + msgPayloadLength) > mtu) + if (!useCoalescing || (ptr > 0 && (ptr + NetPeer.kMaxPacketHeaderSize + msgPayloadLength) > mtu)) { // send packet and start new packet bool connectionReset; @@ -561,6 +562,9 @@ namespace Lidgren.Network { if (msg.IsSent) throw new NetException("Message has already been sent!"); + + NetException.Assert(sequenceChannel >= 0 && sequenceChannel < NetConstants.NetChannelsPerDeliveryMethod, "Sequence channel must be between 0 and NetConstants.NetChannelsPerDeliveryMethod (" + NetConstants.NetChannelsPerDeliveryMethod + ")"); + msg.m_type = (NetMessageType)((int)method + sequenceChannel); EnqueueOutgoingMessage(msg); } diff --git a/Lidgren.Network/NetPeerConfiguration.cs b/Lidgren.Network/NetPeerConfiguration.cs index 8576339..4459cc4 100644 --- a/Lidgren.Network/NetPeerConfiguration.cs +++ b/Lidgren.Network/NetPeerConfiguration.cs @@ -37,6 +37,7 @@ namespace Lidgren.Network internal int m_receiveBufferSize, m_sendBufferSize; internal int m_defaultOutgoingMessageCapacity; internal int m_maximumTransmissionUnit; + internal bool m_useMessageCoalescing; internal int m_maximumConnections; internal NetIncomingMessageType m_disabledTypes; internal int m_throttleBytesPerSecond; @@ -85,6 +86,7 @@ namespace Lidgren.Network m_handshakeAttemptDelay = 1.0f; m_handshakeMaxAttempts = 7; m_maxRecycledBytesKept = 128 * 1024; + m_useMessageCoalescing = true; m_loss = 0.0f; m_minimumOneWayLatency = 0.0f; @@ -254,6 +256,15 @@ namespace Lidgren.Network } } + /// + /// Gets or sets if message coalescing (sending multiple messages in a single packet) should be used. Normally this should be true. + /// + public bool UseMessageCoalescing + { + get { return m_useMessageCoalescing; } + set { m_useMessageCoalescing = value; } + } + /// /// Gets or sets the maximum amount of connections this peer can hold. Cannot be changed once NetPeer is initialized. ///