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.

67 lines
3.1KB

  1. using System;
  2. using System.Collections.Generic;
  3. using Svelto.Common;
  4. namespace Svelto.ECS
  5. {
  6. public partial class EnginesRoot
  7. {
  8. class GenericEntityFactory : IEntityFactory
  9. {
  10. public GenericEntityFactory(EnginesRoot weakReference)
  11. {
  12. _enginesRoot = new Svelto.DataStructures.WeakReference<EnginesRoot>(weakReference);
  13. }
  14. public EntityComponentInitializer BuildEntity<T>
  15. (uint entityID, BuildGroup groupStructId, IEnumerable<object> implementors = null)
  16. where T : IEntityDescriptor, new()
  17. {
  18. return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId)
  19. , EntityDescriptorTemplate<T>.descriptor.componentsToBuild
  20. , TypeCache<T>.type, implementors);
  21. }
  22. public EntityComponentInitializer BuildEntity<T>(EGID egid, IEnumerable<object> implementors = null)
  23. where T : IEntityDescriptor, new()
  24. {
  25. return _enginesRoot.Target.BuildEntity(
  26. egid, EntityDescriptorTemplate<T>.descriptor.componentsToBuild, TypeCache<T>.type, implementors);
  27. }
  28. public EntityComponentInitializer BuildEntity<T>
  29. (EGID egid, T entityDescriptor, IEnumerable<object> implementors) where T : IEntityDescriptor
  30. {
  31. return _enginesRoot.Target.BuildEntity(egid, entityDescriptor.componentsToBuild, TypeCache<T>.type, implementors);
  32. }
  33. #if UNITY_NATIVE
  34. public NativeEntityFactory ToNative<T>(string memberName) where T : IEntityDescriptor, new()
  35. {
  36. return _enginesRoot.Target.ProvideNativeEntityFactoryQueue<T>(memberName);
  37. }
  38. #endif
  39. public EntityComponentInitializer BuildEntity<T>
  40. (uint entityID, BuildGroup groupStructId, T descriptorEntity, IEnumerable<object> implementors)
  41. where T : IEntityDescriptor
  42. {
  43. return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId)
  44. , descriptorEntity.componentsToBuild, TypeCache<T>.type, implementors);
  45. }
  46. public void PreallocateEntitySpace<T>(ExclusiveGroupStruct groupStructId, uint size)
  47. where T : IEntityDescriptor, new()
  48. {
  49. _enginesRoot.Target.Preallocate<T>(groupStructId, size);
  50. }
  51. public EntityComponentInitializer BuildEntity(EGID egid, IComponentBuilder[] componentsToBuild, Type type, IEnumerable<object> implementors = null)
  52. {
  53. return _enginesRoot.Target.BuildEntity(egid, componentsToBuild, type, implementors);
  54. }
  55. //enginesRoot is a weakreference because GenericEntityStreamConsumerFactory can be injected inside
  56. //engines of other enginesRoot
  57. readonly Svelto.DataStructures.WeakReference<EnginesRoot> _enginesRoot;
  58. }
  59. }
  60. }