static private void UpdateLuminanceLightVector(TileManager tileManager)
		{
			while(pendingUpdateLights.Count > 0)
			{
				while(pendingUpdateLights.Count > 0)
				{
					long pos = pendingUpdateLights[pendingUpdateLights.Count - 1];
                    pendingUpdateLights.RemoveAt(pendingUpdateLights.Count - 1);

                    TilePosition tilePos = IntToPosition(pos);
					Tile tile = tileManager.GetTile(tilePos);
					
					if (tile.CastShadow == false)
					{
						byte luminance = tile.LightSourceLuminance;

                        if (luminance > 0)
                        {
                            luminance --;

                            for (int i = 0; i < 6; i++)
                            {
                                switch (i)
                                {
                                    case 0:
                                        tilePos.x -= 1;
                                        break;
                                    case 1:
                                        tilePos.x += 2;
                                        break;
                                    case 2:
                                        tilePos.x -= 1;
                                        tilePos.y -= 1;
                                        break;
                                    case 3:
                                        tilePos.y += 2;
                                        break;
                                    case 4:
                                        tilePos.y -= 1;
                                        tilePos.z -= 1;
                                        break;
                                    case 5:
                                        tilePos.z += 2;
                                        break;
                                }

                                if (tileManager.IsValidTile(tilePos))
                                {
                                    if (tileManager.GetTileLightSourceLuminance(tilePos) < luminance)
                                    {
                                        tileManager.SetTileLightSourceLuminance(tilePos, luminance);
                                        nextPendingUpdateLights.Add(PositionToInt(tilePos.x, tilePos.y, tilePos.z));
                                    }
                                }
                            }
						}
					}
				}

                List<long> old = pendingUpdateLights;
                pendingUpdateLights = nextPendingUpdateLights;
                nextPendingUpdateLights = old;
            }
		}
        static public void UpdateLuminanceDark(TileManager tileManager, TilePosition from)
		{
            updatedTiles.Clear();

            pendingUpdateLights.Add(PositionToInt(from.x, from.y, from.z));
			
			while(pendingUpdateLights.Count > 0)
			{
				while(pendingUpdateLights.Count > 0)
				{
                    long pos = pendingUpdateLights[pendingUpdateLights.Count - 1];
                    pendingUpdateLights.RemoveAt(pendingUpdateLights.Count - 1);

                    TilePosition tilePos = IntToPosition(pos);
					Tile tile = tileManager.GetTile(tilePos);
					
					if (tile.LightSourceLuminance > 0)
					{
						byte oldLuminance = tile.LightSourceLuminance;
                        tileManager.SetTileLightSourceLuminance(tilePos, 0);
						
						updatedTiles.Add(pos);
						
						for (int i = 0; i < 6; i++)
						{
							switch(i)
							{
								case 0:
									tilePos.x -= 1;
									break;
								case 1:
									tilePos.x += 2;
									break;
								case 2:
									tilePos.x -= 1;
									tilePos.y -= 1;
									break;
								case 3:
									tilePos.y += 2;
									break;
								case 4:
                                    tilePos.y -= 1;
									tilePos.z -= 1;
									break;
								case 5:
									tilePos.z += 2;
									break;
							}

                            long nearPos = PositionToInt(tilePos.x, tilePos.y, tilePos.z);
							
							if (tileManager.IsValidTile(tilePos) && 
								updatedTiles.Contains(nearPos) == false)
							{
								int nearLuminance = tileManager.GetTileLightSourceLuminance(tilePos);
								
								if (nearLuminance < oldLuminance)
									nextPendingUpdateLights.Add(nearPos);
								else if (lightsToRecalculate.Contains(nearPos) == false)
									lightsToRecalculate.Add(nearPos);
							}							
						}
					}
				}

                List<long> old = pendingUpdateLights;
				pendingUpdateLights = nextPendingUpdateLights;
				nextPendingUpdateLights = old;
			}

            pendingUpdateLights.AddRange(lightsToRecalculate);
            lightsToRecalculate.Clear();

            UpdateLuminanceLightVector(tileManager);
		}		
        static public void UpdateLuminanceDark(TileManager tileManager, TilePosition from)
		{
            if (tileManager.GetTileAmbientLuminance(from) == 0)
                return;

            updatedTiles.Clear();

            pendingUpdateLights.Add(PositionToInt(from.x, from.y, from.z));

            for (int y = from.y - 1; y >= 0; y--)
            {
                pendingUpdateLights.Add(PositionToInt(from.x, y, from.z));

                if (tileManager.GetTileCastShadow(new TilePosition(from.x, y, from.z)) == true)
                    break;
            }
			
			while(pendingUpdateLights.Count > 0)
			{
				while(pendingUpdateLights.Count > 0)
				{
                    long pos = pendingUpdateLights[pendingUpdateLights.Count - 1];
                    pendingUpdateLights.RemoveAt(pendingUpdateLights.Count - 1);

                    TilePosition tilePos = IntToPosition(pos);
					Tile tile = tileManager.GetTile(tilePos);
					
					if ((tilePos.x == from.x && tilePos.z == from.z) || (tile.AmbientLuminance != 0 && tile.AmbientLuminance != Tile.MAX_LUMINANCE))
					{
                        byte oldLuminance = tile.AmbientLuminance;

                        tileManager.SetTileAmbientLuminance(tilePos, 0);

                        updatedTiles.Add(pos);
						
						for (int i = 0; i < 6; i++)
						{
							switch(i)
							{
								case 0:
									tilePos.x -= 1;
									break;
								case 1:
									tilePos.x += 2;
									break;
								case 2:
									tilePos.x -= 1;
									tilePos.y -= 1;
									break;
								case 3:
									tilePos.y += 2;
									break;
								case 4:
                                    tilePos.y -= 1;
									tilePos.z -= 1;
									break;
								case 5:
									tilePos.z += 2;
									break;
							}

                            long nearPos = PositionToInt(tilePos.x, tilePos.y, tilePos.z);
							
							if (tileManager.IsValidTile(tilePos) && 
								updatedTiles.Contains(nearPos) == false)
							{
								int nearLuminance = tileManager.GetTileAmbientLuminance(tilePos);

                                if (nearLuminance <= oldLuminance && nearLuminance != Tile.MAX_LUMINANCE)
									nextPendingUpdateLights.Add(nearPos);
								else if (lightsToRecalculate.Contains(nearPos) == false)
									lightsToRecalculate.Add(nearPos);
							}							
						}
					}
				}
				
				List<long> old = pendingUpdateLights;
				pendingUpdateLights = nextPendingUpdateLights;
				nextPendingUpdateLights = old;
			}

            pendingUpdateLights.AddRange(lightsToRecalculate);
            lightsToRecalculate.Clear();
			
			UpdateLuminanceLightVector(tileManager);
		}