Mirror of Svelto.ECS because we're a fan of it
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

47 lignes
1.3KB

  1. using Svelto.Common;
  2. using Svelto.DataStructures;
  3. using Svelto.ECS.Internal;
  4. namespace Svelto.ECS
  5. {
  6. interface IFiller
  7. {
  8. void FillFromByteArray(EntityInitializer init, NativeBag buffer);
  9. }
  10. class Filler<T> : IFiller where T : struct, _IInternalEntityComponent
  11. {
  12. static Filler()
  13. {
  14. DBC.ECS.Check.Require(TypeCache<T>.isUnmanaged == true, "invalid type used");
  15. }
  16. //it's an internal interface
  17. public void FillFromByteArray(EntityInitializer init, NativeBag buffer)
  18. {
  19. var component = buffer.Dequeue<T>();
  20. init.Init(component);
  21. }
  22. }
  23. #if UNITY_NATIVE //at the moment I am still considering NativeOperations useful only for Unity
  24. static class EntityComponentIDMap
  25. {
  26. static readonly Svelto.DataStructures.FasterList<IFiller> TYPE_IDS;
  27. static EntityComponentIDMap()
  28. {
  29. TYPE_IDS = new Svelto.DataStructures.FasterList<IFiller>();
  30. }
  31. internal static void Register<T>(IFiller entityBuilder) where T : struct, _IInternalEntityComponent
  32. {
  33. ComponentID location = ComponentTypeID<T>.id;
  34. TYPE_IDS.AddAt(location, entityBuilder);
  35. }
  36. internal static IFiller GetBuilderFromID(uint typeId) { return TYPE_IDS[typeId]; }
  37. }
  38. #endif
  39. }