コード例 #1
0
        public static void Feather(D2dFloodfillIsland island)
        {
            for (var i = island.Pixels.Count - 1; i >= 0; i--)
            {
                var pixel = island.Pixels[i];
                var x     = pixel.X;
                var y     = pixel.Y;

                TryFeather(island, x - 1, y);
                TryFeather(island, x + 1, y);
                TryFeather(island, x, y - 1);
                TryFeather(island, x, y + 1);
            }
        }
コード例 #2
0
        private static void TryFeather(D2dFloodfillIsland island, int x, int y)
        {
            if (x >= 0 && y >= 0 && x < width && y < height)
            {
                var i = x + y * width;

                if (cells[i] == CELL_EMPTY)
                {
                    cells[i] = CELL_CLAIM;

                    island.AddPixel(x, y);
                }
            }
            else
            {
                island.AddPixel(x, y);
            }
        }
コード例 #3
0
        public static void Find(byte[] newData, int newWidth, int newHeight)
        {
            width       = newWidth;
            height      = newHeight;
            total       = newWidth * newHeight;
            spreadCount = 0;

            if (cells == null || total > cells.Length)
            {
                cells = new byte[total];
            }

            for (var i = Islands.Count - 1; i >= 0; i--)
            {
                D2dPool <D2dFloodfillIsland> .Despawn(Islands[i], j => j.Clear());
            }

            Islands.Clear();

            // Find all solid pixels
            for (var i = 0; i < total; i++)
            {
                cells[i] = newData[i] > 127 ? CELL_SOLID : CELL_EMPTY;
            }

            for (var i = 0; i < total; i++)
            {
                if (cells[i] == CELL_SOLID)
                {
                    currentIsland = D2dPool <D2dFloodfillIsland> .Spawn() ?? new D2dFloodfillIsland();

                    BeginFloodFill(i, i % newWidth, i / newWidth);

                    Islands.Add(currentIsland);
                }
            }
        }