Beispiel #1
0
        void OnClick()
        {
            Directory.CreateDirectory("Chunks");
            IsometricLighting lighting      = new IsometricLighting();
            MouseOverList     mouseOverNull = new MouseOverList(new MousePicking());
            SpriteBatch3D     spritebatch   = Service.Get <SpriteBatch3D>();
            RenderTarget2D    render        = new RenderTarget2D(spritebatch.GraphicsDevice, Width + WidthExtra * 2, Height + HeightExtra * 2 + HeightExtra2);
            Map map = new Map(0);

            for (int chunky = 0; chunky < 10; chunky++)
            {
                for (int chunkx = 0; chunkx < 10; chunkx++)
                {
                    spritebatch.GraphicsDevice.SetRenderTarget(render);
                    spritebatch.Reset();
                    uint cx = (uint)chunkx + 200;
                    uint cy = (uint)chunky + 200;
                    map.CenterPosition = new Point((int)(cx << 3), (int)(cy << 3));
                    MapChunk chunk = map.GetMapChunk(cx, cy);
                    chunk.LoadStatics(map.MapData, map);
                    int z = 0;
                    for (int i = 0; i < 64; i++)
                    {
                        int     y    = (i / 8);
                        int     x    = (i % 8);
                        int     sy   = y * 22 + x * 22 + HeightExtra + HeightExtra2;
                        int     sx   = 22 * 8 - y * 22 + x * 22 + WidthExtra;
                        MapTile tile = chunk.Tiles[i];
                        tile.ForceSort();
                        for (int j = 0; j < tile.Entities.Count; j++)
                        {
                            AEntity     e    = tile.Entities[j];
                            AEntityView view = e.GetView();
                            view.Draw(spritebatch, new Vector3(sx, sy, 0), mouseOverNull, map, false);
                        }
                    }
                    spritebatch.SetLightIntensity(lighting.IsometricLightLevel);
                    spritebatch.SetLightDirection(lighting.IsometricLightDirection);
                    spritebatch.GraphicsDevice.Clear(Color.Transparent);
                    spritebatch.FlushSprites(true);
                    spritebatch.GraphicsDevice.SetRenderTarget(null);
                    render.SaveAsPng(new FileStream($"Chunks/{cy}-{cx}.png", FileMode.Create), render.Width, render.Height);
                }
            }
        }
Beispiel #2
0
        private void DrawEntities(Map map, Position3D center, MousePicking mousePicking, out Vector2 renderOffset)
        {
            if (center == null)
            {
                renderOffset = new Vector2();
                return;
            }

            // reset the spritebatch Z
            m_SpriteBatch.Reset();
            // set the lighting variables.
            m_SpriteBatch.SetLightIntensity(Lighting.IsometricLightLevel);
            m_SpriteBatch.SetLightDirection(Lighting.IsometricLightDirection);

            // get variables that describe the tiles drawn in the viewport: the first tile to draw,
            // the offset to that tile, and the number of tiles drawn in the x and y dimensions.
            Point firstTile, renderDimensions;
            int   overDrawTilesOnSides            = 3;
            int   overDrawTilesAtTopAndBottom     = 6;
            int   overDrawAdditionalTilesOnBottom = 10;

            CalculateViewport(center, overDrawTilesOnSides, overDrawTilesAtTopAndBottom, out firstTile, out renderOffset, out renderDimensions);

            CountEntitiesRendered = 0;                                         // Count of objects rendered for statistics and debug

            MouseOverList  overList         = new MouseOverList(mousePicking); // List of entities mouse is over.
            List <AEntity> deferredToRemove = new List <AEntity>();

            for (int y = 0; y < renderDimensions.Y * 2 + 1 + overDrawAdditionalTilesOnBottom; y++)
            {
                Vector3 drawPosition = new Vector3();
                drawPosition.X = (firstTile.X - firstTile.Y + (y % 2)) * TILE_SIZE_FLOAT_HALF + renderOffset.X;
                drawPosition.Y = (firstTile.X + firstTile.Y + y) * TILE_SIZE_FLOAT_HALF + renderOffset.Y;

                Point firstTileInRow = new Point(firstTile.X + ((y + 1) / 2), firstTile.Y + (y / 2));

                for (int x = 0; x < renderDimensions.X + 1; x++)
                {
                    MapTile tile = map.GetMapTile(firstTileInRow.X - x, firstTileInRow.Y + x);
                    if (tile == null)
                    {
                        drawPosition.X -= TILE_SIZE_FLOAT;
                        continue;
                    }

                    List <AEntity> entities = tile.Entities;
                    bool           draw     = true;
                    for (int i = 0; i < entities.Count; i++)
                    {
                        if (entities[i] is DeferredEntity)
                        {
                            deferredToRemove.Add(entities[i]);
                        }

                        if (!m_DrawTerrain)
                        {
                            if ((entities[i] is Ground) || (entities[i].Z > tile.Ground.Z))
                            {
                                draw = false;
                            }
                        }

                        if ((entities[i].Z >= m_DrawMaxItemAltitude || (m_DrawMaxItemAltitude != 255 && entities[i] is Item && (entities[i] as Item).ItemData.IsRoof)) && !(entities[i] is Ground))
                        {
                            continue;
                        }

                        if (draw)
                        {
                            AEntityView view = entities[i].GetView();
                            if (view != null)
                            {
                                if (view.Draw(m_SpriteBatch, drawPosition, overList, map, !m_UnderSurface))
                                {
                                    CountEntitiesRendered++;
                                }
                            }
                        }
                    }

                    foreach (AEntity deferred in deferredToRemove)
                    {
                        tile.OnExit(deferred);
                    }
                    deferredToRemove.Clear();

                    drawPosition.X -= TILE_SIZE_FLOAT;
                }
            }

            OverheadsView.Render(m_SpriteBatch, overList, map, m_UnderSurface);

            // Update the MouseOver objects
            mousePicking.UpdateOverEntities(overList, mousePicking.Position);

            // Draw the objects we just send to the spritebatch.
            m_SpriteBatch.GraphicsDevice.SetRenderTarget(m_RenderTargetSprites);
            m_SpriteBatch.GraphicsDevice.Clear(Color.Black);
            m_SpriteBatch.FlushSprites(true);
            m_SpriteBatch.GraphicsDevice.SetRenderTarget(null);
        }