public static DestroyableSplitGroup GetSplitGroup() { var splitGroup = DestroyablePool <DestroyableSplitGroup> .Spawn() ?? new DestroyableSplitGroup(); SplitGroups.Add(splitGroup); return(splitGroup); }
public void AddPixel(int x, int y) { var pixel = DestroyablePool <DestroyableSplitPixel> .Spawn() ?? new DestroyableSplitPixel(); pixel.Alpha = 255; pixel.X = x; pixel.Y = y; Rect.Add(x, y); Pixels.Add(pixel); }
public static void FastFind(byte[] alphaData, int alphaWidth, int alphaHeight, DestroyableRect 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 = DestroyablePool <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); }