Terraria.WorldSections.GetNextMapDraw C# (CSharp) Method

GetNextMapDraw() public method

public GetNextMapDraw ( Vector2 playerPos, int &x, int &y ) : bool
playerPos Vector2
x int
y int
return bool
        public bool GetNextMapDraw(Vector2 playerPos, out int x, out int y)
        {
            if (this.mapSectionsLeft <= 0)
            {
                x = -1;
                y = -1;
                return false;
            }
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            int num1 = 0;
            int num2 = 0;
            Vector2 vector2 = this.prevMap.centerPos;
            playerPos *= 1 / 16;
            int sectionX = Netplay.GetSectionX((int)playerPos.X);
            int sectionY = Netplay.GetSectionY((int)playerPos.Y);
            int num3 = Netplay.GetSectionX((int)vector2.X);
            int num4 = Netplay.GetSectionY((int)vector2.Y);
            int num5;
            if (num3 != sectionX || num4 != sectionY)
            {
                vector2 = playerPos;
                num3 = sectionX;
                num4 = sectionY;
                num5 = 4;
                x = sectionX;
                y = sectionY;
            }
            else
            {
                num5 = this.prevMap.leg;
                x = this.prevMap.X;
                y = this.prevMap.Y;
                num1 = this.prevMap.xDir;
                num2 = this.prevMap.yDir;
            }
            int num6 = (int)((double)playerPos.X - ((double)num3 + 0.5) * 200.0);
            int num7 = (int)((double)playerPos.Y - ((double)num4 + 0.5) * 150.0);
            if (num1 == 0)
            {
                num1 = num6 <= 0 ? 1 : -1;
                num2 = num7 <= 0 ? 1 : -1;
            }
            int num8 = 0;
            bool flag1 = false;
            bool flag2 = false;
            while (true)
            {
                if (num8 == 4)
                {
                    if (!flag2)
                    {
                        flag2 = true;
                        x = num3;
                        y = num4;
                        num6 = (int)((double)vector2.X - ((double)num3 + 0.5) * 200.0);
                        num7 = (int)((double)vector2.Y - ((double)num4 + 0.5) * 150.0);
                        num1 = num6 <= 0 ? 1 : -1;
                        num2 = num7 <= 0 ? 1 : -1;
                        num5 = 4;
                        num8 = 0;
                    }
                    else
                        break;
                }
                if (y >= 0 && y < this.height && (x >= 0 && x < this.width))
                {
                    flag1 = false;
                    if (!this.data[y * this.width + x][2])
                        goto label_14;
                }
                int num9 = x - num3;
                int num10 = y - num4;
                if (num9 == 0 || num10 == 0)
                {
                    if (num5 == 4)
                    {
                        if (num9 == 0 && num10 == 0)
                        {
                            if (Math.Abs(num6) > Math.Abs(num7))
                                y -= num2;
                            else
                                x -= num1;
                        }
                        else
                        {
                            if (num9 != 0)
                                x += num9 / Math.Abs(num9);
                            if (num10 != 0)
                                y += num10 / Math.Abs(num10);
                        }
                        num5 = 0;
                        num8 = -2;
                        flag1 = true;
                    }
                    else
                    {
                        if (num9 == 0)
                            num2 = num10 <= 0 ? 1 : -1;
                        else
                            num1 = num9 <= 0 ? 1 : -1;
                        x += num1;
                        y += num2;
                        ++num5;
                    }
                    if (flag1)
                        ++num8;
                    else
                        flag1 = true;
                }
                else
                {
                    x += num1;
                    y += num2;
                }
            }
            throw new Exception("Infinite loop in WorldSections.GetNextMapDraw");
        label_14:
            this.data[y * this.width + x][2] = true;
            --this.mapSectionsLeft;
            this.prevMap.centerPos = playerPos;
            this.prevMap.X = x;
            this.prevMap.Y = y;
            this.prevMap.leg = num5;
            this.prevMap.xDir = num1;
            this.prevMap.yDir = num2;
            stopwatch.Stop();
            return true;
        }