diff --git a/src/Tools/ComponentTamplateGenerator/Generator.cs b/src/Tools/ComponentTamplateGenerator/Generator.cs index 1238c99..d7de7a8 100644 --- a/src/Tools/ComponentTamplateGenerator/Generator.cs +++ b/src/Tools/ComponentTamplateGenerator/Generator.cs @@ -1,10 +1,13 @@ #if UNITY_EDITOR using DCFApixels.DragonECS; +using DCFApixels.DragonECS.PoolsCore; using DCFApixels.DragonECS.Unity; using DCFApixels.DragonECS.Unity.Editors; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; +using Unity.Collections.LowLevel.Unsafe; using UnityEditor; using UnityEditor.Compilation; using UnityEngine; @@ -70,4 +73,191 @@ namespace DCFApixels.DragonECS.Unity.Editors } } -#endif \ No newline at end of file +#endif + + + + + + + + + + + + + + +public abstract class GeneratedComponentTemplateBase : ComponentTemplateBase +{ + [Serializable] + protected struct TypeInfo + { + public string asm; + public string ns; + public string name; + public TypeInfo(string asm, string ns, string name) + { + this.asm = asm; + this.ns = ns; + this.name = name; + } + } +} +public abstract class GeneratedComponentTemplateBase : GeneratedComponentTemplateBase +{ + private static Type _componentType; + private static Type _componentInterfaceType; + + private static ConverterWrapperBase _converter; + + [SerializeField] + private TStencil _component; // Stencil + [SerializeField] + private bool _offset; + public override Type Type + { + get { return _componentType; } + } + public override void Apply(short worldID, int entityID) + { + _converter.Apply(ref _component, worldID, entityID); + } + public override object GetRaw() + { + return _converter.GetRaw(ref _component); + } + public override void SetRaw(object raw) + { + _converter.SetRaw(ref _component, raw); + } + + public static void InitStatic(string componentTypeAssemblyQualifiedName, string poolTypeAssemblyQualifiedName) + { + + } +} + +public static class GeneratorUtility +{ + public delegate void ApplyHandler(ref TComponent data); + public delegate void ApplyHandler(ref TComponent data, TPool pool); + + public static bool SkanTypeStructure(Type type) + { + + } + private static bool IsSerializableField(FieldInfo fieldInfo) + { + return fieldInfo.IsPublic || fieldInfo.GetCustomAttribute() != null || fieldInfo.GetCustomAttribute() != null; + } + private static bool IsCanUnsafeOverride(FieldInfo fieldInfo) + { + if (fieldInfo.FieldType.IsValueType) + { + return true; + } + if (fieldInfo.FieldType == typeof(string)) + { + return true; + } + if (typeof(UnityEngine.Object).IsAssignableFrom(fieldInfo.FieldType)) + { + return true; + } + if (fieldInfo.GetCustomAttribute() != null) + { + return true; + } + + return false; + } + + //public interface IUnityCompilatorInfo // defines hack + //{ + // /// VMT size + // public int ObjectVirtualDataSize { get; } + // /// can rewrite VMT + // public bool IsSupportRewriteObjectVirtualData { get; } + //} + //private class UnityCompilatorInfo : IUnityCompilatorInfo + //{ + // public int ObjectVirtualDataSize + // { + // get + // { + // return 8; + // } + // } + // public bool IsSupportRewriteObjectVirtualData + // { + // get + // { + // return true; + // } + // } + //} +} +public abstract class ConverterWrapperBase +{ + public abstract void Apply(ref TStencil component, short worldID, int entityID); + public abstract object GetRaw(ref TStencil stencilComponent); + public abstract void SetRaw(ref TStencil stencilComponent, object raw); +} +public class ConverterWrapper : ConverterWrapperBase where TPool : IEcsPoolImplementation, new() +{ + private F.DoHandler _apply; + private F.DoHandler _apply2; + public override void Apply(ref TStencil stencilComponent, short worldID, int entityID) + { + ref var component = ref UnsafeUtility.As(ref stencilComponent); + _apply(ref component); + + + EcsWorld w = null; + var pool = w.GetPoolInstance(); + _apply2(ref component, pool); + + + //EcsWorld.GetPoolInstance>(worldID).TryAddOrGet(entityID) = component; + } + public override object GetRaw(ref TStencil stencilComponent) + { + ref var component = ref UnsafeUtility.As(ref stencilComponent); + return component; + } + public override void SetRaw(ref TStencil stencilComponent, object raw) + { + TComponent component = (TComponent)raw; + stencilComponent = UnsafeUtility.As(ref component); + } +} + + +public struct TTT : IEcsComponent { } +public class F +{ + public void Do1(ref T data) where T : struct, IEcsComponent { } + public void Do2(ref T data, EcsPool pool) where T : struct, IEcsComponent { } + + public delegate void DoHandler(ref T data); + public delegate void DoHandler(ref T data, TPool pool); + + public void Do() + { + DoHandler dodo1 = Do1; + DoHandler> dodo2 = Do2; + } +} + + + +public class Template_GUID : GeneratedComponentTemplateBase +{ + static Template_GUID() { InitStatic("AssemblyQualifiedName", "AssemblyQualifiedName"); } +} +[System.Serializable] +public struct Component_GUID +{ + // data... +}