Beispiel #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;
        }
Beispiel #2
0
        private void Recycle(LivePixel pixel)
        {
            //TODO..类型池子里找到该粒子所属的对象池子
            //TODO..把他拉出来!!
            //TODO..再把死掉的粒子塞进他的♂去
            //Start..

            if (!dicPixelStackPool.TryGetValue(pixel.GetType(), out pool))
            {
                pool = new Stack <LivePixel>(10);
                dicPixelStackPool[pixel.GetType()] = pool;
            }
            pool.Push(pixel);
        }
Beispiel #3
0
        public T CreateLivePixel <T>(Vector2 pos, EnumCentre.BrushType type) where T : LivePixel, new()
        {
            //TODO...翻一下粒子类型回收池子,看看有没有该类型的回收池子
            //TODO...初始化这个粒子的数据
            //TODO...把该粒子放进堆里(这是还活着的状态的粒子)
            //TODO...返回这个粒子
            //Start...

            Stack <LivePixel> pool = null;

            dicPixelStackPool.TryGetValue(typeof(T), out pool);
            if (pool == null || pool.Count == 0)
            {
                //什么??没有这个类型的粒子回收池子或者回收池子里没有死掉的粒子
                //那就再生一个粒子
                pixel = new T();
            }
            else
            {
                //哈哈哈哈这个类型的回收池子里有死掉的粒子,拿出来,要活的!!!
                pixel        = pool.Pop();
                pixel.isDead = false;
            }


            //初始化
            pixel.position     = pos;
            pixel.renderWStart = pallettePrevData.prevRenderStartEndW.x;
            pixel.renderHStart = pallettePrevData.prevRenderStartEndH.x;
            pixel.renderWEnd   = pallettePrevData.prevRenderStartEndW.y;
            pixel.renderHEnd   = pallettePrevData.prevRenderStartEndH.y;

            pixel.color = dicObjectPixel[type].color;

            //放进活跃堆里
            AddToStack(pixel, pixel.x, pixel.y);

            pixel.Start(this);    //可能会增加GC?


            //返回
            return(pixel as T);
        }
