Beispiel #1
0
        public void Commit()
        {
            foreach (var cq in changeQueues)
            {
                cq.Flush(this);
            }

            Entity[] dirtyEntityData       = dirtyEntities.Data;
            Entity[] entitiesToDestroyData = entitiesToDestroy.Data;

            foreach (Aspect <B> aspect in aspects)
            {
                aspect.ClearAddedAndRemoved();

                B aspectMask = aspect.Bitmask;

                for (int j = 0; j < dirtyEntities.Count; ++j)
                {
                    Entity entity = dirtyEntityData[j];
                    B      mask   = entityMasks[entity.Index];
                    if (mask.Contains(aspect.Bitmask))
                    {
                        aspect.Add(entity);
                    }
                    else if (!mask.Contains(aspect.Bitmask))
                    {
                        aspect.Remove(entity);
                    }
                }

                for (int j = 0; j < entitiesToDestroy.Count; ++j)
                {
                    Entity entity = entitiesToDestroyData[j];
                    B      mask   = entityMasks[entity.Index];
                    if (mask.Contains(aspect.Bitmask))
                    {
                        aspect.Remove(entity);
                    }
                }
            }
            dirtyEntities.Clear();

            for (int j = 0; j < entitiesToDestroy.Count; ++j)
            {
                Entity entity = entitiesToDestroyData[j];
                int    index  = entity.Index;
                sparseComponents.RemoveAll(index);
                entityManager.Destroy(entity);
                entityMasks[index] = default(B);
                entities.Remove(index, out int a, out int b);
            }
            entitiesToDestroy.Clear();
        }
Beispiel #2
0
        public void Remove(Entity entity)
        {
            int index = entity.Index;

            if (!entities.Contains(index))
            {
                return;
            }

            entities.Remove(index, out int lastPackedIndex, out int packedIndex);

            for (int i = 0; i < components.Length; ++i)
            {
                IArrayWrapper array = components[i];
                if (packedIndex != lastPackedIndex)
                {
                    array.Swap(packedIndex, lastPackedIndex);
                }
                array.RemoveElementAt(lastPackedIndex);
            }

            removedEntities[removedEntitiesCount++] = entity;
        }