public void TestParallelPerformance()
        {
            LongLat        longLat       = new LongLat(-87.3294527 * Math.PI / 180, 30.4668536 * Math.PI / 180);
            CubeSector     root          = new CubeSector(CubeSector.CubeSectorFace.LEFT, 0, 0, 0);
            Vector2d       relativeCoord = root.ProjectToLocalCoordinates(longLat.ToSphereVector());
            List <ISector> sectors       = root.GetSectorAt(relativeCoord.X, relativeCoord.Y, 6).GetChildrenAtLevel(8);
            Stopwatch      sw            = new Stopwatch();

            sw.Start();
            foreach (var sector in sectors)
            {
                ProceduralTileBuffer buffer = new ProceduralTileBuffer(sector);
                buffer.LoadLinesFromFile();
                buffer.GenerateVertices();
                buffer.Dispose();
            }
            double sequentialSecs = sw.Elapsed.TotalSeconds; // 5.585 secs

            sw.Restart();
            Parallel.ForEach(sectors, sector =>
            {
                ProceduralTileBuffer buffer = new ProceduralTileBuffer(sector);
                buffer.LoadLinesFromFile();
                buffer.GenerateVertices();
                buffer.Dispose();
            });
            double parallelSecs    = sw.Elapsed.TotalSeconds;       // 5.056 secs
            double speedMultiplier = sequentialSecs / parallelSecs; // 1.105 (seems to vary between 1.7 at highest and 1.1 at lowest, not the best multiplier but could still be worthwhile)
        }
        public void ToughSectorsTest()
        {
            // current errors in LE,X=2,Y=0,Z=2 is 0/4096 ~2 have issues that aren't red
            Constants.DEBUG_MODE = true;
            // add a tough sector whenever one misses a crash issue
            List <ISector> sectors = new List <ISector>();

            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 128, 43, 8));
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 129, 44, 8));
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 128, 42, 8));
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 135, 41, 8)); // "topological inconsistency" during tesselation - aka those wingdings TODO: currently can't test this
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 128, 35, 8)); // has two ways that are deep copies of each other
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 143, 30, 8)); // has vertices exactly on the border of the sector
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 166, 23, 8)); // results in duplicate intersections
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 143, 3, 8));  // error when too agressive with collinear points
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 130, 20, 8)); // fails due to duplicate nodes within a single way - aka node 5007634875
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 151, 5, 8));  // fails because of multiple ways with lines exactly along border of sector joining together
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 141, 30, 8)); // ?
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 148, 13, 8)); // another tiny thin polygon
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 137, 25, 8)); // broke because we weren't even checking intersections on relations...?
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 145, 36, 8)); // broke because of a trisected relation
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 155, 4, 8));  // a lake inside of a lake that should've been deleted triggers more issues when another shape intersects with both (and they disagree on if it should be deleted/alive)
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 139, 24, 8)); // an inner is misidentified as an outer
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 162, 58, 8)); // had a coastline island that was the wrong direction and intersected with the border
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 152, 36, 8)); // coastline with only loops (and incorrectly tagged at that)
            sectors.Add(new CubeSector(CubeSector.CubeSectorFace.LEFT, 148, 8, 8));  // no coastline or even relation outers, just holes (islands) in Lake Erie

            foreach (var sector in sectors)
            {
                ProceduralTileBuffer buffer = new ProceduralTileBuffer(sector);
                buffer.LoadLinesFromFile();
                buffer.GenerateVertices();
                buffer.GenerateBuffers(null);
            }
        }
        public void TestSectorLoadPerformance()
        {
            LongLat    longLat       = new LongLat(-87.3294527 * Math.PI / 180, 30.4668536 * Math.PI / 180);
            CubeSector root          = new CubeSector(CubeSector.CubeSectorFace.LEFT, 0, 0, 0);
            Vector2d   relativeCoord = root.ProjectToLocalCoordinates(longLat.ToSphereVector());
            ISector    sector        = root.GetSectorAt(relativeCoord.X, relativeCoord.Y, 8);
            Stopwatch  sw            = new Stopwatch();

            sw.Start();
            ProceduralTileBuffer buffer = new ProceduralTileBuffer(sector);

            buffer.LoadLinesFromFile();
            double loadTimeSecs = sw.Elapsed.TotalSeconds; // 0.842 secs (1.781 tablet)

            sw.Restart();
            buffer.GenerateVertices();
            double vertSecs = sw.Elapsed.TotalSeconds; // 0.404 secs (0.773 tablet)
        }
Exemple #4
0
        private IGraphicsBuffer GetBuffer(GraphicsDevice graphicsDevice, ISector sector, bool cached)
        {
            if (sector.Zoom > ZCoords.GetSectorManager().GetHighestOSMZoom())
            {
                throw new NotImplementedException();
            }
            if (ZCoords.GetSectorManager().GetHighestCacheZoom() > ZCoords.GetSectorManager().GetHighestOSMZoom())
            {
                throw new NotImplementedException();
            }

            try
            {
                if ((cached || sector.Zoom != ZCoords.GetSectorManager().GetHighestOSMZoom()))
                {
                    string path = OSMPaths.GetSectorImagePath(sector);
#if WINDOWS || LINUX
                    if (File.Exists(path))
                    {
                        using (var reader = File.OpenRead(path))
                        {
                            return(new ImageTileBuffer(graphicsDevice, Texture2D.FromStream(graphicsDevice, reader), sector));
                        }
                    }
#else
                    using (var reader = Activity1.ASSETS.Open(path))
                    {
                        return(new ImageTileBuffer(graphicsDevice, Texture2D.FromStream(graphicsDevice, reader), sector));
                    }
#endif
                }
            }
            catch (Exception ex)
            {
                // sometimes the image is corrupt (or zero bytes)
            }
            // otherwise, build it
            if (sector.Zoom == ZCoords.GetSectorManager().GetHighestOSMZoom())
            {
                if (cached)
                {
                    // TODO: somehow all of this still breaks often and is pretty slow, but at least we only have to run it once
                    if (sector.Zoom <= ZCoords.GetSectorManager().GetHighestCacheZoom())
                    {
                        SuperSave(GlobalContent.Error, OSMPaths.GetSectorImagePath(sector));
                        //RebuildImage(graphicsDevice, sector);
                    }
                    return(new ImageTileBuffer(graphicsDevice, GlobalContent.Error, sector));
                }
                else
                {
                    try
                    {
                        ProceduralTileBuffer buffer = new ProceduralTileBuffer(sector);
                        Stopwatch            sw     = new Stopwatch();
                        sw.Start();
                        buffer.LoadLinesFromFile();
                        buffer.GenerateVertices();
                        buffer.GenerateBuffers(graphicsDevice);
                        Console.WriteLine($"Total load time for {sector} is {sw.Elapsed.TotalSeconds} s");
                        if (sector.Zoom <= ZCoords.GetSectorManager().GetHighestCacheZoom())
                        {
#if WINDOWS || LINUX
                            using (var image = buffer.GetImage(graphicsDevice))
                            {
                                SuperSave(image, OSMPaths.GetSectorImagePath(sector));
                            }
                            RebuildImage(graphicsDevice, sector);
#endif
                        }
                        return(buffer);
                    }
                    catch (Exception ex)
                    {
                        if (sector.Zoom <= ZCoords.GetSectorManager().GetHighestCacheZoom())
                        {
                            SuperSave(GlobalContent.Error, OSMPaths.GetSectorImagePath(sector));
                            RebuildImage(graphicsDevice, sector);
                        }
                        return(new ImageTileBuffer(graphicsDevice, GlobalContent.Error, sector));
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }