susices 2 лет назад
Родитель
Сommit
5397c9f228

+ 1 - 1
Unity/Assets/Scripts/ThirdParty/Kcp/Kcp.cs

@@ -193,7 +193,7 @@ namespace ET
                 
                 ref byte source = ref MemoryMarshal.GetReference(seg.WrittenBuffer);
                 Unsafe.CopyBlockUnaligned(ref dest,ref source,(uint)seg.WrittenCount);
-                dest = ref Unsafe.Add(ref dest, (uint) seg.WrittenCount);
+                dest = ref Unsafe.Add(ref dest, seg.WrittenCount);
 
                 len += seg.WrittenCount;
                 uint fragment = seg.SegHead.frg;

+ 0 - 51
Unity/Assets/Scripts/ThirdParty/Kcp/Pool.cs

@@ -1,51 +0,0 @@
-// Pool to avoid allocations (from libuv2k & Mirror)
-using System;
-using System.Buffers;
-using System.Collections.Generic;
-
-namespace ET
-{
-    public class Pool<T>
-    {
-        // Mirror is single threaded, no need for concurrent collections
-        readonly Stack<T> objects = new Stack<T>();
-
-        // some types might need additional parameters in their constructor, so
-        // we use a Func<T> generator
-        readonly Func<T> objectGenerator;
-
-        // some types might need additional cleanup for returned objects
-        readonly Action<T> objectResetter;
-
-        public Pool(Func<T> objectGenerator, Action<T> objectResetter, int initialCapacity)
-        {
-            this.objectGenerator = objectGenerator;
-            this.objectResetter = objectResetter;
-
-            // allocate an initial pool so we have fewer (if any)
-            // allocations in the first few frames (or seconds).
-            for (int i = 0; i < initialCapacity; ++i)
-                objects.Push(objectGenerator());
-        }
-
-        // take an element from the pool, or create a new one if empty
-        public T Take() => objects.Count > 0 ? objects.Pop() : objectGenerator();
-
-        // return an element to the pool
-        public void Return(T item)
-        {
-            if (this.Count > 1000)
-            {
-                return;
-            }
-            objectResetter(item);
-            objects.Push(item);
-        }
-
-        // clear the pool
-        public void Clear() => objects.Clear();
-
-        // count to see how many objects are in the pool. useful for tests.
-        public int Count => objects.Count;
-    }
-}

+ 0 - 64
Unity/Assets/Scripts/ThirdParty/Kcp/Segment.cs

@@ -65,68 +65,4 @@ namespace ET
             arrayPool.Return(this.buffer);
         }
     }
-    
-    // internal class Segment
-    // {
-    //     internal uint conv;     // conversation
-    //     internal byte cmd;      // command, e.g. Kcp.CMD_ACK etc.
-    //     // fragment (sent as 1 byte).
-    //     // 0 if unfragmented, otherwise fragment numbers in reverse: N,..,32,1,0
-    //     // this way the first received segment tells us how many fragments there are.
-    //     internal byte frg;
-    //     internal ushort wnd;      // window size that the receive can currently receive
-    //     internal uint ts;       // timestamp
-    //     internal uint sn;       // sequence number
-    //     internal uint una;
-    //     internal uint resendts; // resend timestamp
-    //     internal int  rto;
-    //     internal uint fastack;
-    //     internal uint xmit;     // retransmit count
-    //     
-    //     internal MemoryStream data = new MemoryStream(Kcp.MTU_DEF);
-    //
-    //     [MethodImpl(MethodImplOptions.AggressiveInlining)]
-    //     internal int Encode(byte[] ptr, int offset)
-    //     {
-    //         int previousPosition = offset;
-    //         
-    //         var segHead = new Kcp.SegmentHead()
-    //         {
-    //             conv = this.conv,
-    //             cmd = (byte) this.cmd,
-    //             frg = (byte) frg,
-    //             wnd = (ushort) this.wnd,
-    //             ts = this.ts,
-    //             sn = this.sn,
-    //             una = this.una,
-    //             len = (uint) this.data.Position,
-    //         };
-    //         
-    //         Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(ptr.AsSpan(offset)),segHead);
-    //         offset+=Unsafe.SizeOf<Kcp.SegmentHead>();
-    //         
-    //         int written = offset - previousPosition;
-    //         return written;
-    //     }
-    //
-    //     // reset to return a fresh segment to the pool
-    //     [MethodImpl(MethodImplOptions.AggressiveInlining)]
-    //     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;
-    //
-    //         // keep buffer for next pool usage, but reset length (= bytes written)
-    //         data.SetLength(0);
-    //     }
-    // }
 }

