Ejemplo n.º 1
0
        // make a lo-rez map showing where there's coast so we can flood-fill it later with land/water
        public static void SaveCoastLineMap(GraphicsDevice graphicsDevice)
        {
            var manager   = ZCoords.GetSectorManager();
            int imageSize = 1 << manager.GetHighestOSMZoom();

            foreach (var sector in manager.GetTopmostOSMSectors())
            {
                RenderTarget2D newTarget = new RenderTarget2D(graphicsDevice, imageSize, imageSize, false, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
                graphicsDevice.SetRenderTarget(newTarget);
                List <ISector> sectorsToCheck = new List <ISector>();
                sectorsToCheck.AddRange(sector.GetChildrenAtLevel(ZCoords.GetSectorManager().GetHighestOSMZoom()));
                foreach (var s in sectorsToCheck)
                {
                    if (File.Exists(OSMPaths.GetSectorPath(s)))
                    {
                        GraphicsBasic.DrawScreenRect(graphicsDevice, s.X, s.Y, 1, 1, ContainsCoast(s) ? Microsoft.Xna.Framework.Color.Gray : Microsoft.Xna.Framework.Color.White);
                    }
                    else
                    {
                        GraphicsBasic.DrawScreenRect(graphicsDevice, s.X, s.Y, 1, 1, Microsoft.Xna.Framework.Color.Red);
                    }
                }
                string mapFile = OSMPaths.GetCoastlineImagePath(sector);
                using (var writer = File.OpenWrite(mapFile))
                {
                    newTarget.SaveAsPng(writer, imageSize, imageSize);
                }
            }
        }
Ejemplo n.º 2
0
        private Texture2D DownScale(GraphicsDevice graphicsDevice, RenderTarget2D texture, int newsize)
        {
            Texture2D newtexture = new RenderTarget2D(graphicsDevice, newsize, newsize, true, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);

            graphicsDevice.SetRenderTarget((RenderTarget2D)newtexture);
            GraphicsBasic.DrawSpriteRect(graphicsDevice, 0, 0, newsize, newsize, texture, BlendState.AlphaBlend, Microsoft.Xna.Framework.Color.White);
            return(newtexture);
        }
Ejemplo n.º 3
0
 private void RebuildImage(GraphicsDevice graphicsDevice, ISector sector)
 {
     // combination images
     using (Texture2D rendered = new RenderTarget2D(graphicsDevice, 512, 512, false, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24))
     {
         int highestZoom = ZCoords.GetSectorManager().GetHighestCacheZoom();
         foreach (var parent in sector.GetAllParents().OrderBy(x => - x.Zoom).Where(x => x.Zoom <= highestZoom))
         {
             List <ISector> roadSectors = parent.GetChildrenAtLevel(parent.Zoom == highestZoom - 1 ? ZCoords.GetSectorManager().GetHighestOSMZoom() : parent.Zoom + 1);
             Texture2D[]    textures    = new Texture2D[roadSectors.Count];
             for (int i = 0; i < roadSectors.Count; i++)
             {
                 IGraphicsBuffer buffer = null;
                 if (File.Exists(OSMPaths.GetSectorImagePath(roadSectors[i])))
                 {
                     using (var reader = File.OpenRead(OSMPaths.GetSectorImagePath(roadSectors[i])))
                     {
                         buffer = new ImageTileBuffer(graphicsDevice, Texture2D.FromStream(graphicsDevice, reader), roadSectors[i]);
                     }
                 }
                 else
                 {
                     throw new NotImplementedException();
                 }
                 textures[i] = buffer.GetImage(graphicsDevice);
             }
             if (textures.Any(x => x != null))
             {
                 graphicsDevice.SetRenderTarget((RenderTarget2D)rendered);
                 for (int i = 0; i < roadSectors.Count; i++)
                 {
                     int size, x, y;
                     size = 512 >> (roadSectors[i].Zoom - parent.Zoom);
                     x    = parent.GetRelativeXOf(roadSectors[i]) * size;
                     y    = parent.GetRelativeYOf(roadSectors[i]) * size;
                     if (textures[i] != null)
                     {
                         GraphicsBasic.DrawSpriteRect(graphicsDevice, x, y, size, size, textures[i], BlendState.AlphaBlend, Microsoft.Xna.Framework.Color.White);
                     }
                 }
             }
             for (int i = 0; i < textures.Length; i++)
             {
                 if (textures[i] != null && textures[i] != GlobalContent.Error)
                 {
                     textures[i].Dispose();
                 }
             }
             SuperSave(rendered, OSMPaths.GetSectorImagePath(parent));
         }
     }
 }