Ejemplo n.º 1
0
        private void AddToStack(LivePixel pixel, int x, int y)
        {
            //TODO..从对象(还没被回收的)池子中拿到这个对象
            //TODO..这个对象的数据要重新赋值或者是初始化噢!!!!!!!!!!!!!!!!
            //TODO..最后不要忘记把他塞回那个对象(还没被回收的)池子里去!!!
            //TODO..还有把这个对象标记为要渲染状态! Apply = true
            //Start..

            int key = KeyForXY(x, y);


            if (!dicMapLivePixelStack.TryGetValue(key, out stack))
            {
                if (lpsRecyclePool == null || lpsRecyclePool.Count == 0)
                {
                    stack = new LivePixelStack();       //那就创建一个新的
                }
                else
                {
                    stack = lpsRecyclePool.Pop();   //那就把他推出来!
                }

                //赋值
                stack.x = x;
                stack.y = y;
                stack.backgroundColor     = GetPixel(x, y);
                dicMapLivePixelStack[key] = stack;
            }

            stack.livePixels.Add(pixel);
            stack.needsDraw = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 清除给定区域中可能存在的活着的对象
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void ClearLivePixels(int x, int y)
        {
            if (x < 0 || y < 0 || x >= pallettePrevData.prevTotalWidth || y >= pallettePrevData.prevTotalHeight)
            {
                return;
            }
            LivePixelStack stack = null;

            if (dicMapLivePixelStack.TryGetValue(KeyForXY(x, y), out stack))
            {
                if (stack.livePixels.Count > 0)
                {
                    //使用using 是为了调用dispose接口的方法
                    using (var lps = stack.livePixels.GetEnumerator())
                    {
                        while (lps.MoveNext())
                        {
                            Recycle(lps.Current);        //让他的粒子回池子里带着
                        }
                    }
                    stack.livePixels.Clear();
                    stack.needsDraw = true;     //既然livePixels.count已经不大于零了,那这个对象的背景色是啥就画啥
                }
            }
        }
Ejemplo n.º 3
0
        public void SetPixel(int x, int y, Color color)
        {
            //TODO..检查这个像素的pos是否在可绘制区域
            //TODO..检查对象(还没被回收的)池子里是否有这个位置的对象,有的话就把这个粒子的背景色覆盖
            //TODO..绘制他!
            //Start..

            if (x < 0 || y < 0 || x >= pallettePrevData.prevTotalWidth || y >= pallettePrevData.prevTotalHeight)
            {
                return;
            }

            LivePixelStack stack = null;

            if (dicMapLivePixelStack.TryGetValue(KeyForXY(x, y), out stack))
            {
                stack.backgroundColor = color;
                return;
            }

            SetPixelIgnoringStacks(x, y, color);       //走,去把纹理设置了
        }
Ejemplo n.º 4
0
        public Color GetPixel(int x, int y, bool includeLive = false)
        {
            //TODO...所给位置是否再范围内?
            //TODO...根据位置讯息,翻找对象(还活着的)池子,是否存在对象? 是活的,那就返回他的topColor,否则就backgroundColor
            //TODO...若没有找到对象, 那就判断对象位置所在的瓦片位置
            //TODO...画他!!!
            //Start...

            if (x >= pallettePrevData.prevTotalWidth || y >= pallettePrevData.prevTotalHeight || x < 0 || y < 0)
            {
                return(Color.clear);
            }

            int key, col, row, tx, ty;

            LivePixelStack stack = null;

            key = KeyForXY(x, y);

            if (dicMapLivePixelStack.TryGetValue(key, out stack))
            {
                return(includeLive ? stack.topColor : stack.backgroundColor);
            }

            col = x / pallettePrevData.prevTileWidth; row = y / pallettePrevData.prevTileHeight;

            tx = x % pallettePrevData.prevTileWidth; ty = y % pallettePrevData.prevTileHeight;


            if (pallettePrevData.prevUseGPUTexture2D)
            {
                return(palletteData.tileTexsGPU[col, row].GetPixel(tx, ty));      //GPU
            }
            else
            {
                return(palletteData.tileTexs[col, row].GetPixel(tx, ty));  //CPU
            }
            //return palletteData.tileTexs[col, row].GetPixel(tx, ty);  //CPU
        }
Ejemplo n.º 5
0
 private void DrawStack(LivePixelStack stack)
 {
     SetPixelIgnoringStacks(stack.x, stack.y, stack.topColor);
 }