Exemplo n.º 1
0
        private static unsafe NativeArray <EntityArchetype> ReadArchetypes(BinaryReader reader, NativeArray <int> types, ExclusiveEntityTransaction entityManager,
                                                                           out int totalEntityCount)
        {
            int archetypeCount = reader.ReadInt();
            var archetypes     = new NativeArray <EntityArchetype>(archetypeCount, Allocator.Temp);

            totalEntityCount = 0;
            var tempComponentTypes = new NativeList <ComponentType>(Allocator.Temp);

            for (int i = 0; i < archetypeCount; ++i)
            {
                var archetypeEntityCount = reader.ReadInt();
                totalEntityCount += archetypeEntityCount;
                int archetypeComponentTypeCount = reader.ReadInt();
                tempComponentTypes.Clear();
                for (int iType = 0; iType < archetypeComponentTypeCount; ++iType)
                {
                    int typeHashIndexInFile        = reader.ReadInt();
                    int typeHashIndexInFileNoFlags = typeHashIndexInFile & TypeManager.ClearFlagsMask;
                    int typeIndex = types[typeHashIndexInFileNoFlags];
                    if (TypeManager.IsChunkComponent(typeHashIndexInFile))
                    {
                        typeIndex = TypeManager.MakeChunkComponentTypeIndex(typeIndex);
                    }

                    tempComponentTypes.Add(ComponentType.FromTypeIndex(typeIndex));
                }

                archetypes[i] = entityManager.CreateArchetype((ComponentType *)tempComponentTypes.GetUnsafePtr(),
                                                              tempComponentTypes.Length);
            }

            tempComponentTypes.Dispose();
            return(archetypes);
        }
