Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using Svelto.DataStructures;
  5. using Svelto.Utilities;
  6. namespace Svelto.ECS
  7. {
  8. static class EntityView<T> where T: IEntityStruct, new()
  9. {
  10. internal static readonly FasterList<KeyValuePair<Type, ActionCast<T>>> cachedFields;
  11. static EntityView()
  12. {
  13. cachedFields = new FasterList<KeyValuePair<Type, ActionCast<T>>>();
  14. var type = typeof(T);
  15. var fields = type.GetFields(BindingFlags.Public |
  16. BindingFlags.Instance);
  17. for (int i = fields.Length - 1; i >= 0; --i)
  18. {
  19. var field = fields[i];
  20. ActionCast<T> setter = FastInvoke<T>.MakeSetter(field);
  21. cachedFields.Add(new KeyValuePair<Type, ActionCast<T>>(field.FieldType, setter));
  22. }
  23. }
  24. internal static void InitCache()
  25. {}
  26. internal static void BuildEntityView(EGID ID, out T entityView)
  27. {
  28. entityView = new T { ID = ID };
  29. }
  30. }
  31. ///<summary>EntityViews can inherit from the EntityView class</summary>
  32. public class EntityView : IEntityViewStruct
  33. {
  34. public EGID ID
  35. {
  36. get { return _ID; }
  37. set { _ID = value; }
  38. }
  39. EGID _ID;
  40. }
  41. }