+ 0 - 81
Unity/Assets/Scripts/ThirdParty/Kcp/Utils.cs

@@ -15,87 +15,6 @@ namespace ET
             return value;
         }
 
-        // // encode 8 bits unsigned int
-        // [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        // public static int Encode8u(byte[] p, int offset, byte value)
-        // {
-        //     p[0 + offset] = value;
-        //     return 1;
-        // }
-        //
-        // // decode 8 bits unsigned int
-        // [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        // public static int Decode8u(byte[] p, int offset, out byte value)
-        // {
-        //     value = p[0 + offset];
-        //     return 1;
-        // }
-        //
-        // [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        // public static int Decode8u(ReadOnlySpan<byte> data,int offset,out byte value)
-        // {
-        //     value = data[offset];
-        //     return 1;
-        // }
-        //
-        // // encode 16 bits unsigned int (lsb)
-        // [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        // public static int Encode16U(byte[] p, int offset, ushort value)
-        // {
-        //     p[0 + offset] = (byte)(value >> 0);
-        //     p[1 + offset] = (byte)(value >> 8);
-        //     return 2;
-        // }
-        //
-        // // decode 16 bits unsigned int (lsb)
-        // [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        // public static int Decode16U(byte[] p, int offset, out ushort value)
-        // {
-        //     ushort result = 0;
-        //     result |= p[0 + offset];
-        //     result |= (ushort)(p[1 + offset] << 8);
-        //     value = result;
-        //     return 2;
-        // }
-        //
-        // [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        // public static int Decode16U(ReadOnlySpan<byte> data, int offset, out ushort value)
-        // {
-        //     value = Unsafe.ReadUnaligned<ushort>(ref MemoryMarshal.GetReference(data.Slice(offset)));
-        //     return 2;
-        // }
-        //
-        // // encode 32 bits unsigned int (lsb)
-        // [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        // public static int Encode32U(byte[] p, int offset, uint value)
-        // {
-        //     p[0 + offset] = (byte)(value >> 0);
-        //     p[1 + offset] = (byte)(value >> 8);
-        //     p[2 + offset] = (byte)(value >> 16);
-        //     p[3 + offset] = (byte)(value >> 24);
-        //     return 4;
-        // }
-        //
-        // // decode 32 bits unsigned int (lsb)
-        // [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        // public static int Decode32U(byte[] p, int offset, out uint value)
-        // {
-        //     uint result = 0;
-        //     result |= p[0 + offset];
-        //     result |= (uint)(p[1 + offset] << 8);
-        //     result |= (uint)(p[2 + offset] << 16);
-        //     result |= (uint)(p[3 + offset] << 24);
-        //     value = result;
-        //     return 4;
-        // }
-        //
-        // [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        // public static int Decode32U(ReadOnlySpan<byte> data, int offset, out uint value)
-        // {
-        //     value = Unsafe.ReadUnaligned<uint>(ref MemoryMarshal.GetReference(data.Slice(offset)));
-        //     return 4;
-        // }
-
         // timediff was a macro in original Kcp. let's inline it if possible.
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public static int TimeDiff(uint later, uint earlier)