Пример #1
0
        public void Tick(List <Entity> matchingEntities)
        {
            //TODO: Build into system predicates.
            if (StaticStates.Get <GameModeState>().GameMode == GameMode.Design)
            {
                return;
            }

            Profiler.BeginSample("SubstanceSystem");
            foreach (var substanceEntity in matchingEntities)
            {
                if (IsUnobstructed(substanceEntity))
                {
                    foreach (SubstanceType substance in Enum.GetValues(typeof(SubstanceType)))
                    {
                        Profiler.BeginSample("SubstanceSystem-GetNeigbours");
                        var neighbours      = network.NeighboursInclusive(substanceEntity);
                        var validNeighbours = neighbours.Where(IsUnobstructed).ToList();
                        Profiler.EndSample();
                        Profiler.BeginSample("SubstanceSystem-CalcNewValuesAndApply");
                        var averageValue = validNeighbours.Sum(entity => entity.GetState <SubstanceNetworkState>().GetSubstance(substance)) / validNeighbours.Count;
                        foreach (var neighbour in validNeighbours)
                        {
                            neighbour.GetState <SubstanceNetworkState>().UpdateSubstance(substance, averageValue);
                        }
                        Profiler.EndSample();
                    }
                }
            }
            Profiler.EndSample();
        }