From a1ec3250a11bc6544ff337ecf6540099f9431ff5 Mon Sep 17 00:00:00 2001 From: Julien Date: Fri, 23 Aug 2024 21:28:26 +0200 Subject: [PATCH] Dependencies is counter productive --- GameRealisticMap/BuildContext.cs | 5 ----- .../Conditions/ConditionEvaluatorBuilder.cs | 8 -------- GameRealisticMap/DataDependency.cs | 14 -------------- .../ElevationModel/ElevationWithLakesBuilder.cs | 8 -------- GameRealisticMap/IDataBuilder.cs | 2 -- GameRealisticMap/IDataDependency.cs | 11 ----------- .../ManMade/Farmlands/FarmlandsBuilder.cs | 6 ------ .../ManMade/Farmlands/OrchardBuilder.cs | 5 ----- .../ManMade/Farmlands/VineyardBuilder.cs | 2 -- .../ManMade/Objects/OrientedObjectBuilder.cs | 1 + .../ManMade/Surfaces/AsphaltBuilder.cs | 5 ----- GameRealisticMap/Nature/BasicBuilderBase.cs | 7 ------- GameRealisticMap/Nature/BasicRadialBuilder.cs | 17 ----------------- .../Nature/Forests/ForestBuilder.cs | 2 -- .../Nature/Forests/ForestEdgeBuilder.cs | 6 ------ .../Nature/Forests/ForestRadialBuilder.cs | 3 --- GameRealisticMap/Nature/Lakes/LakesBuilder.cs | 4 ---- .../Nature/RockAreas/RocksBuilder.cs | 5 ----- .../Nature/RockAreas/ScreeBuilder.cs | 7 ------- GameRealisticMap/Nature/Scrubs/ScrubBuilder.cs | 4 ---- .../Nature/Scrubs/ScrubRadialBuilder.cs | 4 ---- .../Nature/Surfaces/GrassBuilder.cs | 3 --- .../Nature/Surfaces/IceSurfaceBuilder.cs | 7 ------- .../Nature/Surfaces/MeadowsBuilder.cs | 3 --- .../Nature/Surfaces/SandSurfacesBuilder.cs | 3 --- .../Nature/Watercourses/WatercoursesBuilder.cs | 1 + .../Satellite/RawSatelliteImageBuilder.cs | 8 ++++---- 27 files changed, 6 insertions(+), 145 deletions(-) delete mode 100644 GameRealisticMap/DataDependency.cs delete mode 100644 GameRealisticMap/IDataDependency.cs diff --git a/GameRealisticMap/BuildContext.cs b/GameRealisticMap/BuildContext.cs index dc0e9045..193574e5 100644 --- a/GameRealisticMap/BuildContext.cs +++ b/GameRealisticMap/BuildContext.cs @@ -71,11 +71,6 @@ private Task CreateDataTask(IProgressScope? parentScope) where T : class var builder = catalog.Get(); return Task.Run(async () => { - var tasks = builder.Dependencies.Select(d => d.PreAcquire(this, parentScope)).ToArray(); - if (tasks.Length > 0) - { - await Task.WhenAll(tasks).ConfigureAwait(false); - } using (var scope = (parentScope ?? rootScope).CreateScope(builder.GetType().Name.Replace("Builder", ""))) { if (builder is IDataBuilderAsync asyncBuilder) diff --git a/GameRealisticMap/Conditions/ConditionEvaluatorBuilder.cs b/GameRealisticMap/Conditions/ConditionEvaluatorBuilder.cs index d95764ec..cc861e0a 100644 --- a/GameRealisticMap/Conditions/ConditionEvaluatorBuilder.cs +++ b/GameRealisticMap/Conditions/ConditionEvaluatorBuilder.cs @@ -9,14 +9,6 @@ namespace GameRealisticMap.Conditions { internal class ConditionEvaluatorBuilder : IDataBuilderAsync { - public IEnumerable Dependencies => [ - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency() - ]; - public Task BuildAsync(IBuildContext context, IProgressScope scope) { return ConditionEvaluator.CreateAsync(context); diff --git a/GameRealisticMap/DataDependency.cs b/GameRealisticMap/DataDependency.cs deleted file mode 100644 index df70ca91..00000000 --- a/GameRealisticMap/DataDependency.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Pmad.ProgressTracking; - -namespace GameRealisticMap -{ - public class DataDependency : IDataDependency where T : class - { - public Task PreAcquire(IContext context, IProgressScope? parentScope = null) - { - return context.GetDataAsync(parentScope); - } - - public Type Type => typeof(T); - } -} diff --git a/GameRealisticMap/ElevationModel/ElevationWithLakesBuilder.cs b/GameRealisticMap/ElevationModel/ElevationWithLakesBuilder.cs index 46b5a9ab..319c0bb7 100644 --- a/GameRealisticMap/ElevationModel/ElevationWithLakesBuilder.cs +++ b/GameRealisticMap/ElevationModel/ElevationWithLakesBuilder.cs @@ -39,14 +39,6 @@ public ElevationWithLakesBuilder() this.processors = new IElevationProcessorStage1[] { new AerowaysElevationProcessor() }; } - public IEnumerable Dependencies => [ - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency()]; - public ElevationWithLakesData Build(IBuildContext context, IProgressScope scope) { var raw = context.GetData(); diff --git a/GameRealisticMap/IDataBuilder.cs b/GameRealisticMap/IDataBuilder.cs index 507216a2..7f3bb3e3 100644 --- a/GameRealisticMap/IDataBuilder.cs +++ b/GameRealisticMap/IDataBuilder.cs @@ -4,8 +4,6 @@ namespace GameRealisticMap { public interface IDataBuilder where T : class { - IEnumerable Dependencies => Enumerable.Empty(); - T Build(IBuildContext context, IProgressScope scope); } } diff --git a/GameRealisticMap/IDataDependency.cs b/GameRealisticMap/IDataDependency.cs deleted file mode 100644 index 7bd016c3..00000000 --- a/GameRealisticMap/IDataDependency.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Pmad.ProgressTracking; - -namespace GameRealisticMap -{ - public interface IDataDependency - { - Task PreAcquire(IContext context, IProgressScope? parentScope = null); - - Type Type { get; } - } -} \ No newline at end of file diff --git a/GameRealisticMap/ManMade/Farmlands/FarmlandsBuilder.cs b/GameRealisticMap/ManMade/Farmlands/FarmlandsBuilder.cs index a5fa28d8..9cf24788 100644 --- a/GameRealisticMap/ManMade/Farmlands/FarmlandsBuilder.cs +++ b/GameRealisticMap/ManMade/Farmlands/FarmlandsBuilder.cs @@ -27,12 +27,6 @@ protected override IEnumerable GetPriority(IBuildContext context .Concat(context.GetData().Polygons); } - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency(), - new DataDependency(), - new DataDependency() - ]); - protected override List MergeIfRequired(List polygons, IProgressScope scope) { return polygons; // Do not merge, to be able to place objects at edges and to be able to post-process satellite image diff --git a/GameRealisticMap/ManMade/Farmlands/OrchardBuilder.cs b/GameRealisticMap/ManMade/Farmlands/OrchardBuilder.cs index 8531d9f3..347b010d 100644 --- a/GameRealisticMap/ManMade/Farmlands/OrchardBuilder.cs +++ b/GameRealisticMap/ManMade/Farmlands/OrchardBuilder.cs @@ -25,11 +25,6 @@ protected override IEnumerable GetPriority(IBuildContext context .Concat(context.GetData().Polygons); } - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency(), - new DataDependency() - ]); - protected override List MergeIfRequired(List polygons, IProgressScope scope) { return polygons; // Do not merge, to be able to place objects at edges and to be able to post-process satellite image diff --git a/GameRealisticMap/ManMade/Farmlands/VineyardBuilder.cs b/GameRealisticMap/ManMade/Farmlands/VineyardBuilder.cs index 9408a977..b93b09ce 100644 --- a/GameRealisticMap/ManMade/Farmlands/VineyardBuilder.cs +++ b/GameRealisticMap/ManMade/Farmlands/VineyardBuilder.cs @@ -24,8 +24,6 @@ protected override IEnumerable GetPriority(IBuildContext context .Concat(context.GetData().Polygons); } - public override IEnumerable Dependencies => base.Dependencies.Concat([new DataDependency()]); - protected override List MergeIfRequired(List polygons, IProgressScope scope) { return polygons; // Do not merge, to be able to place objects at edges and to be able to post-process satellite image diff --git a/GameRealisticMap/ManMade/Objects/OrientedObjectBuilder.cs b/GameRealisticMap/ManMade/Objects/OrientedObjectBuilder.cs index a2dc7512..46c6b380 100644 --- a/GameRealisticMap/ManMade/Objects/OrientedObjectBuilder.cs +++ b/GameRealisticMap/ManMade/Objects/OrientedObjectBuilder.cs @@ -1,5 +1,6 @@ using GameRealisticMap.Algorithms; using GameRealisticMap.Geometries; +using GameRealisticMap.ManMade.Railways; using GameRealisticMap.ManMade.Roads; using GameRealisticMap.Osm; using OsmSharp.Geo; diff --git a/GameRealisticMap/ManMade/Surfaces/AsphaltBuilder.cs b/GameRealisticMap/ManMade/Surfaces/AsphaltBuilder.cs index f772ff59..c4429f77 100644 --- a/GameRealisticMap/ManMade/Surfaces/AsphaltBuilder.cs +++ b/GameRealisticMap/ManMade/Surfaces/AsphaltBuilder.cs @@ -34,11 +34,6 @@ protected override IEnumerable GetPriority(IBuildContext context return context.GetData().Polygons; } - public override IEnumerable Dependencies => [ - new DataDependency(), - new DataDependency() - ]; - public override AsphaltData Build(IBuildContext context, IProgressScope scope) { return CreateWrapper(GetPolygons(context, diff --git a/GameRealisticMap/Nature/BasicBuilderBase.cs b/GameRealisticMap/Nature/BasicBuilderBase.cs index aaf54c65..5cb1e466 100644 --- a/GameRealisticMap/Nature/BasicBuilderBase.cs +++ b/GameRealisticMap/Nature/BasicBuilderBase.cs @@ -23,13 +23,6 @@ protected override IEnumerable GetPriority(IBuildContext context .Concat(lakes.Lakes.Select(l => l.TerrainPolygon)); } - public virtual IEnumerable Dependencies => [ - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency() - ]; - protected abstract T CreateWrapper(List polygons); public virtual T Build(IBuildContext context, IProgressScope scope) diff --git a/GameRealisticMap/Nature/BasicRadialBuilder.cs b/GameRealisticMap/Nature/BasicRadialBuilder.cs index b5ea3e5c..bdcafb0e 100644 --- a/GameRealisticMap/Nature/BasicRadialBuilder.cs +++ b/GameRealisticMap/Nature/BasicRadialBuilder.cs @@ -43,23 +43,6 @@ protected virtual IEnumerable GetPriority(IBuildContext context) .Concat(context.GetData().Polygons); } - public virtual IEnumerable Dependencies => [ - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency() - ]; - public TEdge Build(IBuildContext context, IProgressScope scope) { var forest = context.GetData(); diff --git a/GameRealisticMap/Nature/Forests/ForestBuilder.cs b/GameRealisticMap/Nature/Forests/ForestBuilder.cs index caa8a30d..ad853245 100644 --- a/GameRealisticMap/Nature/Forests/ForestBuilder.cs +++ b/GameRealisticMap/Nature/Forests/ForestBuilder.cs @@ -23,7 +23,5 @@ protected override IEnumerable GetPriority(IBuildContext context return base.GetPriority(context) .Concat(cutlines.Polygons); } - - public override IEnumerable Dependencies => base.Dependencies.Concat([new DataDependency()]); } } diff --git a/GameRealisticMap/Nature/Forests/ForestEdgeBuilder.cs b/GameRealisticMap/Nature/Forests/ForestEdgeBuilder.cs index 96e87722..2d741924 100644 --- a/GameRealisticMap/Nature/Forests/ForestEdgeBuilder.cs +++ b/GameRealisticMap/Nature/Forests/ForestEdgeBuilder.cs @@ -7,12 +7,6 @@ namespace GameRealisticMap.Nature.Forests { internal class ForestEdgeBuilder : IDataBuilder { - public IEnumerable Dependencies => [ - new DataDependency(), - new DataDependency(), - new DataDependency() - ]; - public ForestEdgeData Build(IBuildContext context, IProgressScope scope) { var roads = context.GetData().Roads; diff --git a/GameRealisticMap/Nature/Forests/ForestRadialBuilder.cs b/GameRealisticMap/Nature/Forests/ForestRadialBuilder.cs index 858f4d81..174d80a6 100644 --- a/GameRealisticMap/Nature/Forests/ForestRadialBuilder.cs +++ b/GameRealisticMap/Nature/Forests/ForestRadialBuilder.cs @@ -18,9 +18,6 @@ protected override IEnumerable GetPriority(IBuildContext context return base.GetPriority(context) .Concat(cutlines.Polygons); } - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency() - ]); protected override ForestRadialData CreateWrapper(List polygons) { diff --git a/GameRealisticMap/Nature/Lakes/LakesBuilder.cs b/GameRealisticMap/Nature/Lakes/LakesBuilder.cs index 5a8091e3..215e16fa 100644 --- a/GameRealisticMap/Nature/Lakes/LakesBuilder.cs +++ b/GameRealisticMap/Nature/Lakes/LakesBuilder.cs @@ -41,9 +41,5 @@ protected override IEnumerable GetPriority(IBuildContext context .SelectMany(s => s.Path.ToTerrainPolygon(s.Width + embankmentMargin)) .ToList(); } - - public override IEnumerable Dependencies => [ - new DataDependency() - ]; } } diff --git a/GameRealisticMap/Nature/RockAreas/RocksBuilder.cs b/GameRealisticMap/Nature/RockAreas/RocksBuilder.cs index bab8ee4d..5da3a223 100644 --- a/GameRealisticMap/Nature/RockAreas/RocksBuilder.cs +++ b/GameRealisticMap/Nature/RockAreas/RocksBuilder.cs @@ -23,10 +23,5 @@ protected override IEnumerable GetPriority(IBuildContext context .Concat(context.GetData().Polygons) .Concat(context.GetData().Polygons); } - - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency(), - new DataDependency() - ]); } } diff --git a/GameRealisticMap/Nature/RockAreas/ScreeBuilder.cs b/GameRealisticMap/Nature/RockAreas/ScreeBuilder.cs index 0255fc42..8889b2da 100644 --- a/GameRealisticMap/Nature/RockAreas/ScreeBuilder.cs +++ b/GameRealisticMap/Nature/RockAreas/ScreeBuilder.cs @@ -24,12 +24,5 @@ protected override IEnumerable GetPriority(IBuildContext context .Concat(context.GetData().Polygons) .Concat(context.GetData().Polygons); } - - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency(), - new DataDependency(), - new DataDependency() - ]); - } } diff --git a/GameRealisticMap/Nature/Scrubs/ScrubBuilder.cs b/GameRealisticMap/Nature/Scrubs/ScrubBuilder.cs index a84aefd8..1403209d 100644 --- a/GameRealisticMap/Nature/Scrubs/ScrubBuilder.cs +++ b/GameRealisticMap/Nature/Scrubs/ScrubBuilder.cs @@ -21,9 +21,5 @@ protected override IEnumerable GetPriority(IBuildContext context return base.GetPriority(context) .Concat(context.GetData().Polygons); } - - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency() - ]); } } diff --git a/GameRealisticMap/Nature/Scrubs/ScrubRadialBuilder.cs b/GameRealisticMap/Nature/Scrubs/ScrubRadialBuilder.cs index 0e0f2e5a..ee88fd0d 100644 --- a/GameRealisticMap/Nature/Scrubs/ScrubRadialBuilder.cs +++ b/GameRealisticMap/Nature/Scrubs/ScrubRadialBuilder.cs @@ -18,10 +18,6 @@ protected override IEnumerable GetPriority(IBuildContext context .Concat(forestEdge.Polygons); } - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency() - ]); - protected override ScrubRadialData CreateWrapper(List polygons) { return new ScrubRadialData(polygons); diff --git a/GameRealisticMap/Nature/Surfaces/GrassBuilder.cs b/GameRealisticMap/Nature/Surfaces/GrassBuilder.cs index 1e528526..bb6292e4 100644 --- a/GameRealisticMap/Nature/Surfaces/GrassBuilder.cs +++ b/GameRealisticMap/Nature/Surfaces/GrassBuilder.cs @@ -51,9 +51,6 @@ protected override IEnumerable GetPriority(IBuildContext context return base.GetPriority(context) .Concat(context.GetData().Polygons); } - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency() - ]); public override GrassData Build(IBuildContext context, IProgressScope scope) { diff --git a/GameRealisticMap/Nature/Surfaces/IceSurfaceBuilder.cs b/GameRealisticMap/Nature/Surfaces/IceSurfaceBuilder.cs index 55eb6913..8e17d708 100644 --- a/GameRealisticMap/Nature/Surfaces/IceSurfaceBuilder.cs +++ b/GameRealisticMap/Nature/Surfaces/IceSurfaceBuilder.cs @@ -30,12 +30,5 @@ protected override IEnumerable GetPriority(IBuildContext context .Concat(context.GetData().Polygons) .Concat(context.GetData().Polygons); } - - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency(), - new DataDependency(), - new DataDependency(), - new DataDependency() - ]); } } diff --git a/GameRealisticMap/Nature/Surfaces/MeadowsBuilder.cs b/GameRealisticMap/Nature/Surfaces/MeadowsBuilder.cs index 69d5ffef..5e617cc4 100644 --- a/GameRealisticMap/Nature/Surfaces/MeadowsBuilder.cs +++ b/GameRealisticMap/Nature/Surfaces/MeadowsBuilder.cs @@ -32,8 +32,5 @@ protected override IEnumerable GetPriority(IBuildContext context return base.GetPriority(context) .Concat(context.GetData().Polygons); } - public override IEnumerable Dependencies => base.Dependencies.Concat([ - new DataDependency() - ]); } } diff --git a/GameRealisticMap/Nature/Surfaces/SandSurfacesBuilder.cs b/GameRealisticMap/Nature/Surfaces/SandSurfacesBuilder.cs index b0223b27..76aa2668 100644 --- a/GameRealisticMap/Nature/Surfaces/SandSurfacesBuilder.cs +++ b/GameRealisticMap/Nature/Surfaces/SandSurfacesBuilder.cs @@ -25,8 +25,5 @@ protected override IEnumerable GetPriority(IBuildContext context { return Enumerable.Empty(); } - - public override IEnumerable Dependencies => Enumerable.Empty(); - } } diff --git a/GameRealisticMap/Nature/Watercourses/WatercoursesBuilder.cs b/GameRealisticMap/Nature/Watercourses/WatercoursesBuilder.cs index 0cb9c908..b5e6028d 100644 --- a/GameRealisticMap/Nature/Watercourses/WatercoursesBuilder.cs +++ b/GameRealisticMap/Nature/Watercourses/WatercoursesBuilder.cs @@ -1,6 +1,7 @@ using GameRealisticMap.Geometries; using GameRealisticMap.ManMade; using GameRealisticMap.ManMade.Roads; +using GameRealisticMap.Nature.Forests; using GameRealisticMap.Nature.Lakes; using GeoAPI.Geometries; using OsmSharp; diff --git a/GameRealisticMap/Satellite/RawSatelliteImageBuilder.cs b/GameRealisticMap/Satellite/RawSatelliteImageBuilder.cs index 4c1e5689..f66ad4cc 100644 --- a/GameRealisticMap/Satellite/RawSatelliteImageBuilder.cs +++ b/GameRealisticMap/Satellite/RawSatelliteImageBuilder.cs @@ -10,7 +10,7 @@ namespace GameRealisticMap.Satellite { - internal class RawSatelliteImageBuilder : IDataBuilder, IDataSerializer + internal class RawSatelliteImageBuilder : IDataBuilderAsync, IDataSerializer { private readonly ISourceLocations sources; @@ -19,7 +19,7 @@ public RawSatelliteImageBuilder(ISourceLocations sources) this.sources = sources; } - public RawSatelliteImageData Build(IBuildContext context, IProgressScope scope) + public async Task BuildAsync(IBuildContext context, IProgressScope scope) { //Image image; @@ -37,8 +37,8 @@ public RawSatelliteImageData Build(IBuildContext context, IProgressScope scope) using var src = new S2Cloudless(report2, sources); foreach (var part in himage.Parts) { - LoadPart(context, totalSize, part, report2, src).Wait(); - himage.OffloadAsync().Wait(); + await LoadPart(context, totalSize, part, report2, src).ConfigureAwait(false); + await himage.OffloadAsync().ConfigureAwait(false); } }