Просмотр исходного кода

修复EntitySystem分析器Serialize system错误 EntitySystemOf标签新增 ignoreAwake参数 允许忽略生成AwakeSystem函数 (#482)

* 修复EntitySystem分析器Serialize system错误

* EntitySystemOf标签新增 ignoreAwake参数 允许忽略生成AwakeSystem函数

* 修改Kcp byteArrayPool为KService内共用 客户端poolsize减小
susices 2 лет назад
Родитель
Сommit
2ce73aa588

+ 11 - 0
Share/Analyzer/Analyzer/EntitySystemAnalyzer.cs

@@ -122,6 +122,13 @@ public class EntitySystemAnalyzer: DiagnosticAnalyzer
             return;
         }
 
+        bool ignoreAwake = false;
+        if (attr.ConstructorArguments.Length>=2 && attr.ConstructorArguments[1].Value is bool ignore)
+        {
+            ignoreAwake = ignore;
+        }
+        
+
         // 排除非Entity子类
         if (entityTypeSymbol.BaseType?.ToString() != etSystemData.EntityTypeName)
         {
@@ -130,6 +137,10 @@ public class EntitySystemAnalyzer: DiagnosticAnalyzer
 
         foreach (INamedTypeSymbol? interfacetypeSymbol in entityTypeSymbol.AllInterfaces)
         {
+            if (ignoreAwake && interfacetypeSymbol.IsInterface(Definition.IAwakeInterface))
+            {
+                continue;
+            }
             foreach (SystemMethodData systemMethodData in etSystemData.SystemMethods)
             {
                 if (interfacetypeSymbol.IsInterface(systemMethodData.InterfaceName))

+ 1 - 1
Share/Analyzer/Config/Definition.cs

@@ -73,7 +73,7 @@
         public const string LateUpdateMethod = "LateUpdate";
 
         public const string ISerializeInterface = "ET.ISerialize";
-        public const string SerializeMethod = "SerializeMethod";
+        public const string SerializeMethod = "Serialize";
 
         public const string LSEntitySystemAttribute = "LSEntitySystem";
         public const string LSEntitySystemAttributeMetaName = "ET.LSEntitySystemAttribute";

+ 12 - 2
Unity/Assets/Scripts/Core/Analyzer/EntitySystemOf.cs

@@ -7,7 +7,12 @@ namespace ET
     {
         public Type type;
 
-        public EntitySystemOfAttribute(Type type)
+        /// <summary>
+        /// 标记Entity的System静态类 用于自动生成System函数
+        /// </summary>
+        /// <param name="type">Entity类型</param>
+        /// <param name="ignoreAwake">是否忽略生成AwakeSystem</param>
+        public EntitySystemOfAttribute(Type type, bool ignoreAwake = false)
         {
             this.type = type;
         }
@@ -18,7 +23,12 @@ namespace ET
     {
         public Type type;
 
-        public LSEntitySystemOfAttribute(Type type)
+        /// <summary>
+        /// 标记LSEntity的System静态类 用于自动生成System函数
+        /// </summary>
+        /// <param name="type">LSEntity类型</param>
+        /// <param name="ignoreAwake">是否忽略生成AwakeSystem</param>
+        public LSEntitySystemOfAttribute(Type type, bool ignoreAwake = false)
         {
             this.type = type;
         }

+ 2 - 2
Unity/Assets/Scripts/Core/Network/KChannel.cs

@@ -64,14 +64,14 @@ namespace ET
 					this.kcp.SetWindowSize(1024, 1024);
 					this.kcp.SetMtu(1400); // 默认1400
 					this.kcp.SetMinrto(30);
-					this.kcp.InitArrayPool(1600, 10000);
+					this.kcp.SetArrayPool(this.Service.byteArrayPool);
 					break;
 				case ServiceType.Outer:
 					this.kcp.SetNoDelay(1, 10, 2, true);
 					this.kcp.SetWindowSize(256, 256);
 					this.kcp.SetMtu(470);
 					this.kcp.SetMinrto(30);
-					this.kcp.InitArrayPool(600, 10000);
+					this.kcp.SetArrayPool(this.Service.byteArrayPool);
 					break;
 			}
 

+ 6 - 0
Unity/Assets/Scripts/Core/Network/KService.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Buffers;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
@@ -55,6 +56,7 @@ namespace ET
                 this.Socket.SendBufferSize = Kcp.OneM * 64;
                 this.Socket.ReceiveBufferSize = Kcp.OneM * 64;
             }
+            
 
             try
             {
@@ -98,6 +100,10 @@ namespace ET
         private readonly List<long> timeOutTime = new List<long>();
         // 记录最小时间,不用每次都去MultiMap取第一个值
         private long minTime;
+        
+        public readonly ArrayPool<byte> byteArrayPool = ArrayPool<byte>.Create(2048,3000);
+#else
+        public readonly ArrayPool<byte> byteArrayPool = ArrayPool<byte>.Create(2048,200);
 #endif
         
         public override bool IsDisposed()

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

@@ -81,7 +81,7 @@ namespace ET
         internal readonly List<SegmentStruct> rcv_buf = new List<SegmentStruct>(16);   // receive buffer
         internal readonly List<AckItem> acklist = new List<AckItem>(16);
 
-        private ArrayPool<byte> kcpSegmentArrayPool = ArrayPool<byte>.Create();
+        private ArrayPool<byte> kcpSegmentArrayPool;
 
         // memory buffer
         // size depends on MTU.
@@ -1224,9 +1224,9 @@ namespace ET
             this.rx_minrto = minrto;
         }
 
-        public void InitArrayPool(int maxArrayLength, int maxArraysPerBucket)
+        public void SetArrayPool(ArrayPool<byte> arrayPool)
         {
-            this.kcpSegmentArrayPool = ArrayPool<byte>.Create(maxArrayLength,maxArraysPerBucket);
+            this.kcpSegmentArrayPool = arrayPool;
         }
 
         [DoesNotReturn]