private List <Chunk> GetBlockLightChangeChunks(Chunk chunk, int x, int y, int z, Block b, List <Chunk> list)
        {
            BlockAttributeCalculator calculator = BlockAttributeCalculatorFactory.GetCalculator(b.BlockType);
            int curBlockLightLevel = calculator.LightLevel(b.ExtendId);
            int blockLightLevel    = chunk.GetBlockLight(x, y, z, true);

            if (curBlockLightLevel > blockLightLevel)
            {
                int             index = (x * Chunk.chunkDepth + z) * Chunk.chunkHeight + y;
                LightSpreadNode node  = NodeCache.Instance.GetSpreadNode(index, curBlockLightLevel, chunk);
                _blockLightSpread.AddSpreadNode(node);
                chunk.SetBlockLight(x, y, z, curBlockLightLevel, true);
            }
            else if (curBlockLightLevel < blockLightLevel)
            {
                int             index = (x * Chunk.chunkDepth + z) * Chunk.chunkHeight + y;
                LightShrinkNode node  = NodeCache.Instance.GetShrinkNode(index, blockLightLevel, curBlockLightLevel, chunk);
                _blockLightShrink.AddShrinkNode(node);
                chunk.SetBlockLight(x, y, z, curBlockLightLevel, true);
            }
            List <Chunk> spreadList = _blockLightSpread.SpreadInChunk(chunk);
            List <Chunk> shrinkList = _blockLightShrink.ShrinkInChunk(chunk);

            for (int i = 0; i < spreadList.Count; i++)
            {
                if (!list.Contains(spreadList[i]))
                {
                    list.Add(spreadList[i]);
                }
            }
            for (int i = 0; i < shrinkList.Count; i++)
            {
                if (!list.Contains(shrinkList[i]))
                {
                    list.Add(shrinkList[i]);
                }
            }
            return(list);
        }
Exemple #2
0
        public List <Chunk> ShrinkInChunk(Chunk chunk)
        {
            int   nextX;
            int   nextY;
            int   nextZ;
            Chunk nextChunk;

            _changedList.Clear();
            while (_lightBfsQueue.Count > 0)
            {
                LightShrinkNode node = _lightBfsQueue.Dequeue();
                int             y    = node.index % Chunk.chunkHeight;
                int             temp = node.index / Chunk.chunkHeight;
                int             z    = temp % Chunk.chunkDepth;
                int             x    = temp / Chunk.chunkDepth;

                Chunk nodeChunk = node.chunk;

                int prevLightLevel = node.prevLightLevel;

                int curLightLevel = node.lightLevel;

                nextX     = x - 1;
                nextChunk = nodeChunk;
                if (nextX < 0)
                {
                    nextChunk = _world.GetChunk(nextX + nodeChunk.worldPos.x, y + nodeChunk.worldPos.y, z + nodeChunk.worldPos.z);
                    nextX     = Chunk.chunkWidth - 1;
                }

                if (nextChunk != null && (nextChunk.isLightDataPrepared || nextChunk.worldPos.EqualOther(chunk.worldPos)))
                {
                    ShrinkInPos(nextX, y, z, nextChunk, prevLightLevel, curLightLevel);
                }


                //x + 1
                nextX     = x + 1;
                nextChunk = nodeChunk;
                if (nextX >= Chunk.chunkWidth)
                {
                    nextChunk = _world.GetChunk(nextX + nodeChunk.worldPos.x, y + nodeChunk.worldPos.y, z + nodeChunk.worldPos.z);
                    nextX     = 0;
                }

                if (nextChunk != null && (nextChunk.isLightDataPrepared || nextChunk.worldPos.EqualOther(chunk.worldPos)))
                {
                    ShrinkInPos(nextX, y, z, nextChunk, prevLightLevel, curLightLevel);
                }

                //z - 1
                nextZ     = z - 1;
                nextChunk = nodeChunk;
                if (nextZ < 0)
                {
                    nextChunk = _world.GetChunk(x + nodeChunk.worldPos.x, y + nodeChunk.worldPos.y, nextZ + nodeChunk.worldPos.z);
                    nextZ     = Chunk.chunkDepth - 1;
                }
                if (nextChunk != null && (nextChunk.isLightDataPrepared || nextChunk.worldPos.EqualOther(chunk.worldPos)))
                {
                    ShrinkInPos(x, y, nextZ, nextChunk, prevLightLevel, curLightLevel);
                }

                //z + 1
                nextZ     = z + 1;
                nextChunk = nodeChunk;
                if (nextZ >= Chunk.chunkDepth)
                {
                    nextChunk = _world.GetChunk(x + nodeChunk.worldPos.x, y + nodeChunk.worldPos.y, nextZ + nodeChunk.worldPos.z);
                    nextZ     = 0;
                }
                if (nextChunk != null && (nextChunk.isLightDataPrepared || nextChunk.worldPos.EqualOther(chunk.worldPos)))
                {
                    ShrinkInPos(x, y, nextZ, nextChunk, prevLightLevel, curLightLevel);
                }

                //y - 1
                nextY = y - 1;
                if (nextY >= 0)
                {
                    ShrinkInPos(x, nextY, z, nodeChunk, prevLightLevel, curLightLevel);
                }

                // y + 1
                nextY = y + 1;
                if (nextY < Chunk.chunkHeight)
                {
                    ShrinkInPos(x, nextY, z, nodeChunk, prevLightLevel, curLightLevel);
                }
            }
            List <Chunk> spreadList = _lightSpread.SpreadInChunk(chunk);

            for (int i = 0; i < spreadList.Count; i++)
            {
                if (!_changedList.Contains(spreadList[i]))
                {
                    _changedList.Add(spreadList[i]);
                }
            }
            return(_changedList);
        }