Exemple #1
0
        public void AddEntity(EcsEntity entity)
        {
            if (_length >= _entities.Length)
            {
                Array.Resize(ref _entities, 2 * _entities.Length);
            }

            entity.ArchetypeIndex = _length;
            _entities[_length++]  = entity;
            _count++;
        }
Exemple #2
0
        /// <summary>
        /// Remove holes from the archetype
        /// </summary>
        private void RemoveHoles()
        {
            if (_freeIndex >= _length)
            {
                return;
            }

            int current = _freeIndex + 1;

            while (current < _length)
            {
                while (current < _length && _entities[current] == null)
                {
                    current++;
                }

                if (current >= _length)
                {
                    continue;
                }

                EcsEntity entity = _entities[current];
                entity.ArchetypeIndex = _freeIndex;

                _entities[_freeIndex] = entity;
                _entities[current]    = null;

                foreach (byte index in Indices)
                {
                    _compPools[index].Replace(_freeIndex, current);
                }

                current++;
                _freeIndex++;
            }

            _length    = _freeIndex;
            _freeIndex = int.MaxValue;
        }
Exemple #3
0
        public void RemoveEntity(EcsEntity entity)
        {
            _entities[entity.ArchetypeIndex] = null;

            foreach (byte index in Indices)
            {
                _compPools[index].Remove(entity.ArchetypeIndex);
            }

            _freeIndex = Math.Min(_freeIndex, entity.ArchetypeIndex);
            _count--;

            if (_freeIndex == _length - 1)
            {
                _length    = _freeIndex;
                _freeIndex = int.MaxValue;
            }
            else if (_length >= _count + _count)
            {
                RemoveHoles();
            }
        }