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); }
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(); }
public static Island GetIsland() { var island = D2dPool <Island> .Spawn() ?? new Island(); Islands.Add(island); return(island); }
public static D2dSplitGroup AddTempGroup() { var group = D2dPool <D2dSplitGroup> .Spawn() ?? new D2dSplitGroup(); TempGroups.Add(group); return(group); }
public static D2dSplitGroup GetSplitGroup() { var splitGroup = D2dPool <D2dSplitGroup> .Spawn() ?? new D2dSplitGroup(); SplitGroups.Add(splitGroup); return(splitGroup); }
public static void ClearTempGroups() { for (var i = TempGroups.Count - 1; i >= 0; i--) { D2dPool <D2dSplitGroup> .Despawn(TempGroups[i], j => j.Clear()); } TempGroups.Clear(); }
public void AddPixel(int x, int y) { var pixel = D2dPool <D2dFloodfillPixel> .Spawn() ?? new D2dFloodfillPixel(); pixel.X = x; pixel.Y = y; Pixels.Add(pixel); }
private void Mark() { for (var i = cells.Count - 1; i >= 0; i--) { D2dPool <D2dEdgeColliderCell> .Despawn(cells[i], c => c.Clear(unusedColliders)); } cells.Clear(); }
public void Clear() { for (var i = Pixels.Count - 1; i >= 0; i--) { D2dPool <D2dFloodfillPixel> .Despawn(Pixels[i]); } Pixels.Clear(); }
public static D2dSplitGroup SpawnTempSplitGroup(bool addToTempList = true) { var group = D2dPool <D2dSplitGroup> .Spawn() ?? new D2dSplitGroup(); if (addToTempList == true) { TempSplitGroups.Add(group); } return(group); }
public static Island SpawnTempIsland(bool addToTempList = true) { var island = D2dPool <Island> .Spawn() ?? new Island(); if (addToTempList == true) { TempIslands.Add(island); } return(island); }
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); }
public void Clear() { for (var i = Pixels.Count - 1; i >= 0; i--) { D2dPool <D2dSplitPixel> .Despawn(Pixels[i]); } Data = null; Rect.Clear(); Pixels.Clear(); }
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(); }
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(); }
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(); } }
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(); } }
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(); }
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); } } }
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); }