Exemplo n.º 2
0
        public unsafe void *GetPtr(object key)
        {
            switch (key)
            {
            case Type type when type.IsComponentDataType():
            {
                var typeIndex = TypeManager.GetTypeIndex(type);
                if (ComponentType.FromTypeIndex(typeIndex).IsZeroSized)
                {
                    throw new ArgumentException($"SetComponentData<{type}> can not be called with a zero sized component.");
                }
                return(Entity.GetComponentDataRawRW(EntityManager, typeIndex));
            }

            case ulong componentStableHash:
            {
                var typeIndex = TypeManager.GetTypeIndexFromStableTypeHash(componentStableHash);
                if (ComponentType.FromTypeIndex(typeIndex).IsZeroSized)
                {
                    throw new ArgumentException($"SetComponentData can not be called with a zero sized component.");
                }
                return(Entity.GetComponentDataRawRW(EntityManager, typeIndex));
            }

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 3
0
    public T GetComponentData <T>(Entity entity) where T : struct, IComponentData
    {
        var typeIndex = TypeManager.GetTypeIndex <T>();

        EntityComponentStore->AssertEntityHasComponent(entity, typeIndex);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
        if (ComponentType.FromTypeIndex(typeIndex).IsZeroSized)
        {
            throw new System.ArgumentException(
                      $"GetComponentData<{typeof(T)}> can not be called with a zero sized component.");
        }
#endif

        if (m_IsMainThread)
        {
            DependencyManager->CompleteWriteDependency(typeIndex);
        }

        var ptr = EntityComponentStore->GetComponentDataWithTypeRO(entity, typeIndex);

        T value;
        UnsafeUtility.CopyPtrToStructure(ptr, out value);
        return(value);
    }
Exemplo n.º 4
0
    /// <summary>
    /// EntityManager.BeforeStructuralChange must be called before invoking this.
    /// ManagedComponentStore.Playback must be called after invoking this.
    /// ManagedComponentStore.RemoveReference() must be called after Playback for each newSharedComponentDataIndex added
    /// EntityQueryManager.AddAdditionalArchetypes must be called after invoking this.
    /// Invoking this must be wrapped in ArchetypeChangeTracking.
    /// </summary>
    /// <param name="archetypeList"></param>
    /// <param name="filter"></param>
    /// <param name="typeIndex"></param>
    /// <param name="hashCode"></param>
    /// <param name="componentData"></param>
    /// <exception cref="InvalidOperationException"></exception>
    public void AddSharedComponentDataBoxedDefaultMustBeNullDuringStructuralChange(UnsafeMatchingArchetypePtrList archetypeList, EntityQueryFilter filter, int typeIndex, int hashCode, object componentData, UnsafeList *managedReferenceIndexRemovalCount)
    {
        if (!m_IsMainThread)
        {
            throw new InvalidOperationException("Must be called from the main thread");
        }

        ComponentType componentType = ComponentType.FromTypeIndex(typeIndex);

        using (var chunks = ChunkIterationUtility.CreateArchetypeChunkArray(archetypeList, Allocator.TempJob, ref filter, DependencyManager))
        {
            if (chunks.Length == 0)
            {
                return;
            }
            var newSharedComponentDataIndex = 0;
            if (componentData != null) // null means default
            {
                newSharedComponentDataIndex = ManagedComponentStore.InsertSharedComponentAssumeNonDefault(typeIndex, hashCode, componentData);
            }

            AddSharedComponentDataDuringStructuralChange(chunks, newSharedComponentDataIndex, componentType);
            managedReferenceIndexRemovalCount->Add(newSharedComponentDataIndex);
        }
    }
Exemplo n.º 5
0
        private static IEnumerable <ComponentType> GetDynamicAccess(ref BlobVariant blobVariant)
        {
            var hash      = blobVariant.As <DynamicComponentData>().StableHash;
            var typeIndex = TypeManager.GetTypeIndexFromStableTypeHash(hash);

            return(ComponentType.FromTypeIndex(typeIndex).Yield());
        }
Exemplo n.º 6
0
        private static unsafe NativeArray <EntityArchetype> ReadArchetypes(BinaryReader reader, NativeArray <int> types, ExclusiveEntityTransaction entityManager,
                                                                           out int totalEntityCount)
        {
            int archetypeCount        = reader.ReadInt();
            var archetypes            = new NativeArray <EntityArchetype>(archetypeCount, Allocator.Temp);
            var archetypeEntityCounts = new NativeArray <int>(archetypeCount, Allocator.Temp);

            totalEntityCount = 0;
            var tempComponentTypes = new NativeList <ComponentType>(Allocator.Temp);

            for (int i = 0; i < archetypeCount; ++i)
            {
                totalEntityCount += archetypeEntityCounts[i] = reader.ReadInt();
                int archetypeComponentTypeCount = reader.ReadInt();
                tempComponentTypes.Clear();
                for (int iType = 0; iType < archetypeComponentTypeCount; ++iType)
                {
                    int typeIndex = types[reader.ReadInt()];

                    tempComponentTypes.Add(ComponentType.FromTypeIndex(typeIndex));
                }

                archetypes[i] = entityManager.CreateArchetype((ComponentType *)tempComponentTypes.GetUnsafePtr(),
                                                              tempComponentTypes.Length);
            }

            tempComponentTypes.Dispose();
            types.Dispose();
            archetypeEntityCounts.Dispose();
            return(archetypes);
        }
Exemplo n.º 7
0
    /// <summary>
    /// EntityManager.BeforeStructuralChange must be called before invoking this.
    /// ManagedComponentStore.Playback must be called after invoking this.
    /// EntityQueryManager.AddAdditionalArchetypes must be called after invoking this.
    /// Invoking this must be wrapped in ArchetypeChangeTracking.
    /// </summary>
    /// <param name="entity"></param>
    /// <param name="typeIndex"></param>
    /// <param name="hashCode"></param>
    /// <param name="componentData"></param>
    public bool AddSharedComponentDataBoxedDefaultMustBeNullDuringStructuralChange(Entity entity, int typeIndex, int hashCode, object componentData, UnsafeList *managedReferenceIndexRemovalCount)
    {
        //TODO: optimize this (no need to move the entity to a new chunk twice)
        var added = AddComponentDuringStructuralChange(entity, ComponentType.FromTypeIndex(typeIndex));

        SetSharedComponentDataBoxedDefaultMustBeNullDuringStructuralChange(entity, typeIndex, hashCode, componentData, managedReferenceIndexRemovalCount);

        return(added);
    }
Exemplo n.º 8
0
        internal EntityArchetype CreateArchetypeRaw(int *typeIndices, int count)
        {
            // TODO fix this up
            ComponentType *ct = stackalloc ComponentType[count];

            for (int i = 0; i < count; ++i)
            {
                ct[i] = ComponentType.FromTypeIndex(typeIndices[i]);
            }
            return(CreateArchetype(ct, count));
        }
 static void RemoveSystemState(EntityManager entityManager)
 {
     foreach (var s in TypeManager.AllTypes)
     {
         if (TypeManager.IsSystemStateComponent(s.TypeIndex))
         {
             //@TODO: Make query instead of this crazy slow shit
             entityManager.RemoveComponent(entityManager.UniversalQuery, ComponentType.FromTypeIndex(s.TypeIndex));
         }
     }
 }
        public void SectionMetadata()
        {
            using (var world = TestWorldSetup.CreateEntityWorld("World", false))
            {
                var resolveParams = new SceneSystem.LoadParameters
                {
                    Flags = SceneLoadFlags.BlockOnImport | SceneLoadFlags.DisableAutoLoad
                };
                var sceneSystem = world.GetOrCreateSystem <SceneSystem>();
                var sceneEntity = sceneSystem.LoadSceneAsync(SceneGUID, resolveParams);
                world.Update();
                var manager         = world.EntityManager;
                var sectionEntities = manager.GetBuffer <ResolvedSectionEntity>(sceneEntity);

                Assert.AreEqual(3, sectionEntities.Length);
                Assert.IsTrue(manager.HasComponent <TestMetadata>(sectionEntities[0].SectionEntity));
                Assert.IsFalse(manager.HasComponent <TestMetadata>(sectionEntities[1].SectionEntity));
                Assert.IsTrue(manager.HasComponent <TestMetadata>(sectionEntities[2].SectionEntity));

                Assert.IsTrue(manager.HasComponent <TestMetadataTag>(sectionEntities[0].SectionEntity));
                Assert.IsFalse(manager.HasComponent <TestMetadataTag>(sectionEntities[1].SectionEntity));
                Assert.IsTrue(manager.HasComponent <TestMetadataTag>(sectionEntities[2].SectionEntity));

                // These components should not be added, instead an error is logged that meta info components can't contain entities or blob assets
                var filteredTypes = new[]
                {
                    typeof(TestMetadataWithEntity), typeof(TestMetadataWithBlobAsset), typeof(EcsTestSharedComp), typeof(EcsIntElement), typeof(EcsState1),
#if !UNITY_DISABLE_MANAGED_COMPONENTS
                    typeof(EcsTestManagedComponent)
#endif
                };

                foreach (var type in filteredTypes)
                {
                    var componentType = ComponentType.FromTypeIndex(TypeManager.GetTypeIndex(type));
                    Assert.IsFalse(manager.HasComponent(sectionEntities[0].SectionEntity, componentType));
                }

                Assert.AreEqual(0, manager.GetComponentData <TestMetadata>(sectionEntities[0].SectionEntity).SectionIndex);
                Assert.AreEqual(13, manager.GetComponentData <TestMetadata>(sectionEntities[0].SectionEntity).Value);
                Assert.AreEqual(42, manager.GetComponentData <TestMetadata>(sectionEntities[2].SectionEntity).SectionIndex);
                Assert.AreEqual(100, manager.GetComponentData <TestMetadata>(sectionEntities[2].SectionEntity).Value);

                var hash = EntityScenesPaths.GetSubSceneArtifactHash(SceneGUID, sceneSystem.BuildConfigurationGUID, true, ImportMode.Synchronous);
                Assert.IsTrue(hash.IsValid);
                AssetDatabaseCompatibility.GetArtifactPaths(hash, out var paths);
                var logPath = EntityScenesPaths.GetLoadPathFromArtifactPaths(paths, EntityScenesPaths.PathType.EntitiesConversionLog);
                Assert.NotNull(logPath);
                var log = System.IO.File.ReadAllText(logPath);
                Assert.IsTrue(log.Contains("The component type must contains only blittable/basic data types"));
                Assert.IsFalse(log.Contains("entities in the scene 'TestSubSceneWithSectionMetadata' had no SceneSection and as a result were not serialized at all."));
            }
        }
Exemplo n.º 11
0
    /// <summary>
    /// EntityManager.BeforeStructuralChange must be called before invoking this.
    /// ManagedComponentStore.Playback must be called after invoking this.
    /// ManagedComponentStore.RemoveReference() must be called after Playback for each newSharedComponentDataIndex added
    /// EntityQueryManager.AddAdditionalArchetypes must be called after invoking this.
    /// Invoking this must be wrapped in ArchetypeChangeTracking.
    /// </summary>
    /// <param name="entity"></param>
    /// <param name="typeIndex"></param>
    /// <param name="hashCode"></param>
    /// <param name="componentData"></param>
    public void SetSharedComponentDataBoxedDefaultMustBeNullDuringStructuralChange(Entity entity, int typeIndex, int hashCode, object componentData, UnsafeList *managedReferenceIndexRemovalCount)
    {
        EntityComponentStore->AssertEntityHasComponent(entity, typeIndex);

        var newSharedComponentDataIndex = 0;

        if (componentData != null) // null means default
        {
            newSharedComponentDataIndex = ManagedComponentStore.InsertSharedComponentAssumeNonDefault(typeIndex,
                                                                                                      hashCode, componentData);
        }
        var componentType = ComponentType.FromTypeIndex(typeIndex);

        EntityComponentStore->SetSharedComponentDataIndex(entity, componentType, newSharedComponentDataIndex);

        managedReferenceIndexRemovalCount->Add(newSharedComponentDataIndex);
    }
Exemplo n.º 12
0
        public unsafe ref T GetRef <T>(object key) where T : struct
        {
            var type = typeof(T);

            if (!type.IsComponentDataType())
            {
                throw new NotImplementedException();
            }

            var typeIndex = TypeManager.GetTypeIndex <T>();

            if (ComponentType.FromTypeIndex(typeIndex).IsZeroSized)
            {
                throw new ArgumentException($"SetComponentData<{type}> can not be called with a zero sized component.");
            }

            return(ref UnsafeUtilityEx.AsRef <T>(Entity.GetComponentDataRawRW(EntityManager, typeIndex)));
        }
Exemplo n.º 13
0
    public void SetSharedComponentData <T>(Entity entity, T componentData, ManagedComponentStore managedComponentStore) where T : struct, ISharedComponentData
    {
        if (m_IsMainThread)
        {
            BeforeStructuralChange();
        }

        var typeIndex     = TypeManager.GetTypeIndex <T>();
        var componentType = ComponentType.FromTypeIndex(typeIndex);

        EntityComponentStore->AssertEntityHasComponent(entity, typeIndex);

        var newSharedComponentDataIndex = managedComponentStore.InsertSharedComponent(componentData);

        EntityComponentStore->SetSharedComponentDataIndex(entity, componentType, newSharedComponentDataIndex);
        managedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker);
        managedComponentStore.RemoveReference(newSharedComponentDataIndex);
    }
Exemplo n.º 14
0
        public ComponentTypeListView(TreeViewState state, out MultiColumnHeaderState headerState, SelectionChange <ComponentType, object> selectionChange, Func <World> worldChanged) : base(state, BuilMultiColumnHeader(out headerState))
        {
            selectionChanged  = selectionChange;
            this.worldChanged = worldChanged;

            foreach (var type in TypeManager.AllTypes())
            {
                if (type.Type == typeof(Entity))
                {
                    continue;
                }
                var typeIndex     = TypeManager.GetTypeIndex(type.Type);
                var componentType = ComponentType.FromTypeIndex(typeIndex);
                if (componentType.GetManagedType() == null)
                {
                    continue;
                }

                //Currently IsZeroSized is broken and returns true for both SharedComponents and SystemStateSharedComponents //Case #1086719 @
                if (componentType.IsZeroSized())
                {
                    //Debug.Log($"{componentType} : {componentType.IsSharedComponent} : {componentType.IsSystemStateComponent} : {componentType.IsSystemStateSharedComponent} : {componentType.IsZeroSized} : {componentType.BufferCapacity}");
                    Objects.Add(componentType, null);
                }
                else
                {
                    var obj = Activator.CreateInstance(type.Type, true);
                    Objects.Add(componentType, obj);
                    if (componentType.IsSharedComponent || componentType.IsSystemStateSharedComponent)
                    {
                        foreach (var fieldInfo in obj.GetType().GetFields().Where(f => f.FieldType.IsClass))
                        {
                            //if(fieldInfo.FieldType != typeof(Material))
                            if (fieldInfo.FieldType.GetConstructor(Type.EmptyTypes) != null)
                            {
                                var value = Activator.CreateInstance(fieldInfo.FieldType);
                                fieldInfo.SetValue(obj, value);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
    protected override void OnDestroy()
    {
        base.OnDestroy();

        MethodInfo toComponentDataArrayMethod = typeof(EntityQuery).GetMethod("ToComponentDataArray", new Type[] { typeof(Allocator) });

        if (toComponentDataArrayMethod == null)
        {
            Debug.LogError("EntityQuery.ToComponentDataArray<T> doesn't seem to exist anymore. Did the APi change?");
            return;
        }
        object[] parameters = new object[1] {
            Allocator.TempJob
        };

        TypeManager.TypeInfo[] typeInfos = TypeManager.GetAllTypes();
        for (int i = 0; i < typeInfos.Length; i++)
        {
            Type type = typeInfos[i].Type;

            if (type != null &&
                typeof(IDisposeComponentDataOnWorldDestroy).IsAssignableFrom(type))
            {
                var query = EntityManager.CreateEntityQuery(ComponentType.FromTypeIndex(typeInfos[i].TypeIndex));
                if (query.CalculateEntityCount() > 0)
                {
                    object componentDataArray = toComponentDataArrayMethod.MakeGenericMethod(type).Invoke(query, parameters);

                    foreach (var item in (IEnumerable)componentDataArray)
                    {
                        ((IDisposable)item).Dispose();
                    }

                    if (componentDataArray is IDisposable disposable)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
    }
        internal void GetTypes()
        {
            if (getWorldSelection() == null)
            {
                return;
            }
            if (!TypeListValid())
            {
                filterTypes.Clear();
                selectedFilterTypes.Clear();
                var requiredTypes    = new List <ComponentType>();
                var subtractiveTypes = new List <ComponentType>();
                var typeCount        = TypeManager.GetTypeCount();
                filterTypes.Capacity         = typeCount;
                selectedFilterTypes.Capacity = typeCount;
                foreach (var typeInfo in TypeManager.AllTypes)
                {
                    Type type = TypeManager.GetType(typeInfo.TypeIndex);
                    if (type == typeof(Entity))
                    {
                        continue;
                    }
                    var typeIndex     = typeInfo.TypeIndex;
                    var componentType = ComponentType.FromTypeIndex(typeIndex);
                    if (componentType.GetManagedType() == null)
                    {
                        continue;
                    }
                    requiredTypes.Add(componentType);
                    componentType.AccessModeType = ComponentType.AccessMode.Exclude;
                    subtractiveTypes.Add(componentType);
                    selectedFilterTypes.Add(false);
                    selectedFilterTypes.Add(false);
                }

                filterTypes.AddRange(requiredTypes);
                filterTypes.AddRange(subtractiveTypes);

                filterTypes.Sort(EntityQueryGUI.CompareTypes);
            }
        }
Exemplo n.º 17
0
        private static unsafe NativeArray <EntityArchetype> ReadArchetypes(BinaryReader reader, NativeArray <int> types, ExclusiveEntityTransaction entityManager, out int totalEntityCount)
        {
            int length = reader.ReadInt();
            NativeArray <EntityArchetype> array  = new NativeArray <EntityArchetype>(length, Allocator.Temp, NativeArrayOptions.ClearMemory);
            NativeArray <int>             array2 = new NativeArray <int>(length, Allocator.Temp, NativeArrayOptions.ClearMemory);

            totalEntityCount = 0;
            NativeList <ComponentType> nativeList = new NativeList <ComponentType>(Allocator.Temp);
            int index = 0;

            while (true)
            {
                int num4;
                if (index >= length)
                {
                    nativeList.Dispose();
                    types.Dispose();
                    array2.Dispose();
                    return(array);
                }
                array2.set_Item(index, num4 = reader.ReadInt());
                totalEntityCount           += num4;
                int num3 = reader.ReadInt();
                nativeList.Clear();
                int num5 = 0;
                while (true)
                {
                    if (num5 >= num3)
                    {
                        array.set_Item(index, entityManager.CreateArchetype((ComponentType *)nativeList.GetUnsafePtr <ComponentType>(), nativeList.Length));
                        index++;
                        break;
                    }
                    int typeIndex = types[reader.ReadInt()];
                    nativeList.Add(ComponentType.FromTypeIndex(typeIndex));
                    num5++;
                }
            }
        }
Exemplo n.º 18
0
    public void SetSharedComponentDataBoxedDefaultMustBeNull(Entity entity, int typeIndex, int hashCode, object componentData, ManagedComponentStore managedComponentStore)
    {
        if (m_IsMainThread)
        {
            BeforeStructuralChange();
        }

        EntityComponentStore->AssertEntityHasComponent(entity, typeIndex);

        var newSharedComponentDataIndex = 0;

        if (componentData != null) // null means default
        {
            newSharedComponentDataIndex = managedComponentStore.InsertSharedComponentAssumeNonDefault(typeIndex, hashCode, componentData);
        }

        var componentType = ComponentType.FromTypeIndex(typeIndex);

        EntityComponentStore->SetSharedComponentDataIndex(entity, componentType, newSharedComponentDataIndex);
        ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker);
        ManagedComponentStore.RemoveReference(newSharedComponentDataIndex);
    }
Exemplo n.º 19
0
    public void SetComponentData <T>(Entity entity, T componentData) where T : struct, IComponentData
    {
        var typeIndex = TypeManager.GetTypeIndex <T>();

        EntityComponentStore->AssertEntityHasComponent(entity, typeIndex);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
        if (ComponentType.FromTypeIndex(typeIndex).IsZeroSized)
        {
            throw new System.ArgumentException(
                      $"SetComponentData<{typeof(T)}> can not be called with a zero sized component.");
        }
#endif

        if (m_IsMainThread)
        {
            DependencyManager->CompleteReadAndWriteDependency(typeIndex);
        }

        var ptr = EntityComponentStore->GetComponentDataWithTypeRW(entity, typeIndex,
                                                                   EntityComponentStore->GlobalSystemVersion);
        UnsafeUtility.CopyStructureToPtr(ref componentData, ptr);
    }
Exemplo n.º 20
0
        /// <summary>
        /// Add a fixed array to the entity
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="length"></param>
        /// <typeparam name="T"></typeparam>
        protected void AddFixedArray <T>(Entity entity, int length)
            where T : struct
        {
            var typeIndex = TypeManager.GetTypeIndex <T>();

            void LocalCreateFixedArray()
            {
                EntityManager.AddComponent(entity, ComponentType.FixedArray(typeof(T), length));
            }

            if (EntityManager.HasComponent(entity, ComponentType.FromTypeIndex(typeIndex)))
            {
                var fixedArray = EntityManager.GetFixedArray <T>(entity);
                if (fixedArray.Length != length)
                {
                    EntityManager.RemoveComponent(entity, ComponentType.FromTypeIndex(typeIndex));
                    LocalCreateFixedArray();
                }
            }
            else
            {
                LocalCreateFixedArray();
            }
        }
Exemplo n.º 21
0
 public ComponentDataState()
 {
     allState    = new NativeHashMap <Entity, State>(64, Allocator.Persistent);
     isZeroSized = ComponentType.FromTypeIndex(TypeManager.GetTypeIndex <T>()).IsZeroSized;
 }
Exemplo n.º 22
0
        public static bool IsSupported(TypeManager.TypeInfo info, out string notSupportedReason)
        {
            if (info.Category != TypeManager.TypeCategory.BufferData && info.Category != TypeManager.TypeCategory.ComponentData)
            {
                notSupportedReason = $"Persisting components need to be either ComponentData or BufferElementData. Type: {ComponentType.FromTypeIndex(info.TypeIndex).ToString()}";
                return(false);
            }

            if (info.EntityOffsetCount > 0)
            {
                notSupportedReason = $"Persisting components with Entity References is not supported. Type: {ComponentType.FromTypeIndex(info.TypeIndex).ToString()}";
                return(false);
            }

            if (info.BlobAssetRefOffsetCount > 0)
            {
                notSupportedReason = $"Persisting components with BlobAssetReferences is not supported. Type: {ComponentType.FromTypeIndex(info.TypeIndex).ToString()}";
                return(false);
            }

            if (TypeManager.IsManagedComponent(info.TypeIndex))
            {
                notSupportedReason = $"Persisting managed components supported. Type: {ComponentType.FromTypeIndex(info.TypeIndex).ToString()}";
                return(false);
            }

            notSupportedReason = "";
            return(true);
        }
Exemplo n.º 23
0
 public bool Has(object key)
 {
     return(EntityManager.HasComponent(Entity, ComponentType.FromTypeIndex(key.FetchTypeIndex())));
 }
 public ComponentType GetComponentType() => ComponentType.FromTypeIndex(TypeIndex);
Exemplo n.º 25
0
 public void AddSharedComponentDataBoxedDefaultMustBeNull(Entity entity, int typeIndex, int hashCode, object componentData, ManagedComponentStore managedComponentStore)
 {
     //TODO: optimize this (no need to move the entity to a new chunk twice)
     AddComponent(entity, ComponentType.FromTypeIndex(typeIndex));
     SetSharedComponentDataBoxedDefaultMustBeNull(entity, typeIndex, hashCode, componentData, managedComponentStore);
 }
Exemplo n.º 26
0
        public EventBatch(EntityManager em, EventDefinition definition, Allocator allocator = Allocator.Persistent) : this()
        {
            var componentType  = ComponentType.FromTypeIndex(definition.ComponentTypeInfo.TypeIndex);
            var bufferType     = ComponentType.FromTypeIndex(definition.BufferTypeInfo.TypeIndex);
            var bufferLinkType = ComponentType.ReadWrite <BufferLink>();

            HasBuffer    = definition.BufferTypeInfo.TypeIndex != 0;
            HasComponent = definition.ComponentTypeInfo.TypeIndex != 0;

            var components = new List <ComponentType>()
            {
                definition.MetaType,
            };

            if (HasComponent)
            {
                components.AddRange(new[] {
                    componentType,
                });
            }

            if (HasBuffer)
            {
                components.AddRange(new[] {
                    bufferType,
                    bufferLinkType,
                });
            }

            Archetype = em.CreateArchetype(components.ToArray());

            var inactiveComponents = new List <ComponentType>(components)
            {
                ComponentType.ReadWrite <Disabled>()
            };

            InactiveArchetype = em.CreateArchetype(inactiveComponents.ToArray());


            Allocator          = allocator;
            ComponentType      = componentType;
            ComponentTypeIndex = definition.ComponentTypeInfo.TypeIndex;
            ComponentTypeSize  = definition.ComponentTypeInfo.SizeInChunk;

            BufferType             = bufferType;
            BufferTypeIndex        = definition.BufferTypeInfo.TypeIndex;
            BufferElementSize      = definition.BufferTypeInfo.ElementSize;
            BufferSizeInChunk      = definition.BufferTypeInfo.SizeInChunk;
            BufferAlignmentInBytes = definition.BufferTypeInfo.AlignmentInBytes;
            BufferLinkTypeIndex    = TypeManager.GetTypeIndex <BufferLink>();

            StartingPoolSize = definition.StartingPoolSize;

            ComponentQueue = new EventQueue(ComponentTypeIndex, ComponentTypeSize, BufferTypeIndex, BufferElementSize, allocator);
            Offsets        = GetChunkOffsets(em, Archetype, definition.MetaType, componentType, bufferType, bufferLinkType);

            ActiveChunks   = new ArchetypeView(Archetype);
            InactiveChunks = new ArchetypeView(InactiveArchetype);

            ActiveArchetypeChunks         = new UnsafeList(Allocator.Persistent);
            ActiveFullArchetypeChunks     = new UnsafeList(Allocator.Persistent);
            ActivePartialArchetypeChunk   = new UnsafeList(Allocator.Persistent);
            InactiveFullArchetypeChunks   = new UnsafeList(Allocator.Persistent);
            InactivePartialArchetypeChunk = new UnsafeList(Allocator.Persistent);

            if (definition.StartingPoolSize > 0)
            {
                CreateInactiveEntities(em, definition.StartingPoolSize);
                UpdateChunkCollections();
            }
        }