Пример #1
0
        public static void Construct(EntityQueryCache *cache)
        {
            cache->typeLookup = HashMap <EntityQuery> .Empty();

            cache->count    = 0;
            cache->capacity = cache->typeLookup.capacity;
            cache->queries  = MemoryUtility.Malloc <EntityQueryData>(cache->capacity);
        }
Пример #2
0
        public static void Construct(ArchetypeStore *store)
        {
            store->typeLookup = HashMap <EntityArchetype> .Empty();

            store->count      = 0;
            store->capacity   = store->typeLookup.capacity;
            store->archetypes = MemoryUtility.Malloc <Archetype>(store->capacity);
        }
Пример #3
0
        private HashMap(int capacity)
        {
            this.count      = 0;
            this.capacity   = capacity;
            this.m_Hashes   = MemoryUtility.Malloc <int>(this.capacity);
            this.m_Elements = MemoryUtility.Malloc <T>(this.capacity);

            MemoryUtility.MemSet(this.m_Hashes, 0, sizeof(int) * this.capacity);
        }
Пример #4
0
        public static void Construct(EntityStore *store)
        {
            store->version         = 1;
            store->capacity        = DefaultCapacity;
            store->count           = 0;
            store->entitiesInChunk = MemoryUtility.Malloc <EntityInChunk>(store->capacity);
            store->freeSlots       = FreeEntitySlotList.Empty();

            Unsafe.InitBlock(store->entitiesInChunk, 0, (uint)(sizeof(EntityInChunk) * store->capacity));
        }
Пример #5
0
        public static ArchetypeChunkArray *Allocate(Archetype *archetype)
        {
            ArchetypeChunkArray *array = MemoryUtility.Malloc <ArchetypeChunkArray>();

            array->archetype = archetype;
            array->count     = 0;
            array->capacity  = 2;
            array->chunks    = MemoryUtility.MallocPtrArray <Chunk>(array->capacity);

            return(array);
        }
Пример #6
0
        private void Construct()
        {
            // Revisit with threading (cache invalidation).
            byte *ptr = MemoryUtility.Malloc <byte>(
                sizeof(ArchetypeStore) +
                sizeof(EntityStore) +
                sizeof(EntityQueryCache));

            this.archetypeStore = (ArchetypeStore *)ptr;
            this.entityStore    = (EntityStore *)(ptr += sizeof(ArchetypeStore));
            this.queryCache     = (EntityQueryCache *)(ptr += sizeof(EntityStore));

            ArchetypeStore.Construct(this.archetypeStore);
            EntityStore.Construct(this.entityStore);
            EntityQueryCache.Construct(this.queryCache);
        }
Пример #7
0
        public static void CalculateComponentOffsets(Archetype *archetype, int chunkCapacity)
        {
            var count          = archetype->componentCount;
            var componentSizes = archetype->componentSizes;

            int *offsets = MemoryUtility.Malloc <int>(count);            // This can be done in ConstructComponentData.

            offsets[0] = sizeof(Entity) * chunkCapacity;

            for (int i = 1; i < count; ++i)
            {
                offsets[i] = offsets[i - 1] + (chunkCapacity * componentSizes[i - 1]);
            }

            archetype->componentOffsets = offsets;
        }
Пример #8
0
        public static void ConstructComponentData(Archetype *archetype,
                                                  Span <int> componentTypes, Span <int> componentSizes, int hashCode)
        {
            archetype->entityCount       = 0;
            archetype->componentCount    = componentSizes.Length;          // Temporary fix... see CreateArchetype()
            archetype->componentHashCode = hashCode;

            if (componentSizes.Length == 0)
            {
                return;
            }

            var size = componentSizes.Length * sizeof(int);

            archetype->componentTypes = (int *)MemoryUtility.Malloc(size);
            archetype->componentSizes = (int *)MemoryUtility.Malloc(size);

            fixed(int *srcTypes = componentTypes, srcSizes = componentSizes)
            {
                Buffer.MemoryCopy(srcTypes, archetype->componentTypes, size, size);
                Buffer.MemoryCopy(srcSizes, archetype->componentSizes, size, size);
            }
        }
Пример #9
0
        internal EntityQuery CreateQueryInternal(Span <int> types, int includeTypesCount, int excludeTypesCount)
        {
            int hashCode = GetQueryTypeHash(types.Slice(0, includeTypesCount), types.Slice(includeTypesCount));

            if (this.queryCache->typeLookup.TryGet(hashCode, out EntityQuery query))
            {
                return(query);
            }

            this.queryCache->EnsureCapacity();

            int index = this.queryCache->count++;

            // InitBlock the struct?
            EntityQueryData *queryData = this.queryCache->queries + index;

            queryData->matchedArchetypeCount = 0;
            queryData->archetypeCount        = 0;
            queryData->includeTypesCount     = includeTypesCount;
            queryData->excludeTypesCount     = excludeTypesCount;
            queryData->componentTypes        = null;
            queryData->archetypes            = MemoryUtility.MallocPtrArray <Archetype>(0); // This is dumb but works, otherwise realloc throws.

            if (types.Length > 0)                                                           // Because Marshal.AllocHGlobal(0) does not return IntPtr.Zero.
            {
                queryData->componentTypes = MemoryUtility.Malloc <int>(types.Length);
                types.CopyTo(new Span <int>(queryData->componentTypes, types.Length));
            }

            MatchArchetypesToQueryData(queryData);             // Lazy?

            query = new EntityQuery(index);

            this.queryCache->typeLookup.Add(hashCode, query);

            return(query);
        }
Пример #10
0
        public static Chunk *AllocateChunk()
        {
            Chunk *chunk = (Chunk *)MemoryUtility.Malloc(Chunk.ChunkSize);

            return(chunk);
        }
Пример #11
0
 private FreeEntitySlotList(int capacity)
 {
     this.count    = 0;
     this.capacity = capacity;
     this.slots    = MemoryUtility.Malloc <int>(this.capacity);
 }