Ejemplo n.º 1
0
            public D2dSplitGroup CreateSplitGroup(bool feather, bool allowExpand)
            {
                if (feather == true)
                {
                    D2dFloodfill.Feather(this);
                }

                var group = D2dPool <D2dSplitGroup> .Spawn() ?? new D2dSplitGroup();

                for (var j = Pixels.Count - 1; j >= 0; j--)
                {
                    var pixel = Pixels[j];

                    group.AddPixel(pixel.X, pixel.Y);
                }

                // Feather will automatically add a transparent border
                if (allowExpand == true && feather == false)
                {
                    group.Rect.MinX -= 1;
                    group.Rect.MaxX += 1;
                    group.Rect.MinY -= 1;
                    group.Rect.MaxY += 1;
                }

                return(group);
            }
Ejemplo n.º 2
0
        private void Rebuild()
        {
            Mark();
            {
                if (CellSize > 0)
                {
                    width  = (destructible.AlphaWidth + CellSize - 1) / CellSize;
                    height = (destructible.AlphaHeight + CellSize - 1) / CellSize;

                    for (var y = 0; y < height; y++)
                    {
                        for (var x = 0; x < width; x++)
                        {
                            var cell = D2dPool <D2dEdgeColliderCell> .Spawn() ?? new D2dEdgeColliderCell();

                            RebuildCell(cell, x, y);

                            cells.Add(cell);
                        }
                    }

                    UpdateColliderSettings();
                }
            }
            Sweep();
        }
Ejemplo n.º 3
0
        public static Island GetIsland()
        {
            var island = D2dPool <Island> .Spawn() ?? new Island();

            Islands.Add(island);

            return(island);
        }
Ejemplo n.º 4
0
        public static D2dSplitGroup AddTempGroup()
        {
            var group = D2dPool <D2dSplitGroup> .Spawn() ?? new D2dSplitGroup();

            TempGroups.Add(group);

            return(group);
        }
Ejemplo n.º 5
0
        public static D2dSplitGroup GetSplitGroup()
        {
            var splitGroup = D2dPool <D2dSplitGroup> .Spawn() ?? new D2dSplitGroup();

            SplitGroups.Add(splitGroup);

            return(splitGroup);
        }
Ejemplo n.º 6
0
        public static void ClearTempGroups()
        {
            for (var i = TempGroups.Count - 1; i >= 0; i--)
            {
                D2dPool <D2dSplitGroup> .Despawn(TempGroups[i], j => j.Clear());
            }

            TempGroups.Clear();
        }
Ejemplo n.º 7
0
            public void AddPixel(int x, int y)
            {
                var pixel = D2dPool <D2dFloodfillPixel> .Spawn() ?? new D2dFloodfillPixel();

                pixel.X = x;
                pixel.Y = y;

                Pixels.Add(pixel);
            }
Ejemplo n.º 8
0
        private void Mark()
        {
            for (var i = cells.Count - 1; i >= 0; i--)
            {
                D2dPool <D2dEdgeColliderCell> .Despawn(cells[i], c => c.Clear(unusedColliders));
            }

            cells.Clear();
        }
Ejemplo n.º 9
0
            public void Clear()
            {
                for (var i = Pixels.Count - 1; i >= 0; i--)
                {
                    D2dPool <D2dFloodfillPixel> .Despawn(Pixels[i]);
                }

                Pixels.Clear();
            }
Ejemplo n.º 10
0
        public static D2dSplitGroup SpawnTempSplitGroup(bool addToTempList = true)
        {
            var group = D2dPool <D2dSplitGroup> .Spawn() ?? new D2dSplitGroup();

            if (addToTempList == true)
            {
                TempSplitGroups.Add(group);
            }

            return(group);
        }
Ejemplo n.º 11
0
        public static Island SpawnTempIsland(bool addToTempList = true)
        {
            var island = D2dPool <Island> .Spawn() ?? new Island();

            if (addToTempList == true)
            {
                TempIslands.Add(island);
            }

            return(island);
        }
Ejemplo n.º 12
0
        public void AddPixel(int x, int y)
        {
            var pixel = D2dPool <D2dSplitPixel> .Spawn() ?? new D2dSplitPixel();

            pixel.Alpha = 255;
            pixel.X     = x;
            pixel.Y     = y;

            Rect.Add(x, y);

            Pixels.Add(pixel);
        }
Ejemplo n.º 13
0
        public void Clear()
        {
            for (var i = Pixels.Count - 1; i >= 0; i--)
            {
                D2dPool <D2dSplitPixel> .Despawn(Pixels[i]);
            }

            Data = null;

            Rect.Clear();

            Pixels.Clear();
        }