Beispiel #4
0
        //NoGCList<LivePixelStack> stacks = new NoGCList<LivePixelStack>(3000, 10);
        //List<LivePixelStack> stacks = new List<LivePixelStack>(3000);
        private void UpdateToDoSth()
        {
            //TODO...遍历对象(还没被回收的)池子中所有粒子对象
            //TODO...拿到各个粒子对象后,各个进行数据操作, 像他们的移动位置,进行纹理更改?
            //TODO...从特定类型的回收对象池子里拿出特定类型的粒子
            //Start...

            if (dicMapLivePixelStack == null | dicMapLivePixelStack.Count == 0)
            {
                return;
            }

            int key, curframe, i, j, newkey;

            curframe = Time.frameCount;

            #region -- 20190609 --

            //List<LivePixelStack> stacks = new List<LivePixelStack>(dicMapLivePixelStack.Values);

            //foreach (LivePixelStack stack in stacks)
            //{
            //    List<LivePixel> pixels = stack.livePixels;

            //    if (pixels.Count == 0)
            //        continue;

            //    Color lastTopColor = stack.topColor;

            //    key = KeyForXY(stack.x, stack.y);

            //    for (i = pixels.Count - 1; i >= 0; i--)
            //    {
            //        LivePixel pixel = pixels[i];

            //        if (pixel.lastUpdateFrame == curframe)
            //            continue;

            //        pixel.Update(this);

            //        pixel.lastUpdateFrame = curframe;

            //        if (i >= pixels.Count || pixels[i] != pixel)        //这个粒子可能已经死了
            //            continue;

            //        newkey = KeyForXY(pixel.x, pixel.y);

            //        if (pixel.isDead)
            //        {
            //            //快把这对象里的粒子移除了,因为他死了
            //            pixels.RemoveAt(i);
            //            //如果这个粒子像素是透明的,那就不要覆盖背景了
            //            if (pixel.color.a > 0)
            //                SetPixel(pixel.x, pixel.y, pixel.color);    //如果是单一像素,so 单一颜色 colors.length = 1··
            //            Recycle(pixel);
            //        }
            //        else if (newkey != key)
            //        {
            //            // 这个粒子已经移动了.  那就把它从池子里移除
            //            // 然后再把新的粒子添加进池子来替换他
            //            pixels.RemoveAt(i);
            //            AddToStack(pixel, pixel.x, pixel.y);
            //        }
            //    }

            //    //检查这两个对象(stack),颜色是否相同,相同说明这个对象里的粒子已经静止了,不相同说明正在运动,那就清除之前的渲染位置的粒子纹理,从而实现粒子纹理位移
            //    if (stack.topColor != lastTopColor)
            //        stack.needsDraw = true;
            //}
            #endregion

            #region -- 20190614 --
            Dictionary <int, LivePixelStack> .KeyCollection stacksKey = dicMapLivePixelStack.Keys;

            //拿到迭代器
            Dictionary <int, LivePixelStack> .KeyCollection.Enumerator enumerator = stacksKey.GetEnumerator();
            while (enumerator.MoveNext())
            {
                keys.Add(enumerator.Current);
            }

            for (j = 0; j < keys.Count; j++)
            {
                List <LivePixel> pixels = dicMapLivePixelStack[keys[j]].livePixels;

                if (pixels.Count == 0)
                {
                    continue;
                }

                Color lastTopColor = dicMapLivePixelStack[keys[j]].topColor;

                key = KeyForXY(dicMapLivePixelStack[keys[j]].x, dicMapLivePixelStack[keys[j]].y);

                for (i = pixels.Count - 1; i >= 0; i--)
                {
                    LivePixel pixel = pixels[i];

                    if (pixel.lastUpdateFrame == curframe)
                    {
                        continue;
                    }

                    pixel.Update(this);

                    pixel.lastUpdateFrame = curframe;

                    if (i >= pixels.Count || pixels[i] != pixel)        //这个粒子可能已经死了
                    {
                        continue;
                    }

                    newkey = KeyForXY(pixel.x, pixel.y);

                    if (pixel.isDead)
                    {
                        //快把这对象里的粒子移除了,因为他死了
                        pixels.RemoveAt(i);
                        //如果这个粒子像素是透明的,那就不要覆盖背景了
                        if (pixel.color.a > 0)
                        {
                            SetPixel(pixel.x, pixel.y, pixel.color);    //如果是单一像素,so 单一颜色 colors.length = 1··
                        }
                        Recycle(pixel);
                    }
                    else if (newkey != key)
                    {
                        // 这个粒子已经移动了.  那就把它从池子里移除
                        // 然后再把新的粒子添加进池子来替换他
                        pixels.RemoveAt(i);
                        AddToStack(pixel, pixel.x, pixel.y);
                    }
                }

                //检查这两个对象(stack),颜色是否相同,相同说明这个对象里的粒子已经静止了,不相同说明正在运动,那就清除之前的渲染位置的粒子纹理,从而实现粒子纹理位移
                if (dicMapLivePixelStack[keys[j]].topColor != lastTopColor)
                {
                    dicMapLivePixelStack[keys[j]].needsDraw = true;
                }
            }

            keys.Clear();

            #endregion

            #region -- 20190615 --
            //Dictionary<int, LivePixelStack>.ValueCollection stacksValues = dicMapLivePixelStack.Values;
            //var enumerator = stacksValues.GetEnumerator();
            //while (enumerator.MoveNext())
            //{
            //    stacks.Add(enumerator.Current);
            //}


            //foreach (LivePixelStack stack in stacks)
            //{
            //    List<LivePixel> pixels = stack.livePixels;

            //    if (pixels.Count == 0)
            //        continue;

            //    Color lastTopColor = stack.topColor;

            //    key = KeyForXY(stack.x, stack.y);

            //    for (i = pixels.Count - 1; i >= 0; i--)
            //    {
            //        LivePixel pixel = pixels[i];

            //        if (pixel.lastUpdateFrame == curframe)
            //            continue;

            //        pixel.Update(this);

            //        pixel.lastUpdateFrame = curframe;

            //        if (i >= pixels.Count || pixels[i] != pixel)        //这个粒子可能已经死了
            //            continue;

            //        newkey = KeyForXY(pixel.x, pixel.y);

            //        if (pixel.isDead)
            //        {
            //            //快把这对象里的粒子移除了,因为他死了
            //            pixels.RemoveAt(i);
            //            //如果这个粒子像素是透明的,那就不要覆盖背景了
            //            if (pixel.color.a > 0)
            //                SetPixel(pixel.x, pixel.y, pixel.color);    //如果是单一像素,so 单一颜色 colors.length = 1··
            //            Recycle(pixel);
            //        }
            //        else if (newkey != key)
            //        {
            //            // 这个粒子已经移动了.  那就把它从池子里移除
            //            // 然后再把新的粒子添加进池子来替换他
            //            pixels.RemoveAt(i);
            //            AddToStack(pixel, pixel.x, pixel.y);
            //        }
            //    }

            //    //检查这两个对象(stack),颜色是否相同,相同说明这个对象里的粒子已经静止了,不相同说明正在运动,那就清除之前的渲染位置的粒子纹理,从而实现粒子纹理位移
            //    if (stack.topColor != lastTopColor)
            //        stack.needsDraw = true;
            //}

            //stacks.Clear();
            #endregion
        }