Ejemplo n.º 1
0
        private void _UpdateTransparentBottom(FogTransparentRange rangeData, int view_lt_x, int view_lt_y,
                                              int view_left, int view_right, int view_top, int view_bottom)
        {
            int xMin = Max(view_left, rangeData.l);
            int xMax = Min(view_right, rangeData.r + 1);
            int yMin = Max(view_top, rangeData.b);
            int yMax = Min(view_bottom, rangeData.size);

            _UpdateTransparentCustom(rangeData, view_lt_x, view_lt_y, xMin, xMax, yMin, yMax);
        }
Ejemplo n.º 2
0
        public void UpdateTransparent(int x, int y, int r)
        {
            FogTransparentRange rangeData = _GetFogTransparentRange(r);
            /// 先求取视野范围内的有效坐标
            /// 即根据视点坐标求出视野范围内有效用于战场的尺寸范围
            /// 有效坐标奉行左闭右开原则
            //if (x - r >= 0) {
            //	vl = 0;
            //} else {
            //	vl = r - x;
            //}
            /// 视野范围左侧有效值
            int view_l = (x - r >= 0) ? 0 : (r - x);
            //if (x + r < w) {
            //	vr = 2 * r + 1;
            //} else {
            //	vr = r - x + w;
            //}
            /// 视野范围右侧有效值
            int view_r = (x + r < w) ? (2 * r + 1) : (r - x + w);
            //if (y - r >= 0) {
            //	vt = 0;
            //} else {
            //	vt = r - y;
            //}
            /// 视野范围上侧有效值(上侧为y值小的一侧)
            int view_t = (y - r >= 0) ? 0 : (r - y);
            //if (y + r < h) {
            //	vb = 2 * r + 1;
            //} else {
            //	vb = r - y + h;
            //}
            /// 视野范围下侧有效值(下侧为y值大的一侧)
            int view_b = (y + r < h) ? (2 * r + 1) : (r - y + h);
            /// 视野范围最小点x值
            int view_lt_x = x - r;
            /// 视野范围最小点y值
            int view_lt_y = y - r;

            /// 操作九宫格四边 上(y值为0开始)
            _UpdateTransparentTop(rangeData, view_lt_x, view_lt_y, view_l, view_r, view_t, view_b);
            /// 操作九宫格四边 左(x值为0开始)
            _UpdateTransparentLeft(rangeData, view_lt_x, view_lt_y, view_l, view_r, view_t, view_b);
            /// 操作九宫格中心全部为透明区域
            _UpdateTransparentCenter(rangeData, view_lt_x, view_lt_y, view_l, view_r, view_t, view_b);
            /// 操作九宫格四边 右
            _UpdateTransparentRight(rangeData, view_lt_x, view_lt_y, view_l, view_r, view_t, view_b);
            /// 操作九宫格四边 下
            _UpdateTransparentBottom(rangeData, view_lt_x, view_lt_y, view_l, view_r, view_t, view_b);

            /// 忽略九宫格四角操作
        }
Ejemplo n.º 3
0
        private FogTransparentRange _GetFogTransparentRange(int r)
        {
            FogTransparentRange rangeData = null;

            if (!fogRangeDic.ContainsKey(r))
            {
                rangeData      = new FogTransparentRange(r);
                fogRangeDic[r] = rangeData;
            }
            else
            {
                rangeData = fogRangeDic[r];
            }
            return(rangeData);
        }
