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.

57 lines
2.4KB

  1. using System.Collections.Generic;
  2. using Svelto.DataStructures;
  3. namespace Svelto.ECS
  4. {
  5. public partial class EnginesRoot
  6. {
  7. class GenericEntityFactory : IEntityFactory
  8. {
  9. public GenericEntityFactory(EnginesRoot weakReference)
  10. {
  11. _enginesRoot = new WeakReference<EnginesRoot>(weakReference);
  12. }
  13. public EntityStructInitializer BuildEntity<T>(uint entityID,
  14. ExclusiveGroup.ExclusiveGroupStruct groupStructId, IEnumerable<object> implementors = null)
  15. where T : IEntityDescriptor, new()
  16. {
  17. return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId),
  18. EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, implementors);
  19. }
  20. public EntityStructInitializer BuildEntity<T>(EGID egid, IEnumerable<object> implementors = null)
  21. where T : IEntityDescriptor, new()
  22. {
  23. return _enginesRoot.Target.BuildEntity(egid,
  24. EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, implementors);
  25. }
  26. public EntityStructInitializer BuildEntity<T>(EGID egid, T entityDescriptor,
  27. IEnumerable<object> implementors)
  28. where T : IEntityDescriptor
  29. {
  30. return _enginesRoot.Target.BuildEntity(egid, entityDescriptor.entitiesToBuild, implementors);
  31. }
  32. public EntityStructInitializer BuildEntity<T>(uint entityID,
  33. ExclusiveGroup.ExclusiveGroupStruct groupStructId, T descriptorEntity, IEnumerable<object> implementors)
  34. where T : IEntityDescriptor
  35. {
  36. return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId),
  37. descriptorEntity.entitiesToBuild,
  38. implementors);
  39. }
  40. public void PreallocateEntitySpace<T>(ExclusiveGroup.ExclusiveGroupStruct groupStructId, uint size)
  41. where T : IEntityDescriptor, new()
  42. {
  43. _enginesRoot.Target.Preallocate<T>(groupStructId, size);
  44. }
  45. //enginesRoot is a weakreference because GenericEntityStreamConsumerFactory can be injected inside
  46. //engines of other enginesRoot
  47. readonly WeakReference<EnginesRoot> _enginesRoot;
  48. }
  49. }
  50. }