diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp1.meta deleted file mode 100644 index 33faaa30..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 454f6287cca1ad140aa09757624c67f6 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/ByteBuffer.cs b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/ByteBuffer.cs deleted file mode 100644 index 83c41559..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/ByteBuffer.cs +++ /dev/null @@ -1,1200 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace KcpProject -{ - class ByteBuffer : ICloneable - { - //字节缓存区 - private byte[] buf; - //读取索引 - private int readIndex = 0; - //写入索引 - private int writeIndex = 0; - //读取索引标记 - private int markReadIndex = 0; - //写入索引标记 - private int markWirteIndex = 0; - //缓存区字节数组的长度 - private int capacity; - - //对象池 - private static List pool = new List(); - private static int poolMaxCount = 200; - - //此对象是否池化 - private bool isPool = false; - - /// - /// 构造方法 - /// - /// 初始容量 - private ByteBuffer(int capacity) - { - this.buf = new byte[capacity]; - this.capacity = capacity; - this.readIndex = 0; - this.writeIndex = 0; - } - - /// - /// 构造方法 - /// - /// 初始字节数组 - private ByteBuffer(byte[] bytes) - { - this.buf = new byte[bytes.Length]; - Array.Copy(bytes, 0, buf, 0, buf.Length); - this.capacity = buf.Length; - this.readIndex = 0; - this.writeIndex = bytes.Length + 1; - } - - /// - /// 构建一个capacity长度的字节缓存区ByteBuffer对象 - /// - /// 初始容量 - /// - /// true表示获取一个池化的ByteBuffer对象,池化的对象必须在调用Dispose后才会推入池中,此方法为线程安全的。 - /// 当为true时,从池中获取的对象的实际capacity值。 - /// - /// ByteBuffer对象 - public static ByteBuffer Allocate(int capacity, bool fromPool = false) - { - if (!fromPool) - { - return new ByteBuffer(capacity); - } - lock (pool) - { - ByteBuffer bbuf; - if (pool.Count == 0) - { - bbuf = new ByteBuffer(capacity) - { - isPool = true - }; - return bbuf; - } - int lastIndex = pool.Count - 1; - bbuf = pool[lastIndex]; - pool.RemoveAt(lastIndex); - if (!bbuf.isPool) - { - bbuf.isPool = true; - } - return bbuf; - } - } - - /// - /// 构建一个以bytes为字节缓存区的ByteBuffer对象,一般不推荐使用 - /// - /// 初始字节数组 - /// - /// true表示获取一个池化的ByteBuffer对象,池化的对象必须在调用Dispose后才会推入池中,此方法为线程安全的。 - /// - /// ByteBuffer对象 - public static ByteBuffer Allocate(byte[] bytes, bool fromPool = false) - { - if (!fromPool) - { - return new ByteBuffer(bytes); - } - lock (pool) - { - ByteBuffer bbuf; - if (pool.Count == 0) - { - bbuf = new ByteBuffer(bytes) - { - isPool = true - }; - return bbuf; - } - int lastIndex = pool.Count - 1; - bbuf = pool[lastIndex]; - bbuf.WriteBytes(bytes); - pool.RemoveAt(lastIndex); - if (!bbuf.isPool) - { - bbuf.isPool = true; - } - return bbuf; - } - } - - /// - /// 根据value,确定大于此length的最近的2次方数,如length=7,则返回值为8;length=12,则返回16 - /// - /// 参考容量 - /// 比参考容量大的最接近的2次方数 - private int FixLength(int value) - { - if (value == 0) - { - return 1; - } - value--; - value |= value >> 1; - value |= value >> 2; - value |= value >> 4; - value |= value >> 8; - value |= value >> 16; - return value + 1; - //int n = 2; - //int b = 2; - //while (b < length) - //{ - // b = 2 << n; - // n++; - //} - //return b; - } - - /// - /// 翻转字节数组,如果本地字节序列为高字节序列,则进行翻转以转换为低字节序列 - /// - /// 待转为高字节序的字节数组 - /// 低字节序列的字节数组 - private byte[] Flip(byte[] bytes) - { - //if (BitConverter.IsLittleEndian) - //{ - // Array.Reverse(bytes); - //} - return bytes; - } - - /// - /// 确定内部字节缓存数组的大小 - /// - /// 当前容量 - /// 将来的容量 - /// 当前缓冲区的最大容量 - private int FixSizeAndReset(int currLen, int futureLen) - { - if (futureLen > currLen) - { - //以原大小的2次方数的两倍确定内部字节缓存区大小 - int size = FixLength(currLen) * 2; - if (futureLen > size) - { - //以将来的大小的2次方的两倍确定内部字节缓存区大小 - size = FixLength(futureLen) * 2; - } - byte[] newbuf = new byte[size]; - Array.Copy(buf, 0, newbuf, 0, currLen); - buf = newbuf; - capacity = size; - } - return futureLen; - } - - /// - /// 确保有这么多字节可以用来写入 - /// - /// - public void EnsureWritableBytes(int minBytes) - { - // 如果没有足够的空间进行写入了 - if (WritableBytes < minBytes) - { - - // 优先整理空间 - if (ReaderIndex >= minBytes) - { - // 整理出来可用空间 - TrimReadedBytes(); - } - else - { - // 空间不足时,重新分配内存 - FixSizeAndReset(buf.Length, buf.Length + minBytes); - } - } - } - - public void TrimReadedBytes() - { - Buffer.BlockCopy(buf, readIndex, buf, 0, writeIndex - readIndex); - writeIndex -= readIndex; - readIndex = 0; - } - - /// - /// 将bytes字节数组从startIndex开始的length字节写入到此缓存区 - /// - /// 待写入的字节数据 - /// 写入的开始位置 - /// 写入的长度 - public void WriteBytes(byte[] bytes, int startIndex, int length) - { - if (length <= 0 || startIndex < 0) return; - - int total = length + writeIndex; - int len = buf.Length; - FixSizeAndReset(len, total); - Array.Copy(bytes, startIndex, buf, writeIndex, length); - writeIndex = total; - } - - /// - /// 将字节数组中从0到length的元素写入缓存区 - /// - /// 待写入的字节数据 - /// 写入的长度 - public void WriteBytes(byte[] bytes, int length) - { - WriteBytes(bytes, 0, length); - } - - /// - /// 将字节数组全部写入缓存区 - /// - /// 待写入的字节数据 - public void WriteBytes(byte[] bytes) - { - WriteBytes(bytes, bytes.Length); - } - - /// - /// 将一个ByteBuffer的有效字节区写入此缓存区中 - /// - /// 待写入的字节缓存区 - public void Write(ByteBuffer buffer) - { - if (buffer == null) return; - if (buffer.ReadableBytes <= 0) return; - WriteBytes(buffer.ToArray()); - } - - /// - /// 写入一个int16数据 - /// - /// short数据 - public void WriteShort(short value) - { - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 写入一个uint16数据 - /// - /// ushort数据 - public void WriteUshort(ushort value) - { - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 写入一个int32数据 - /// - /// int数据 - public void WriteInt(int value) - { - //byte[] array = new byte[4]; - //for (int i = 3; i >= 0; i--) - //{ - // array[i] = (byte)(value & 0xff); - // value = value >> 8; - //} - //Array.Reverse(array); - //Write(array); - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 写入一个uint32数据 - /// - /// uint数据 - public void WriteUint(uint value) - { - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 写入一个int64数据 - /// - /// long数据 - public void WriteLong(long value) - { - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 写入一个uint64数据 - /// - /// ulong数据 - public void WriteUlong(ulong value) - { - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 写入一个float数据 - /// - /// float数据 - public void WriteFloat(float value) - { - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 写入一个byte数据 - /// - /// byte数据 - public void WriteByte(byte value) - { - int afterLen = writeIndex + 1; - int len = buf.Length; - FixSizeAndReset(len, afterLen); - buf[writeIndex] = value; - writeIndex = afterLen; - } - - /// - /// 写入一个byte数据 - /// - /// byte数据 - public void WriteByte(int value) - { - byte b = (byte)value; - WriteByte(b); - } - - /// - /// 写入一个double类型数据 - /// - /// double数据 - public void WriteDouble(double value) - { - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 写入一个字符 - /// - /// - public void WriteChar(char value) - { - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 写入一个布尔型数据 - /// - /// - public void WriteBoolean(bool value) - { - WriteBytes(Flip(BitConverter.GetBytes(value))); - } - - /// - /// 读取一个字节 - /// - /// 字节数据 - public byte ReadByte() - { - byte b = buf[readIndex]; - readIndex++; - return b; - } - - /// - /// 获取从index索引处开始len长度的字节 - /// - /// - /// - /// - private byte[] Get(int index, int len) - { - byte[] bytes = new byte[len]; - Array.Copy(buf, index, bytes, 0, len); - return Flip(bytes); - } - - /// - /// 从读取索引位置开始读取len长度的字节数组 - /// - /// 待读取的字节长度 - /// 字节数组 - private byte[] Read(int len) - { - byte[] bytes = Get(readIndex, len); - readIndex += len; - return bytes; - } - - /// - /// 读取一个uint16数据 - /// - /// ushort数据 - public ushort ReadUshort() - { - return BitConverter.ToUInt16(Read(2), 0); - } - - /// - /// 读取一个int16数据 - /// - /// short数据 - public short ReadShort() - { - return BitConverter.ToInt16(Read(2), 0); - } - - /// - /// 读取一个uint32数据 - /// - /// uint数据 - public uint ReadUint() - { - return BitConverter.ToUInt32(Read(4), 0); - } - - /// - /// 读取一个int32数据 - /// - /// int数据 - public int ReadInt() - { - return BitConverter.ToInt32(Read(4), 0); - } - - /// - /// 读取一个uint64数据 - /// - /// ulong数据 - public ulong ReadUlong() - { - return BitConverter.ToUInt64(Read(8), 0); - } - - /// - /// 读取一个long数据 - /// - /// long数据 - public long ReadLong() - { - return BitConverter.ToInt64(Read(8), 0); - } - - /// - /// 读取一个float数据 - /// - /// float数据 - public float ReadFloat() - { - return BitConverter.ToSingle(Read(4), 0); - } - - /// - /// 读取一个double数据 - /// - /// double数据 - public double ReadDouble() - { - return BitConverter.ToDouble(Read(8), 0); - } - - /// - /// 读取一个字符 - /// - /// - public char ReadChar() - { - return BitConverter.ToChar(Read(2), 0); - } - - /// - /// 读取布尔型数据 - /// - /// - public bool ReadBoolean() - { - return BitConverter.ToBoolean(Read(1), 0); - } - - /// - /// 从读取索引位置开始读取len长度的字节到disbytes目标字节数组中 - /// - /// 读取的字节将存入此字节数组 - /// 目标字节数组的写入索引 - /// 读取的长度 - public void ReadBytes(byte[] disbytes, int disstart, int len) - { - int size = disstart + len; - for (int i = disstart; i < size; i++) - { - disbytes[i] = this.ReadByte(); - } - } - - public byte[] ReadBytes(int len) - { - return ReadBytes(readIndex, len); - } - - public byte[] ReadBytes(int index, int len) - { - if (ReadableBytes < len) - throw new Exception("no more readable bytes"); - - var buffer = new byte[len]; - Array.Copy(buf, index, buffer, 0, len); - readIndex += len; - return buffer; - } - - /// - /// 获取一个字节 - /// - /// - /// - public byte GetByte(int index) - { - return buf[index]; - } - - /// - /// 获取一个字节 - /// - /// - public byte GetByte() - { - return GetByte(readIndex); - } - - /// - /// 获取一个双精度浮点数据,不改变数据内容 - /// - /// 字节索引 - /// - public double GetDouble(int index) - { - return BitConverter.ToDouble(Get(index, 8), 0); - } - - /// - /// 获取一个双精度浮点数据,不改变数据内容 - /// - /// - public double GetDouble() - { - return GetDouble(readIndex); - } - - /// - /// 获取一个浮点数据,不改变数据内容 - /// - /// 字节索引 - /// - public float GetFloat(int index) - { - return BitConverter.ToSingle(Get(index, 4), 0); - } - - /// - /// 获取一个浮点数据,不改变数据内容 - /// - /// - public float GetFloat() - { - return GetFloat(readIndex); - } - - /// - /// 获取一个长整形数据,不改变数据内容 - /// - /// 字节索引 - /// - public long GetLong(int index) - { - return BitConverter.ToInt64(Get(index, 8), 0); - } - - /// - /// 获取一个长整形数据,不改变数据内容 - /// - /// - public long GetLong() - { - return GetLong(readIndex); - } - - /// - /// 获取一个长整形数据,不改变数据内容 - /// - /// 字节索引 - /// - public ulong GetUlong(int index) - { - return BitConverter.ToUInt64(Get(index, 8), 0); - } - - /// - /// 获取一个长整形数据,不改变数据内容 - /// - /// - public ulong GetUlong() - { - return GetUlong(readIndex); - } - - /// - /// 获取一个整形数据,不改变数据内容 - /// - /// 字节索引 - /// - public int GetInt(int index) - { - return BitConverter.ToInt32(Get(index, 4), 0); - } - - /// - /// 获取一个整形数据,不改变数据内容 - /// - /// - public int GetInt() - { - return GetInt(readIndex); - } - - /// - /// 获取一个整形数据,不改变数据内容 - /// - /// 字节索引 - /// - public uint GetUint(int index) - { - return BitConverter.ToUInt32(Get(index, 4), 0); - } - - /// - /// 获取一个整形数据,不改变数据内容 - /// - /// - public uint GetUint() - { - return GetUint(readIndex); - } - - /// - /// 获取一个短整形数据,不改变数据内容 - /// - /// 字节索引 - /// - public int GetShort(int index) - { - return BitConverter.ToInt16(Get(index, 2), 0); - } - - /// - /// 获取一个短整形数据,不改变数据内容 - /// - /// - public int GetShort() - { - return GetShort(readIndex); - } - - /// - /// 获取一个短整形数据,不改变数据内容 - /// - /// 字节索引 - /// - public int GetUshort(int index) - { - return BitConverter.ToUInt16(Get(index, 2), 0); - } - - /// - /// 获取一个短整形数据,不改变数据内容 - /// - /// - public int GetUshort() - { - return GetUshort(readIndex); - } - - /// - /// 获取一个char数据,不改变数据内容 - /// - /// 字节索引 - /// - public char GetChar(int index) - { - return BitConverter.ToChar(Get(index, 2), 0); - } - - /// - /// 获取一个char数据,不改变数据内容 - /// - /// - public char GetChar() - { - return GetChar(readIndex); - } - - /// - /// 获取一个布尔数据,不改变数据内容 - /// - /// 字节索引 - /// - public bool GetBoolean(int index) - { - return BitConverter.ToBoolean(Get(index, 1), 0); - } - - /// - /// 获取一个布尔数据,不改变数据内容 - /// - /// - public bool GetBoolean() - { - return GetBoolean(readIndex); - } - - /// - /// 清除已读字节并重建缓存区 - /// - public void DiscardReadBytes() - { - if (readIndex <= 0) return; - int len = buf.Length - readIndex; - byte[] newbuf = new byte[len]; - Array.Copy(buf, readIndex, newbuf, 0, len); - buf = newbuf; - writeIndex -= readIndex; - markReadIndex -= readIndex; - if (markReadIndex < 0) - { - //markReadIndex = readIndex; - markReadIndex = 0; - } - markWirteIndex -= readIndex; - if (markWirteIndex < 0 || markWirteIndex < readIndex || markWirteIndex < markReadIndex) - { - markWirteIndex = writeIndex; - } - readIndex = 0; - } - - /// - /// 设置/获取读指针位置 - /// - public int ReaderIndex - { - get - { - return readIndex; - } - set - { - if (value < 0) return; - readIndex = value; - } - } - - /// - /// 设置/获取写指针位置 - /// - public int WriterIndex - { - get - { - return writeIndex; - } - set - { - if (value < 0) return; - writeIndex = value; - } - } - - /// - /// 标记读取的索引位置 - /// - public void MarkReaderIndex() - { - markReadIndex = readIndex; - } - - /// - /// 标记写入的索引位置 - /// - public void MarkWriterIndex() - { - markWirteIndex = writeIndex; - } - - /// - /// 将读取的索引位置重置为标记的读取索引位置 - /// - public void ResetReaderIndex() - { - readIndex = markReadIndex; - } - - /// - /// 将写入的索引位置重置为标记的写入索引位置 - /// - public void ResetWriterIndex() - { - writeIndex = markWirteIndex; - } - - /// - /// 可读的有效字节数 - /// - /// 可读的字节数 - public int ReadableBytes - { - get - { - return writeIndex - readIndex; - } - } - - /// - /// 可写的剩余空间数 - /// - /// 可写的字节数 - public int WritableBytes - { - get - { - return capacity - writeIndex; - } - } - - /// - /// 获取缓存区容量大小 - /// - /// 缓存区容量 - public int Capacity - { - get - { - return this.capacity; - } - } - - public byte[] RawBuffer - { - get - { - return buf; - } - } - - /// - /// 获取可读的字节数组 - /// - /// 字节数据 - public byte[] ToArray() - { - byte[] bytes = new byte[writeIndex - readIndex]; - Array.Copy(buf, readIndex, bytes, 0, bytes.Length); - return bytes; - } - - /// - /// 简单的数据类型 - /// - public enum DataType - { - //byte类型 - BYTE = 1, - //short类型 - SHORT = 2, - //int类型 - INT = 3, - //long类型 - LONG = 4 - } - - /// - /// 写入一个数据 - /// - /// 待写入的数据 - /// 待写入的数据类型 - private void WriteValue(int value, DataType type) - { - switch (type) - { - case DataType.BYTE: - this.WriteByte(value); - break; - case DataType.SHORT: - this.WriteShort((short)value); - break; - case DataType.LONG: - this.WriteLong((long)value); - break; - default: - this.WriteInt(value); - break; - } - } - - /// - /// 读取一个值,值类型根据type决定,int或short或byte - /// - /// 值类型 - /// int数据 - private int ReadValue(DataType type) - { - switch (type) - { - case DataType.BYTE: - return (int)ReadByte(); - case DataType.SHORT: - return (int)ReadShort(); - case DataType.INT: - return (int)ReadInt(); - case DataType.LONG: - return (int)ReadLong(); - default: - return -1; - } - } - - /// - /// 写入可变长的UTF-8字符串 - /// 以长度类型(byte:1, short:2, int:3) + 长度(根据长度类型写入到字节缓冲区) + 字节数组表示一个字符串 - /// - /// - //public void WriteUTF8VarString(string content) - //{ - // byte[] bytes = System.Text.Encoding.UTF8.GetBytes(content); - // ValueType lenType; - // if (bytes.Length <= byte.MaxValue) - // { - // lenType = ValueType.BYTE; - // } - // else if (bytes.Length <= short.MaxValue) - // { - // lenType = ValueType.SHORT; - // } - // else - // { - // lenType = ValueType.INT; - // } - // WriteByte((int)lenType); - // if (lenType == ValueType.BYTE) - // { - // WriteByte(bytes.Length); - // } - // else if (lenType == ValueType.SHORT) - // { - // WriteShort((short)bytes.Length); - // } - // else - // { - // WriteInt(bytes.Length); - // } - // WriteBytes(bytes); - //} - - /// - /// 读取可变长的UTF-8字符串 - /// 以长度类型(byte:1, short:2, int:3) + 长度(根据长度类型从字节缓冲区读取) + 字节数组表示一个字符串 - /// - /// - //public string ReadUTF8VarString() - //{ - // int lenTypeValue = ReadByte(); - // int len = 0; - // if (lenTypeValue == (int)ValueType.BYTE) - // { - // len = ReadByte(); - // } - // else if (lenTypeValue == (int)ValueType.SHORT) - // { - // len = ReadShort(); - // } - // else if (lenTypeValue == (int)ValueType.INT) - // { - // len = ReadInt(); - // } - // if (len > 0) - // { - // byte[] bytes = new byte[len]; - // ReadBytes(bytes, 0, len); - // return System.Text.Encoding.UTF8.GetString(bytes); - // } - // return ""; - //} - - /// - /// 写入一个UTF-8字符串,UTF-8字符串无高低字节序问题 - /// 写入缓冲区的结构为字符串字节长度(类型由lenType指定) + 字符串字节数组 - /// - /// 待写入的字符串 - /// 写入的字符串长度类型 - public void WriteUTF8String(string content, DataType lenType) - { - byte[] bytes = System.Text.Encoding.UTF8.GetBytes(content); - int max; - if (lenType == DataType.BYTE) - { - WriteByte(bytes.Length); - max = byte.MaxValue; - } - else if (lenType == DataType.SHORT) - { - WriteShort((short)bytes.Length); - max = short.MaxValue; - } - else - { - WriteInt(bytes.Length); - max = int.MaxValue; - } - if (bytes.Length > max) - { - WriteBytes(bytes, 0, max); - } - else - { - WriteBytes(bytes, 0, bytes.Length); - } - } - - /// - /// 写入以short表示的字符串字节长度和字符串字节数据 - /// - /// - public void WriteUTF(string content) - { - this.WriteUTF8String(content, DataType.SHORT); - } - - /// - /// 读取一个UTF-8字符串,UTF-8字符串无高低字节序问题 - /// - /// 需读取的字符串长度 - /// 字符串 - public string ReadUTF8String(int len) - { - byte[] bytes = new byte[len]; - this.ReadBytes(bytes, 0, len); - return System.Text.Encoding.UTF8.GetString(bytes); - } - - /// - /// 读取一个UTF-8字符串,UTF-8字符串无高低字节序问题 - /// - /// 字符串长度类型 - /// 字符串 - public string ReadUTF8String(DataType lenType) - { - int len = ReadValue(lenType); - return ReadUTF8String(len); - } - - /// - /// 读取short类型的字符串字节长度,然后根据此长度读取对应数量的字节数据后转为字符串 - /// - /// UTF-8字符串 - public string ReadUTF() - { - return this.ReadUTF8String(DataType.SHORT); - } - - /// - /// 复制一个对象,具有与原对象相同的数据,不改变原对象的数据,不包括已读数据 - /// - /// - public ByteBuffer Copy() - { - if (buf == null) - { - return new ByteBuffer(16); - } - if (readIndex < writeIndex) - { - byte[] newbytes = new byte[writeIndex - readIndex]; - Array.Copy(buf, readIndex, newbytes, 0, newbytes.Length); - ByteBuffer buffer = new ByteBuffer(newbytes.Length); - buffer.WriteBytes(newbytes); - buffer.isPool = this.isPool; - return buffer; - } - return new ByteBuffer(16); - } - - /// - /// 深度复制,具有与原对象相同的数据,不改变原对象的数据,包括已读数据 - /// - /// - public object Clone() - { - if (buf == null) - { - return new ByteBuffer(16); - } - ByteBuffer newBuf = new ByteBuffer(buf) - { - capacity = this.capacity, - readIndex = this.readIndex, - writeIndex = this.writeIndex, - markReadIndex = this.markReadIndex, - markWirteIndex = this.markWirteIndex, - isPool = this.isPool - }; - return newBuf; - } - - /// - /// 遍历所有的字节数据 - /// - /// - public void ForEach(Action action) - { - for (int i = 0; i < this.ReadableBytes; i++) - { - action.Invoke(this.buf[i]); - } - } - - /// - /// 清空此对象,但保留字节缓存数组(空数组) - /// - public void Clear() - { - readIndex = 0; - writeIndex = 0; - markReadIndex = 0; - markWirteIndex = 0; - capacity = buf.Length; - } - - /// - /// 释放对象,清除字节缓存数组,如果此对象为可池化,那么调用此方法将会把此对象推入到池中等待下次调用 - /// - public void Dispose() - { - if (isPool) { - lock (pool) { - if (pool.Count < poolMaxCount) { - this.Clear(); - pool.Add(this); - return; - } - } - } - - readIndex = 0; - writeIndex = 0; - markReadIndex = 0; - markWirteIndex = 0; - capacity = 0; - buf = null; - } - } -} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/ByteBuffer.cs.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/ByteBuffer.cs.meta deleted file mode 100644 index 85e1758c..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/ByteBuffer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 886c48d92cb0ea4419c8131cf0b2f865 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCP.cs b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCP.cs deleted file mode 100644 index f34daae5..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCP.cs +++ /dev/null @@ -1,1151 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace KcpProject -{ - - public class KCP - { - public const int IKCP_RTO_NDL = 30; // no delay min rto - public const int IKCP_RTO_MIN = 100; // normal min rto - public const int IKCP_RTO_DEF = 200; - public const int IKCP_RTO_MAX = 60000; - public const int IKCP_CMD_PUSH = 81; // cmd: push data - public const int IKCP_CMD_ACK = 82; // cmd: ack - public const int IKCP_CMD_WASK = 83; // cmd: window probe (ask) - public const int IKCP_CMD_WINS = 84; // cmd: window size (tell) - public const int IKCP_ASK_SEND = 1; // need to send IKCP_CMD_WASK - public const int IKCP_ASK_TELL = 2; // need to send IKCP_CMD_WINS - public const int IKCP_WND_SND = 32; - public const int IKCP_WND_RCV = 32; - public const int IKCP_MTU_DEF = 1400; - public const int IKCP_ACK_FAST = 3; - public const int IKCP_INTERVAL = 100; - public const int IKCP_OVERHEAD = 24; - public const int IKCP_DEADLINK = 20; - public const int IKCP_THRESH_INIT = 2; - public const int IKCP_THRESH_MIN = 2; - public const int IKCP_PROBE_INIT = 7000; // 7 secs to probe window size - public const int IKCP_PROBE_LIMIT = 120000; // up to 120 secs to probe window - public const int IKCP_SN_OFFSET = 12; - - - // encode 8 bits unsigned int - public static int ikcp_encode8u(byte[] p, int offset, byte c) - { - p[0 + offset] = c; - return 1; - } - - // decode 8 bits unsigned int - public static int ikcp_decode8u(byte[] p, int offset, ref byte c) - { - c = p[0 + offset]; - return 1; - } - - /* encode 16 bits unsigned int (lsb) */ - public static int ikcp_encode16u(byte[] p, int offset, UInt16 w) - { - p[0 + offset] = (byte)(w >> 0); - p[1 + offset] = (byte)(w >> 8); - return 2; - } - - /* decode 16 bits unsigned int (lsb) */ - public static int ikcp_decode16u(byte[] p, int offset, ref UInt16 c) - { - UInt16 result = 0; - result |= (UInt16)p[0 + offset]; - result |= (UInt16)(p[1 + offset] << 8); - c = result; - return 2; - } - - /* encode 32 bits unsigned int (lsb) */ - public static int ikcp_encode32u(byte[] p, int offset, UInt32 l) - { - p[0 + offset] = (byte)(l >> 0); - p[1 + offset] = (byte)(l >> 8); - p[2 + offset] = (byte)(l >> 16); - p[3 + offset] = (byte)(l >> 24); - return 4; - } - - /* decode 32 bits unsigned int (lsb) */ - public static int ikcp_decode32u(byte[] p, int offset, ref UInt32 c) - { - UInt32 result = 0; - result |= (UInt32)p[0 + offset]; - result |= (UInt32)(p[1 + offset] << 8); - result |= (UInt32)(p[2 + offset] << 16); - result |= (UInt32)(p[3 + offset] << 24); - c = result; - return 4; - } - - static UInt32 _imin_(UInt32 a, UInt32 b) - { - return a <= b ? a : b; - } - - private static DateTime refTime = DateTime.Now; - - private static UInt32 currentMS() - { - var ts = DateTime.Now.Subtract(refTime); - return (UInt32)ts.TotalMilliseconds; - } - - static UInt32 _imax_(UInt32 a, UInt32 b) - { - return a >= b ? a : b; - } - - static UInt32 _ibound_(UInt32 lower, UInt32 middle, UInt32 upper) - { - return _imin_(_imax_(lower, middle), upper); - } - - static Int32 _itimediff(UInt32 later, UInt32 earlier) - { - return ((Int32)(later - earlier)); - } - - // KCP Segment Definition - internal class Segment - { - internal UInt32 conv = 0; - internal UInt32 cmd = 0; - internal UInt32 frg = 0; - internal UInt32 wnd = 0; - internal UInt32 ts = 0; - internal UInt32 sn = 0; - internal UInt32 una = 0; - internal UInt32 rto = 0; - internal UInt32 xmit = 0; - internal UInt32 resendts = 0; - internal UInt32 fastack = 0; - internal UInt32 acked = 0; - internal ByteBuffer data; - - private static Stack msSegmentPool = new Stack(32); - - public static Segment Get(int size) - { - lock (msSegmentPool) - { - if (msSegmentPool.Count > 0) - { - var seg = msSegmentPool.Pop(); - seg.data = ByteBuffer.Allocate(size, true); - return seg; - } - } - return new Segment(size); - } - - public static void Put(Segment seg) - { - seg.reset(); - lock (msSegmentPool) { - msSegmentPool.Push(seg); - } - } - - private Segment(int size) - { - data = ByteBuffer.Allocate(size, true); - } - - // encode a segment into buffer - internal int encode(byte[] ptr, int offset) - { - - var offset_ = offset; - - offset += ikcp_encode32u(ptr, offset, conv); - offset += ikcp_encode8u(ptr, offset, (byte)cmd); - offset += ikcp_encode8u(ptr, offset, (byte)frg); - offset += ikcp_encode16u(ptr, offset, (UInt16)wnd); - offset += ikcp_encode32u(ptr, offset, ts); - offset += ikcp_encode32u(ptr, offset, sn); - offset += ikcp_encode32u(ptr, offset, una); - offset += ikcp_encode32u(ptr, offset, (UInt32)data.ReadableBytes); - - return offset - offset_; - } - - internal void reset() - { - conv = 0; - cmd = 0; - frg = 0; - wnd = 0; - ts = 0; - sn = 0; - una = 0; - rto = 0; - xmit = 0; - resendts = 0; - fastack = 0; - acked = 0; - - data.Clear(); - data.Dispose(); - data = null; - } - } - - internal struct ackItem - { - internal UInt32 sn; - internal UInt32 ts; - } - - // kcp members. - UInt32 conv; UInt32 mtu; UInt32 mss; UInt32 state; - UInt32 snd_una; UInt32 snd_nxt; UInt32 rcv_nxt; - UInt32 ts_recent; UInt32 ts_lastack; UInt32 ssthresh; - Int32 rx_rttval; Int32 rx_srtt; - UInt32 rx_rto; UInt32 rx_minrto; - UInt32 snd_wnd; UInt32 rcv_wnd; UInt32 rmt_wnd; UInt32 cwnd; UInt32 probe; - UInt32 interval; UInt32 ts_flush; - UInt32 nodelay; UInt32 updated; - UInt32 ts_probe; UInt32 probe_wait; - UInt32 dead_link; UInt32 incr; - - Int32 fastresend; - Int32 nocwnd; Int32 stream; - - List snd_queue = new List(16); - List rcv_queue = new List(16); - List snd_buf = new List(16); - List rcv_buf = new List(16); - - List acklist = new List(16); - - byte[] buffer; - Int32 reserved; - Action output; // buffer, size - - // send windowd & recv window - public UInt32 SndWnd { get { return snd_wnd; } } - public UInt32 RcvWnd { get { return rcv_wnd; } } - public UInt32 RmtWnd { get { return rmt_wnd; } } - public UInt32 Mss { get { return mss; } } - - // get how many packet is waiting to be sent - public int WaitSnd { get { return snd_buf.Count + snd_queue.Count; } } - - // internal time. - public UInt32 CurrentMS { get { return currentMS(); } } - - // create a new kcp control object, 'conv' must equal in two endpoint - // from the same connection. - public KCP(UInt32 conv_, Action output_) - { - conv = conv_; - snd_wnd = IKCP_WND_SND; - rcv_wnd = IKCP_WND_RCV; - rmt_wnd = IKCP_WND_RCV; - mtu = IKCP_MTU_DEF; - mss = mtu - IKCP_OVERHEAD; - rx_rto = IKCP_RTO_DEF; - rx_minrto = IKCP_RTO_MIN; - interval = IKCP_INTERVAL; - ts_flush = IKCP_INTERVAL; - ssthresh = IKCP_THRESH_INIT; - dead_link = IKCP_DEADLINK; - buffer = new byte[mtu]; - output = output_; - } - - // check the size of next message in the recv queue - public int PeekSize() - { - - if (0 == rcv_queue.Count) return -1; - - var seq = rcv_queue[0]; - - if (0 == seq.frg) return seq.data.ReadableBytes; - - if (rcv_queue.Count < seq.frg + 1) return -1; - - int length = 0; - - foreach (var item in rcv_queue) - { - length += item.data.ReadableBytes; - if (0 == item.frg) - break; - } - - return length; - } - - - public int Recv(byte[] buffer) - { - return Recv(buffer, 0, buffer.Length); - } - - // Receive data from kcp state machine - // - // Return number of bytes read. - // - // Return -1 when there is no readable data. - // - // Return -2 if len(buffer) is smaller than kcp.PeekSize(). - public int Recv(byte[] buffer, int index, int length) - { - var peekSize = PeekSize(); - if (peekSize < 0) - return -1; - - if (peekSize > length) - return -2; - - var fast_recover = false; - if (rcv_queue.Count >= rcv_wnd) - fast_recover = true; - - // merge fragment. - var count = 0; - var n = index; - foreach (var seg in rcv_queue) - { - // copy fragment data into buffer. - Buffer.BlockCopy(seg.data.RawBuffer, seg.data.ReaderIndex, buffer, n, seg.data.ReadableBytes); - n += seg.data.ReadableBytes; - - count++; - var fragment = seg.frg; - Segment.Put(seg); - if (0 == fragment) break; - } - - if (count > 0) - { - rcv_queue.RemoveRange(0, count); - } - - // move available data from rcv_buf -> rcv_queue - count = 0; - foreach (var seg in rcv_buf) - { - if (seg.sn == rcv_nxt && rcv_queue.Count + count < rcv_wnd) - { - rcv_queue.Add(seg); - rcv_nxt++; - count++; - } - else - { - break; - } - } - - if (count > 0) - { - rcv_buf.RemoveRange(0, count); - } - - - // fast recover - if (rcv_queue.Count < rcv_wnd && fast_recover) - { - // ready to send back IKCP_CMD_WINS in ikcp_flush - // tell remote my window size - probe |= IKCP_ASK_TELL; - } - - return n - index; - } - - public int Send(byte[] buffer) - { - return Send(buffer, 0, buffer.Length); - } - - // user/upper level send, returns below zero for error - public int Send(byte[] buffer, int index, int length) - { - if (0 == length) return -1; - - if (stream != 0) - { - var n = snd_queue.Count; - if (n > 0) - { - var seg = snd_queue[n - 1]; - if (seg.data.ReadableBytes < mss) - { - var capacity = (int)(mss - seg.data.ReadableBytes); - var writen = Math.Min(capacity, length); - seg.data.WriteBytes(buffer, index, writen); - index += writen; - length -= writen; - } - } - } - - if (length == 0) - return 0; - - var count = 0; - if (length <= mss) - count = 1; - else - count = (int)(((length) + mss - 1) / mss); - - if (count > 255) return -2; - - if (count == 0) count = 1; - - for (var i = 0; i < count; i++) - { - var size = Math.Min(length, (int)mss); - - var seg = Segment.Get(size); - seg.data.WriteBytes(buffer, index, size); - index += size; - length -= size; - - seg.frg = (stream == 0 ? (byte)(count - i - 1) : (byte)0); - snd_queue.Add(seg); - } - - return 0; - } - - // update ack. - void update_ack(Int32 rtt) - { - // https://tools.ietf.org/html/rfc6298 - if (0 == rx_srtt) - { - rx_srtt = rtt; - rx_rttval = rtt >> 1; - } - else - { - Int32 delta = rtt - rx_srtt; - rx_srtt += (delta >> 3); - if (0 > delta) delta = -delta; - - if (rtt < rx_srtt - rx_rttval) - { - // if the new RTT sample is below the bottom of the range of - // what an RTT measurement is expected to be. - // give an 8x reduced weight versus its normal weighting - rx_rttval += ((delta - rx_rttval) >> 5); - } - else - { - rx_rttval += ((delta - rx_rttval) >> 2); - } - } - - uint rto = (uint)(rx_srtt) + _imax_(interval, (uint)(rx_rttval) << 2); - rx_rto = _ibound_(rx_minrto, rto, IKCP_RTO_MAX); - } - - void shrink_buf() - { - if (snd_buf.Count > 0) - snd_una = snd_buf[0].sn; - else - snd_una = snd_nxt; - } - - void parse_ack(UInt32 sn) - { - - if (_itimediff(sn, snd_una) < 0 || _itimediff(sn, snd_nxt) >= 0) return; - - foreach (var seg in snd_buf) - { - if (sn == seg.sn) - { - // mark and free space, but leave the segment here, - // and wait until `una` to delete this, then we don't - // have to shift the segments behind forward, - // which is an expensive operation for large window - seg.acked = 1; - break; - } - if (_itimediff(sn, seg.sn) < 0) - break; - } - } - - void parse_fastack(UInt32 sn, UInt32 ts) - { - if (_itimediff(sn, snd_una) < 0 || _itimediff(sn, snd_nxt) >= 0) - return; - - foreach (var seg in snd_buf) - { - if (_itimediff(sn, seg.sn) < 0) - break; - else if (sn != seg.sn && _itimediff(seg.ts, ts) <= 0) - seg.fastack++; - } - } - - int parse_una(UInt32 una) - { - var count = 0; - foreach (var seg in snd_buf) - { - if (_itimediff(una, seg.sn) > 0) { - count++; - Segment.Put(seg); - } - else - break; - } - - if (count > 0) - snd_buf.RemoveRange(0, count); - return count; - } - - void ack_push(UInt32 sn, UInt32 ts) - { - acklist.Add(new ackItem { sn = sn, ts = ts }); - } - - bool parse_data(Segment newseg) - { - var sn = newseg.sn; - if (_itimediff(sn, rcv_nxt + rcv_wnd) >= 0 || _itimediff(sn, rcv_nxt) < 0) - return true; - - var n = rcv_buf.Count - 1; - var insert_idx = 0; - var repeat = false; - for (var i = n; i >= 0; i--) - { - var seg = rcv_buf[i]; - if (seg.sn == sn) - { - repeat = true; - break; - } - - if (_itimediff(sn, seg.sn) > 0) - { - insert_idx = i + 1; - break; - } - } - - if (!repeat) - { - if (insert_idx == n + 1) - rcv_buf.Add(newseg); - else - rcv_buf.Insert(insert_idx, newseg); - } - - // move available data from rcv_buf -> rcv_queue - var count = 0; - foreach (var seg in rcv_buf) - { - if (seg.sn == rcv_nxt && rcv_queue.Count + count < rcv_wnd) - { - rcv_nxt++; - count++; - } - else - { - break; - } - } - - if (count > 0) - { - for (var i = 0; i < count; i++) - rcv_queue.Add(rcv_buf[i]); - rcv_buf.RemoveRange(0, count); - } - return repeat; - } - - // Input when you received a low level packet (eg. UDP packet), call it - // regular indicates a regular packet has received(not from FEC) - // - // 'ackNoDelay' will trigger immediate ACK, but surely it will not be efficient in bandwidth - public int Input(byte[] data, int index, int size, bool regular, bool ackNoDelay) - { - var s_una = snd_una; - if (size < IKCP_OVERHEAD) return -1; - - Int32 offset = index; - UInt32 latest = 0; - int flag = 0; - UInt64 inSegs = 0; - bool windowSlides = false; - - while (true) - { - UInt32 ts = 0; - UInt32 sn = 0; - UInt32 length = 0; - UInt32 una = 0; - UInt32 conv_ = 0; - - UInt16 wnd = 0; - byte cmd = 0; - byte frg = 0; - - if (size - (offset - index) < IKCP_OVERHEAD) break; - - offset += ikcp_decode32u(data, offset, ref conv_); - - if (conv != conv_) return -1; - - offset += ikcp_decode8u(data, offset, ref cmd); - offset += ikcp_decode8u(data, offset, ref frg); - offset += ikcp_decode16u(data, offset, ref wnd); - offset += ikcp_decode32u(data, offset, ref ts); - offset += ikcp_decode32u(data, offset, ref sn); - offset += ikcp_decode32u(data, offset, ref una); - offset += ikcp_decode32u(data, offset, ref length); - - if (size - (offset - index) < length) return -2; - - switch (cmd) - { - case IKCP_CMD_PUSH: - case IKCP_CMD_ACK: - case IKCP_CMD_WASK: - case IKCP_CMD_WINS: - break; - default: - return -3; - } - - // only trust window updates from regular packets. i.e: latest update - if (regular) - { - rmt_wnd = wnd; - } - - if (parse_una(una) > 0) { - windowSlides = true; - } - - shrink_buf(); - - if (IKCP_CMD_ACK == cmd) - { - parse_ack(sn); - parse_fastack(sn, ts); - flag |= 1; - latest = ts; - } - else if (IKCP_CMD_PUSH == cmd) - { - var repeat = true; - if (_itimediff(sn, rcv_nxt + rcv_wnd) < 0) - { - ack_push(sn, ts); - if (_itimediff(sn, rcv_nxt) >= 0) - { - var seg = Segment.Get((int)length); - seg.conv = conv_; - seg.cmd = (UInt32)cmd; - seg.frg = (UInt32)frg; - seg.wnd = (UInt32)wnd; - seg.ts = ts; - seg.sn = sn; - seg.una = una; - seg.data.WriteBytes(data, offset, (int)length); - repeat = parse_data(seg); - } - } - } - else if (IKCP_CMD_WASK == cmd) - { - // ready to send back IKCP_CMD_WINS in Ikcp_flush - // tell remote my window size - probe |= IKCP_ASK_TELL; - } - else if (IKCP_CMD_WINS == cmd) - { - // do nothing - } - else - { - return -3; - } - - inSegs++; - offset += (int)length; - } - - // update rtt with the latest ts - // ignore the FEC packet - if (flag != 0 && regular) - { - var current = currentMS(); - if (_itimediff(current, latest) >= 0) - { - update_ack(_itimediff(current, latest)); - } - } - - // cwnd update when packet arrived - if (nocwnd == 0) - { - if (_itimediff(snd_una, s_una) > 0) - { - if (cwnd < rmt_wnd) - { - var _mss = mss; - if (cwnd < ssthresh) - { - cwnd++; - incr += _mss; - } - else - { - if (incr < _mss) - { - incr = _mss; - } - incr += (_mss * _mss) / incr + (_mss) / 16; - if ((cwnd + 1) * _mss <= incr) - { - if (_mss > 0) - cwnd = (incr + _mss - 1) / _mss; - else - cwnd = incr + _mss - 1; - } - } - if (cwnd > rmt_wnd) - { - cwnd = rmt_wnd; - incr = rmt_wnd * _mss; - } - } - } - } - - if (windowSlides) // if window has slided, flush - { - Flush(false); - } - else if (ackNoDelay && acklist.Count > 0) // // ack immediately - { - Flush(true); - } - - return 0; - } - - UInt16 wnd_unused() - { - if (rcv_queue.Count < rcv_wnd) - return (UInt16)(rcv_wnd - rcv_queue.Count); - return 0; - } - - // flush pending data - public UInt32 Flush(bool ackOnly) - { - var seg = Segment.Get(32); - seg.conv = conv; - seg.cmd = IKCP_CMD_ACK; - seg.wnd = (UInt32)wnd_unused(); - seg.una = rcv_nxt; - - var writeIndex = reserved; - - Action makeSpace = (space) => - { - if (writeIndex + space > mtu) - { - output(buffer, writeIndex); - writeIndex = reserved; - } - }; - - Action flushBuffer = () => - { - if (writeIndex > reserved) - { - output(buffer, writeIndex); - } - }; - - // flush acknowledges - for (var i = 0; i < acklist.Count; i++) - { - makeSpace(KCP.IKCP_OVERHEAD); - var ack = acklist[i]; - if ( _itimediff(ack.sn, rcv_nxt) >=0 || acklist.Count - 1 == i) - { - seg.sn = ack.sn; - seg.ts = ack.ts; - writeIndex += seg.encode(buffer, writeIndex); - } - } - acklist.Clear(); - - // flash remain ack segments - if (ackOnly) - { - flushBuffer(); - return interval; - } - - uint current = 0; - // probe window size (if remote window size equals zero) - if (0 == rmt_wnd) - { - current = currentMS(); - if (0 == probe_wait) - { - probe_wait = IKCP_PROBE_INIT; - ts_probe = current + probe_wait; - } - else - { - if (_itimediff(current, ts_probe) >= 0) - { - if (probe_wait < IKCP_PROBE_INIT) - probe_wait = IKCP_PROBE_INIT; - probe_wait += probe_wait / 2; - if (probe_wait > IKCP_PROBE_LIMIT) - probe_wait = IKCP_PROBE_LIMIT; - ts_probe = current + probe_wait; - probe |= IKCP_ASK_SEND; - } - } - } - else - { - ts_probe = 0; - probe_wait = 0; - } - - // flush window probing commands - if ((probe & IKCP_ASK_SEND) != 0) - { - seg.cmd = IKCP_CMD_WASK; - makeSpace(IKCP_OVERHEAD); - writeIndex += seg.encode(buffer, writeIndex); - } - - if ((probe & IKCP_ASK_TELL) != 0) - { - seg.cmd = IKCP_CMD_WINS; - makeSpace(IKCP_OVERHEAD); - writeIndex += seg.encode(buffer, writeIndex); - } - - probe = 0; - - // calculate window size - var cwnd_ = _imin_(snd_wnd, rmt_wnd); - if (0 == nocwnd) - cwnd_ = _imin_(cwnd, cwnd_); - - // sliding window, controlled by snd_nxt && sna_una+cwnd - var newSegsCount = 0; - for (var k = 0; k < snd_queue.Count; k++) - { - if (_itimediff(snd_nxt, snd_una + cwnd_) >= 0) - break; - - var newseg = snd_queue[k]; - newseg.conv = conv; - newseg.cmd = IKCP_CMD_PUSH; - newseg.sn = snd_nxt; - snd_buf.Add(newseg); - snd_nxt++; - newSegsCount++; - } - - if (newSegsCount > 0) - { - snd_queue.RemoveRange(0, newSegsCount); - } - - // calculate resent - var resent = (UInt32)fastresend; - if (fastresend <= 0) resent = 0xffffffff; - - // check for retransmissions - current = currentMS(); - UInt64 change = 0; UInt64 lostSegs = 0; UInt64 fastRetransSegs = 0; UInt64 earlyRetransSegs = 0; - var minrto = (Int32)interval; - - for (var k = 0; k < snd_buf.Count; k++) - { - var segment = snd_buf[k]; - var needsend = false; - if (segment.acked == 1) - continue; - if (segment.xmit == 0) // initial transmit - { - needsend = true; - segment.rto = rx_rto; - segment.resendts = current + segment.rto; - } - else if (segment.fastack >= resent) // fast retransmit - { - needsend = true; - segment.fastack = 0; - segment.rto = rx_rto; - segment.resendts = current + segment.rto; - change++; - fastRetransSegs++; - } - else if (segment.fastack > 0 && newSegsCount == 0) // early retransmit - { - needsend = true; - segment.fastack = 0; - segment.rto = rx_rto; - segment.resendts = current + segment.rto; - change++; - earlyRetransSegs++; - } - else if (_itimediff(current, segment.resendts) >= 0) // RTO - { - needsend = true; - if (nodelay == 0) - segment.rto += rx_rto; - else - segment.rto += rx_rto / 2; - segment.fastack = 0; - segment.resendts = current + segment.rto; - lostSegs++; - } - - if (needsend) - { - current = CurrentMS; - segment.xmit++; - segment.ts = current; - segment.wnd = seg.wnd; - segment.una = seg.una; - - var need = IKCP_OVERHEAD + segment.data.ReadableBytes; - makeSpace(need); - writeIndex += segment.encode(buffer, writeIndex); - Buffer.BlockCopy(segment.data.RawBuffer, segment.data.ReaderIndex, buffer, writeIndex, segment.data.ReadableBytes); - writeIndex += segment.data.ReadableBytes; - - if (segment.xmit >= dead_link) - { - state = 0xFFFFFFFF; - } - } - - // get the nearest rto - var _rto = _itimediff(segment.resendts, current); - if (_rto > 0 && _rto < minrto) - { - minrto = _rto; - } - } - - // flash remain segments - flushBuffer(); - - // cwnd update - if (nocwnd == 0) - { - // update ssthresh - // rate halving, https://tools.ietf.org/html/rfc6937 - if (change > 0) - { - var inflght = snd_nxt - snd_una; - ssthresh = inflght / 2; - if (ssthresh < IKCP_THRESH_MIN) - ssthresh = IKCP_THRESH_MIN; - cwnd = ssthresh + resent; - incr = cwnd * mss; - } - - // congestion control, https://tools.ietf.org/html/rfc5681 - if (lostSegs > 0) - { - ssthresh = cwnd / 2; - if (ssthresh < IKCP_THRESH_MIN) - ssthresh = IKCP_THRESH_MIN; - cwnd = 1; - incr = mss; - } - - if (cwnd < 1) - { - cwnd = 1; - incr = mss; - } - } - - return (UInt32)minrto; - } - - // update state (call it repeatedly, every 10ms-100ms), or you can ask - // ikcp_check when to call it again (without ikcp_input/_send calling). - // 'current' - current timestamp in millisec. - public void Update() - { - var current = currentMS(); - - if (0 == updated) - { - updated = 1; - ts_flush = current; - } - - var slap = _itimediff(current, ts_flush); - - if (slap >= 10000 || slap < -10000) - { - ts_flush = current; - slap = 0; - } - - if (slap >= 0) - { - ts_flush += interval; - if (_itimediff(current, ts_flush) >= 0) - ts_flush = current + interval; - Flush(false); - } - } - - // Determine when should you invoke ikcp_update: - // returns when you should invoke ikcp_update in millisec, if there - // is no ikcp_input/_send calling. you can call ikcp_update in that - // time, instead of call update repeatly. - // Important to reduce unnacessary ikcp_update invoking. use it to - // schedule ikcp_update (eg. implementing an epoll-like mechanism, - // or optimize ikcp_update when handling massive kcp connections) - public UInt32 Check() - { - var current = currentMS(); - - var ts_flush_ = ts_flush; - var tm_flush_ = 0x7fffffff; - var tm_packet = 0x7fffffff; - var minimal = 0; - - if (updated == 0) - return current; - - if (_itimediff(current, ts_flush_) >= 10000 || _itimediff(current, ts_flush_) < -10000) - ts_flush_ = current; - - if (_itimediff(current, ts_flush_) >= 0) - return current; - - tm_flush_ = (int)_itimediff(ts_flush_, current); - - foreach (var seg in snd_buf) - { - var diff = _itimediff(seg.resendts, current); - if (diff <= 0) - return current; - if (diff < tm_packet) - tm_packet = (int)diff; - } - - minimal = (int)tm_packet; - if (tm_packet >= tm_flush_) - minimal = (int)tm_flush_; - if (minimal >= interval) - minimal = (int)interval; - - return current + (UInt32)minimal; - } - - // change MTU size, default is 1400 - public int SetMtu(Int32 mtu_) - { - if (mtu_ < 50 || mtu_ < (Int32)IKCP_OVERHEAD) - return -1; - if (reserved >= (int)(mtu - IKCP_OVERHEAD) || reserved < 0) - return -1; - - var buffer_ = new byte[mtu_]; - if (null == buffer_) - return -2; - - mtu = (UInt32)mtu_; - mss = mtu - IKCP_OVERHEAD - (UInt32)reserved; - buffer = buffer_; - return 0; - } - - // fastest: ikcp_nodelay(kcp, 1, 20, 2, 1) - // nodelay: 0:disable(default), 1:enable - // interval: internal update timer interval in millisec, default is 100ms - // resend: 0:disable fast resend(default), 1:enable fast resend - // nc: 0:normal congestion control(default), 1:disable congestion control - public int NoDelay(int nodelay_, int interval_, int resend_, int nc_) - { - - if (nodelay_ >= 0) - { - nodelay = (UInt32)nodelay_; - if (nodelay_ != 0) - rx_minrto = IKCP_RTO_NDL; - else - rx_minrto = IKCP_RTO_MIN; - } - - if (interval_ >= 0) - { - if (interval_ > 5000) - interval_ = 5000; - else if (interval_ < 10) - interval_ = 10; - interval = (UInt32)interval_; - } - - if (resend_ >= 0) - fastresend = resend_; - - if (nc_ >= 0) - nocwnd = nc_; - - return 0; - } - - // set maximum window size: sndwnd=32, rcvwnd=32 by default - public int WndSize(int sndwnd, int rcvwnd) - { - if (sndwnd > 0) - snd_wnd = (UInt32)sndwnd; - - if (rcvwnd > 0) - rcv_wnd = (UInt32)rcvwnd; - return 0; - } - - public bool ReserveBytes(int reservedSize) - { - if (reservedSize >= (mtu - IKCP_OVERHEAD) || reservedSize < 0) - return false; - - reserved = reservedSize; - mss = mtu - IKCP_OVERHEAD - (uint)(reservedSize); - return true; - } - - public void SetStreamMode(bool enabled) - { - stream = enabled ? 1 : 0; - } - } -} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCP.cs.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCP.cs.meta deleted file mode 100644 index 71386533..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCP.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1b33a27a75114b7488254dac4703efad -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCPSession.cs b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCPSession.cs deleted file mode 100644 index cb8a6ceb..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCPSession.cs +++ /dev/null @@ -1,158 +0,0 @@ -using System; -using System.Net; -using System.Net.Sockets; - -namespace KcpProject -{ - class KCPSession - { - private Socket mSocket = null; - private KCP mKCP = null; - - private ByteBuffer mRecvBuffer = ByteBuffer.Allocate(1024 * 32); - private UInt32 mNextUpdateTime = 0; - - public bool IsConnected { get { return mSocket != null && mSocket.Connected; } } - public bool WriteDelay { get; set; } - public bool AckNoDelay { get; set; } - - public IPEndPoint RemoteAddress { get; private set; } - public IPEndPoint LocalAddress { get; private set; } - - public void Connect(string host, int port) - { - IPHostEntry hostEntry = Dns.GetHostEntry(host); - if (hostEntry.AddressList.Length == 0) - { - throw new Exception("Unable to resolve host: " + host); - } - var endpoint = hostEntry.AddressList[0]; - mSocket = new Socket(endpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp); - mSocket.Connect(endpoint, port); - RemoteAddress = (IPEndPoint)mSocket.RemoteEndPoint; - LocalAddress = (IPEndPoint)mSocket.LocalEndPoint; - mKCP = new KCP((uint)(new Random().Next(1, Int32.MaxValue)), rawSend); - // normal: 0, 40, 2, 1 - // fast: 0, 30, 2, 1 - // fast2: 1, 20, 2, 1 - // fast3: 1, 10, 2, 1 - mKCP.NoDelay(1, 20, 2, 1); - mKCP.SetStreamMode(true); - mRecvBuffer.Clear(); - } - - public void Close() - { - if (mSocket != null) { - mSocket.Close(); - mSocket = null; - mRecvBuffer.Clear(); - } - } - - private void rawSend(byte[] data, int length) - { - if (mSocket != null) { - mSocket.Send(data, length, SocketFlags.None); - } - } - - public int Send(byte[] data, int index, int length) - { - if (mSocket == null) - return -1; - - var waitsnd = mKCP.WaitSnd; - if (waitsnd < mKCP.SndWnd && waitsnd < mKCP.RmtWnd) { - - var sendBytes = 0; - do { - var n = Math.Min((int)mKCP.Mss, length - sendBytes); - mKCP.Send(data, index + sendBytes, n); - sendBytes += n; - } while (sendBytes < length); - - waitsnd = mKCP.WaitSnd; - if (waitsnd >= mKCP.SndWnd || waitsnd >= mKCP.RmtWnd || !WriteDelay) { - mKCP.Flush(false); - } - - return length; - } - - return 0; - } - - public int Recv(byte[] data, int index, int length) - { - // 上次剩下的部分 - if (mRecvBuffer.ReadableBytes > 0) { - var recvBytes = Math.Min(mRecvBuffer.ReadableBytes, length); - Buffer.BlockCopy(mRecvBuffer.RawBuffer, mRecvBuffer.ReaderIndex, data, index, recvBytes); - mRecvBuffer.ReaderIndex += recvBytes; - // 读完重置读写指针 - if (mRecvBuffer.ReaderIndex == mRecvBuffer.WriterIndex) { - mRecvBuffer.Clear(); - } - return recvBytes; - } - - if (mSocket == null) - return -1; - - if (!mSocket.Poll(0, SelectMode.SelectRead)) { - return 0; - } - - var rn = 0; - try { - rn = mSocket.Receive(mRecvBuffer.RawBuffer, mRecvBuffer.WriterIndex, mRecvBuffer.WritableBytes, SocketFlags.None); - } catch(Exception ex) { - UnityEngine.Debug.LogError(ex); - rn = -1; - } - - if (rn <= 0) { - return rn; - } - mRecvBuffer.WriterIndex += rn; - - var inputN = mKCP.Input(mRecvBuffer.RawBuffer, mRecvBuffer.ReaderIndex, mRecvBuffer.ReadableBytes, true, AckNoDelay); - if (inputN < 0) { - mRecvBuffer.Clear(); - return inputN; - } - mRecvBuffer.Clear(); - - // 读完所有完整的消息 - for (;;) { - var size = mKCP.PeekSize(); - if (size <= 0) break; - - mRecvBuffer.EnsureWritableBytes(size); - - var n = mKCP.Recv(mRecvBuffer.RawBuffer, mRecvBuffer.WriterIndex, size); - if (n > 0) mRecvBuffer.WriterIndex += n; - } - - // 有数据待接收 - if (mRecvBuffer.ReadableBytes > 0) { - return Recv(data, index, length); - } - - return 0; - } - - public void Update() - { - if (mSocket == null) - return; - - if (0 == mNextUpdateTime || mKCP.CurrentMS >= mNextUpdateTime) - { - mKCP.Update(); - mNextUpdateTime = mKCP.Check(); - } - } - } -} diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCPSession.cs.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCPSession.cs.meta deleted file mode 100644 index 5fc9ee04..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KCPSession.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ae3b5d0742eaa4440b71c417a13d8a6f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/Kcp.unity b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/Kcp.unity deleted file mode 100644 index ef6a2b03..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/Kcp.unity +++ /dev/null @@ -1,341 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!29 &1 -OcclusionCullingSettings: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_OcclusionBakeSettings: - smallestOccluder: 5 - smallestHole: 0.25 - backfaceThreshold: 100 - m_SceneGUID: 00000000000000000000000000000000 - m_OcclusionCullingData: {fileID: 0} ---- !u!104 &2 -RenderSettings: - m_ObjectHideFlags: 0 - serializedVersion: 9 - m_Fog: 0 - m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} - m_FogMode: 3 - m_FogDensity: 0.01 - m_LinearFogStart: 0 - m_LinearFogEnd: 300 - m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} - m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} - m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} - m_AmbientIntensity: 1 - m_AmbientMode: 0 - m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} - m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} - m_HaloStrength: 0.5 - m_FlareStrength: 1 - m_FlareFadeSpeed: 3 - m_HaloTexture: {fileID: 0} - m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} - m_DefaultReflectionMode: 0 - m_DefaultReflectionResolution: 128 - m_ReflectionBounces: 1 - m_ReflectionIntensity: 1 - m_CustomReflection: {fileID: 0} - m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} - m_UseRadianceAmbientProbe: 0 ---- !u!157 &3 -LightmapSettings: - m_ObjectHideFlags: 0 - serializedVersion: 11 - m_GIWorkflowMode: 1 - m_GISettings: - serializedVersion: 2 - m_BounceScale: 1 - m_IndirectOutputScale: 1 - m_AlbedoBoost: 1 - m_EnvironmentLightingMode: 0 - m_EnableBakedLightmaps: 1 - m_EnableRealtimeLightmaps: 0 - m_LightmapEditorSettings: - serializedVersion: 12 - m_Resolution: 2 - m_BakeResolution: 40 - m_AtlasSize: 1024 - m_AO: 0 - m_AOMaxDistance: 1 - m_CompAOExponent: 1 - m_CompAOExponentDirect: 0 - m_ExtractAmbientOcclusion: 0 - m_Padding: 2 - m_LightmapParameters: {fileID: 0} - m_LightmapsBakeMode: 1 - m_TextureCompression: 1 - m_FinalGather: 0 - m_FinalGatherFiltering: 1 - m_FinalGatherRayCount: 256 - m_ReflectionCompression: 2 - m_MixedBakeMode: 2 - m_BakeBackend: 1 - m_PVRSampling: 1 - m_PVRDirectSampleCount: 32 - m_PVRSampleCount: 512 - m_PVRBounces: 2 - m_PVREnvironmentSampleCount: 256 - m_PVREnvironmentReferencePointCount: 2048 - m_PVRFilteringMode: 1 - m_PVRDenoiserTypeDirect: 1 - m_PVRDenoiserTypeIndirect: 1 - m_PVRDenoiserTypeAO: 1 - m_PVRFilterTypeDirect: 0 - m_PVRFilterTypeIndirect: 0 - m_PVRFilterTypeAO: 0 - m_PVREnvironmentMIS: 1 - m_PVRCulling: 1 - m_PVRFilteringGaussRadiusDirect: 1 - m_PVRFilteringGaussRadiusIndirect: 5 - m_PVRFilteringGaussRadiusAO: 2 - m_PVRFilteringAtrousPositionSigmaDirect: 0.5 - m_PVRFilteringAtrousPositionSigmaIndirect: 2 - m_PVRFilteringAtrousPositionSigmaAO: 1 - m_ExportTrainingData: 0 - m_TrainingDataDestination: TrainingData - m_LightProbeSampleCountMultiplier: 4 - m_LightingDataAsset: {fileID: 0} - m_UseShadowmask: 1 ---- !u!196 &4 -NavMeshSettings: - serializedVersion: 2 - m_ObjectHideFlags: 0 - m_BuildSettings: - serializedVersion: 2 - agentTypeID: 0 - agentRadius: 0.5 - agentHeight: 2 - agentSlope: 45 - agentClimb: 0.4 - ledgeDropHeight: 0 - maxJumpAcrossDistance: 0 - minRegionArea: 2 - manualCellSize: 0 - cellSize: 0.16666667 - manualTileSize: 0 - tileSize: 256 - accuratePlacement: 0 - debug: - m_Flags: 0 - m_NavMeshData: {fileID: 0} ---- !u!1 &495368858 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 495368861} - - component: {fileID: 495368860} - - component: {fileID: 495368859} - m_Layer: 0 - m_Name: Main Camera - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!81 &495368859 -AudioListener: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 495368858} - m_Enabled: 1 ---- !u!20 &495368860 -Camera: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 495368858} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} - m_projectionMatrixMode: 1 - m_GateFitMode: 2 - m_FOVAxisMode: 0 - m_SensorSize: {x: 36, y: 24} - m_LensShift: {x: 0, y: 0} - m_FocalLength: 50 - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 1 - m_AllowMSAA: 1 - m_AllowDynamicResolution: 0 - m_ForceIntoRT: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 ---- !u!4 &495368861 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 495368858} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -10} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1154372134 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1154372135} - - component: {fileID: 1154372136} - m_Layer: 0 - m_Name: GameObject - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1154372135 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1154372134} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &1154372136 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1154372134} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b251dc2e3e09685448a5f448f611731e, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!1 &1547899605 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1547899607} - - component: {fileID: 1547899606} - m_Layer: 0 - m_Name: Directional Light - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!108 &1547899606 -Light: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1547899605} - m_Enabled: 1 - serializedVersion: 10 - m_Type: 1 - m_Shape: 0 - m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} - m_Intensity: 1 - m_Range: 10 - m_SpotAngle: 30 - m_InnerSpotAngle: 21.80208 - m_CookieSize: 10 - m_Shadows: - m_Type: 2 - m_Resolution: -1 - m_CustomResolution: -1 - m_Strength: 1 - m_Bias: 0.05 - m_NormalBias: 0.4 - m_NearPlane: 0.2 - m_CullingMatrixOverride: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 - m_UseCullingMatrixOverride: 0 - m_Cookie: {fileID: 0} - m_DrawHalo: 0 - m_Flare: {fileID: 0} - m_RenderMode: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingLayerMask: 1 - m_Lightmapping: 4 - m_LightShadowCasterMode: 0 - m_AreaSize: {x: 1, y: 1} - m_BounceIntensity: 1 - m_ColorTemperature: 6570 - m_UseColorTemperature: 0 - m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} - m_UseBoundingSphereOverride: 0 - m_ShadowRadius: 0 - m_ShadowAngle: 0 ---- !u!4 &1547899607 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1547899605} - m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} - m_LocalPosition: {x: 0, y: 3, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/Kcp.unity.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/Kcp.unity.meta deleted file mode 100644 index 1ac4a0ab..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/Kcp.unity.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 8211cbb6cf3d03d479184d2a4d5eec0c -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KcpTest.cs b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KcpTest.cs deleted file mode 100644 index aa81a857..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KcpTest.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Threading; -using KcpProject; -using TEngine; -using UnityEngine; - -public class KcpTest : MonoBehaviour -{ - private KCPSession connection; - byte[] buffer = new byte[1500]; - int counter = 0; - int sendBytes = 0; - int recvBytes = 0; - - void Start() - { - connection = new KCPSession(); - connection.AckNoDelay = true; - connection.WriteDelay = false; - - connection.Connect("127.0.0.1", 4444); - } - - // Update is called once per frame - void Update() - { - if (connection == null || !connection.IsConnected) - { - return; - } - connection.Update(); - - //firstSend = false; - // Console.WriteLine("Write Message..."); - //var text = Encoding.UTF8.GetBytes(string.Format("Hello KCP: {0}", ++counter)); - var sent = connection.Send(buffer, 0, buffer.Length); - if (sent < 0) - { - TLogger.LogError("Write message failed."); - } - - if (sent > 0) - { - counter++; - sendBytes += buffer.Length; - if (counter >= 500) - { - - } - } - - var n = connection.Recv(buffer, 0, buffer.Length); - if (n == 0) - { - Thread.Sleep(10); - } - else if (n < 0) - { - TLogger.LogError("Receive Message failed."); - } - else - { - recvBytes += n; - TLogger.LogError($"{recvBytes} / {sendBytes}"); - } - } -} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KcpTest.cs.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KcpTest.cs.meta deleted file mode 100644 index 81f54cd3..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp1/KcpTest.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b251dc2e3e09685448a5f448f611731e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2.meta deleted file mode 100644 index 26bf7fb3..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 6ba3d5fa738b00f448f8e0d610c54564 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpClient.cs b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpClient.cs deleted file mode 100644 index 25282ee7..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpClient.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Buffers; -using System.Net; -using System.Net.Sockets; -using System.Net.Sockets.Kcp; -using System.Threading.Tasks; - -namespace Kcp -{ - public class KcpClient : IKcpCallback - { - UdpClient client; - - public KcpClient(int port) - : this(port, null) - { - - } - - public KcpClient(int port, IPEndPoint endPoint) - { - client = new UdpClient(port); - kcp = new System.Net.Sockets.Kcp.Kcp(2001, this); - this.EndPoint = endPoint; - BeginRecv(); - } - - public System.Net.Sockets.Kcp.Kcp kcp { get; } - public IPEndPoint EndPoint { get; set; } - - public void Output(IMemoryOwner buffer, int avalidLength) - { - var s = buffer.Memory.Span.Slice(0, avalidLength).ToArray(); - client.SendAsync(s, s.Length, EndPoint); - buffer.Dispose(); - } - - public async void SendAsync(byte[] datagram, int bytes) - { - kcp.Send(datagram.AsSpan().Slice(0, bytes)); - } - - public async Task ReceiveAsync() - { - var (buffer, avalidLength) = kcp.TryRecv(); - if (buffer == null) - { - await Task.Delay(10); - return await ReceiveAsync(); - } - else - { - var s = buffer.Memory.Span.Slice(0, avalidLength).ToArray(); - return s; - } - } - - private async void BeginRecv() - { - var res = await client.ReceiveAsync(); - EndPoint = res.RemoteEndPoint; - kcp.Input(res.Buffer); - BeginRecv(); - } - - public IMemoryOwner RentBuffer(int length) - { - return null; - } - } -} diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpClient.cs.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpClient.cs.meta deleted file mode 100644 index e04d5ee6..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpClient.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d42aa219010afaf4584ebc1b0ce71c35 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp.meta deleted file mode 100644 index 11ce82db..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: d62fe636d4b136647a9fb837609f35a8 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.dll b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.dll deleted file mode 100644 index 410115d9..00000000 Binary files a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.dll and /dev/null differ diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.dll.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.dll.meta deleted file mode 100644 index 6bfc62ec..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.dll.meta +++ /dev/null @@ -1,32 +0,0 @@ -fileFormatVersion: 2 -guid: 46160d30013b98c4ba33d5b915fe37a7 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 0 - isExplicitlyReferenced: 0 - platformData: - - first: - Any: - second: - enabled: 1 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - - first: - Windows Store Apps: WindowsStoreApps - second: - enabled: 0 - settings: - CPU: AnyCPU - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.xml b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.xml deleted file mode 100644 index 75fc3579..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.xml +++ /dev/null @@ -1,331 +0,0 @@ - - - - Kcp - - - - - Kcp回调 - - - - - kcp 发送方向输出 - - kcp 交出发送缓冲区控制权,缓冲区来自 - 数据的有效长度 - 不需要返回值 - 通过增加 avalidLength 能够在协议栈中有效的减少数据拷贝 - - - - 外部提供缓冲区,可以在外部链接一个内存池 - - - - - https://github.com/skywind3000/kcp/wiki/Network-Layer - 外部buffer ----拆分拷贝----等待列表 -----移动----发送列表----拷贝----发送buffer---output - https://github.com/skywind3000/kcp/issues/118#issuecomment-338133930 - - - - - create a new kcp control object, 'conv' must equal in two endpoint - from the same connection. - - - - - - - 频道号 - - - - - 最大传输单元(Maximum Transmission Unit,MTU) - - - - - 缓冲区最小大小 - - - - - 最大报文段长度 - - - - - 下一个等待接收消息ID - - - - - https://github.com/skywind3000/kcp/issues/53 - 按照 C版 设计,使用小端字节序 - - - - - 发送 ack 队列 - - - - - 发送等待队列 - - - - - 正在发送列表 - - - - - 正在等待触发接收回调函数消息列表 - 需要执行的操作 添加 遍历 删除 - - - - - 正在等待重组消息列表 - 需要执行的操作 添加 插入 遍历 删除 - - - - - 是否正在释放 - - - - - 释放不是严格线程安全的,尽量使用和Update相同的线程调用, - 或者等待析构时自动释放。 - - - - - 如果外部能够提供缓冲区则使用外部缓冲区,否则new byte[] - - - - - - - user/upper level recv: returns size, returns below zero for EAGAIN - - - - - - - 这个函数不检查任何参数 - - - - - - - move available data from rcv_buf -> rcv_queue - - - - - check the size of next message in the recv queue - - - - - - user/upper level send, returns below zero for error - - - - - - - update ack. - - - - - - when you received a low level packet (eg. UDP packet), call it - - - - - - - flush pending data - - - - - update state (call it repeatedly, every 10ms-100ms), or you can ask - ikcp_check when to call it again (without ikcp_input/_send calling). - - DateTime.UtcNow - - - - Determine when should you invoke ikcp_update: - returns when you should invoke ikcp_update in millisec, if there - is no ikcp_input/_send calling. you can call ikcp_update in that - time, instead of call update repeatly. - - Important to reduce unnacessary ikcp_update invoking. use it to - schedule ikcp_update (eg. implementing an epoll-like mechanism, - or optimize ikcp_update when handling massive kcp connections) - - - - - - - - change MTU size, default is 1400 - ** 这个方法不是线程安全的。请在没有发送和接收时调用 。 - - - - - - - - - - - - - - fastest: ikcp_nodelay(kcp, 1, 20, 2, 1) - - 0:disable(default), 1:enable - internal update timer interval in millisec, default is 100ms - 0:disable fast resend(default), 1:enable fast resend - 0:normal congestion control(default), 1:disable congestion control - - - - - set maximum window size: sndwnd=32, rcvwnd=32 by default - - - - - - - - get how many packet is waiting to be sent - - - - - - 调整了没存布局,直接拷贝块提升性能。 - 结构体保存内容只有一个指针,不用担心参数传递过程中的性能 - https://github.com/skywind3000/kcp/issues/118#issuecomment-338133930 - 不要对没有初始化的KcpSegment(内部指针为0,所有属性都将指向位置区域) 进行任何赋值操作,可能导致内存损坏。 - 出于性能考虑,没有对此项进行安全检查。 - - - - - 使用完必须显示释放,否则内存泄漏 - - - - - - - 释放非托管内存 - - - - - 以下为本机使用的参数 - - offset = 0 - - - - - offset = 4 - - - - - offset = 8 - - - - - offset = 12 - - - - 以下为需要网络传输的参数 - - - - offset = - - https://github.com/skywind3000/kcp/issues/134 - - - - offset = + 4 - - - - - offset = + 5 - - - - - offset = + 6 - - - - - offset = + 8 - - - - - SendNumber? - offset = + 12 - - - - - offset = + 16 - - - - - AppendDateSize - offset = + 20 - - - - - - - https://github.com/skywind3000/kcp/issues/35#issuecomment-263770736 - - - - 将片段中的要发送的数据拷贝到指定缓冲区 - - - - - - diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.xml.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.xml.meta deleted file mode 100644 index 85c99c89..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/Kcp.xml.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 63423a3fccdee0649a1b108ff1c8fb27 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.dll b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.dll deleted file mode 100644 index c517a3b6..00000000 Binary files a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.dll and /dev/null differ diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.dll.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.dll.meta deleted file mode 100644 index 878fad3a..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.dll.meta +++ /dev/null @@ -1,32 +0,0 @@ -fileFormatVersion: 2 -guid: 6adb9236ae2345f4e9c263bc7e4a5f6e -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 0 - isExplicitlyReferenced: 0 - platformData: - - first: - Any: - second: - enabled: 1 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - - first: - Windows Store Apps: WindowsStoreApps - second: - enabled: 0 - settings: - CPU: AnyCPU - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.xml b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.xml deleted file mode 100644 index e243dcef..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - System.Buffers - - - - Provides a resource pool that enables reusing instances of type . - The type of the objects that are in the resource pool. - - - Initializes a new instance of the class. - - - Creates a new instance of the class. - A new instance of the class. - - - Creates a new instance of the class using the specifed configuration. - The maximum length of an array instance that may be stored in the pool. - The maximum number of array instances that may be stored in each bucket in the pool. The pool groups arrays of similar lengths into buckets for faster access. - A new instance of the class with the specified configuration. - - - Retrieves a buffer that is at least the requested length. - The minimum length of the array. - An array of type that is at least minimumLength in length. - - - Returns an array to the pool that was previously obtained using the method on the same instance. - A buffer to return to the pool that was previously obtained using the method. - Indicates whether the contents of the buffer should be cleared before reuse. If clearArray is set to true, and if the pool will store the buffer to enable subsequent reuse, the method will clear the array of its contents so that a subsequent caller using the method will not see the content of the previous caller. If clearArray is set to false or if the pool will release the buffer, the array&#39;s contents are left unchanged. - - - Gets a shared instance. - A shared instance. - - - \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.xml.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.xml.meta deleted file mode 100644 index 72c8ad33..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Buffers.xml.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 28cf99f49856cc445826675c24598a57 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.dll b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.dll deleted file mode 100644 index 2d543169..00000000 Binary files a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.dll and /dev/null differ diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.dll.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.dll.meta deleted file mode 100644 index 98ae7b0d..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.dll.meta +++ /dev/null @@ -1,32 +0,0 @@ -fileFormatVersion: 2 -guid: 4533b86b9dd0e1d4daa22c442238c69e -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 0 - isExplicitlyReferenced: 0 - platformData: - - first: - Any: - second: - enabled: 1 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - - first: - Windows Store Apps: WindowsStoreApps - second: - enabled: 0 - settings: - CPU: AnyCPU - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.xml b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.xml deleted file mode 100644 index 4d12fd71..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.xml +++ /dev/null @@ -1,355 +0,0 @@ - - - System.Memory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.xml.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.xml.meta deleted file mode 100644 index 692fcfbd..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Memory.xml.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: b54c1784b3e803c45a1d68bfaafbb283 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.dll b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.dll deleted file mode 100644 index 31562392..00000000 Binary files a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.dll and /dev/null differ diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.dll.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.dll.meta deleted file mode 100644 index 21115073..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.dll.meta +++ /dev/null @@ -1,32 +0,0 @@ -fileFormatVersion: 2 -guid: 6e8ded56d8468f749a68256f26df209c -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 0 - isExplicitlyReferenced: 0 - platformData: - - first: - Any: - second: - enabled: 1 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - - first: - Windows Store Apps: WindowsStoreApps - second: - enabled: 0 - settings: - CPU: AnyCPU - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.xml b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.xml deleted file mode 100644 index 6a7cfcff..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.xml +++ /dev/null @@ -1,200 +0,0 @@ - - - System.Runtime.CompilerServices.Unsafe - - - - Contains generic, low-level functionality for manipulating pointers. - - - Adds an element offset to the given reference. - The reference to add the offset to. - The offset to add. - The type of reference. - A new reference that reflects the addition of offset to pointer. - - - Adds an element offset to the given reference. - The reference to add the offset to. - The offset to add. - The type of reference. - A new reference that reflects the addition of offset to pointer. - - - Adds a byte offset to the given reference. - The reference to add the offset to. - The offset to add. - The type of reference. - A new reference that reflects the addition of byte offset to pointer. - - - Determines whether the specified references point to the same location. - The first reference to compare. - The second reference to compare. - The type of reference. - true if left and right point to the same location; otherwise, false. - - - Casts the given object to the specified type. - The object to cast. - The type which the object will be cast to. - The original object, casted to the given type. - - - Reinterprets the given reference as a reference to a value of type TTo. - The reference to reinterpret. - The type of reference to reinterpret.. - The desired type of the reference. - A reference to a value of type TTo. - - - Returns a pointer to the given by-ref parameter. - The object whose pointer is obtained. - The type of object. - A pointer to the given value. - - - Reinterprets the given location as a reference to a value of type T. - The location of the value to reference. - The type of the interpreted location. - A reference to a value of type T. - - - Determines the byte offset from origin to target from the given references. - The reference to origin. - The reference to target. - The type of reference. - Byte offset from origin to target i.e. target - origin. - - - Copies a value of type T to the given location. - The location to copy to. - A reference to the value to copy. - The type of value to copy. - - - Copies a value of type T to the given location. - The location to copy to. - A pointer to the value to copy. - The type of value to copy. - - - Copies bytes from the source address to the destination address. - The destination address to copy to. - The source address to copy from. - The number of bytes to copy. - - - Copies bytes from the source address to the destination address. - The destination address to copy to. - The source address to copy from. - The number of bytes to copy. - - - Copies bytes from the source address to the destination address -without assuming architecture dependent alignment of the addresses. - The destination address to copy to. - The source address to copy from. - The number of bytes to copy. - - - Copies bytes from the source address to the destination address -without assuming architecture dependent alignment of the addresses. - The destination address to copy to. - The source address to copy from. - The number of bytes to copy. - - - Initializes a block of memory at the given location with a given initial value. - The address of the start of the memory block to initialize. - The value to initialize the block to. - The number of bytes to initialize. - - - Initializes a block of memory at the given location with a given initial value. - The address of the start of the memory block to initialize. - The value to initialize the block to. - The number of bytes to initialize. - - - Initializes a block of memory at the given location with a given initial value -without assuming architecture dependent alignment of the address. - The address of the start of the memory block to initialize. - The value to initialize the block to. - The number of bytes to initialize. - - - Initializes a block of memory at the given location with a given initial value -without assuming architecture dependent alignment of the address. - The address of the start of the memory block to initialize. - The value to initialize the block to. - The number of bytes to initialize. - - - Reads a value of type T from the given location. - The location to read from. - The type to read. - An object of type T read from the given location. - - - Reads a value of type T from the given location -without assuming architecture dependent alignment of the addresses. - The location to read from. - The type to read. - An object of type T read from the given location. - - - Reads a value of type T from the given location -without assuming architecture dependent alignment of the addresses. - The location to read from. - The type to read. - An object of type T read from the given location. - - - Returns the size of an object of the given type parameter. - The type of object whose size is retrieved. - The size of an object of type T. - - - Subtracts an element offset from the given reference. - The reference to subtract the offset from. - The offset to subtract. - The type of reference. - A new reference that reflects the subraction of offset from pointer. - - - Subtracts an element offset from the given reference. - The reference to subtract the offset from. - The offset to subtract. - The type of reference. - A new reference that reflects the subraction of offset from pointer. - - - Subtracts a byte offset from the given reference. - The reference to subtract the offset from. - - The type of reference. - A new reference that reflects the subraction of byte offset from pointer. - - - Writes a value of type T to the given location. - The location to write to. - The value to write. - The type of value to write. - - - Writes a value of type T to the given location -without assuming architecture dependent alignment of the addresses. - The location to write to. - The value to write. - The type of value to write. - - - Writes a value of type T to the given location -without assuming architecture dependent alignment of the addresses. - The location to write to. - The value to write. - The type of value to write. - - - \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.xml.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.xml.meta deleted file mode 100644 index 2d0d1a51..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/KcpImp/System.Runtime.CompilerServices.Unsafe.xml.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 4550353da13e98b4d8fa8a94c97a4067 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/Test.unity b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/Test.unity deleted file mode 100644 index 2d0c892a..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/Test.unity +++ /dev/null @@ -1,384 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!29 &1 -OcclusionCullingSettings: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_OcclusionBakeSettings: - smallestOccluder: 5 - smallestHole: 0.25 - backfaceThreshold: 100 - m_SceneGUID: 00000000000000000000000000000000 - m_OcclusionCullingData: {fileID: 0} ---- !u!104 &2 -RenderSettings: - m_ObjectHideFlags: 0 - serializedVersion: 9 - m_Fog: 0 - m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} - m_FogMode: 3 - m_FogDensity: 0.01 - m_LinearFogStart: 0 - m_LinearFogEnd: 300 - m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} - m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} - m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} - m_AmbientIntensity: 1 - m_AmbientMode: 0 - m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} - m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} - m_HaloStrength: 0.5 - m_FlareStrength: 1 - m_FlareFadeSpeed: 3 - m_HaloTexture: {fileID: 0} - m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} - m_DefaultReflectionMode: 0 - m_DefaultReflectionResolution: 128 - m_ReflectionBounces: 1 - m_ReflectionIntensity: 1 - m_CustomReflection: {fileID: 0} - m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} - m_UseRadianceAmbientProbe: 0 ---- !u!157 &3 -LightmapSettings: - m_ObjectHideFlags: 0 - serializedVersion: 11 - m_GIWorkflowMode: 1 - m_GISettings: - serializedVersion: 2 - m_BounceScale: 1 - m_IndirectOutputScale: 1 - m_AlbedoBoost: 1 - m_EnvironmentLightingMode: 0 - m_EnableBakedLightmaps: 1 - m_EnableRealtimeLightmaps: 0 - m_LightmapEditorSettings: - serializedVersion: 12 - m_Resolution: 2 - m_BakeResolution: 40 - m_AtlasSize: 1024 - m_AO: 0 - m_AOMaxDistance: 1 - m_CompAOExponent: 1 - m_CompAOExponentDirect: 0 - m_ExtractAmbientOcclusion: 0 - m_Padding: 2 - m_LightmapParameters: {fileID: 0} - m_LightmapsBakeMode: 1 - m_TextureCompression: 1 - m_FinalGather: 0 - m_FinalGatherFiltering: 1 - m_FinalGatherRayCount: 256 - m_ReflectionCompression: 2 - m_MixedBakeMode: 2 - m_BakeBackend: 1 - m_PVRSampling: 1 - m_PVRDirectSampleCount: 32 - m_PVRSampleCount: 512 - m_PVRBounces: 2 - m_PVREnvironmentSampleCount: 256 - m_PVREnvironmentReferencePointCount: 2048 - m_PVRFilteringMode: 1 - m_PVRDenoiserTypeDirect: 1 - m_PVRDenoiserTypeIndirect: 1 - m_PVRDenoiserTypeAO: 1 - m_PVRFilterTypeDirect: 0 - m_PVRFilterTypeIndirect: 0 - m_PVRFilterTypeAO: 0 - m_PVREnvironmentMIS: 1 - m_PVRCulling: 1 - m_PVRFilteringGaussRadiusDirect: 1 - m_PVRFilteringGaussRadiusIndirect: 5 - m_PVRFilteringGaussRadiusAO: 2 - m_PVRFilteringAtrousPositionSigmaDirect: 0.5 - m_PVRFilteringAtrousPositionSigmaIndirect: 2 - m_PVRFilteringAtrousPositionSigmaAO: 1 - m_ExportTrainingData: 0 - m_TrainingDataDestination: TrainingData - m_LightProbeSampleCountMultiplier: 4 - m_LightingDataAsset: {fileID: 0} - m_UseShadowmask: 1 ---- !u!196 &4 -NavMeshSettings: - serializedVersion: 2 - m_ObjectHideFlags: 0 - m_BuildSettings: - serializedVersion: 2 - agentTypeID: 0 - agentRadius: 0.5 - agentHeight: 2 - agentSlope: 45 - agentClimb: 0.4 - ledgeDropHeight: 0 - maxJumpAcrossDistance: 0 - minRegionArea: 2 - manualCellSize: 0 - cellSize: 0.16666667 - manualTileSize: 0 - tileSize: 256 - accuratePlacement: 0 - debug: - m_Flags: 0 - m_NavMeshData: {fileID: 0} ---- !u!1 &722190521 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 722190523} - - component: {fileID: 722190522} - m_Layer: 0 - m_Name: Directional Light - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!108 &722190522 -Light: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 722190521} - m_Enabled: 1 - serializedVersion: 10 - m_Type: 1 - m_Shape: 0 - m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} - m_Intensity: 1 - m_Range: 10 - m_SpotAngle: 30 - m_InnerSpotAngle: 21.80208 - m_CookieSize: 10 - m_Shadows: - m_Type: 2 - m_Resolution: -1 - m_CustomResolution: -1 - m_Strength: 1 - m_Bias: 0.05 - m_NormalBias: 0.4 - m_NearPlane: 0.2 - m_CullingMatrixOverride: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 - m_UseCullingMatrixOverride: 0 - m_Cookie: {fileID: 0} - m_DrawHalo: 0 - m_Flare: {fileID: 0} - m_RenderMode: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingLayerMask: 1 - m_Lightmapping: 4 - m_LightShadowCasterMode: 0 - m_AreaSize: {x: 1, y: 1} - m_BounceIntensity: 1 - m_ColorTemperature: 6570 - m_UseColorTemperature: 0 - m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} - m_UseBoundingSphereOverride: 0 - m_ShadowRadius: 0 - m_ShadowAngle: 0 ---- !u!4 &722190523 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 722190521} - m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} - m_LocalPosition: {x: 0, y: 3, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} ---- !u!1 &929006872 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 929006873} - - component: {fileID: 929006874} - m_Layer: 0 - m_Name: GameObject - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &929006873 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 929006872} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &929006874 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 929006872} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9cd86f429bda8b54491fe8ca650b4efa, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!1 &1140885832 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1140885835} - - component: {fileID: 1140885834} - - component: {fileID: 1140885833} - m_Layer: 0 - m_Name: Main Camera - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!81 &1140885833 -AudioListener: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1140885832} - m_Enabled: 1 ---- !u!20 &1140885834 -Camera: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1140885832} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} - m_projectionMatrixMode: 1 - m_GateFitMode: 2 - m_FOVAxisMode: 0 - m_SensorSize: {x: 36, y: 24} - m_LensShift: {x: 0, y: 0} - m_FocalLength: 50 - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 1 - m_AllowMSAA: 1 - m_AllowDynamicResolution: 0 - m_ForceIntoRT: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 ---- !u!4 &1140885835 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1140885832} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -10} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1321805467 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1321805468} - - component: {fileID: 1321805469} - m_Layer: 0 - m_Name: GameObject (1) - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1321805468 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1321805467} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 3 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &1321805469 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1321805467} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 704cf15a4f065de46ac4a78fcc39b500, type: 3} - m_Name: - m_EditorClassIdentifier: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/Test.unity.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/Test.unity.meta deleted file mode 100644 index a9bc3c0e..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/Test.unity.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 71fb536dfa2527442a9a70ae0a41e861 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestClient.cs b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestClient.cs deleted file mode 100644 index 81e684a2..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestClient.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Net; -using System.Threading.Tasks; -using Kcp; -using TEngine; -using UnityEngine; - -public class TestClient : MonoBehaviour -{ - static IPEndPoint end = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback, 40001); - private KcpClient kcpClient; - private Task task; - void Start() - { - kcpClient = new KcpClient(50001, end); - task = Task.Run(async () => - { - while (true) - { - kcpClient.kcp.Update(DateTime.UtcNow); - await Task.Delay(10); - } - }); - } - - static async void Send(KcpClient client, string v) - { - var buffer = System.Text.Encoding.UTF8.GetBytes(v); - client.SendAsync(buffer, buffer.Length); - var resp = await client.ReceiveAsync(); - var respstr = System.Text.Encoding.UTF8.GetString(resp); - TLogger.LogError($"收到服务器回复: {respstr}"); - } - - void Update() - { - if (Input.GetKeyDown(KeyCode.Space)) - { - TLogger.LogError($"发送一条消息"); - Send(kcpClient, "发送一条消息"); - } - } -} diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestClient.cs.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestClient.cs.meta deleted file mode 100644 index a8979a6b..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestClient.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 704cf15a4f065de46ac4a78fcc39b500 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestServer.cs b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestServer.cs deleted file mode 100644 index 1d2f7058..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestServer.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Threading.Tasks; -using Kcp; -using UnityEngine; - -public class TestServer : MonoBehaviour -{ - void Start() - { - KcpClient kcpClient = new KcpClient(40001); - Task.Run(async () => - { - while (true) - { - kcpClient.kcp.Update(DateTime.UtcNow); - await Task.Delay(10); - } - }); - - StartRecv(kcpClient); - } - - static async void StartRecv(KcpClient client) - { - var res = await client.ReceiveAsync(); - StartRecv(client); - - await Task.Delay(1); - var str = System.Text.Encoding.UTF8.GetString(res); - if ("发送一条消息" == str) - { - Console.WriteLine(str); - - var buffer = System.Text.Encoding.UTF8.GetBytes("回复一条消息"); - client.SendAsync(buffer, buffer.Length); - } - } -} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestServer.cs.meta b/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestServer.cs.meta deleted file mode 100644 index 4f904a87..00000000 --- a/Assets/TEngine/Runtime/Net/Kcp/Kcp2/TestServer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9cd86f429bda8b54491fe8ca650b4efa -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: