void AddArchetypeIfMatching(Archetype *archetype, EntityGroupData *group) { if (!IsMatchingArchetype(archetype, group)) { return; } var match = (MatchingArchetypes *)m_GroupDataChunkAllocator.Allocate( MatchingArchetypes.GetAllocationSize(group->RequiredComponentsCount), 8); match->Archetype = archetype; var typeIndexInArchetypeArray = match->IndexInArchetype; if (group->LastMatchingArchetype == null) { group->LastMatchingArchetype = match; } match->Next = group->FirstMatchingArchetype; group->FirstMatchingArchetype = match; for (var component = 0; component < group->RequiredComponentsCount; ++component) { var typeComponentIndex = -1; if (group->RequiredComponents[component].AccessModeType != ComponentType.AccessMode.Subtractive) { typeComponentIndex = ChunkDataUtility.GetIndexInTypeArray(archetype, group->RequiredComponents[component].TypeIndex); Assert.AreNotEqual(-1, typeComponentIndex); } typeIndexInArchetypeArray[component] = typeComponentIndex; } }
private unsafe void AddArchetypeIfMatching(Archetype *archetype, EntityGroupData *group) { if (IsMatchingArchetype(archetype, group)) { MatchingArchetypes *archetypesPtr = (MatchingArchetypes *)ref this.m_GroupDataChunkAllocator.Allocate(MatchingArchetypes.GetAllocationSize(group.RequiredComponentsCount), 8); archetypesPtr->Archetype = archetype; int *numPtr = &archetypesPtr->IndexInArchetype.FixedElementField; if (group.LastMatchingArchetype == null) { group.LastMatchingArchetype = archetypesPtr; } archetypesPtr->Next = group.FirstMatchingArchetype; group.FirstMatchingArchetype = archetypesPtr; int index = 0; while (true) { if (index >= group.RequiredComponentsCount) { break; } int actual = -1; if (group.RequiredComponents[index].AccessModeType != ComponentType.AccessMode.Subtractive) { actual = ChunkDataUtility.GetIndexInTypeArray(archetype, group.RequiredComponents[index].TypeIndex); Assert.AreNotEqual(-1, actual); } numPtr[index] = actual; index++; } } }
private void AddArchetypeIfMatching(Archetype *archetype, EntityGroupData *group) { // If the group has more actually required types than the archetype it can never match, so early out as an optimization if (group->RequiredComponentsCount - group->SubtractiveComponentsCount > archetype->TypesCount) { return; } var typeI = 0; var prevTypeI = 0; var disabledIndex = TypeManager.GetTypeIndex <Disabled>(); var requestedDisabled = false; for (var i = 0; i < group->RequiredComponentsCount; ++i, ++typeI) { while (archetype->Types[typeI].TypeIndex < group->RequiredComponents[i].TypeIndex && typeI < archetype->TypesCount) { ++typeI; } if (group->RequiredComponents[i].TypeIndex == disabledIndex) { requestedDisabled = true; } var hasComponent = !(typeI >= archetype->TypesCount); // Type mismatch if (hasComponent && archetype->Types[typeI].TypeIndex != group->RequiredComponents[i].TypeIndex) { hasComponent = false; } if (hasComponent && group->RequiredComponents[i].AccessModeType == ComponentType.AccessMode.Subtractive) { return; } if (!hasComponent && group->RequiredComponents[i].AccessModeType != ComponentType.AccessMode.Subtractive) { return; } if (hasComponent) { prevTypeI = typeI; } else { typeI = prevTypeI; } } if (archetype->Disabled && (!requestedDisabled)) { return; } var match = (MatchingArchetypes *)m_GroupDataChunkAllocator.Allocate( MatchingArchetypes.GetAllocationSize(group->RequiredComponentsCount), 8); match->Archetype = archetype; var typeIndexInArchetypeArray = match->TypeIndexInArchetypeArray; if (group->LastMatchingArchetype == null) { group->LastMatchingArchetype = match; } match->Next = group->FirstMatchingArchetype; group->FirstMatchingArchetype = match; for (var component = 0; component < group->RequiredComponentsCount; ++component) { var typeComponentIndex = -1; if (group->RequiredComponents[component].AccessModeType != ComponentType.AccessMode.Subtractive) { typeComponentIndex = ChunkDataUtility.GetIndexInTypeArray(archetype, group->RequiredComponents[component].TypeIndex); Assert.AreNotEqual(-1, typeComponentIndex); } typeIndexInArchetypeArray[component] = typeComponentIndex; } }