示例#1
0
        private void ShrinkInPos(int x, int y, int z, Chunk chunk, int prevLightLevel, int curLightLevel)
        {
            //当前光照强度为最大值时不收缩
            if (curLightLevel >= WorldConfig.Instance.maxLightLevel)
            {
                return;
            }
            Block b = chunk.GetBlock(x, y, z, true);
            BlockAttributeCalculator calculator = BlockAttributeCalculatorFactory.GetCalculator(b.BlockType);
            int lightDamp = calculator.LightDamp(b.ExtendId);

            if (lightDamp < WorldConfig.Instance.maxLightLevel)
            {
                int lightLevel = chunk.GetBlockLight(x, y, z);
                if (lightLevel > 0)
                {
                    int temp = prevLightLevel - lightDamp;
                    //如果前一个物块比当前物块的太阳光亮,那么减弱当前物块的亮度
                    if (temp > lightLevel)
                    {
                        int nextLightLevel = curLightLevel - lightDamp - 1;
                        if (nextLightLevel < 0)
                        {
                            nextLightLevel = 0;
                        }
                        //如果最终结果没有发生改变,那么不收缩
                        if (nextLightLevel == lightLevel)
                        {
                            return;
                        }
                        chunk.SetBlockLight(x, y, z, nextLightLevel, true);
                        if (!_changedList.Contains(chunk))
                        {
                            _changedList.Add(chunk);
                        }
                        int nextIndex = (x * Chunk.chunkDepth + z) * Chunk.chunkHeight + y;
                        _lightBfsQueue.Enqueue(NodeCache.Instance.GetShrinkNode(nextIndex, lightLevel, nextLightLevel, chunk));
                    }
                    //如果前一个物块比当前物块的太阳光暗,那么增强前一个物块的亮度
                    else if (temp < lightLevel)
                    {
                        int nextIndex = (x * Chunk.chunkDepth + z) * Chunk.chunkHeight + y;
                        _lightSpread.AddSpreadNode(NodeCache.Instance.GetSpreadNode(nextIndex, lightLevel, chunk));
                    }
                }
            }
        }
        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);
        }