Beispiel #1
0
        public void FillRectangle(RectI area, ref TilePicker tile)
        {
            // validate area
            int w = _world.Header.WorldBounds.W;
            area.Rebound(_world.Header.WorldBounds);

            for (int x = area.Left; x <= area.Right; x++) {
                for (int y = area.Top; y <= area.Bottom; y++) {
                    UpdateTile(ref tile, ref x, ref y, ref w);
                }
            }
        }
Beispiel #2
0
        public void DrawRectangle(RectI area, ref TilePicker tile)
        {
            // Use refs for faster access (really important!) speeds up a lot!
            int w = _world.Header.WorldBounds.W;
            int h = _world.Header.WorldBounds.H;

            // Check boundaries
            area.Rebound(_world.Header.WorldBounds);

            // (needed for refs)
            int x1 = area.Left;
            int x2 = area.Right;
            int y1 = area.Top;
            int y2 = area.Bottom;

            // top and bottom horizontal scanlines
            for (int x = area.Left; x <= area.Right; x++) {
                UpdateTile(ref tile, ref x, ref y1, ref w);
                UpdateTile(ref tile, ref x, ref y2, ref w);
            }

            for (int y = area.Top; y <= area.Bottom; y++) {
                UpdateTile(ref tile, ref x1, ref y, ref w);
                UpdateTile(ref tile, ref x2, ref y, ref w);
            }
        }
        public void UpdateWorldImage(RectI area, bool isRenderedLayer = false, string renderMsg = "Render Update Complete.", WriteableBitmap img = null)
        {
            // validate area
            area.Rebound(_world.Header.WorldBounds);

            int width = area.Width;
            int height = area.Height;
            int rts = isRenderedLayer ? 8 : 1;
            string renderProgressMsg = isRenderedLayer ? "Rendering Textured World..." : "Rendering Pixel World...";

            if (img == null) img = isRenderedLayer ? _worldImage.Rendered : _worldImage.Image;
            var pixels = new BytePixels(area.Size * rts, 4);
            var stride = img.PixelWidth * img.Format.BitsPerPixel / 8;

            for (int x = area.X; x <= area.Right; x++)
            {
                int dx = x - area.X;
                if (renderMsg != null) OnProgressChanged(this, dx, width, renderProgressMsg);

                for (int y = area.Y; y <= area.Bottom; y++)
                {
                    int dy = y - area.Y;
                    Tile tile = _world.Tiles[x, y];
                    if (tile != null)
                    {
                        var xy = (new PointInt32(x, y) - area.TopLeft) * rts;
                        var bp = isRenderedLayer ? GetTexture(y, tile) : GetTextureLayer("TilePixel", y, tile);
                        bp.PutData(pixels, xy);
                    }
                }
            }

            SizeInt32 ts = new SizeInt32(rts, rts);
            var realArea = isRenderedLayer ? new RectI(new PointInt32(), area.Size * ts) : area; // Rendered layer starts at 0,0

            img.Lock();
            img.WritePixels(realArea, pixels.GetData(), stride, 0);
            if (!isRenderedLayer) img.AddDirtyRect(realArea);
            img.Unlock();

            if (renderMsg != null) OnProgressChanged(this, 100, 100, renderMsg);
        }