Exemple #1
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);
        }
Exemple #2
0
        public static Chunk *AllocateChunk()
        {
            Chunk *chunk = (Chunk *)MemoryUtility.Malloc(Chunk.ChunkSize);

            return(chunk);
        }
Exemple #3
0
 public void Dispose()
 {
     this.count    = 0;
     this.capacity = 0;
     MemoryUtility.Free <int>(this.slots);
 }
Exemple #4
0
 private FreeEntitySlotList(int capacity)
 {
     this.count    = 0;
     this.capacity = capacity;
     this.slots    = MemoryUtility.Malloc <int>(this.capacity);
 }
Exemple #5
0
 public static void Free(Chunk *chunk)
 {
     MemoryUtility.Free <Chunk>(chunk);
     --rentedCount;
 }