public ChunkIterator(int capacity) { this.capacity = capacity; this.count = 0; this.index = 0; this.chunks = MemoryUtility.MallocPtrArray <Chunk>(this.capacity); }
static ChunkPool() { nextSequenceNumber = 0; rentedCount = 0; count = 0; capacity = 16; chunks = MemoryUtility.MallocPtrArray <Chunk>(capacity); }
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); }
internal void MatchArchetypesToQueryData(EntityQueryData *queryData) { var count = this.archetypeStore->count; var unmatchedArchetypeCount = count - queryData->matchedArchetypeCount; var archetypes = this.archetypeStore->archetypes + queryData->matchedArchetypeCount; // Update the query data to the current archetype count. This only // works because a created archetype cannot be removed. queryData->matchedArchetypeCount = count; if (unmatchedArchetypeCount == 0) // Can this be done better? { return; } var matchCount = 0; if (unmatchedArchetypeCount <= 16) { var matchingArchetypes = stackalloc Archetype *[unmatchedArchetypeCount]; for (int i = 0; i < unmatchedArchetypeCount; ++i, ++archetypes) // This loop can be written shorter and better! { if (ArchetypeMatchesQueryFilter(archetypes, queryData)) { matchingArchetypes[matchCount++] = archetypes; } } AppendArchetypesToQueryData(queryData, matchingArchetypes, matchCount); } else { var matchingArchetypes = MemoryUtility.MallocPtrArray <Archetype>(unmatchedArchetypeCount); for (int i = 0; i < unmatchedArchetypeCount; ++i, ++archetypes) { if (ArchetypeMatchesQueryFilter(archetypes, queryData)) { matchingArchetypes[matchCount++] = archetypes; } } AppendArchetypesToQueryData(queryData, matchingArchetypes, matchCount); MemoryUtility.Free(matchingArchetypes); } }
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); }