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.

79 lines
3.6KB

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