using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using Svelto.Common; namespace Svelto.ECS { public partial class EnginesRoot { class GenericEntityFactory : IEntityFactory { public GenericEntityFactory(EnginesRoot weakReference) { _enginesRoot = new Svelto.DataStructures.WeakReference(weakReference); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public EntityInitializer BuildEntity (uint entityID, ExclusiveBuildGroup groupStructId, IEnumerable implementors = null , [CallerMemberName] string caller = null) where T : IEntityDescriptor, new() { return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId) , EntityDescriptorTemplate.realDescriptor.componentsToBuild , TypeCache.type, implementors, caller); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public EntityInitializer BuildEntity (EGID egid, IEnumerable implementors = null , [CallerMemberName] string caller = null) where T : IEntityDescriptor, new() { return _enginesRoot.Target.BuildEntity(egid, EntityDescriptorTemplate.realDescriptor.componentsToBuild , TypeCache.type, implementors, caller); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public EntityInitializer BuildEntity (EGID egid, T entityDescriptor, IEnumerable implementors , [CallerMemberName] string caller = null) where T : IEntityDescriptor { return _enginesRoot.Target.BuildEntity(egid, entityDescriptor.componentsToBuild, TypeCache.type , implementors, caller); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public EntityInitializer BuildEntity (uint entityID, ExclusiveBuildGroup groupStructId, T descriptorEntity, IEnumerable implementors , [CallerMemberName] string caller = null) where T : IEntityDescriptor { return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId) , descriptorEntity.componentsToBuild, TypeCache.type , implementors, caller); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public EntityInitializer BuildEntity (EGID egid, IComponentBuilder[] componentsToBuild, Type type, IEnumerable implementors = null , [CallerMemberName] string caller = null) { return _enginesRoot.Target.BuildEntity(egid, componentsToBuild, type, implementors, caller); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PreallocateEntitySpace(ExclusiveGroupStruct groupStructId, uint numberOfEntities) where T : IEntityDescriptor, new() { _enginesRoot.Target.Preallocate(groupStructId, numberOfEntities , EntityDescriptorTemplate.realDescriptor.componentsToBuild); } #if UNITY_NATIVE public Native.NativeEntityFactory ToNative ([CallerMemberName] string caller = null) where T : IEntityDescriptor, new() { return _enginesRoot.Target.ProvideNativeEntityFactoryQueue(caller); } #endif //enginesRoot is a weakreference because GenericEntityStreamConsumerFactory can be injected inside //engines of other enginesRoot readonly Svelto.DataStructures.WeakReference _enginesRoot; } } }