You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-15 14:46:29 +09:00
Added WriteAt() methods and fixed unnecessarily large allocation
This commit is contained in:
@@ -161,6 +161,18 @@ namespace Lidgren.Network
|
||||
m_bitLength += 16;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 16 bit unsigned integer at a given offset in the buffer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void WriteAt(Int32 offset, UInt16 source)
|
||||
{
|
||||
int newBitLength = Math.Max(m_bitLength, offset + 16);
|
||||
EnsureBufferSize(newBitLength);
|
||||
NetBitWriter.WriteUInt16(source, 16, m_data, offset);
|
||||
m_bitLength = newBitLength;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an unsigned integer using 1 to 16 bits
|
||||
/// </summary>
|
||||
@@ -183,6 +195,17 @@ namespace Lidgren.Network
|
||||
m_bitLength += 16;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 16 bit signed integer at a given offset in the buffer
|
||||
/// </summary>
|
||||
public void WriteAt(Int32 offset, Int16 source)
|
||||
{
|
||||
int newBitLength = Math.Max(m_bitLength, offset + 16);
|
||||
EnsureBufferSize(newBitLength);
|
||||
NetBitWriter.WriteUInt16((ushort)source, 16, m_data, offset);
|
||||
m_bitLength = newBitLength;
|
||||
}
|
||||
|
||||
#if UNSAFE
|
||||
/// <summary>
|
||||
/// Writes a 32 bit signed integer
|
||||
@@ -222,7 +245,7 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public void WriteAt(Int32 offset, Int32 source)
|
||||
{
|
||||
int newBitLength = Math.Max(m_bitLength + 32, offset + 32);
|
||||
int newBitLength = Math.Max(m_bitLength, offset + 32);
|
||||
EnsureBufferSize(newBitLength);
|
||||
NetBitWriter.WriteUInt32((UInt32)source, 32, m_data, offset);
|
||||
m_bitLength = newBitLength;
|
||||
@@ -267,9 +290,10 @@ namespace Lidgren.Network
|
||||
/// <summary>
|
||||
/// Writes a 32 bit unsigned integer at a given offset in the buffer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void WriteAt(Int32 offset, UInt32 source)
|
||||
{
|
||||
int newBitLength = Math.Max(m_bitLength + 32, offset + 32);
|
||||
int newBitLength = Math.Max(m_bitLength, offset + 32);
|
||||
EnsureBufferSize(newBitLength);
|
||||
NetBitWriter.WriteUInt32(source, 32, m_data, offset);
|
||||
m_bitLength = newBitLength;
|
||||
@@ -321,6 +345,18 @@ namespace Lidgren.Network
|
||||
m_bitLength += 64;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 64 bit unsigned integer at a given offset in the buffer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void WriteAt(Int32 offset, UInt64 source)
|
||||
{
|
||||
int newBitLength = Math.Max(m_bitLength, offset + 64);
|
||||
EnsureBufferSize(newBitLength);
|
||||
NetBitWriter.WriteUInt64(source, 64, m_data, offset);
|
||||
m_bitLength = newBitLength;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an unsigned integer using 1 to 64 bits
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user