コード例 #1
0
ファイル: LiquidRenderer.cs プロジェクト: xiongyaya/Terraria
        private unsafe void InternalPrepareDraw(Rectangle drawArea)
        {
            Rectangle rectangle;

            // ISSUE: explicit reference operation
            ((Rectangle)@rectangle).\u002Ector(drawArea.X - 2, drawArea.Y - 2, drawArea.Width + 4, drawArea.Height + 4);
            this._drawArea = drawArea;
            if (this._cache.Length < rectangle.Width * rectangle.Height + 1)
            {
                this._cache = new LiquidRenderer.LiquidCache[rectangle.Width * rectangle.Height + 1];
            }
            if (this._drawCache.Length < drawArea.Width * drawArea.Height + 1)
            {
                this._drawCache = new LiquidRenderer.LiquidDrawCache[drawArea.Width * drawArea.Height + 1];
            }
            if (this._waveMask.Length < drawArea.Width * drawArea.Height)
            {
                this._waveMask = new Color[drawArea.Width * drawArea.Height];
                fixed(LiquidRenderer.LiquidCache *liquidCachePtr1 = &this._cache[1])
                {
                    int num1 = rectangle.Height * 2 + 2;

                    LiquidRenderer.LiquidCache *liquidCachePtr2 = liquidCachePtr1;
                    for (int x = (int)rectangle.X; x < rectangle.X + rectangle.Width; ++x)
                    {
                        for (int y = (int)rectangle.Y; y < rectangle.Y + rectangle.Height; ++y)
                        {
                            Tile tile = this._tiles[x, y] ?? new Tile();
                            liquidCachePtr2->LiquidLevel        = (float)tile.liquid / (float)byte.MaxValue;
                            liquidCachePtr2->IsHalfBrick        = tile.halfBrick() && liquidCachePtr2[-1].HasLiquid;
                            liquidCachePtr2->IsSolid            = WorldGen.SolidOrSlopedTile(tile) && !liquidCachePtr2->IsHalfBrick;
                            liquidCachePtr2->HasLiquid          = (uint)tile.liquid > 0U;
                            liquidCachePtr2->VisibleLiquidLevel = 0.0f;
                            liquidCachePtr2->HasWall            = (uint)tile.wall > 0U;
                            liquidCachePtr2->Type = tile.liquidType();
                            if (liquidCachePtr2->IsHalfBrick && !liquidCachePtr2->HasLiquid)
                            {
                                liquidCachePtr2->Type = liquidCachePtr2[-1].Type;
                            }
                            ++liquidCachePtr2;
                        }
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr3 = liquidCachePtr1 + num1;
                    for (int index1 = 2; index1 < rectangle.Width - 2; ++index1)
                    {
                        for (int index2 = 2; index2 < rectangle.Height - 2; ++index2)
                        {
                            float val1 = 0.0f;
                            float num2;
                            if (liquidCachePtr3->IsHalfBrick && liquidCachePtr3[-1].HasLiquid)
                            {
                                num2 = 1f;
                            }
                            else if (!liquidCachePtr3->HasLiquid)
                            {
                                LiquidRenderer.LiquidCache liquidCache1 = *(LiquidRenderer.LiquidCache *)((IntPtr)liquidCachePtr3 + (IntPtr) - rectangle.Height * sizeof(LiquidRenderer.LiquidCache));
                                LiquidRenderer.LiquidCache liquidCache2 = *(LiquidRenderer.LiquidCache *)((IntPtr)liquidCachePtr3 + (IntPtr)rectangle.Height * sizeof(LiquidRenderer.LiquidCache));
                                LiquidRenderer.LiquidCache liquidCache3 = liquidCachePtr3[-1];
                                LiquidRenderer.LiquidCache liquidCache4 = liquidCachePtr3[1];
                                if (liquidCache1.HasLiquid && liquidCache2.HasLiquid && (int)liquidCache1.Type == (int)liquidCache2.Type)
                                {
                                    val1 = liquidCache1.LiquidLevel + liquidCache2.LiquidLevel;
                                    liquidCachePtr3->Type = liquidCache1.Type;
                                }
                                if (liquidCache3.HasLiquid && liquidCache4.HasLiquid && (int)liquidCache3.Type == (int)liquidCache4.Type)
                                {
                                    val1 = Math.Max(val1, liquidCache3.LiquidLevel + liquidCache4.LiquidLevel);
                                    liquidCachePtr3->Type = liquidCache3.Type;
                                }
                                num2 = val1 * 0.5f;
                            }
                            else
                            {
                                num2 = liquidCachePtr3->LiquidLevel;
                            }
                            liquidCachePtr3->VisibleLiquidLevel = num2;
                            liquidCachePtr3->HasVisibleLiquid   = (double)num2 != 0.0;
                            ++liquidCachePtr3;
                        }
                        liquidCachePtr3 += 4;
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr4 = liquidCachePtr1;
                    for (int index1 = 0; index1 < rectangle.Width; ++index1)
                    {
                        for (int index2 = 0; index2 < rectangle.Height - 10; ++index2)
                        {
                            if (liquidCachePtr4->HasVisibleLiquid && !liquidCachePtr4->IsSolid)
                            {
                                liquidCachePtr4->Opacity     = 1f;
                                liquidCachePtr4->VisibleType = liquidCachePtr4->Type;
                                float num2 = 1f / (float)(LiquidRenderer.WATERFALL_LENGTH[(int)liquidCachePtr4->Type] + 1);
                                float num3 = 1f;
                                for (int index3 = 1; index3 <= LiquidRenderer.WATERFALL_LENGTH[(int)liquidCachePtr4->Type]; ++index3)
                                {
                                    num3 -= num2;
                                    if (!liquidCachePtr4[index3].IsSolid)
                                    {
                                        liquidCachePtr4[index3].VisibleLiquidLevel = Math.Max(liquidCachePtr4[index3].VisibleLiquidLevel, liquidCachePtr4->VisibleLiquidLevel * num3);
                                        liquidCachePtr4[index3].Opacity            = num3;
                                        liquidCachePtr4[index3].VisibleType        = liquidCachePtr4->Type;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            if (liquidCachePtr4->IsSolid)
                            {
                                liquidCachePtr4->VisibleLiquidLevel = 1f;
                                liquidCachePtr4->HasVisibleLiquid   = false;
                            }
                            else
                            {
                                liquidCachePtr4->HasVisibleLiquid = (double)liquidCachePtr4->VisibleLiquidLevel != 0.0;
                            }
                            ++liquidCachePtr4;
                        }
                        liquidCachePtr4 += 10;
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr5 = liquidCachePtr1 + num1;
                    for (int index1 = 2; index1 < rectangle.Width - 2; ++index1)
                    {
                        for (int index2 = 2; index2 < rectangle.Height - 2; ++index2)
                        {
                            if (!liquidCachePtr5->HasVisibleLiquid || liquidCachePtr5->IsSolid)
                            {
                                liquidCachePtr5->HasLeftEdge   = false;
                                liquidCachePtr5->HasTopEdge    = false;
                                liquidCachePtr5->HasRightEdge  = false;
                                liquidCachePtr5->HasBottomEdge = false;
                            }
                            else
                            {
                                LiquidRenderer.LiquidCache liquidCache1 = liquidCachePtr5[-1];
                                LiquidRenderer.LiquidCache liquidCache2 = liquidCachePtr5[1];
                                LiquidRenderer.LiquidCache liquidCache3 = *(LiquidRenderer.LiquidCache *)((IntPtr)liquidCachePtr5 + (IntPtr) - rectangle.Height * sizeof(LiquidRenderer.LiquidCache));
                                LiquidRenderer.LiquidCache liquidCache4 = *(LiquidRenderer.LiquidCache *)((IntPtr)liquidCachePtr5 + (IntPtr)rectangle.Height * sizeof(LiquidRenderer.LiquidCache));
                                float num2 = 0.0f;
                                float num3 = 1f;
                                float num4 = 0.0f;
                                float num5 = 1f;
                                float visibleLiquidLevel = liquidCachePtr5->VisibleLiquidLevel;
                                if (!liquidCache1.HasVisibleLiquid)
                                {
                                    num4 += liquidCache2.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                                }
                                if (!liquidCache2.HasVisibleLiquid && !liquidCache2.IsSolid && !liquidCache2.IsHalfBrick)
                                {
                                    num5 -= liquidCache1.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                                }
                                if (!liquidCache3.HasVisibleLiquid && !liquidCache3.IsSolid && !liquidCache3.IsHalfBrick)
                                {
                                    num2 += liquidCache4.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                                }
                                if (!liquidCache4.HasVisibleLiquid && !liquidCache4.IsSolid && !liquidCache4.IsHalfBrick)
                                {
                                    num3 -= liquidCache3.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                                }
                                liquidCachePtr5->LeftWall   = num2;
                                liquidCachePtr5->RightWall  = num3;
                                liquidCachePtr5->BottomWall = num5;
                                liquidCachePtr5->TopWall    = num4;
                                Point zero = Point.get_Zero();
                                liquidCachePtr5->HasTopEdge    = !liquidCache1.HasVisibleLiquid && !liquidCache1.IsSolid || (double)num4 != 0.0;
                                liquidCachePtr5->HasBottomEdge = !liquidCache2.HasVisibleLiquid && !liquidCache2.IsSolid || (double)num5 != 1.0;
                                liquidCachePtr5->HasLeftEdge   = !liquidCache3.HasVisibleLiquid && !liquidCache3.IsSolid || (double)num2 != 0.0;
                                liquidCachePtr5->HasRightEdge  = !liquidCache4.HasVisibleLiquid && !liquidCache4.IsSolid || (double)num3 != 1.0;
                                if (!liquidCachePtr5->HasLeftEdge)
                                {
                                    if (liquidCachePtr5->HasRightEdge)
                                    {
                                        // ISSUE: explicit reference operation
                                        // ISSUE: variable of a reference type
                                        __Null& local = @zero.X;
                                        // ISSUE: cast to a reference type
                                        // ISSUE: explicit reference operation
                                        int num6 = ^ (int&)local + 32;
コード例 #2
0
        private unsafe void InternalPrepareDraw(Rectangle drawArea)
        {
            Rectangle rectangle = new Rectangle(drawArea.X - 2, drawArea.Y - 2, drawArea.Width + 4, drawArea.Height + 4);

            this._drawArea = drawArea;
            if (this._cache.Length < rectangle.Width * rectangle.Height + 1)
            {
                this._cache = new LiquidRenderer.LiquidCache[rectangle.Width * rectangle.Height + 1];
            }
            if (this._drawCache.Length < drawArea.Width * drawArea.Height + 1)
            {
                this._drawCache = new LiquidRenderer.LiquidDrawCache[drawArea.Width * drawArea.Height + 1];
            }
            if (this._waveMask.Length < drawArea.Width * drawArea.Height)
            {
                this._waveMask = new Color[drawArea.Width * drawArea.Height];
                fixed(LiquidRenderer.LiquidCache *liquidCachePtr1 = &this._cache[1])
                {
                    int num1 = rectangle.Height * 2 + 2;

                    LiquidRenderer.LiquidCache *liquidCachePtr2 = liquidCachePtr1;
                    for (int x = rectangle.X; x < rectangle.X + rectangle.Width; ++x)
                    {
                        for (int y = rectangle.Y; y < rectangle.Y + rectangle.Height; ++y)
                        {
                            Tile tile = LiquidRenderer.Tiles[x, y] ?? new Tile();
                            liquidCachePtr2->LiquidLevel        = (float)tile.liquid / (float)byte.MaxValue;
                            liquidCachePtr2->IsHalfBrick        = tile.halfBrick() && liquidCachePtr2[-1].HasLiquid && !TileID.Sets.Platforms[(int)tile.type];
                            liquidCachePtr2->IsSolid            = WorldGen.SolidOrSlopedTile(tile);
                            liquidCachePtr2->HasLiquid          = tile.liquid > (byte)0;
                            liquidCachePtr2->VisibleLiquidLevel = 0.0f;
                            liquidCachePtr2->HasWall            = tile.wall > (ushort)0;
                            liquidCachePtr2->Type = tile.liquidType();
                            if (liquidCachePtr2->IsHalfBrick && !liquidCachePtr2->HasLiquid)
                            {
                                liquidCachePtr2->Type = liquidCachePtr2[-1].Type;
                            }
                            ++liquidCachePtr2;
                        }
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr3 = liquidCachePtr1 + num1;
                    for (int index1 = 2; index1 < rectangle.Width - 2; ++index1)
                    {
                        for (int index2 = 2; index2 < rectangle.Height - 2; ++index2)
                        {
                            float val1 = 0.0f;
                            float num2;
                            if (liquidCachePtr3->IsHalfBrick && liquidCachePtr3[-1].HasLiquid)
                            {
                                num2 = 1f;
                            }
                            else if (!liquidCachePtr3->HasLiquid)
                            {
                                LiquidRenderer.LiquidCache liquidCache1 = liquidCachePtr3[-1];
                                LiquidRenderer.LiquidCache liquidCache2 = liquidCachePtr3[1];
                                LiquidRenderer.LiquidCache liquidCache3 = liquidCachePtr3[-rectangle.Height];
                                LiquidRenderer.LiquidCache liquidCache4 = liquidCachePtr3[rectangle.Height];
                                if (liquidCache1.HasLiquid && liquidCache2.HasLiquid && ((int)liquidCache1.Type == (int)liquidCache2.Type && !liquidCache1.IsSolid) && !liquidCache2.IsSolid)
                                {
                                    val1 = liquidCache1.LiquidLevel + liquidCache2.LiquidLevel;
                                    liquidCachePtr3->Type = liquidCache1.Type;
                                }
                                if (liquidCache3.HasLiquid && liquidCache4.HasLiquid && ((int)liquidCache3.Type == (int)liquidCache4.Type && !liquidCache3.IsSolid) && !liquidCache4.IsSolid)
                                {
                                    val1 = Math.Max(val1, liquidCache3.LiquidLevel + liquidCache4.LiquidLevel);
                                    liquidCachePtr3->Type = liquidCache3.Type;
                                }
                                num2 = val1 * 0.5f;
                            }
                            else
                            {
                                num2 = liquidCachePtr3->LiquidLevel;
                            }
                            liquidCachePtr3->VisibleLiquidLevel = num2;
                            liquidCachePtr3->HasVisibleLiquid   = (double)num2 != 0.0;
                            ++liquidCachePtr3;
                        }
                        liquidCachePtr3 += 4;
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr4 = liquidCachePtr1;
                    for (int index1 = 0; index1 < rectangle.Width; ++index1)
                    {
                        for (int index2 = 0; index2 < rectangle.Height - 10; ++index2)
                        {
                            if (liquidCachePtr4->HasVisibleLiquid && (!liquidCachePtr4->IsSolid || liquidCachePtr4->IsHalfBrick))
                            {
                                liquidCachePtr4->Opacity     = 1f;
                                liquidCachePtr4->VisibleType = liquidCachePtr4->Type;
                                float num2 = 1f / (float)(LiquidRenderer.WATERFALL_LENGTH[(int)liquidCachePtr4->Type] + 1);
                                float num3 = 1f;
                                for (int index3 = 1; index3 <= LiquidRenderer.WATERFALL_LENGTH[(int)liquidCachePtr4->Type]; ++index3)
                                {
                                    num3 -= num2;
                                    if (!liquidCachePtr4[index3].IsSolid)
                                    {
                                        liquidCachePtr4[index3].VisibleLiquidLevel = Math.Max(liquidCachePtr4[index3].VisibleLiquidLevel, liquidCachePtr4->VisibleLiquidLevel * num3);
                                        liquidCachePtr4[index3].Opacity            = num3;
                                        liquidCachePtr4[index3].VisibleType        = liquidCachePtr4->Type;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            if (liquidCachePtr4->IsSolid && !liquidCachePtr4->IsHalfBrick)
                            {
                                liquidCachePtr4->VisibleLiquidLevel = 1f;
                                liquidCachePtr4->HasVisibleLiquid   = false;
                            }
                            else
                            {
                                liquidCachePtr4->HasVisibleLiquid = (double)liquidCachePtr4->VisibleLiquidLevel != 0.0;
                            }
                            ++liquidCachePtr4;
                        }
                        liquidCachePtr4 += 10;
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr5 = liquidCachePtr1 + num1;
                    for (int index1 = 2; index1 < rectangle.Width - 2; ++index1)
                    {
                        for (int index2 = 2; index2 < rectangle.Height - 2; ++index2)
                        {
                            if (!liquidCachePtr5->HasVisibleLiquid)
                            {
                                liquidCachePtr5->HasLeftEdge   = false;
                                liquidCachePtr5->HasTopEdge    = false;
                                liquidCachePtr5->HasRightEdge  = false;
                                liquidCachePtr5->HasBottomEdge = false;
                            }
                            else
                            {
                                LiquidRenderer.LiquidCache liquidCache1 = liquidCachePtr5[-1];
                                LiquidRenderer.LiquidCache liquidCache2 = liquidCachePtr5[1];
                                LiquidRenderer.LiquidCache liquidCache3 = liquidCachePtr5[-rectangle.Height];
                                LiquidRenderer.LiquidCache liquidCache4 = liquidCachePtr5[rectangle.Height];
                                float num2 = 0.0f;
                                float num3 = 1f;
                                float num4 = 0.0f;
                                float num5 = 1f;
                                float visibleLiquidLevel = liquidCachePtr5->VisibleLiquidLevel;
                                if (!liquidCache1.HasVisibleLiquid)
                                {
                                    num4 += liquidCache2.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                                }
                                if (!liquidCache2.HasVisibleLiquid && !liquidCache2.IsSolid && !liquidCache2.IsHalfBrick)
                                {
                                    num5 -= liquidCache1.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                                }
                                if (!liquidCache3.HasVisibleLiquid && !liquidCache3.IsSolid && !liquidCache3.IsHalfBrick)
                                {
                                    num2 += liquidCache4.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                                }
                                if (!liquidCache4.HasVisibleLiquid && !liquidCache4.IsSolid && !liquidCache4.IsHalfBrick)
                                {
                                    num3 -= liquidCache3.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                                }
                                liquidCachePtr5->LeftWall   = num2;
                                liquidCachePtr5->RightWall  = num3;
                                liquidCachePtr5->BottomWall = num5;
                                liquidCachePtr5->TopWall    = num4;
                                Point zero = Point.Zero;
                                liquidCachePtr5->HasTopEdge    = !liquidCache1.HasVisibleLiquid && !liquidCache1.IsSolid || (double)num4 != 0.0;
                                liquidCachePtr5->HasBottomEdge = !liquidCache2.HasVisibleLiquid && !liquidCache2.IsSolid || (double)num5 != 1.0;
                                liquidCachePtr5->HasLeftEdge   = !liquidCache3.HasVisibleLiquid && !liquidCache3.IsSolid || (double)num2 != 0.0;
                                liquidCachePtr5->HasRightEdge  = !liquidCache4.HasVisibleLiquid && !liquidCache4.IsSolid || (double)num3 != 1.0;
                                if (!liquidCachePtr5->HasLeftEdge)
                                {
                                    if (liquidCachePtr5->HasRightEdge)
                                    {
                                        zero.X += 32;
                                    }
                                    else
                                    {
                                        zero.X += 16;
                                    }
                                }
                                if (liquidCachePtr5->HasLeftEdge && liquidCachePtr5->HasRightEdge)
                                {
                                    zero.X  = 16;
                                    zero.Y += 32;
                                    if (liquidCachePtr5->HasTopEdge)
                                    {
                                        zero.Y = 16;
                                    }
                                }
                                else if (!liquidCachePtr5->HasTopEdge)
                                {
                                    if (!liquidCachePtr5->HasLeftEdge && !liquidCachePtr5->HasRightEdge)
                                    {
                                        zero.Y += 48;
                                    }
                                    else
                                    {
                                        zero.Y += 16;
                                    }
                                }
                                if (zero.Y == 16 && liquidCachePtr5->HasLeftEdge ^ liquidCachePtr5->HasRightEdge && (index2 + rectangle.Y) % 2 == 0)
                                {
                                    zero.Y += 16;
                                }
                                liquidCachePtr5->FrameOffset = zero;
                            }
                            ++liquidCachePtr5;
                        }
                        liquidCachePtr5 += 4;
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr6 = liquidCachePtr1 + num1;
                    for (int index1 = 2; index1 < rectangle.Width - 2; ++index1)
                    {
                        for (int index2 = 2; index2 < rectangle.Height - 2; ++index2)
                        {
                            if (liquidCachePtr6->HasVisibleLiquid)
                            {
                                LiquidRenderer.LiquidCache liquidCache1 = liquidCachePtr6[-1];
                                LiquidRenderer.LiquidCache liquidCache2 = liquidCachePtr6[1];
                                LiquidRenderer.LiquidCache liquidCache3 = liquidCachePtr6[-rectangle.Height];
                                LiquidRenderer.LiquidCache liquidCache4 = liquidCachePtr6[rectangle.Height];
                                liquidCachePtr6->VisibleLeftWall   = liquidCachePtr6->LeftWall;
                                liquidCachePtr6->VisibleRightWall  = liquidCachePtr6->RightWall;
                                liquidCachePtr6->VisibleTopWall    = liquidCachePtr6->TopWall;
                                liquidCachePtr6->VisibleBottomWall = liquidCachePtr6->BottomWall;
                                if (liquidCache1.HasVisibleLiquid && liquidCache2.HasVisibleLiquid)
                                {
                                    if (liquidCachePtr6->HasLeftEdge)
                                    {
                                        liquidCachePtr6->VisibleLeftWall = (float)(((double)liquidCachePtr6->LeftWall * 2.0 + (double)liquidCache1.LeftWall + (double)liquidCache2.LeftWall) * 0.25);
                                    }
                                    if (liquidCachePtr6->HasRightEdge)
                                    {
                                        liquidCachePtr6->VisibleRightWall = (float)(((double)liquidCachePtr6->RightWall * 2.0 + (double)liquidCache1.RightWall + (double)liquidCache2.RightWall) * 0.25);
                                    }
                                }
                                if (liquidCache3.HasVisibleLiquid && liquidCache4.HasVisibleLiquid)
                                {
                                    if (liquidCachePtr6->HasTopEdge)
                                    {
                                        liquidCachePtr6->VisibleTopWall = (float)(((double)liquidCachePtr6->TopWall * 2.0 + (double)liquidCache3.TopWall + (double)liquidCache4.TopWall) * 0.25);
                                    }
                                    if (liquidCachePtr6->HasBottomEdge)
                                    {
                                        liquidCachePtr6->VisibleBottomWall = (float)(((double)liquidCachePtr6->BottomWall * 2.0 + (double)liquidCache3.BottomWall + (double)liquidCache4.BottomWall) * 0.25);
                                    }
                                }
                            }
                            ++liquidCachePtr6;
                        }
                        liquidCachePtr6 += 4;
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr7 = liquidCachePtr1 + num1;
                    for (int index1 = 2; index1 < rectangle.Width - 2; ++index1)
                    {
                        for (int index2 = 2; index2 < rectangle.Height - 2; ++index2)
                        {
                            if (liquidCachePtr7->HasLiquid)
                            {
                                LiquidRenderer.LiquidCache liquidCache1 = liquidCachePtr7[-1];
                                LiquidRenderer.LiquidCache liquidCache2 = liquidCachePtr7[1];
                                LiquidRenderer.LiquidCache liquidCache3 = liquidCachePtr7[-rectangle.Height];
                                LiquidRenderer.LiquidCache liquidCache4 = liquidCachePtr7[rectangle.Height];
                                if (liquidCachePtr7->HasTopEdge && !liquidCachePtr7->HasBottomEdge && liquidCachePtr7->HasLeftEdge ^ liquidCachePtr7->HasRightEdge)
                                {
                                    if (liquidCachePtr7->HasRightEdge)
                                    {
                                        liquidCachePtr7->VisibleRightWall = liquidCache2.VisibleRightWall;
                                        liquidCachePtr7->VisibleTopWall   = liquidCache3.VisibleTopWall;
                                    }
                                    else
                                    {
                                        liquidCachePtr7->VisibleLeftWall = liquidCache2.VisibleLeftWall;
                                        liquidCachePtr7->VisibleTopWall  = liquidCache4.VisibleTopWall;
                                    }
                                }
                                else if (liquidCache2.FrameOffset.X == 16 && liquidCache2.FrameOffset.Y == 32)
                                {
                                    if ((double)liquidCachePtr7->VisibleLeftWall > 0.5)
                                    {
                                        liquidCachePtr7->VisibleLeftWall = 0.0f;
                                        liquidCachePtr7->FrameOffset     = new Point(0, 0);
                                    }
                                    else if ((double)liquidCachePtr7->VisibleRightWall < 0.5)
                                    {
                                        liquidCachePtr7->VisibleRightWall = 1f;
                                        liquidCachePtr7->FrameOffset      = new Point(32, 0);
                                    }
                                }
                            }
                            ++liquidCachePtr7;
                        }
                        liquidCachePtr7 += 4;
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr8 = liquidCachePtr1 + num1;
                    for (int index1 = 2; index1 < rectangle.Width - 2; ++index1)
                    {
                        for (int index2 = 2; index2 < rectangle.Height - 2; ++index2)
                        {
                            if (liquidCachePtr8->HasLiquid)
                            {
                                LiquidRenderer.LiquidCache liquidCache1 = liquidCachePtr8[-1];
                                LiquidRenderer.LiquidCache liquidCache2 = liquidCachePtr8[1];
                                LiquidRenderer.LiquidCache liquidCache3 = liquidCachePtr8[-rectangle.Height];
                                LiquidRenderer.LiquidCache liquidCache4 = liquidCachePtr8[rectangle.Height];
                                if (!liquidCachePtr8->HasBottomEdge && !liquidCachePtr8->HasLeftEdge && (!liquidCachePtr8->HasTopEdge && !liquidCachePtr8->HasRightEdge))
                                {
                                    if (liquidCache3.HasTopEdge && liquidCache1.HasLeftEdge)
                                    {
                                        liquidCachePtr8->FrameOffset.X     = Math.Max(4, (int)(16.0 - (double)liquidCache1.VisibleLeftWall * 16.0)) - 4;
                                        liquidCachePtr8->FrameOffset.Y     = 48 + Math.Max(4, (int)(16.0 - (double)liquidCache3.VisibleTopWall * 16.0)) - 4;
                                        liquidCachePtr8->VisibleLeftWall   = 0.0f;
                                        liquidCachePtr8->VisibleTopWall    = 0.0f;
                                        liquidCachePtr8->VisibleRightWall  = 1f;
                                        liquidCachePtr8->VisibleBottomWall = 1f;
                                    }
                                    else if (liquidCache4.HasTopEdge && liquidCache1.HasRightEdge)
                                    {
                                        liquidCachePtr8->FrameOffset.X     = 32 - Math.Min(16, (int)((double)liquidCache1.VisibleRightWall * 16.0) - 4);
                                        liquidCachePtr8->FrameOffset.Y     = 48 + Math.Max(4, (int)(16.0 - (double)liquidCache4.VisibleTopWall * 16.0)) - 4;
                                        liquidCachePtr8->VisibleLeftWall   = 0.0f;
                                        liquidCachePtr8->VisibleTopWall    = 0.0f;
                                        liquidCachePtr8->VisibleRightWall  = 1f;
                                        liquidCachePtr8->VisibleBottomWall = 1f;
                                    }
                                }
                            }
                            ++liquidCachePtr8;
                        }
                        liquidCachePtr8 += 4;
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr9 = liquidCachePtr1 + num1;
                    fixed(LiquidRenderer.LiquidDrawCache *liquidDrawCachePtr1 = &this._drawCache[0])
                    fixed(Color * colorPtr1 = &this._waveMask[0])
                    {
                        LiquidRenderer.LiquidDrawCache *liquidDrawCachePtr2 = liquidDrawCachePtr1;
                        Color *colorPtr2 = colorPtr1;

                        for (int index1 = 2; index1 < rectangle.Width - 2; ++index1)
                        {
                            for (int index2 = 2; index2 < rectangle.Height - 2; ++index2)
                            {
                                if (liquidCachePtr9->HasVisibleLiquid)
                                {
                                    float num2 = Math.Min(0.75f, liquidCachePtr9->VisibleLeftWall);
                                    float num3 = Math.Max(0.25f, liquidCachePtr9->VisibleRightWall);
                                    float num4 = Math.Min(0.75f, liquidCachePtr9->VisibleTopWall);
                                    float num5 = Math.Max(0.25f, liquidCachePtr9->VisibleBottomWall);
                                    if (liquidCachePtr9->IsHalfBrick && liquidCachePtr9->IsSolid && (double)num5 > 0.5)
                                    {
                                        num5 = 0.5f;
                                    }
                                    liquidDrawCachePtr2->IsVisible       = liquidCachePtr9->HasWall || (!liquidCachePtr9->IsHalfBrick || !liquidCachePtr9->HasLiquid || (double)liquidCachePtr9->LiquidLevel >= 1.0);
                                    liquidDrawCachePtr2->SourceRectangle = new Rectangle((int)(16.0 - (double)num3 * 16.0) + liquidCachePtr9->FrameOffset.X, (int)(16.0 - (double)num5 * 16.0) + liquidCachePtr9->FrameOffset.Y, (int)Math.Ceiling(((double)num3 - (double)num2) * 16.0), (int)Math.Ceiling(((double)num5 - (double)num4) * 16.0));
                                    liquidDrawCachePtr2->IsSurfaceLiquid = liquidCachePtr9->FrameOffset.X == 16 && liquidCachePtr9->FrameOffset.Y == 0 && (double)(index2 + rectangle.Y) > Main.worldSurface - 40.0;
                                    liquidDrawCachePtr2->Opacity         = liquidCachePtr9->Opacity;
                                    liquidDrawCachePtr2->LiquidOffset    = new Vector2((float)Math.Floor((double)num2 * 16.0), (float)Math.Floor((double)num4 * 16.0));
                                    liquidDrawCachePtr2->Type            = liquidCachePtr9->VisibleType;
                                    liquidDrawCachePtr2->HasWall         = liquidCachePtr9->HasWall;
                                    byte num6 = LiquidRenderer.WAVE_MASK_STRENGTH[(int)liquidCachePtr9->VisibleType];
                                    byte num7 = (byte)((uint)num6 >> 1);
                                    colorPtr2->R = num7;
                                    colorPtr2->G = num7;
                                    colorPtr2->B = LiquidRenderer.VISCOSITY_MASK[(int)liquidCachePtr9->VisibleType];
                                    colorPtr2->A = num6;
                                    LiquidRenderer.LiquidCache *liquidCachePtr10 = liquidCachePtr9 - 1;
                                    if (index2 != 2 && !liquidCachePtr10->HasVisibleLiquid && (!liquidCachePtr10->IsSolid && !liquidCachePtr10->IsHalfBrick))
                                    {
                                        *(colorPtr2 - 1) = *colorPtr2;
                                    }
                                }
                                else
                                {
                                    liquidDrawCachePtr2->IsVisible = false;
                                    int  index3 = liquidCachePtr9->IsSolid || liquidCachePtr9->IsHalfBrick ? 3 : 4;
                                    byte num2   = LiquidRenderer.WAVE_MASK_STRENGTH[index3];
                                    byte num3   = (byte)((uint)num2 >> 1);
                                    colorPtr2->R = num3;
                                    colorPtr2->G = num3;
                                    colorPtr2->B = LiquidRenderer.VISCOSITY_MASK[index3];
                                    colorPtr2->A = num2;
                                }
                                ++liquidCachePtr9;
                                ++liquidDrawCachePtr2;
                                ++colorPtr2;
                            }
                            liquidCachePtr9 += 4;
                        }
                    }
                    LiquidRenderer.LiquidCache *liquidCachePtr11 = liquidCachePtr1;
                    for (int x = rectangle.X; x < rectangle.X + rectangle.Width; ++x)
                    {
                        for (int y = rectangle.Y; y < rectangle.Y + rectangle.Height; ++y)
                        {
                            if (liquidCachePtr11->VisibleType == (byte)1 && liquidCachePtr11->HasVisibleLiquid && Dust.lavaBubbles < 200)
                            {
                                if (this._random.Next(700) == 0)
                                {
                                    Dust.NewDust(new Vector2((float)(x * 16), (float)(y * 16)), 16, 16, 35, 0.0f, 0.0f, 0, Color.White, 1f);
                                }
                                if (this._random.Next(350) == 0)
                                {
                                    int index = Dust.NewDust(new Vector2((float)(x * 16), (float)(y * 16)), 16, 8, 35, 0.0f, 0.0f, 50, Color.White, 1.5f);
                                    Main.dust[index].velocity   *= 0.8f;
                                    Main.dust[index].velocity.X *= 2f;
                                    Main.dust[index].velocity.Y -= (float)this._random.Next(1, 7) * 0.1f;
                                    if (this._random.Next(10) == 0)
                                    {
                                        Main.dust[index].velocity.Y *= (float)this._random.Next(2, 5);
                                    }
                                    Main.dust[index].noGravity = true;
                                }
                            }
                            ++liquidCachePtr11;
                        }
                    }
                }

                if (this.WaveFilters == null)
                {
                    return;
                }
                this.WaveFilters(this._waveMask, this.GetCachedDrawArea());
        }
コード例 #3
0
ファイル: LiquidRenderer.cs プロジェクト: windlex/mylualib
        // Token: 0x06000F3A RID: 3898 RVA: 0x003F2558 File Offset: 0x003F0758
        private unsafe void InternalPrepareDraw(Rectangle drawArea)
        {
            Rectangle rectangle = new Rectangle(drawArea.X - 2, drawArea.Y - 2, drawArea.Width + 4, drawArea.Height + 4);

            this._drawArea = drawArea;
            if (this._cache.Length < rectangle.Width * rectangle.Height + 1)
            {
                this._cache = new LiquidRenderer.LiquidCache[rectangle.Width * rectangle.Height + 1];
            }
            if (this._drawCache.Length < drawArea.Width * drawArea.Height + 1)
            {
                this._drawCache = new LiquidRenderer.LiquidDrawCache[drawArea.Width * drawArea.Height + 1];
            }
            if (this._waveMask.Length < drawArea.Width * drawArea.Height)
            {
                this._waveMask = new Color[drawArea.Width * drawArea.Height];
            }

            fixed(LiquidRenderer.LiquidCache *ptr = &this._cache[1])
            {
                LiquidRenderer.LiquidCache *ptr2 = ptr;
                int num = rectangle.Height * 2 + 2;

                ptr2 = ptr;
                for (int i = rectangle.X; i < rectangle.X + rectangle.Width; i++)
                {
                    for (int j = rectangle.Y; j < rectangle.Y + rectangle.Height; j++)
                    {
                        Tile tile = this._tiles[i, j];
                        if (tile == null)
                        {
                            tile = new Tile();
                        }
                        ptr2->LiquidLevel        = (float)tile.liquid / 255f;
                        ptr2->IsHalfBrick        = (tile.halfBrick() && ptr2[-1].HasLiquid);
                        ptr2->IsSolid            = (WorldGen.SolidOrSlopedTile(tile) && !ptr2->IsHalfBrick);
                        ptr2->HasLiquid          = (tile.liquid > 0);
                        ptr2->VisibleLiquidLevel = 0f;
                        ptr2->HasWall            = (tile.wall > 0);
                        ptr2->Type = tile.liquidType();
                        if (ptr2->IsHalfBrick && !ptr2->HasLiquid)
                        {
                            ptr2->Type = ptr2[-1].Type;
                        }
                        ptr2++;
                    }
                }
                ptr2  = ptr;
                ptr2 += num;
                for (int k = 2; k < rectangle.Width - 2; k++)
                {
                    for (int l = 2; l < rectangle.Height - 2; l++)
                    {
                        float num2 = 0f;
                        if (ptr2->IsHalfBrick && ptr2[-1].HasLiquid)
                        {
                            num2 = 1f;
                        }
                        else if (!ptr2->HasLiquid)
                        {
                            LiquidRenderer.LiquidCache liquidCache  = ptr2[-rectangle.Height];
                            LiquidRenderer.LiquidCache liquidCache2 = ptr2[rectangle.Height];
                            LiquidRenderer.LiquidCache liquidCache3 = ptr2[-1];
                            LiquidRenderer.LiquidCache liquidCache4 = ptr2[1];
                            if (liquidCache.HasLiquid && liquidCache2.HasLiquid && liquidCache.Type == liquidCache2.Type)
                            {
                                num2       = liquidCache.LiquidLevel + liquidCache2.LiquidLevel;
                                ptr2->Type = liquidCache.Type;
                            }
                            if (liquidCache3.HasLiquid && liquidCache4.HasLiquid && liquidCache3.Type == liquidCache4.Type)
                            {
                                num2       = Math.Max(num2, liquidCache3.LiquidLevel + liquidCache4.LiquidLevel);
                                ptr2->Type = liquidCache3.Type;
                            }
                            num2 *= 0.5f;
                        }
                        else
                        {
                            num2 = ptr2->LiquidLevel;
                        }
                        ptr2->VisibleLiquidLevel = num2;
                        ptr2->HasVisibleLiquid   = (num2 != 0f);
                        ptr2++;
                    }
                    ptr2 += 4;
                }
                ptr2 = ptr;
                for (int m = 0; m < rectangle.Width; m++)
                {
                    for (int n = 0; n < rectangle.Height - 10; n++)
                    {
                        if (ptr2->HasVisibleLiquid && !ptr2->IsSolid)
                        {
                            ptr2->Opacity     = 1f;
                            ptr2->VisibleType = ptr2->Type;
                            float num3 = 1f / (float)(LiquidRenderer.WATERFALL_LENGTH[(int)ptr2->Type] + 1);
                            float num4 = 1f;
                            for (int num5 = 1; num5 <= LiquidRenderer.WATERFALL_LENGTH[(int)ptr2->Type]; num5++)
                            {
                                num4 -= num3;
                                if (ptr2[num5].IsSolid)
                                {
                                    break;
                                }
                                ptr2[num5].VisibleLiquidLevel = Math.Max(ptr2[num5].VisibleLiquidLevel, ptr2->VisibleLiquidLevel * num4);
                                ptr2[num5].Opacity            = num4;
                                ptr2[num5].VisibleType        = ptr2->Type;
                            }
                        }
                        if (ptr2->IsSolid)
                        {
                            ptr2->VisibleLiquidLevel = 1f;
                            ptr2->HasVisibleLiquid   = false;
                        }
                        else
                        {
                            ptr2->HasVisibleLiquid = (ptr2->VisibleLiquidLevel != 0f);
                        }
                        ptr2++;
                    }
                    ptr2 += 10;
                }
                ptr2  = ptr;
                ptr2 += num;
                for (int num6 = 2; num6 < rectangle.Width - 2; num6++)
                {
                    for (int num7 = 2; num7 < rectangle.Height - 2; num7++)
                    {
                        if (!ptr2->HasVisibleLiquid || ptr2->IsSolid)
                        {
                            ptr2->HasLeftEdge   = false;
                            ptr2->HasTopEdge    = false;
                            ptr2->HasRightEdge  = false;
                            ptr2->HasBottomEdge = false;
                        }
                        else
                        {
                            LiquidRenderer.LiquidCache liquidCache  = ptr2[-1];
                            LiquidRenderer.LiquidCache liquidCache2 = ptr2[1];
                            LiquidRenderer.LiquidCache liquidCache3 = ptr2[-rectangle.Height];
                            LiquidRenderer.LiquidCache liquidCache4 = ptr2[rectangle.Height];
                            float num8  = 0f;
                            float num9  = 1f;
                            float num10 = 0f;
                            float num11 = 1f;
                            float visibleLiquidLevel = ptr2->VisibleLiquidLevel;
                            if (!liquidCache.HasVisibleLiquid)
                            {
                                num10 += liquidCache2.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                            }
                            if (!liquidCache2.HasVisibleLiquid && !liquidCache2.IsSolid && !liquidCache2.IsHalfBrick)
                            {
                                num11 -= liquidCache.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                            }
                            if (!liquidCache3.HasVisibleLiquid && !liquidCache3.IsSolid && !liquidCache3.IsHalfBrick)
                            {
                                num8 += liquidCache4.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                            }
                            if (!liquidCache4.HasVisibleLiquid && !liquidCache4.IsSolid && !liquidCache4.IsHalfBrick)
                            {
                                num9 -= liquidCache3.VisibleLiquidLevel * (1f - visibleLiquidLevel);
                            }
                            ptr2->LeftWall   = num8;
                            ptr2->RightWall  = num9;
                            ptr2->BottomWall = num11;
                            ptr2->TopWall    = num10;
                            Point zero = Point.Zero;
                            ptr2->HasTopEdge    = ((!liquidCache.HasVisibleLiquid && !liquidCache.IsSolid) || num10 != 0f);
                            ptr2->HasBottomEdge = ((!liquidCache2.HasVisibleLiquid && !liquidCache2.IsSolid) || num11 != 1f);
                            ptr2->HasLeftEdge   = ((!liquidCache3.HasVisibleLiquid && !liquidCache3.IsSolid) || num8 != 0f);
                            ptr2->HasRightEdge  = ((!liquidCache4.HasVisibleLiquid && !liquidCache4.IsSolid) || num9 != 1f);
                            if (!ptr2->HasLeftEdge)
                            {
                                if (ptr2->HasRightEdge)
                                {
                                    zero.X += 32;
                                }
                                else
                                {
                                    zero.X += 16;
                                }
                            }
                            if (ptr2->HasLeftEdge && ptr2->HasRightEdge)
                            {
                                zero.X  = 16;
                                zero.Y += 32;
                                if (ptr2->HasTopEdge)
                                {
                                    zero.Y = 16;
                                }
                            }
                            else if (!ptr2->HasTopEdge)
                            {
                                if (!ptr2->HasLeftEdge && !ptr2->HasRightEdge)
                                {
                                    zero.Y += 48;
                                }
                                else
                                {
                                    zero.Y += 16;
                                }
                            }
                            if (zero.Y == 16 && (ptr2->HasLeftEdge ^ ptr2->HasRightEdge) && (num7 + rectangle.Y) % 2 == 0)
                            {
                                zero.Y += 16;
                            }
                            ptr2->FrameOffset = zero;
                        }
                        ptr2++;
                    }
                    ptr2 += 4;
                }
                ptr2  = ptr;
                ptr2 += num;
                for (int num12 = 2; num12 < rectangle.Width - 2; num12++)
                {
                    for (int num13 = 2; num13 < rectangle.Height - 2; num13++)
                    {
                        if (ptr2->HasVisibleLiquid)
                        {
                            LiquidRenderer.LiquidCache liquidCache  = ptr2[-1];
                            LiquidRenderer.LiquidCache liquidCache2 = ptr2[1];
                            LiquidRenderer.LiquidCache liquidCache3 = ptr2[-rectangle.Height];
                            LiquidRenderer.LiquidCache liquidCache4 = ptr2[rectangle.Height];
                            ptr2->VisibleLeftWall   = ptr2->LeftWall;
                            ptr2->VisibleRightWall  = ptr2->RightWall;
                            ptr2->VisibleTopWall    = ptr2->TopWall;
                            ptr2->VisibleBottomWall = ptr2->BottomWall;
                            if (liquidCache.HasVisibleLiquid && liquidCache2.HasVisibleLiquid)
                            {
                                if (ptr2->HasLeftEdge)
                                {
                                    ptr2->VisibleLeftWall = (ptr2->LeftWall * 2f + liquidCache.LeftWall + liquidCache2.LeftWall) * 0.25f;
                                }
                                if (ptr2->HasRightEdge)
                                {
                                    ptr2->VisibleRightWall = (ptr2->RightWall * 2f + liquidCache.RightWall + liquidCache2.RightWall) * 0.25f;
                                }
                            }
                            if (liquidCache3.HasVisibleLiquid && liquidCache4.HasVisibleLiquid)
                            {
                                if (ptr2->HasTopEdge)
                                {
                                    ptr2->VisibleTopWall = (ptr2->TopWall * 2f + liquidCache3.TopWall + liquidCache4.TopWall) * 0.25f;
                                }
                                if (ptr2->HasBottomEdge)
                                {
                                    ptr2->VisibleBottomWall = (ptr2->BottomWall * 2f + liquidCache3.BottomWall + liquidCache4.BottomWall) * 0.25f;
                                }
                            }
                        }
                        ptr2++;
                    }
                    ptr2 += 4;
                }
                ptr2  = ptr;
                ptr2 += num;
                for (int num14 = 2; num14 < rectangle.Width - 2; num14++)
                {
                    for (int num15 = 2; num15 < rectangle.Height - 2; num15++)
                    {
                        if (ptr2->HasLiquid)
                        {
                            LiquidRenderer.LiquidCache liquidCache  = ptr2[-1];
                            LiquidRenderer.LiquidCache liquidCache2 = ptr2[1];
                            LiquidRenderer.LiquidCache liquidCache3 = ptr2[-rectangle.Height];
                            LiquidRenderer.LiquidCache liquidCache4 = ptr2[rectangle.Height];
                            if (ptr2->HasTopEdge && !ptr2->HasBottomEdge && (ptr2->HasLeftEdge ^ ptr2->HasRightEdge))
                            {
                                if (ptr2->HasRightEdge)
                                {
                                    ptr2->VisibleRightWall = liquidCache2.VisibleRightWall;
                                    ptr2->VisibleTopWall   = liquidCache3.VisibleTopWall;
                                }
                                else
                                {
                                    ptr2->VisibleLeftWall = liquidCache2.VisibleLeftWall;
                                    ptr2->VisibleTopWall  = liquidCache4.VisibleTopWall;
                                }
                            }
                            else if (liquidCache2.FrameOffset.X == 16 && liquidCache2.FrameOffset.Y == 32)
                            {
                                if (ptr2->VisibleLeftWall > 0.5f)
                                {
                                    ptr2->VisibleLeftWall = 0f;
                                    ptr2->FrameOffset     = new Point(0, 0);
                                }
                                else if (ptr2->VisibleRightWall < 0.5f)
                                {
                                    ptr2->VisibleRightWall = 1f;
                                    ptr2->FrameOffset      = new Point(32, 0);
                                }
                            }
                        }
                        ptr2++;
                    }
                    ptr2 += 4;
                }
                ptr2  = ptr;
                ptr2 += num;
                for (int num16 = 2; num16 < rectangle.Width - 2; num16++)
                {
                    for (int num17 = 2; num17 < rectangle.Height - 2; num17++)
                    {
                        if (ptr2->HasLiquid)
                        {
                            LiquidRenderer.LiquidCache liquidCache  = ptr2[-1];
                            LiquidRenderer.LiquidCache liquidCache2 = ptr2[1];
                            LiquidRenderer.LiquidCache liquidCache3 = ptr2[-rectangle.Height];
                            LiquidRenderer.LiquidCache liquidCache4 = ptr2[rectangle.Height];
                            if (!ptr2->HasBottomEdge && !ptr2->HasLeftEdge && !ptr2->HasTopEdge && !ptr2->HasRightEdge)
                            {
                                if (liquidCache3.HasTopEdge && liquidCache.HasLeftEdge)
                                {
                                    ptr2->FrameOffset.X     = Math.Max(4, (int)(16f - liquidCache.VisibleLeftWall * 16f)) - 4;
                                    ptr2->FrameOffset.Y     = 48 + Math.Max(4, (int)(16f - liquidCache3.VisibleTopWall * 16f)) - 4;
                                    ptr2->VisibleLeftWall   = 0f;
                                    ptr2->VisibleTopWall    = 0f;
                                    ptr2->VisibleRightWall  = 1f;
                                    ptr2->VisibleBottomWall = 1f;
                                }
                                else if (liquidCache4.HasTopEdge && liquidCache.HasRightEdge)
                                {
                                    ptr2->FrameOffset.X     = 32 - Math.Min(16, (int)(liquidCache.VisibleRightWall * 16f) - 4);
                                    ptr2->FrameOffset.Y     = 48 + Math.Max(4, (int)(16f - liquidCache4.VisibleTopWall * 16f)) - 4;
                                    ptr2->VisibleLeftWall   = 0f;
                                    ptr2->VisibleTopWall    = 0f;
                                    ptr2->VisibleRightWall  = 1f;
                                    ptr2->VisibleBottomWall = 1f;
                                }
                            }
                        }
                        ptr2++;
                    }
                    ptr2 += 4;
                }
                ptr2  = ptr;
                ptr2 += num;
                fixed(LiquidRenderer.LiquidDrawCache *ptr3 = &this._drawCache[0])
                {
                    fixed(Color *ptr4 = &this._waveMask[0])
                    {
                        LiquidRenderer.LiquidDrawCache *ptr5 = ptr3;
                        Color *ptr6 = ptr4;

                        for (int num18 = 2; num18 < rectangle.Width - 2; num18++)
                        {
                            for (int num19 = 2; num19 < rectangle.Height - 2; num19++)
                            {
                                if (ptr2->HasVisibleLiquid)
                                {
                                    float num20 = Math.Min(0.75f, ptr2->VisibleLeftWall);
                                    float num21 = Math.Max(0.25f, ptr2->VisibleRightWall);
                                    float num22 = Math.Min(0.75f, ptr2->VisibleTopWall);
                                    float num23 = Math.Max(0.25f, ptr2->VisibleBottomWall);
                                    if (ptr2->IsHalfBrick && num23 > 0.5f)
                                    {
                                        num23 = 0.5f;
                                    }
                                    ptr5->IsVisible       = (ptr2->HasWall || !ptr2->IsHalfBrick || !ptr2->HasLiquid);
                                    ptr5->SourceRectangle = new Rectangle((int)(16f - num21 * 16f) + ptr2->FrameOffset.X, (int)(16f - num23 * 16f) + ptr2->FrameOffset.Y, (int)Math.Ceiling((double)((num21 - num20) * 16f)), (int)Math.Ceiling((double)((num23 - num22) * 16f)));
                                    ptr5->IsSurfaceLiquid = (ptr2->FrameOffset.X == 16 && ptr2->FrameOffset.Y == 0 && (double)(num19 + rectangle.Y) > Main.worldSurface - 40.0);
                                    ptr5->Opacity         = ptr2->Opacity;
                                    ptr5->LiquidOffset    = new Vector2((float)Math.Floor((double)(num20 * 16f)), (float)Math.Floor((double)(num22 * 16f)));
                                    ptr5->Type            = ptr2->VisibleType;
                                    ptr5->HasWall         = ptr2->HasWall;
                                    byte b  = LiquidRenderer.WAVE_MASK_STRENGTH[(int)ptr2->VisibleType];
                                    byte b2 = (byte)(b >> 1);
                                    ptr6->R = b2;
                                    ptr6->G = b2;
                                    ptr6->B = LiquidRenderer.VISCOSITY_MASK[(int)ptr2->VisibleType];
                                    ptr6->A = b;
                                    LiquidRenderer.LiquidCache *ptr7 = ptr2 - 1;
                                    if (num19 != 2 && !ptr7->HasVisibleLiquid && !ptr7->IsSolid && !ptr7->IsHalfBrick)
                                    {
                                        *(ptr6 - 1) = *ptr6;
                                    }
                                }
                                else
                                {
                                    ptr5->IsVisible = false;
                                    int  num24 = (!ptr2->IsSolid && !ptr2->IsHalfBrick) ? 4 : 3;
                                    byte b3    = LiquidRenderer.WAVE_MASK_STRENGTH[num24];
                                    byte b4    = (byte)(b3 >> 1);
                                    ptr6->R = b4;
                                    ptr6->G = b4;
                                    ptr6->B = LiquidRenderer.VISCOSITY_MASK[num24];
                                    ptr6->A = b3;
                                }
                                ptr2++;
                                ptr5++;
                                ptr6++;
                            }
                            ptr2 += 4;
                        }
                    }
                }

                ptr2 = ptr;
                for (int num25 = rectangle.X; num25 < rectangle.X + rectangle.Width; num25++)
                {
                    for (int num26 = rectangle.Y; num26 < rectangle.Y + rectangle.Height; num26++)
                    {
                        if (ptr2->VisibleType == 1 && ptr2->HasVisibleLiquid && Dust.lavaBubbles < 200)
                        {
                            if (this._random.Next(700) == 0)
                            {
                                Dust.NewDust(new Vector2((float)(num25 * 16), (float)(num26 * 16)), 16, 16, 35, 0f, 0f, 0, Color.White, 1f);
                            }
                            if (this._random.Next(350) == 0)
                            {
                                int num27 = Dust.NewDust(new Vector2((float)(num25 * 16), (float)(num26 * 16)), 16, 8, 35, 0f, 0f, 50, Color.White, 1.5f);
                                Main.dust[num27].velocity *= 0.8f;
                                Dust expr_11BF_cp_0_cp_0 = Main.dust[num27];
                                expr_11BF_cp_0_cp_0.velocity.X = expr_11BF_cp_0_cp_0.velocity.X * 2f;
                                Dust expr_11DA_cp_0_cp_0 = Main.dust[num27];
                                expr_11DA_cp_0_cp_0.velocity.Y = expr_11DA_cp_0_cp_0.velocity.Y - (float)this._random.Next(1, 7) * 0.1f;
                                if (this._random.Next(10) == 0)
                                {
                                    Dust expr_1213_cp_0_cp_0 = Main.dust[num27];
                                    expr_1213_cp_0_cp_0.velocity.Y = expr_1213_cp_0_cp_0.velocity.Y * (float)this._random.Next(2, 5);
                                }
                                Main.dust[num27].noGravity = true;
                            }
                        }
                        ptr2++;
                    }
                }
            }

            if (this.WaveFilters != null)
            {
                this.WaveFilters(this._waveMask, this.GetCachedDrawArea());
            }
        }