Example #1
0
        public void ExtendExistingPatches()
        {
            if (MaxSpread != 177)
            {
                throw new Exception($"Unexpected value of MaxSpread={MaxSpread}");
            }
            var filenames = (new DirectoryInfo(LunarHorizon.HorizonsRoot)).EnumerateFiles("*.bin").Select(fi => fi.FullName).ToList();

            foreach (var filename in filenames)
            {
                var patch     = TerrainPatch.ReadFrom(filename);
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                Console.WriteLine($"Starting [{patch.Line},{patch.Sample}] ...");
                patch.FillPointsAndMatrices(Terrain);
                try
                {
                    var far_field = new List <TerrainPatch>();
                    if (MapView != null)
                    {
                        MapView.ProcessingPatches = new List <TerrainPatch> {
                            patch
                        }
                    }
                    ;
                    var options = new ParallelOptions {
                        MaxDegreeOfParallelism = MaxDegreeOfParallelism
                    };
                    for (var i = 1; i < MaxSpread; i++)
                    {
                        var other1 = patch.SurroundingPatches(i).Where(p => !patch.ShadowCasters.Contains(p.Id)).ToList();
                        Parallel.ForEach(other1, options, o => o.FillPoints(Terrain));
                        var other2 = other1.Where(patch.IsOverHorizon).ToList();
                        if (MapView != null)
                        {
                            far_field.AddRange(other2);
                            MapView.FarPatches = far_field;
                            MapView.Invalidate();
                        }
                        Parallel.ForEach(other2, options, o => patch.UpdateHorizon(o));
                    }
                    patch.Write();
                    patch.InitializeHorizons();  // Unload the horizon data (100MB)
                    stopwatch.Stop();
                    var seconds_per_patch = far_field.Count == 0 ? 0f : (stopwatch.ElapsedMilliseconds / 1000f) / far_field.Count;
                    Console.WriteLine($"  Finished [{patch.Line},{patch.Sample}] time={stopwatch.Elapsed}.  sec/patch={seconds_per_patch}");
                }
                catch (Exception e1)
                {
                    Console.WriteLine(e1);
                    Console.WriteLine(e1.StackTrace);
                }
            }
        }