예제 #1
0
        public void UpdateTransparent(int x, int y, int r)
        {
            FogTransparentRange rangeData = __GetRangeInfo(r);

            /// 先求取视野范围内的有效坐标
            /// 即根据视点坐标求出视野范围内有效用于战场的尺寸范围
            /// 有效坐标奉行小闭大开原则
            int view_l    = (x - r >= 0) ? 0 : (r - x);
            int view_r    = (x + r < w) ? (2 * r + 1) : (r - x + w);
            int view_t    = (y - r >= 0) ? 0 : (r - y);
            int view_b    = (y + r < h) ? (2 * r + 1) : (r - y + h);
            int view_lt_x = x - r;
            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);
            /// 忽略九宫格四角
        }
예제 #2
0
 public void Release()
 {
     totalAlphaArray = null;
     for (int i = 0, imax = __fogRangeList.Count; i < imax; i++)
     {
         __fogRangeList [i].Release();
     }
     __fogRangeList.Clear();
     __fogRangeTable.Clear();
     __fogRangeCache = null;
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Battle.Logic.FogAbout.FogBaseData"/> class.
        /// </summary>
        /// <param name="w">世界地图数据存储宽度.</param>
        /// <param name="h">世界地图数据存储高度.</param>
        public FogBaseData(int w, int h)
        {
            this.w = w;
            this.h = h;

            array_w = (int)System.Math.Ceiling((double)w / AlphaArraySize);
            array_h = (int)System.Math.Ceiling((double)h / AlphaArraySize);

            totalAlphaArray = new ulong [array_w, array_h];

            __fogRangeList  = new List <FogTransparentRange> ();
            __fogRangeTable = new Dictionary <int, int> ();
            __fogRangeCache = null;
        }
예제 #4
0
        private FogTransparentRange __GetRangeInfo(int r)
        {
            if (__fogRangeCache != null && __fogRangeCache.base_r == r)
            {
                return(__fogRangeCache);
            }
            int index;

            if (!__fogRangeTable.TryGetValue(r, out index))
            {
                FogTransparentRange rangeData = new FogTransparentRange(r);
                __fogRangeTable.Add(r, __fogRangeList.Count);
                __fogRangeList.Add(rangeData);
                __fogRangeCache = rangeData;
            }
            else
            {
                __fogRangeCache = __fogRangeList [index];
            }
            return(__fogRangeCache);
        }
예제 #5
0
        private void __UpdateTransparentRight(FogTransparentRange rangeData,
                                              int view_lt_x, int view_lt_y,
                                              int view_left, int view_right, int view_top, int view_bottom)
        {
            int yMin = __Max(view_top, rangeData.t);
            int yMax = __Min(view_bottom, rangeData.b + 1);

            if (yMin < yMax)
            {
                int xMin = __Max(view_left, rangeData.r);
                int xMax = __Min(view_right, rangeData.size);
                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);
                        }
                    }
                }
            }
        }
예제 #6
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) {
        //				// 求出方形透明区域内的几个临界值,然后采用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++) {
        //						totalAlphaArray [i, j] |= TRANSPARENT;
        //					}
        //				}
        //
        //				// 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);
        //					}
        //				}
        //			}
        //		}

        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)
            {
                // 求出方形透明区域内的几个临界值,然后采用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 = (_left_bit_x == 0) ? _left_array_x : (_left_array_x + 1);
                int _c_array_r = (_right_bit_x == AlphaArraySize - 1) ? _right_array_x : (_right_array_x - 1);
                int _c_array_t = (_top_bit_y == 0) ? _top_array_y : (_top_array_y + 1);
                int _c_array_b = (_bottom_bit_y == AlphaArraySize - 1) ? _bottom_array_y : (_bottom_array_y - 1);

                // +---+--------+---+
                // | A |        | B |
                // +---+--------+---+
                // |   |        |   |
                // |   |        |   |
                // |   |        |   |
                // |   |        |   |
                // +---+--------+---+
                // | D |        | C |
                // +---+--------+---+
                int i, j, imax, jmax;

                for (i = _c_array_l, imax = _c_array_r + 1, jmax = _c_array_b + 1; i < imax; i++)
                {
                    for (j = _c_array_t; j < jmax; j++)
                    {
                        totalAlphaArray [i, j] |= TRANSPARENT;
                    }
                }

                int __last_bit_left   = AlphaArraySizeMask - _left_bit_x;
                int __last_bit_right  = _right_bit_x;
                int __last_bit_top    = AlphaArraySizeMask - _top_bit_y;
                int __last_bit_bottom = _bottom_bit_y;

                if (_left_bit_x != 0 && _top_bit_y != 0)
                {
                    totalAlphaArray [_left_array_x, _top_array_y] |= MASK_XMAX_YMAX [__last_bit_left, __last_bit_top];
                }
                if (_left_bit_x != 0 && _bottom_bit_y != AlphaArraySizeMask)
                {
                    totalAlphaArray [_left_array_x, _bottom_array_y] |= MASK_XMAX_YMIN [__last_bit_left, __last_bit_bottom];
                }
                if (_right_bit_x != AlphaArraySizeMask && _top_bit_y != 0)
                {
                    totalAlphaArray [_right_array_x, _top_array_y] |= MASK_XMIN_YMAX [__last_bit_right, __last_bit_top];
                }
                if (_right_bit_x != AlphaArraySizeMask && _bottom_bit_y != AlphaArraySizeMask)
                {
                    totalAlphaArray [_right_array_x, _bottom_array_y] |= MASK_XMIN_YMIN [__last_bit_right, __last_bit_bottom];
                }

                for (i = _c_array_l, imax = _c_array_r + 1; i < imax; i++)
                {
                    totalAlphaArray [i, _top_array_y] |= MASK_XMIN_YMAX [AlphaArraySizeMask, __last_bit_top];
                }
                for (i = _c_array_l, imax = _c_array_r + 1; i < imax; i++)
                {
                    totalAlphaArray [i, _bottom_array_y] |= MASK_XMIN_YMIN [AlphaArraySizeMask, __last_bit_bottom];
                }
                for (j = _c_array_t, jmax = _c_array_b + 1; j < jmax; j++)
                {
                    totalAlphaArray [_left_array_x, j] |= MASK_XMAX_YMAX [__last_bit_left, AlphaArraySizeMask];
                }
                for (j = _c_array_t, jmax = _c_array_b + 1; j < jmax; j++)
                {
                    totalAlphaArray [_right_array_x, j] |= MASK_XMIN_YMAX [__last_bit_right, AlphaArraySizeMask];
                }
            }
        }