Ver código fonte

Entity反序列化0GC实现

tanghai 1 ano atrás
pai
commit
46043acff2

+ 4 - 0
Share/Share.SourceGenerator/Generator/ETEntitySerializeFormatterGenerator.cs

@@ -150,6 +150,10 @@ namespace ET
         {
             sb.AppendLine($$"""
             case {{entityName.GetLongHashCode()}}:
+                    if(value == null)
+                    {
+                        value = global::{{entityName}}.Fetch<global::{{entityName}}>();
+                    }
                     if(value is global::{{entityName}})
                     {
                         reader.ReadPackable(ref System.Runtime.CompilerServices.Unsafe.As<global::{{Definition.EntityType}}?, global::{{entityName}}>(ref value));

BIN
Unity/Assets/Plugins/Share.SourceGenerator.dll


+ 6 - 0
Unity/Assets/Scripts/Core/Entity/Entity.cs

@@ -20,6 +20,12 @@ namespace ET
     [MemoryPackable(GenerateType.NoGenerate)]
     public abstract partial class Entity: DisposeObject, IPool
     {
+        // 给source generater调用的
+        public static T Fetch<T>() where T : Entity
+        {
+            return ObjectPool.Fetch<T>();
+        }
+        
         public static long GetLongHashCodeByType(Type type)
         {
             return EntitySystemSingleton.Instance.GetLongHashCode(type);