Ejemplo n.º 1
0
        private void RemoveDeletedEntities()
        {
            for (int i = 0; i < Compatible.Count; i++)
            {
                bool removed = false;
                do
                {
                    for (int j = 0; j < _toRemove.Count; j++)
                    {
                        if (Compatible[i].Id == _toRemove[j].Id)
                        {
                            // Swap removed
                            SwapRemove.SwapRemoveList(Compatible, i);
                            SwapRemove.SwapRemoveList(_toRemove, j);
                            removed = true;
                            break;
                        }
                    }
                    if (removed && _toRemove.Count == 0)
                    {
                        // Can do a simple return instead of carrying on looping through the list.
                        return;
                    }
                } while (removed);

                // If for some reason we still have entities to remove,
                // then we can just clear the list as they are not being tracked by the physics system anyway
                _toRemove.Clear();
            }
        }
Ejemplo n.º 2
0
        protected override void OnPoolEntityChanged(EntityManager pool, Entity entity)
        {
            var index = Compatible.IndexOf(entity);

            // If we already have the entity, check if we are still compatible
            if (index >= 0)
            {
                if (!CompatiblePredicate(entity))
                {
                    SwapRemove.SwapRemoveList(Compatible, index);
                }
            }
            else
            // If we do not have it but we are compatible, add it
            {
                if (CompatiblePredicate(entity))
                {
                    Compatible.Add(entity);
                    var brain = entity.GetComponent <BrainComponent>();

                    // This will happen with the initial critters. Place into 'origin' species.
                    if (brain.ParentSpecies is null)
                    {
                        brain.Species = Species[entity.Tag][0];
                        return;
                    }
                    // Check what species the child should go in.
                    // If compatible with the parent species then place it in that species.
                    // Else, create a new species.
                    if (brain.ParentSpecies.Representative.CompareSimilarity(brain.BrainGenotype) <= _similarityThreshold)
                    {
                        brain.Species = brain.ParentSpecies;
                    }
                    else
                    {
                        int newId = NextSpeciesId;
                        NextSpeciesId++;

                        // Create representative for species
                        AbstractBrainGenotype rep = (AbstractBrainGenotype)brain.BrainGenotype.Clone();

                        var newSpecies = new Species()
                        {
                            Id             = newId,
                            Representative = rep,
                            TimeCreated    = _simulation.Tick * _simulation.SimDeltaTime,
                        };
                        // Create new species.
                        Species[entity.Tag].Add(newSpecies);
                        brain.Species = newSpecies;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected virtual void OnPoolEntityChanged(EntityManager pool, Entity entity)
        {
            var index = Compatible.IndexOf(entity);

            // If we already have the entity, check if we are still compatible
            if (index >= 0)
            {
                if (!CompatiblePredicate(entity))
                {
                    SwapRemove.SwapRemoveList(Compatible, index);
                }
            }
            else
            // If we do not have it but we are compatible, add it
            {
                if (CompatiblePredicate(entity))
                {
                    Compatible.Add(entity);
                }
            }
        }