Esempio n. 1
0
        public void SetClean(RectangleInt areaToSetClean)
        {
            int curRow;

            RectangleInt BoundRect = new RectangleInt(0, 0, numCellsX << xCellFactor, numCellsY << yCellFactor);
            RectangleInt Area      = areaToSetClean;

            if (Area.IntersectWithRectangle(BoundRect))
            {
                Area.Right--;
                Area.Top--;
                Area.Left   = Area.Left >> xCellFactor;
                Area.Right  = Area.Right >> xCellFactor;
                Area.Bottom = Area.Bottom >> yCellFactor;
                Area.Top    = Area.Top >> yCellFactor;

                curRow = yTable[Area.Bottom];

                for (int y = Area.Bottom; y <= Area.Top; y++)
                {
                    for (int x = Area.Left; x <= Area.Right; x++)
                    {
                        dirtyCells[curRow + x].isDirty = false;
                    }
                    curRow += numCellsX;
                }
            }
        }
Esempio n. 2
0
        public void SetDirty(RectangleInt areaToSetDirty)
        {
            if (areaToSetDirty.Left >= areaToSetDirty.Right || areaToSetDirty.Bottom >= areaToSetDirty.Top)
            {
                return;
            }

            RectangleInt BoundRect = new RectangleInt(0, 0, numCellsX << xCellFactor, numCellsY << yCellFactor);
            RectangleInt Area      = areaToSetDirty;

            if (Area.IntersectWithRectangle(BoundRect))
            {
                Area.Right--;
                Area.Top--;
                Area.Left   = Area.Left >> xCellFactor;
                Area.Right  = Area.Right >> xCellFactor;
                Area.Bottom = Area.Bottom >> yCellFactor;
                Area.Top    = Area.Top >> yCellFactor;

                int offsetForY = yTable[Area.Bottom];

                for (int y = Area.Bottom; y <= Area.Top; y++)
                {
                    for (int x = Area.Left; x <= Area.Right; x++)
                    {
                        DirtyCell currCell = dirtyCells[offsetForY + x];

                        // if it's not set or it's not totally covered
                        RectangleInt CurCellBounds = new RectangleInt((x << xCellFactor), (y << yCellFactor),
                                                                      ((x << xCellFactor) + xCellSize), ((y << yCellFactor) + yCellSize));
                        // if we are setting it for the first time
                        if (!currCell.isDirty)
                        {
                            currCell.coverage.Left   = Math.Max(Math.Min((areaToSetDirty.Left - CurCellBounds.Left), xCellSize), 0);
                            currCell.coverage.Bottom = Math.Max(Math.Min((areaToSetDirty.Bottom - CurCellBounds.Bottom), yCellSize), 0);
                            currCell.coverage.Right  = Math.Max(Math.Min((areaToSetDirty.Right - CurCellBounds.Left), xCellSize), 0);
                            currCell.coverage.Top    = Math.Max(Math.Min((areaToSetDirty.Top - CurCellBounds.Bottom), yCellSize), 0);
                        }
                        else                         // we are adding to it's coverage
                        {
                            currCell.coverage.Left   = Math.Max(Math.Min(Math.Min(currCell.coverage.Left, (areaToSetDirty.Left - CurCellBounds.Left)), xCellSize), 0);
                            currCell.coverage.Bottom = Math.Max(Math.Min(Math.Min(currCell.coverage.Bottom, (areaToSetDirty.Bottom - CurCellBounds.Bottom)), yCellSize), 0);
                            currCell.coverage.Right  = Math.Max(Math.Min(Math.Max(currCell.coverage.Right, (areaToSetDirty.Right - CurCellBounds.Left)), xCellSize), 0);
                            currCell.coverage.Top    = Math.Max(Math.Min(Math.Max(currCell.coverage.Top, (areaToSetDirty.Top - CurCellBounds.Bottom)), yCellSize), 0);
                        }

                        currCell.isDirty = true;
                    }

                    offsetForY += numCellsX;
                }
            }
        }