Ejemplo n.º 14
0
        public static void ClearAll()
        {
            for (var i = SplitGroups.Count - 1; i >= 0; i--)
            {
                var splitGroup = SplitGroups[i];

                splitGroup.Clear();

                D2dPool <D2dSplitGroup> .Despawn(splitGroup);
            }

            SplitGroups.Clear();
        }
Ejemplo n.º 15
0
        private static void Clear(List <Island> islands)
        {
            for (var i = islands.Count - 1; i >= 0; i--)
            {
                var island = islands[i];

                island.Clear();

                D2dPool <Island> .Despawn(island);
            }

            islands.Clear();
        }
Ejemplo n.º 16
0
        public static void DespawnTempIslands(Island borderIsland = null)
        {
            if (borderIsland != null)
            {
                D2dPool <Island> .Despawn(borderIsland, j => j.Clear());
            }

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

                TempIslands.Clear();
            }
        }
Ejemplo n.º 17
0
        public static void DespawnTempSplitGroups(D2dSplitGroup borderGroup = null)
        {
            if (borderGroup != null)
            {
                D2dPool <D2dSplitGroup> .Despawn(borderGroup, g => g.Clear());
            }

            if (TempSplitGroups.Count > 0)
            {
                for (var i = TempSplitGroups.Count - 1; i >= 0; i--)
                {
                    D2dPool <D2dSplitGroup> .Despawn(TempSplitGroups[i], g => g.Clear());
                }

                TempSplitGroups.Clear();
            }
        }
Ejemplo n.º 18
0
        public static void Clear()
        {
            for (var i = Islands.Count - 1; i >= 0; i--)
            {
                var island = Islands[i];

                island.Clear();

                D2dPool <Island> .Despawn(island);
            }

            for (var i = BorderIslands.Count - 1; i >= 0; i--)
            {
                var island = BorderIslands[i];

                island.Clear();

                D2dPool <Island> .Despawn(island);
            }

            Islands.Clear();
            BorderIslands.Clear();
        }
Ejemplo n.º 19
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);
                }
            }
        }
Ejemplo n.º 20
0
        public static void FastFind(byte[] alphaData, int alphaWidth, int alphaHeight, D2dRect rect)
        {
            Clear();

            if (rect.MinX < 0)
            {
                rect.MinX = 0;
            }
            if (rect.MinY < 0)
            {
                rect.MinY = 0;
            }
            if (rect.MaxX > alphaWidth)
            {
                rect.MaxX = alphaWidth;
            }
            if (rect.MaxY > alphaHeight)
            {
                rect.MaxY = alphaHeight;
            }

            lineCount = 0;

            CalculateLayout(rect, alphaWidth, alphaHeight);

            var oldCount = 0;

            for (var y = rect.MinY; y < rect.MaxY; y++)
            {
                var newCount = FastFindLines(alphaData, alphaWidth, y, rect.MinX, rect.MaxX);

                FastLinkLines(lineCount - newCount - oldCount, lineCount - newCount, lineCount);

                oldCount = newCount;
            }

            for (var i = 0; i < lineCount; i++)
            {
                var line = lines[i];

                if (line.Used == false)
                {
                    var island = D2dPool <Island> .Spawn() ?? new Island();

                    island.MinX  = line.MinX;
                    island.MaxX  = line.MaxX;
                    island.MinY  = line.Y;
                    island.MaxY  = line.Y + 1;
                    island.Count = 0;

                    // Scan though all connected lines and add to list
                    linkedLines.Clear(); linkedLines.Add(line); line.Used = true;

                    for (var j = 0; j < linkedLines.Count; j++)
                    {
                        var linkedLine = linkedLines[j];

                        island.MinX   = Mathf.Min(island.MinX, linkedLine.MinX);
                        island.MaxX   = Mathf.Max(island.MaxX, linkedLine.MaxX);
                        island.MinY   = Mathf.Min(island.MinY, linkedLine.Y);
                        island.MaxY   = Mathf.Max(island.MaxY, linkedLine.Y + 1);
                        island.Count += linkedLine.MaxX - linkedLine.MinX;

                        AddToScan(linkedLine.Ups);
                        AddToScan(linkedLine.Dns);

                        linkedLine.Island = island;

                        island.Lines.Add(linkedLine);
                    }

                    // Bridge layout?
                    switch (IslandLayout)
                    {
                    case Layout.Vertical:
                        if (island.MinY <= rect.MinY && island.MaxY >= rect.MaxY)
                        {
                            IslandLayout = Layout.Island;
                        }
                        break;

                    case Layout.Horizontal:
                        if (island.MinX <= rect.MinX && island.MaxX >= rect.MaxX)
                        {
                            IslandLayout = Layout.Island;
                        }
                        break;
                    }

                    tempIslands.Add(island);
                }
            }

            SortIslands(rect, alphaWidth, alphaHeight);
        }