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.

69 lines
3.2KB

  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 EntityInitializer BuildEntity<T>
  15. (uint entityID, ExclusiveBuildGroup 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 EntityInitializer 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 EntityInitializer 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. public EntityInitializer BuildEntity<T>
  34. (uint entityID, ExclusiveBuildGroup groupStructId, T descriptorEntity, IEnumerable<object> implementors)
  35. where T : IEntityDescriptor
  36. {
  37. return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId)
  38. , descriptorEntity.componentsToBuild, TypeCache<T>.type, implementors);
  39. }
  40. public void PreallocateEntitySpace<T>(ExclusiveGroupStruct groupStructId, uint numberOfEntities)
  41. where T : IEntityDescriptor, new()
  42. {
  43. _enginesRoot.Target.Preallocate(groupStructId, numberOfEntities, EntityDescriptorTemplate<T>.descriptor.componentsToBuild);
  44. }
  45. public EntityInitializer BuildEntity(EGID egid, IComponentBuilder[] componentsToBuild, Type type, IEnumerable<object> implementors = null)
  46. {
  47. return _enginesRoot.Target.BuildEntity(egid, componentsToBuild, type, implementors);
  48. }
  49. #if UNITY_NATIVE
  50. public Svelto.ECS.Native.NativeEntityFactory ToNative<T>(string callerName) where T : IEntityDescriptor, new()
  51. {
  52. return _enginesRoot.Target.ProvideNativeEntityFactoryQueue<T>(callerName);
  53. }
  54. #endif
  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. }