Exemple #1
0
        public static void TrySplit(D2dDestructible destructible, int feather)
        {
            if (destructible != null)
            {
                Search(destructible);

                if (islands.Count > 1)
                {
                    var baseRect = new D2dRect(0, alphaWidth, 0, alphaHeight);

                    if (feather > 0)
                    {
                        baseField.Transform(baseRect, alphaWidth, alphaHeight, alphaData);

                        destructible.SplitBegin();

                        for (var i = islands.Count - 1; i >= 0; i--)
                        {
                            var island = islands[i];
                            var sprite = destructible.SplitNext(i == 0);
                            var rect   = new D2dRect(island.MinX, island.MaxX, island.MinY, island.MaxY); rect.Expand(feather); rect.ClampTo(baseRect);

                            D2dHelper.ReserveTempAlphaDataClear(rect.SizeX, rect.SizeY);

                            island.Fill(baseField, baseRect, rect);

                            sprite.SubsetAlphaWith(D2dHelper.tempAlphaData, rect, island.Count);
                        }
                    }
                    else
                    {
                        destructible.SplitBegin();

                        for (var i = islands.Count - 1; i >= 0; i--)
                        {
                            var island = islands[i];
                            var chunk  = destructible.SplitNext(i == 0);
                            var rect   = new D2dRect(island.MinX, island.MaxX, island.MinY, island.MaxY); rect.ClampTo(baseRect);

                            D2dHelper.ReserveTempAlphaDataClear(rect.SizeX, rect.SizeY);

                            island.Fill(rect);

                            chunk.SubsetAlphaWith(D2dHelper.tempAlphaData, rect);
                        }
                    }

                    destructible.SplitEnd();
                }
            }
        }
        public static void TrySplit(D2dDestructible destructible, int feather, int healThreshold)
        {
            if (destructible != null)
            {
                Search(destructible);

                if (islands.Count > 1)
                {
                    var baseRect = new D2dRect(0, alphaWidth, 0, alphaHeight);

                    if (feather > 0)
                    {
                        baseField.Transform(baseRect, alphaWidth, alphaHeight, alphaData);

                        destructible.SplitBegin();

                        for (var i = islands.Count - 1; i >= 0; i--)
                        {
                            var island = islands[i];
                            var piece  = destructible.SplitNext(i == 0);
                            var rect   = default(D2dRect);

                            if (healThreshold >= 0 && island.Count >= healThreshold)
                            {
                                rect = baseRect;
                            }
                            else
                            {
                                rect.MinX = island.MinX;
                                rect.MaxX = island.MaxX;
                                rect.MinY = island.MinY;
                                rect.MaxY = island.MaxY;

                                rect.Expand(feather);

                                rect.ClampTo(baseRect);

                                piece.HealSnapshot = null;
                            }

                            D2dHelper.ReserveTempAlphaDataClear(rect.SizeX, rect.SizeY);

                            island.Fill(baseField, baseRect, rect);

                            piece.SubsetAlphaWith(D2dHelper.tempAlphaData, rect, island.Count);
                        }
                    }
                    else
                    {
                        destructible.SplitBegin();

                        for (var i = islands.Count - 1; i >= 0; i--)
                        {
                            var island = islands[i];
                            var chunk  = destructible.SplitNext(i == 0);
                            var rect   = new D2dRect(island.MinX, island.MaxX, island.MinY, island.MaxY); rect.ClampTo(baseRect);

                            D2dHelper.ReserveTempAlphaDataClear(rect.SizeX, rect.SizeY);

                            island.Fill(rect);

                            chunk.SubsetAlphaWith(D2dHelper.tempAlphaData, rect);
                        }
                    }

                    destructible.SplitEnd(D2dDestructible.SplitMode.Split);
                }
            }
        }
Exemple #3
0
        public static void Trim(D2dDestructible destructible)
        {
            alphaData   = destructible.AlphaData;
            alphaWidth  = destructible.AlphaWidth;
            alphaHeight = destructible.AlphaHeight;

            var xMin = 0;
            var xMax = alphaWidth;
            var yMin = 0;
            var yMax = alphaHeight;

            for (var x = xMin; x < xMax; x++)
            {
                if (FastSolidAlphaVertical(yMin, yMax, x, alphaWidth) == false)
                {
                    xMin += 1;
                }
                else
                {
                    break;
                }
            }

            for (var x = xMax - 1; x >= xMin; x--)
            {
                if (FastSolidAlphaVertical(yMin, yMax, x, alphaWidth) == false)
                {
                    xMax -= 1;
                }
                else
                {
                    break;
                }
            }

            for (var y = yMin; y < yMax; y++)
            {
                if (FastSolidAlphaHorizontal(xMin, xMax, y, alphaWidth) == false)
                {
                    yMin += 1;
                }
                else
                {
                    break;
                }
            }

            for (var y = yMax - 1; y >= yMin; y--)
            {
                if (FastSolidAlphaHorizontal(xMin, xMax, y, alphaWidth) == false)
                {
                    yMax -= 1;
                }
                else
                {
                    break;
                }
            }

            var width  = xMax - xMin + 2;
            var height = yMax - yMin + 2;
            var rect   = D2dRect.CreateFromMinSize(xMin - 1, yMin - 1, width, height);

            D2dHelper.ReserveTempAlphaDataClear(width, height);

            D2dHelper.PasteAlpha(alphaData, alphaWidth, xMin, xMax, yMin, yMax, 1, 1, width);

            destructible.SubsetAlphaWith(D2dHelper.tempAlphaData, rect, destructible.AlphaCountRaw);
        }