using System; using System.Collections.Generic; using System.Reflection; using Svelto.DataStructures; using Svelto.Utilities; namespace Svelto.ECS { public interface IEntityView { int ID { get; } } public interface IEntityStruct:IEntityView { new int ID { set; } } public class EntityView : IEntityView { public int ID { get { return _ID; } } internal FasterList>> entityViewBlazingFastReflection; internal int _ID; } internal static class EntityView where T: EntityView, new() { internal static T BuildEntityView(int ID) { if (FieldCache.list.Count == 0) { var type = typeof(T); var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance); for (int i = fields.Length - 1; i >= 0; --i) { var field = fields[i]; Action setter = FastInvoke.MakeSetter(field); FieldCache.list.Add(new KeyValuePair>(field.FieldType, setter)); } } return new T { _ID = ID, entityViewBlazingFastReflection = FieldCache.list }; } static class FieldCache where W:T { internal static readonly FasterList>> list = new FasterList>>(); } } }