private static SystemSpec GetNextCandidate(List <SystemSpec> unorderedSystemSpecs, List <SystemSpec> orderedSystemSpecs) { var maxDistance = int.MinValue; SystemSpec candidate = null; foreach (var systemSpec in unorderedSystemSpecs) { // The best candidate has the largest distance from the items that produce their requirements // so that it does not have to wait long for what it needs. var minDistance = int.MaxValue; foreach (var requirement in systemSpec.RequiredResources) { var distance = DistanceToProducer(requirement, orderedSystemSpecs); if (distance == null) { goto NextCandidate; } minDistance = Math.Min(distance.Value, minDistance); } if (minDistance > maxDistance) { maxDistance = minDistance; candidate = systemSpec; } NextCandidate : { } } return(candidate); }
public SystemSpec AddSystem <T>() where T : ISystem, new() { var spec = SystemSpec.Construct <T>(); this.SystemSpecs.Add(spec); return(spec); }
private static bool AllRequirementsHaveBeenProduced(SystemSpec systemSpec, List <ResourceState> produced) => systemSpec.RequiredResources.All(resource => produced.Contains(resource));