示例#1
0
 private void DefloodLight(IEnumerable<Vector3i> start)
 {
     FastStack<Vector3i> q = new FastStack<Vector3i>();
     q.Initialize(1024);
     Vector3i ss = new Vector3i();
     foreach (var s in start)
     {
         q.Push(s);
         ss = s;
     }
     Dictionary<Vector3i, bool> reflood = new Dictionary<Vector3i, bool>();
     int searched = 1;
     for (; ; )
     {
         if (q.Count == 0)
         {
             break;
         }
         Vector3i v = q.Pop();
         searched++;
         if (distancesquare(v, new Vector3i(ss.x, ss.y, ss.z)) > maxlight * 2 * maxlight * 2)
         {
             continue;
         }
         int vblock = map.GetBlock(v.x, v.y, v.z);
         if (!data.GrassGrowsUnder(vblock)
             && data.GetLightRadius(vblock) == 0)
         {
             continue;
         }
         int vlight = LightGetBlock(v.x, v.y, v.z);
         if (vlight == maxlight
             || data.GetLightRadius(vblock) != 0)
         {
             reflood[v] = true;
             continue;
         }
         if (vlight == minlight)
         {
             continue;
         }
         SetLight(v.x, v.y, v.z, minlight);
         foreach (var n in BlocksNear(v.x, v.y, v.z))
         {
             if (!MapUtil.IsValidPos(map, n.x, n.y, n.z))
             {
                 continue;
             }
             if (LightGetBlock(n.x, n.y, n.z) < vlight)
             {
                 q.Push(n);
             }
             else
             {
                 reflood[n] = true;
             }
         }
     }
     //Console.WriteLine("reflood: {0}, searched: {1}", reflood.Keys.Count, searched);
     foreach (var p in reflood.Keys)
     {
         currentlightchunk = null;
         FloodLight(p.x, p.y, p.z);
     }
 }