diff --git a/Lidgren.Network/NetBigInteger.cs b/Lidgren.Network/NetBigInteger.cs index 241c883..8f57fd7 100644 --- a/Lidgren.Network/NetBigInteger.cs +++ b/Lidgren.Network/NetBigInteger.cs @@ -12,7 +12,7 @@ namespace Lidgren.Network internal class NetBigInteger { private const long IMASK = 0xffffffffL; - private static readonly ulong UIMASK = (ulong)IMASK; + private const ulong UIMASK = (ulong)IMASK; private static readonly int[] ZeroMagnitude = new int[0]; private static readonly byte[] ZeroEncoding = new byte[0]; @@ -23,15 +23,15 @@ namespace Lidgren.Network public static readonly NetBigInteger Three = createUValueOf(3); public static readonly NetBigInteger Ten = createUValueOf(10); - private static readonly int chunk2 = 1; + private const int chunk2 = 1; private static readonly NetBigInteger radix2 = ValueOf(2); private static readonly NetBigInteger radix2E = radix2.Pow(chunk2); - private static readonly int chunk10 = 19; + private const int chunk10 = 19; private static readonly NetBigInteger radix10 = ValueOf(10); private static readonly NetBigInteger radix10E = radix10.Pow(chunk10); - private static readonly int chunk16 = 16; + private const int chunk16 = 16; private static readonly NetBigInteger radix16 = ValueOf(16); private static readonly NetBigInteger radix16E = radix16.Pow(chunk16); diff --git a/Lidgren.Network/NetBitWriter.cs b/Lidgren.Network/NetBitWriter.cs index 44e4cbf..25a616f 100644 --- a/Lidgren.Network/NetBitWriter.cs +++ b/Lidgren.Network/NetBitWriter.cs @@ -97,6 +97,9 @@ namespace Lidgren.Network return; } + /// + /// Write 0-8 bits of data to buffer + /// public static void WriteByte(byte source, int numberOfBits, byte[] destination, int destBitOffset) { if (numberOfBits == 0) diff --git a/Lidgren.Network/NetBuffer.Write.cs b/Lidgren.Network/NetBuffer.Write.cs index b611a20..2c8b169 100644 --- a/Lidgren.Network/NetBuffer.Write.cs +++ b/Lidgren.Network/NetBuffer.Write.cs @@ -601,32 +601,14 @@ namespace Lidgren.Network /// /// Append all the bits of message to this message /// - public void Write(NetOutgoingMessage message) + public void Write(NetBuffer buffer) { - EnsureBufferSize(m_bitLength + (message.LengthBytes * 8)); + EnsureBufferSize(m_bitLength + (buffer.LengthBytes * 8)); - Write(message.m_data, 0, message.LengthBytes); + Write(buffer.m_data, 0, buffer.LengthBytes); // did we write excessive bits? - int bitsInLastByte = (message.m_bitLength % 8); - if (bitsInLastByte != 0) - { - int excessBits = 8 - bitsInLastByte; - m_bitLength -= excessBits; - } - } - - /// - /// Append all the bits of message to this message - /// - public void Write(NetIncomingMessage message) - { - EnsureBufferSize(m_bitLength + (message.LengthBytes * 8)); - - Write(message.m_data, 0, message.LengthBytes); - - // did we write excessive bits? - int bitsInLastByte = (message.m_bitLength % 8); + int bitsInLastByte = (buffer.m_bitLength % 8); if (bitsInLastByte != 0) { int excessBits = 8 - bitsInLastByte; diff --git a/Lidgren.Network/NetConnection.MTU.cs b/Lidgren.Network/NetConnection.MTU.cs index 11a5195..6de22fe 100644 --- a/Lidgren.Network/NetConnection.MTU.cs +++ b/Lidgren.Network/NetConnection.MTU.cs @@ -46,7 +46,7 @@ namespace Lidgren.Network } // begin expansion - ExpandMTU(now, true); + ExpandMTU(now); return; } @@ -61,11 +61,11 @@ namespace Lidgren.Network // timed out; ie. failed m_smallestFailedMTU = m_lastSentMTUAttemptSize; - ExpandMTU(now, false); + ExpandMTU(now); } } - private void ExpandMTU(double now, bool succeeded) + private void ExpandMTU(double now) { int tryMTU; @@ -120,7 +120,7 @@ namespace Lidgren.Network return; } } - ExpandMTU(now, false); + ExpandMTU(now); return; } @@ -169,7 +169,7 @@ namespace Lidgren.Network //m_peer.LogDebug("Expanding MTU to " + size); m_currentMTU = size; - ExpandMTU(now, true); + ExpandMTU(now); } } } diff --git a/Lidgren.Network/NetOutgoingMessage.Write.Reflection.cs b/Lidgren.Network/NetOutgoingMessage.Write.Reflection.cs deleted file mode 100644 index a05e6b3..0000000 --- a/Lidgren.Network/NetOutgoingMessage.Write.Reflection.cs +++ /dev/null @@ -1,91 +0,0 @@ -/* Copyright (c) 2010 Michael Lidgren - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software -and associated documentation files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom -the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -using System; -using System.Reflection; - -namespace Lidgren.Network -{ - public partial class NetOutgoingMessage - { - /// - /// Writes all public and private declared instance fields of the object in alphabetical order using reflection - /// - public void WriteAllFields(object ob) - { - WriteAllFields(ob, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); - } - - /// - /// Writes all fields with specified binding in alphabetical order using reflection - /// - public void WriteAllFields(object ob, BindingFlags flags) - { - if (ob == null) - return; - Type tp = ob.GetType(); - - FieldInfo[] fields = tp.GetFields(flags); - NetUtility.SortMembersList(fields); - - foreach (FieldInfo fi in fields) - { - object value = fi.GetValue(ob); - - // find the appropriate Write method - MethodInfo writeMethod; - if (s_writeMethods.TryGetValue(fi.FieldType, out writeMethod)) - writeMethod.Invoke(this, new object[] { value }); - else - throw new NetException("Failed to find write method for type " + fi.FieldType); - } - } - - /// - /// Writes all public and private declared instance properties of the object in alphabetical order using reflection - /// - public void WriteAllProperties(object ob) - { - WriteAllProperties(ob, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); - } - - /// - /// Writes all properties with specified binding in alphabetical order using reflection - /// - public void WriteAllProperties(object ob, BindingFlags flags) - { - if (ob == null) - return; - Type tp = ob.GetType(); - - PropertyInfo[] fields = tp.GetProperties(flags); - NetUtility.SortMembersList(fields); - - foreach (PropertyInfo fi in fields) - { - MethodInfo getMethod = fi.GetGetMethod((flags & BindingFlags.NonPublic) == BindingFlags.NonPublic); - object value = getMethod.Invoke(ob, null); - - // find the appropriate Write method - MethodInfo writeMethod; - if (s_writeMethods.TryGetValue(fi.PropertyType, out writeMethod)) - writeMethod.Invoke(this, new object[] { value }); - } - } - } -} \ No newline at end of file diff --git a/Lidgren.Network/NetOutgoingMessage.Write.cs b/Lidgren.Network/NetOutgoingMessage.Write.cs deleted file mode 100644 index 5c098ca..0000000 --- a/Lidgren.Network/NetOutgoingMessage.Write.cs +++ /dev/null @@ -1,659 +0,0 @@ -/* Copyright (c) 2010 Michael Lidgren - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software -and associated documentation files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom -the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or -substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -using System; -using System.Collections.Generic; -using System.Net; -using System.Reflection; -using System.Text; -using System.Runtime.InteropServices; - -namespace Lidgren.Network -{ - public sealed partial class NetOutgoingMessage - { - private const int c_overAllocateAmount = 4; - - private static Dictionary s_writeMethods; - - internal byte[] m_data; - internal int m_bitLength; - - static NetOutgoingMessage() - { - s_writeMethods = new Dictionary(); - MethodInfo[] methods = typeof(NetOutgoingMessage).GetMethods(BindingFlags.Instance | BindingFlags.Public); - foreach (MethodInfo mi in methods) - { - if (mi.Name.Equals("Write", StringComparison.InvariantCulture)) - { - ParameterInfo[] pis = mi.GetParameters(); - if (pis.Length == 1) - s_writeMethods[pis[0].ParameterType] = mi; - } - } - } - - /// - /// Returns the internal data buffer, don't modify - /// - public byte[] PeekDataBuffer() - { - return m_data; - } - - /// - /// Gets or sets the length of the buffer in bytes - /// - public int LengthBytes - { - get { return ((m_bitLength + 7) >> 3); } - set - { - m_bitLength = value * 8; - InternalEnsureBufferSize(m_bitLength); - } - } - - /// - /// Gets or sets the length of the buffer in bits - /// - public int LengthBits - { - get { return m_bitLength; } - set - { - m_bitLength = value; - InternalEnsureBufferSize(m_bitLength); - } - } - - /// - /// Ensures the buffer can hold this number of bits - /// - public void EnsureBufferSize(int numberOfBits) - { - int byteLen = ((numberOfBits + 7) >> 3); - if (m_data == null) - { - m_data = new byte[byteLen + c_overAllocateAmount]; - return; - } - if (m_data.Length < byteLen) - Array.Resize(ref m_data, byteLen + c_overAllocateAmount); - return; - } - - /// - /// Ensures the buffer can hold this number of bits - /// - public void InternalEnsureBufferSize(int numberOfBits) - { - int byteLen = ((numberOfBits + 7) >> 3); - if (m_data == null) - { - m_data = new byte[byteLen]; - return; - } - if (m_data.Length < byteLen) - Array.Resize(ref m_data, byteLen); - return; - } - - /// - /// Writes a boolean value using 1 bit - /// - public void Write(bool value) - { - EnsureBufferSize(m_bitLength + 1); - NetBitWriter.WriteByte((value ? (byte)1 : (byte)0), 1, m_data, m_bitLength); - m_bitLength += 1; - } - - /// - /// Write a byte - /// - public void Write(byte source) - { - EnsureBufferSize(m_bitLength + 8); - NetBitWriter.WriteByte(source, 8, m_data, m_bitLength); - m_bitLength += 8; - } - - /// - /// Writes a signed byte - /// - [CLSCompliant(false)] - public void Write(sbyte source) - { - EnsureBufferSize(m_bitLength + 8); - NetBitWriter.WriteByte((byte)source, 8, m_data, m_bitLength); - m_bitLength += 8; - } - - /// - /// Writes 1 to 8 bits of a byte - /// - public void Write(byte source, int numberOfBits) - { - NetException.Assert((numberOfBits > 0 && numberOfBits <= 8), "Write(byte, numberOfBits) can only write between 1 and 8 bits"); - EnsureBufferSize(m_bitLength + numberOfBits); - NetBitWriter.WriteByte(source, numberOfBits, m_data, m_bitLength); - m_bitLength += numberOfBits; - } - - /// - /// Writes all bytes in an array - /// - public void Write(byte[] source) - { - if (source == null) - throw new ArgumentNullException("source"); - int bits = source.Length * 8; - EnsureBufferSize(m_bitLength + bits); - NetBitWriter.WriteBytes(source, 0, source.Length, m_data, m_bitLength); - m_bitLength += bits; - } - - /// - /// Writes the specified number of bytes from an array - /// - public void Write(byte[] source, int offsetInBytes, int numberOfBytes) - { - if (source == null) - throw new ArgumentNullException("source"); - int bits = numberOfBytes * 8; - EnsureBufferSize(m_bitLength + bits); - NetBitWriter.WriteBytes(source, offsetInBytes, numberOfBytes, m_data, m_bitLength); - m_bitLength += bits; - } - - /// - /// Writes an unsigned 16 bit integer - /// - /// - [CLSCompliant(false)] - public void Write(UInt16 source) - { - EnsureBufferSize(m_bitLength + 16); - NetBitWriter.WriteUInt32((uint)source, 16, m_data, m_bitLength); - m_bitLength += 16; - } - - /// - /// Writes an unsigned integer using 1 to 16 bits - /// - [CLSCompliant(false)] - public void Write(UInt16 source, int numberOfBits) - { - NetException.Assert((numberOfBits > 0 && numberOfBits <= 16), "Write(ushort, numberOfBits) can only write between 1 and 16 bits"); - EnsureBufferSize(m_bitLength + numberOfBits); - NetBitWriter.WriteUInt32((uint)source, numberOfBits, m_data, m_bitLength); - m_bitLength += numberOfBits; - } - - /// - /// Writes a signed 16 bit integer - /// - public void Write(Int16 source) - { - EnsureBufferSize(m_bitLength + 16); - NetBitWriter.WriteUInt32((uint)source, 16, m_data, m_bitLength); - m_bitLength += 16; - } - -#if UNSAFE - /// - /// Writes a 32 bit signed integer - /// - public unsafe void Write(Int32 source) - { - EnsureBufferSize(m_bitLength + 32); - - // can write fast? - if (m_bitLength % 8 == 0) - { - fixed (byte* numRef = &Data[m_bitLength / 8]) - { - *((int*)numRef) = source; - } - } - else - { - NetBitWriter.WriteUInt32((UInt32)source, 32, Data, m_bitLength); - } - m_bitLength += 32; - } -#else - /// - /// Writes a 32 bit signed integer - /// - public void Write(Int32 source) - { - EnsureBufferSize(m_bitLength + 32); - NetBitWriter.WriteUInt32((UInt32)source, 32, m_data, m_bitLength); - m_bitLength += 32; - } -#endif - -#if UNSAFE - /// - /// Writes a 32 bit unsigned integer - /// - public unsafe void Write(UInt32 source) - { - EnsureBufferSize(m_bitLength + 32); - - // can write fast? - if (m_bitLength % 8 == 0) - { - fixed (byte* numRef = &Data[m_bitLength / 8]) - { - *((uint*)numRef) = source; - } - } - else - { - NetBitWriter.WriteUInt32(source, 32, Data, m_bitLength); - } - - m_bitLength += 32; - } -#else - /// - /// Writes a 32 bit unsigned integer - /// - [CLSCompliant(false)] - public void Write(UInt32 source) - { - EnsureBufferSize(m_bitLength + 32); - NetBitWriter.WriteUInt32(source, 32, m_data, m_bitLength); - m_bitLength += 32; - } -#endif - - /// - /// Writes a 32 bit signed integer - /// - [CLSCompliant(false)] - public void Write(UInt32 source, int numberOfBits) - { - NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "Write(uint, numberOfBits) can only write between 1 and 32 bits"); - EnsureBufferSize(m_bitLength + numberOfBits); - NetBitWriter.WriteUInt32(source, numberOfBits, m_data, m_bitLength); - m_bitLength += numberOfBits; - } - - /// - /// Writes a signed integer using 1 to 32 bits - /// - public void Write(Int32 source, int numberOfBits) - { - NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "Write(int, numberOfBits) can only write between 1 and 32 bits"); - EnsureBufferSize(m_bitLength + numberOfBits); - - if (numberOfBits != 32) - { - // make first bit sign - int signBit = 1 << (numberOfBits - 1); - if (source < 0) - source = (-source - 1) | signBit; - else - source &= (~signBit); - } - - NetBitWriter.WriteUInt32((uint)source, numberOfBits, m_data, m_bitLength); - - m_bitLength += numberOfBits; - } - - /// - /// Writes a 64 bit unsigned integer - /// - [CLSCompliant(false)] - public void Write(UInt64 source) - { - EnsureBufferSize(m_bitLength + 64); - NetBitWriter.WriteUInt64(source, 64, m_data, m_bitLength); - m_bitLength += 64; - } - - /// - /// Writes an unsigned integer using 1 to 64 bits - /// - [CLSCompliant(false)] - public void Write(UInt64 source, int numberOfBits) - { - EnsureBufferSize(m_bitLength + numberOfBits); - NetBitWriter.WriteUInt64(source, numberOfBits, m_data, m_bitLength); - m_bitLength += numberOfBits; - } - - /// - /// Writes a 64 bit signed integer - /// - public void Write(Int64 source) - { - EnsureBufferSize(m_bitLength + 64); - ulong usource = (ulong)source; - NetBitWriter.WriteUInt64(usource, 64, m_data, m_bitLength); - m_bitLength += 64; - } - - /// - /// Writes a signed integer using 1 to 64 bits - /// - public void Write(Int64 source, int numberOfBits) - { - EnsureBufferSize(m_bitLength + numberOfBits); - ulong usource = (ulong)source; - NetBitWriter.WriteUInt64(usource, numberOfBits, m_data, m_bitLength); - m_bitLength += numberOfBits; - } - - // - // Floating point - // -#if UNSAFE - /// - /// Writes a 32 bit floating point value - /// - public unsafe void Write(float source) - { - uint val = *((uint*)&source); -#if BIGENDIAN - val = NetUtility.SwapByteOrder(val); -#endif - Write(val); - } -#else - /// - /// Writes a 32 bit floating point value - /// - public void Write(float source) - { - // Use union to avoid BitConverter.GetBytes() which allocates memory on the heap - SingleUIntUnion su; - su.UIntValue = 0; // must initialize every member of the union to avoid warning - su.SingleValue = source; - -#if BIGENDIAN - // swap byte order - su.UIntValue = NetUtility.SwapByteOrder(su.UIntValue); -#endif - Write(su.UIntValue); - } -#endif - -#if UNSAFE - /// - /// Writes a 64 bit floating point value - /// - public unsafe void Write(double source) - { - ulong val = *((ulong*)&source); -#if BIGENDIAN - val = NetUtility.SwapByteOrder(val); -#endif - Write(val); - } -#else - /// - /// Writes a 64 bit floating point value - /// - public void Write(double source) - { - byte[] val = BitConverter.GetBytes(source); -#if BIGENDIAN - // 0 1 2 3 4 5 6 7 - - // swap byte order - byte tmp = val[7]; - val[7] = val[0]; - val[0] = tmp; - - tmp = val[6]; - val[6] = val[1]; - val[1] = tmp; - - tmp = val[5]; - val[5] = val[2]; - val[2] = tmp; - - tmp = val[4]; - val[4] = val[3]; - val[3] = tmp; -#endif - Write(val); - } -#endif - - // - // Variable bits - // - - /// - /// Write Base128 encoded variable sized unsigned integer of up to 32 bits - /// - /// number of bytes written - [CLSCompliant(false)] - public int WriteVariableUInt32(uint value) - { - int retval = 1; - uint num1 = (uint)value; - while (num1 >= 0x80) - { - this.Write((byte)(num1 | 0x80)); - num1 = num1 >> 7; - retval++; - } - this.Write((byte)num1); - return retval; - } - - /// - /// Write Base128 encoded variable sized signed integer of up to 32 bits - /// - /// number of bytes written - public int WriteVariableInt32(int value) - { - uint zigzag = (uint)(value << 1) ^ (uint)(value >> 31); - return WriteVariableUInt32(zigzag); - } - - /// - /// Write Base128 encoded variable sized signed integer of up to 64 bits - /// - /// number of bytes written - public int WriteVariableInt64(Int64 value) - { - ulong zigzag = (ulong)(value << 1) ^ (ulong)(value >> 63); - return WriteVariableUInt64(zigzag); - } - - /// - /// Write Base128 encoded variable sized unsigned integer of up to 64 bits - /// - /// number of bytes written - [CLSCompliant(false)] - public int WriteVariableUInt64(UInt64 value) - { - int retval = 1; - UInt64 num1 = (UInt64)value; - while (num1 >= 0x80) - { - this.Write((byte)(num1 | 0x80)); - num1 = num1 >> 7; - retval++; - } - this.Write((byte)num1); - return retval; - } - - /// - /// Compress (lossy) a float in the range -1..1 using numberOfBits bits - /// - public void WriteSignedSingle(float value, int numberOfBits) - { - NetException.Assert(((value >= -1.0) && (value <= 1.0)), " WriteSignedSingle() must be passed a float in the range -1 to 1; val is " + value); - - float unit = (value + 1.0f) * 0.5f; - int maxVal = (1 << numberOfBits) - 1; - uint writeVal = (uint)(unit * (float)maxVal); - - Write(writeVal, numberOfBits); - } - - /// - /// Compress (lossy) a float in the range 0..1 using numberOfBits bits - /// - public void WriteUnitSingle(float value, int numberOfBits) - { - NetException.Assert(((value >= 0.0) && (value <= 1.0)), " WriteUnitSingle() must be passed a float in the range 0 to 1; val is " + value); - - int maxValue = (1 << numberOfBits) - 1; - uint writeVal = (uint)(value * (float)maxValue); - - Write(writeVal, numberOfBits); - } - - /// - /// Compress a float within a specified range using a certain number of bits - /// - public void WriteRangedSingle(float value, float min, float max, int numberOfBits) - { - NetException.Assert(((value >= min) && (value <= max)), " WriteRangedSingle() must be passed a float in the range MIN to MAX; val is " + value); - - float range = max - min; - float unit = ((value - min) / range); - int maxVal = (1 << numberOfBits) - 1; - Write((UInt32)((float)maxVal * unit), numberOfBits); - } - - /// - /// Writes an integer with the least amount of bits need for the specified range - /// Returns number of bits written - /// - public int WriteRangedInteger(int min, int max, int value) - { - NetException.Assert(value >= min && value <= max, "Value not within min/max range!"); - - uint range = (uint)(max - min); - int numBits = NetUtility.BitsToHoldUInt(range); - - uint rvalue = (uint)(value - min); - Write(rvalue, numBits); - - return numBits; - } - - /// - /// Write a string - /// - public void Write(string source) - { - if (string.IsNullOrEmpty(source)) - { - EnsureBufferSize(m_bitLength + 8); - WriteVariableUInt32(0); - return; - } - - byte[] bytes = Encoding.UTF8.GetBytes(source); - EnsureBufferSize(m_bitLength + 8 + (bytes.Length * 8)); - WriteVariableUInt32((uint)bytes.Length); - Write(bytes); - } - - /// - /// Writes an endpoint description - /// - public void Write(IPEndPoint endPoint) - { - byte[] bytes = endPoint.Address.GetAddressBytes(); - Write((byte)bytes.Length); - Write(bytes); - Write((ushort)endPoint.Port); - } - - /// - /// Writes the local time to a message; readable (and convertable to local time) by the remote host using ReadTime() - /// - public void WriteTime(double localTime, bool highPrecision) - { - if (highPrecision) - Write(localTime); - else - Write((float)localTime); - } - - /// - /// Pads data with enough bits to reach a full byte. Decreases cpu usage for subsequent byte writes. - /// - public void WritePadBits() - { - m_bitLength = ((m_bitLength + 7) >> 3) * 8; - EnsureBufferSize(m_bitLength); - } - - /// - /// Pads data with the specified number of bits. - /// - public void WritePadBits(int numberOfBits) - { - m_bitLength += numberOfBits; - EnsureBufferSize(m_bitLength); - } - - /// - /// Append all the bits of message to this message - /// - public void Write(NetOutgoingMessage message) - { - EnsureBufferSize(m_bitLength + (message.LengthBytes * 8)); - - Write(message.m_data, 0, message.LengthBytes); - - // did we write excessive bits? - int bitsInLastByte = (message.m_bitLength % 8); - if (bitsInLastByte != 0) - { - int excessBits = 8 - bitsInLastByte; - m_bitLength -= excessBits; - } - } - - /// - /// Append all the bits of message to this message - /// - public void Write(NetIncomingMessage message) - { - EnsureBufferSize(m_bitLength + (message.LengthBytes * 8)); - - Write(message.m_data, 0, message.LengthBytes); - - // did we write excessive bits? - int bitsInLastByte = (message.m_bitLength % 8); - if (bitsInLastByte != 0) - { - int excessBits = 8 - bitsInLastByte; - m_bitLength -= excessBits; - } - } - } -} diff --git a/Lidgren.Network/NetPeer.Send.cs b/Lidgren.Network/NetPeer.Send.cs index 86e3323..575a5f9 100644 --- a/Lidgren.Network/NetPeer.Send.cs +++ b/Lidgren.Network/NetPeer.Send.cs @@ -62,7 +62,7 @@ namespace Lidgren.Network } } - internal int GetMTU(IList recipients) + internal static int GetMTU(IList recipients) { int count = recipients.Count; NetException.Assert(count > 0); diff --git a/Lidgren.Network/NetRandom.cs b/Lidgren.Network/NetRandom.cs index 2f9bf34..9c2abf6 100644 --- a/Lidgren.Network/NetRandom.cs +++ b/Lidgren.Network/NetRandom.cs @@ -75,7 +75,7 @@ namespace Lidgren.Network /// /// Create a semi-random seed based on an object /// - public int GetSeed(object forObject) + public static int GetSeed(object forObject) { // mix some semi-random properties int seed = (int)Environment.TickCount; diff --git a/Lidgren.Network/NetUnreliableSenderChannel.cs b/Lidgren.Network/NetUnreliableSenderChannel.cs index 7d54c23..29a88ab 100644 --- a/Lidgren.Network/NetUnreliableSenderChannel.cs +++ b/Lidgren.Network/NetUnreliableSenderChannel.cs @@ -65,12 +65,12 @@ namespace Lidgren.Network { NetOutgoingMessage om; if (m_queuedSends.TryDequeue(out om)) - ExecuteSend(now, om); + ExecuteSend(om); num--; } } - private void ExecuteSend(float now, NetOutgoingMessage message) + private void ExecuteSend(NetOutgoingMessage message) { m_connection.m_peer.VerifyNetworkThread();