Ejemplo n.º 4
0
 private void _UpdateTransparentCustom(FogTransparentRange rangeData, int view_lt_x, int view_lt_y, int xMin,
                                       int xMax, int yMin, int yMax)
 {
     if (xMin < xMax && yMin < yMax)
     {
         for (int i = xMin, j = 0; i < xMax; i++)
         {
             for (j = yMin; j < yMax; j++)
             {
                 if (rangeData.array[i, j])
                 {
                     SetTransparent(view_lt_x + i, view_lt_y + j);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
        private void _UpdateTransparentCenter(FogTransparentRange rangeData, int view_lt_x, int view_lt_y,
                                              int view_left, int view_right, int view_top, int view_bottom)
        {
            int xMin = Max(view_left, rangeData.l) + view_lt_x;
            int xMax = Min(view_right, rangeData.r + 1) + view_lt_x;
            int yMin = Max(view_top, rangeData.t) + view_lt_y;
            int yMax = Min(view_bottom, rangeData.b + 1) + view_lt_y;

            if (xMin < xMax && yMin < yMax)
            {
                /// 旧方案,使用遍历依次对各点设置alpha为0
                //for (int i = xMin, j = 0; i < xMax; i++) {
                //	for (j = yMin; j < yMax; j++) {
                //		SetTransparent (view_lt_x + i, view_lt_y + j);
                //	}
                //}

                /// 新方案,计算当前区域具体方格数据,减少遍历次数,提高设置alpha的效率
                /// 求出方形透明区域内的几个临界值,然后采用for循环与位运算结合求值
                int _left_array_x   = xMin >> AlphaArrayBitSize;
                int _left_bit_x     = xMin & AlphaArraySizeMask;
                int _right_array_x  = (xMax - 1) >> AlphaArrayBitSize;
                int _right_bit_x    = (xMax - 1) & AlphaArraySizeMask;
                int _top_array_y    = yMin >> AlphaArrayBitSize;
                int _top_bit_y      = yMin & AlphaArraySizeMask;
                int _bottom_array_y = (yMax - 1) >> AlphaArrayBitSize;
                int _bottom_bit_y   = (yMax - 1) & AlphaArraySizeMask;

                /// 刷新求出区域后的中间场景
                int _c_array_l, _c_array_r, _c_array_t, _c_array_b;
                _c_array_l = (_left_bit_x == 0) ? _left_array_x : (_left_array_x + 1);
                _c_array_r = (_right_bit_x == AlphaArraySize - 1) ? _right_array_x : (_right_array_x - 1);
                _c_array_t = (_top_bit_y == 0) ? _top_array_y : (_top_array_y + 1);
                _c_array_b = (_bottom_bit_y == AlphaArraySize - 1) ? _bottom_array_y : (_bottom_array_y - 1);

                /// top
                for (int i = xMin, j = yMin, jmax = _c_array_t * AlphaArraySize; i < xMax; i++)
                {
                    for (j = yMin; j < jmax; j++)
                    {
                        SetTransparent(i, j);
                    }
                }

                /// left
                for (int i = xMin, j = 0, jbegin = _c_array_t * AlphaArraySize, imax = _c_array_l * AlphaArraySize,
                     jmax = (_c_array_b + 1) * AlphaArraySize; i < imax; i++)
                {
                    for (j = jbegin; j < jmax; j++)
                    {
                        SetTransparent(i, j);
                    }
                }

                /// center
                for (int i = _c_array_l, j = _c_array_t, imax = _c_array_r + 1, jmax = _c_array_b + 1; i < imax; i++)
                {
                    for (j = _c_array_t; j < jmax; j++)
                    {
                        SetArrayTransparent(i, j);
                    }
                }

                /// right
                for (int i = (_c_array_r + 1) * AlphaArraySize, j = 0, jbegin = _c_array_t * AlphaArraySize,
                     jmax = (_c_array_b + 1) * AlphaArraySize; i < xMax; i++)
                {
                    for (j = jbegin; j < jmax; j++)
                    {
                        SetTransparent(i, j);
                    }
                }

                /// bottom
                for (int i = xMin, j = 0, jBegin = (_c_array_b + 1) * AlphaArraySize; i < xMax; i++)
                {
                    for (j = jBegin; j < yMax; j++)
                    {
                        SetTransparent(i, j);
                    }
                }
            }
        }