コード例 #1
0
        public unsafe Chunk *GetChunkWithEmptySlots(int *sharedComponentDataIndices, int numSharedComponents)
        {
            uint  hashCode = this.GetHashCode(sharedComponentDataIndices, numSharedComponents);
            Node *buckets  = this.buckets + ((hashCode & this.hashMask) * sizeof(Node));
            Node *nodePtr2 = this.buckets + (this.hashMask * sizeof(Node));

            while (true)
            {
                Chunk *chunkFromEmptySlotNode;
                if (buckets.IsFree())
                {
                    chunkFromEmptySlotNode = null;
                }
                else
                {
                    if (!(!buckets.IsDeleted() && buckets.CheckEqual(hashCode, sharedComponentDataIndices, numSharedComponents)))
                    {
                        buckets++;
                        if (buckets <= nodePtr2)
                        {
                            continue;
                        }
                        buckets = this.buckets;
                        continue;
                    }
                    chunkFromEmptySlotNode = ArchetypeManager.GetChunkFromEmptySlotNode(buckets->list.Begin);
                }
                return(chunkFromEmptySlotNode);
            }
        }
コード例 #2
0
        void AddMultiple(UnsafeLinkedListNode *list)
        {
            var    firstChunk = ArchetypeManager.GetChunkFromEmptySlotNode(list->Begin);
            UInt32 hash       = GetHashCode(firstChunk->SharedComponentValueArray, firstChunk->Archetype->NumSharedComponents);

            int * sharedComponentDataIndices = firstChunk->SharedComponentValueArray;
            int   numSharedComponents        = firstChunk->Archetype->NumSharedComponents;
            Node *node     = &buckets[hash & hashMask];
            Node *lastNode = &buckets[hashMask];
            Node *freeNode = null;

            while (!node->IsFree())
            {
                if (!node->IsDeleted())
                {
                    if (node->CheckEqual(hash, sharedComponentDataIndices, numSharedComponents))
                    {
                        UnsafeLinkedListNode.InsertListBefore(node->list.End, list);
                        return;
                    }
                }
                else
                {
                    if (freeNode == null)
                    {
                        freeNode = node;
                    }
                }

                node = node + 1;
                if (node > lastNode)
                {
                    node = buckets;
                }
            }

            if (freeNode == null)
            {
                freeNode = node;
                --emptyNodes;
            }

            freeNode->hash = hash;
            UnsafeLinkedListNode.InitializeList(&freeNode->list);
            UnsafeLinkedListNode.InsertListBefore(freeNode->list.End, list);

            if (ShouldGrow(emptyNodes))
            {
                Grow();
            }
        }
コード例 #3
0
        private unsafe void AddMultiple(UnsafeLinkedListNode *list)
        {
            Chunk *chunkPtr = ref ArchetypeManager.GetChunkFromEmptySlotNode(list.Begin);
            uint   hashCode = this.GetHashCode(chunkPtr->SharedComponentValueArray, chunkPtr->Archetype.NumSharedComponents);
            int *  sharedComponentValueArray = chunkPtr->SharedComponentValueArray;
            int    numSharedComponents       = chunkPtr->Archetype.NumSharedComponents;
            Node * buckets  = this.buckets + ((hashCode & this.hashMask) * sizeof(Node));
            Node * nodePtr2 = this.buckets + (this.hashMask * sizeof(Node));
            Node * nodePtr3 = null;

            while (true)
            {
                if (buckets.IsFree())
                {
                    if (nodePtr3 == null)
                    {
                        nodePtr3 = buckets;
                        this.emptyNodes--;
                    }
                    nodePtr3->hash = hashCode;
                    UnsafeLinkedListNode.InitializeList(&nodePtr3->list);
                    UnsafeLinkedListNode.InsertListBefore(nodePtr3->list.End, list);
                    if (this.ShouldGrow(this.emptyNodes))
                    {
                        this.Grow();
                    }
                    break;
                }
                if (!buckets.IsDeleted())
                {
                    if (buckets.CheckEqual(hashCode, sharedComponentValueArray, numSharedComponents))
                    {
                        UnsafeLinkedListNode.InsertListBefore(buckets->list.End, list);
                        break;
                    }
                }
                else if (nodePtr3 == null)
                {
                    nodePtr3 = buckets;
                }
                buckets++;
                if (buckets > nodePtr2)
                {
                    buckets = this.buckets;
                }
            }
        }
コード例 #4
0
        public Chunk *GetChunkWithEmptySlots(int *sharedComponentDataIndices, int numSharedComponents)
        {
            uint  hash     = GetHashCode(sharedComponentDataIndices, numSharedComponents);
            Node *node     = &buckets[hash & hashMask];
            Node *lastNode = &buckets[hashMask];

            while (!node->IsFree())
            {
                if (!node->IsDeleted() && node->CheckEqual(hash, sharedComponentDataIndices, numSharedComponents))
                {
                    return(ArchetypeManager.GetChunkFromEmptySlotNode(node->list.Begin));
                }

                node = node + 1;
                if (node > lastNode)
                {
                    node = buckets;
                }
            }

            return(null);
        }
コード例 #5
0
 public unsafe bool CheckEqual(uint hash, int *sharedComponentDataIndices, int numSharedComponents) =>
 ((this.hash == hash) && (UnsafeUtility.MemCmp((void *)sharedComponentDataIndices, (void *)ArchetypeManager.GetChunkFromEmptySlotNode(this.list.Begin).SharedComponentValueArray, (long)(numSharedComponents * 4)) == 0));
コード例 #6
0
 public bool CheckEqual(uint hash, int *sharedComponentDataIndices, int numSharedComponents)
 {
     return((this.hash == hash) &&
            (UnsafeUtility.MemCmp(sharedComponentDataIndices, ArchetypeManager.GetChunkFromEmptySlotNode(list.Begin)->SharedComponentValueArray,
                                  numSharedComponents * sizeof(int)) == 0));
 }