Example #1
0
        private static unsafe void WriteArchetypes(BinaryWriter writer, EntityArchetype[] archetypeArray, Dictionary <int, int> typeIndexMap)
        {
            writer.Write(archetypeArray.Length);
            EntityArchetype[] archetypeArray2 = archetypeArray;
            int index = 0;

            while (index < archetypeArray2.Length)
            {
                EntityArchetype archetype = archetypeArray2[index];
                writer.Write(archetype.Archetype.EntityCount);
                writer.Write((int)(archetype.Archetype.TypesCount - 1));
                int num2 = 1;
                while (true)
                {
                    if (num2 >= archetype.Archetype.TypesCount)
                    {
                        index++;
                        break;
                    }
                    ComponentTypeInArchetype archetype2 = archetype.Archetype.Types[num2];
                    writer.Write(typeIndexMap[archetype2.TypeIndex]);
                    num2++;
                }
            }
        }
Example #2
0
        void MatchesChunkTypes <A, B>(params ComponentTypeInArchetype[] types)
        {
            var expected = new ComponentTypeInArchetype[]
            {
                new ComponentTypeInArchetype(ComponentType.ChunkComponent <A>()),
                new ComponentTypeInArchetype(ComponentType.ChunkComponent <B>())
            };

            CollectionAssert.AreEquivalent(expected, types);
        }
Example #3
0
        void MatchesTypes <A, B>(params ComponentTypeInArchetype[] types)
        {
            var expected = new ComponentTypeInArchetype[]
            {
                new ComponentTypeInArchetype(typeof(A)),
                new ComponentTypeInArchetype(typeof(B))
            };

            CollectionAssert.AreEquivalent(expected, types);
        }
Example #4
0
            public unsafe void LogEntityInfo(Entity entity)
            {
                Archetype *archetypePtr = ref this.m_Manager.Entities.GetArchetype(entity);

                Unity.Debug.Log($"Entity {entity.Index}.{entity.Version}");
                for (int i = 0; i < archetypePtr->TypesCount; i++)
                {
                    ComponentTypeInArchetype archetype = archetypePtr->Types[i];
                    Unity.Debug.Log($"  - {archetype.ToString()}");
                }
            }
Example #5
0
    internal static int FillSortedArchetypeArray(ComponentTypeInArchetype *dst, ComponentType *requiredComponents, int count)
    {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
        if (count + 1 > 1024)
        {
            throw new ArgumentException($"Archetypes can't hold more than 1024 components");
        }
#endif

        dst[0] = new ComponentTypeInArchetype(ComponentType.ReadWrite <Entity>());
        for (var i = 0; i < count; ++i)
        {
            SortingUtilities.InsertSorted(dst, i + 1, requiredComponents[i]);
        }
        return(count + 1);
    }
Example #6
0
    public EntityArchetype GetEntityOnlyArchetype()
    {
        if (!m_EntityOnlyArchetype.Valid)
        {
            var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();
            ComponentTypeInArchetype entityType = new ComponentTypeInArchetype(ComponentType.ReadWrite <Entity>());
            var archetype = EntityComponentStore->GetOrCreateArchetype(&entityType, 1);
            m_EntityOnlyArchetype = new EntityArchetype {
                Archetype = archetype
            };
            var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);
            EntityQueryManager.AddAdditionalArchetypes(changedArchetypes);
        }

        return(m_EntityOnlyArchetype);
    }
Example #7
0
        public unsafe void TypesInArchetypeAreOrderedAsExpected_ManagedComponents()
        {
            var archetype = m_Manager.CreateArchetype(
                typeof(ComponentData1), typeof(SystemState1), typeof(Buffer1), typeof(SystemBuffer1),
                typeof(Tag1), typeof(SystemTag1), typeof(Shared1), typeof(SystemShared1),
                chunk <ComponentData1>(), chunk <SystemState1>(), chunk <Buffer1>(), chunk <SystemBuffer1>(),
                chunk <Tag1>(), chunk <SystemTag1>(), typeof(ManagedComponentData1),

                typeof(ComponentData2), typeof(SystemState2), typeof(Buffer2), typeof(SystemBuffer2),
                typeof(Tag2), typeof(SystemTag2), typeof(Shared2), typeof(SystemShared2),
                chunk <ComponentData2>(), chunk <SystemState2>(), chunk <Buffer2>(), chunk <SystemBuffer2>(),
                chunk <Tag2>(), chunk <SystemTag2>(), typeof(ManagedComponentData2));


            Assert.AreEqual(31, archetype.Archetype->TypesCount);

            var entityType = new ComponentTypeInArchetype(typeof(Entity));

            //Expected order: Entity, ComponentData*, SystemState*, Buffer*, SystemBuffer*, ManagedComponentData *, Tag*,
            // SystemTag*, Shared*, SystemShared*, ChunkComponentData* and ChunkTag*, ChunkSystemState* and ChunkSystemTag*,
            // ChunkBuffer*, ChunkSystemBuffer*

            var t = archetype.Archetype->Types;

            Assert.AreEqual(entityType, t[0]);

            MatchesTypes <ComponentData1, ComponentData2>(t[1], t[2]);
            MatchesTypes <SystemState1, SystemState2>(t[3], t[4]);
            MatchesTypes <Buffer1, Buffer2>(t[5], t[6]);
            MatchesTypes <SystemBuffer1, SystemBuffer2>(t[7], t[8]);
            MatchesTypes <ManagedComponentData1, ManagedComponentData2>(t[9], t[10]);

            MatchesTypes <Tag1, Tag2>(t[11], t[12]);
            MatchesTypes <SystemTag1, SystemTag2>(t[13], t[14]);
            MatchesTypes <Shared1, Shared2>(t[15], t[16]);
            MatchesTypes <SystemShared1, SystemShared2>(t[17], t[18]);

            MatchesChunkTypes <ComponentData1, ComponentData2, Tag1, Tag2>(t[19], t[20], t[21], t[22]);
            MatchesChunkTypes <SystemState1, SystemState2, SystemTag1, SystemTag2>(t[23], t[24], t[25], t[26]);

            MatchesChunkTypes <Buffer1, Buffer2>(t[27], t[28]);
            MatchesChunkTypes <SystemBuffer1, SystemBuffer2>(t[29], t[30]);
        }
Example #8
0
            internal static unsafe string GetArchetypeDebugString(Archetype *a)
            {
                StringBuilder builder = new StringBuilder();

                builder.Append("(");
                int index = 0;

                while (true)
                {
                    if (index >= a.TypesCount)
                    {
                        builder.Append(")");
                        return(builder.ToString());
                    }
                    ComponentTypeInArchetype archetype = a.Types[index];
                    if (index > 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append(archetype.ToString());
                    index++;
                }
            }