using System.Collections.Generic; using Svelto.DataStructures; namespace Svelto.ECS { public partial class EnginesRoot { class GenericEntityFactory : IEntityFactory { public GenericEntityFactory(EnginesRoot weakReference) { _enginesRoot = new WeakReference(weakReference); } public EntityStructInitializer BuildEntity(uint entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId, IEnumerable implementors = null) where T : IEntityDescriptor, new() { return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId), EntityDescriptorTemplate.descriptor.entitiesToBuild, implementors); } public EntityStructInitializer BuildEntity(EGID egid, IEnumerable implementors = null) where T : IEntityDescriptor, new() { return _enginesRoot.Target.BuildEntity(egid, EntityDescriptorTemplate.descriptor.entitiesToBuild, implementors); } public EntityStructInitializer BuildEntity(EGID egid, T entityDescriptor, IEnumerable implementors) where T : IEntityDescriptor { return _enginesRoot.Target.BuildEntity(egid, entityDescriptor.entitiesToBuild, implementors); } public EntityStructInitializer BuildEntity(uint entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId, T descriptorEntity, IEnumerable implementors) where T : IEntityDescriptor { return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId), descriptorEntity.entitiesToBuild, implementors); } public void PreallocateEntitySpace(ExclusiveGroup.ExclusiveGroupStruct groupStructId, uint size) where T : IEntityDescriptor, new() { _enginesRoot.Target.Preallocate(groupStructId, size); } //enginesRoot is a weakreference because GenericEntityStreamConsumerFactory can be injected inside //engines of other enginesRoot readonly WeakReference _enginesRoot; } } }