Example #1
0
    private static void Scatter(Map map, List <Vector3i> list)      // рассеивание
    {
        SunLightMap lightmap = map.GetSunLightmap();

        for (int i = 0; i < list.Count; i++)
        {
            Vector3i pos = list[i];
            if (pos.y < 0)
            {
                continue;
            }

            BlockData block = map.GetBlock(pos);
            int       light = lightmap.GetLight(pos) - LightComputerUtils.GetLightStep(block);
            if (light <= MIN_LIGHT)
            {
                continue;
            }

            foreach (Vector3i dir in Vector3i.directions)
            {
                Vector3i nextPos = pos + dir;
                block = map.GetBlock(nextPos);
                if (block.IsAlpha() && lightmap.SetMaxLight((byte)light, nextPos))
                {
                    list.Add(nextPos);
                }
                if (!block.IsEmpty())
                {
                    LightComputerUtils.SetLightDirty(map, nextPos);
                }
            }
        }
    }
Example #2
0
    private static void RemoveLight(Map map, List <Vector3i> list)
    {
        LightMap lightmap = map.GetLightmap();

        foreach (Vector3i pos in list)
        {
            lightmap.SetLight(MAX_LIGHT, pos);
        }

        List <Vector3i> lightPoints = new List <Vector3i>();

        for (int i = 0; i < list.Count; i++)
        {
            Vector3i pos = list[i];
            if (pos.y < 0)
            {
                continue;
            }

            int light = lightmap.GetLight(pos) - STEP_LIGHT;

            lightmap.SetLight(MIN_LIGHT, pos);
            if (light <= MIN_LIGHT)
            {
                continue;
            }

            foreach (Vector3i dir in Vector3i.directions)
            {
                Vector3i  nextPos = pos + dir;
                BlockData block   = map.GetBlock(nextPos);

                if (block.IsAlpha())
                {
                    if (lightmap.GetLight(nextPos) <= light)
                    {
                        list.Add(nextPos);
                    }
                    else
                    {
                        lightPoints.Add(nextPos);
                    }
                }
                if (block.GetLight() > MIN_LIGHT)
                {
                    lightPoints.Add(nextPos);
                }

                if (!block.IsEmpty())
                {
                    LightComputerUtils.SetLightDirty(map, nextPos);
                }
            }
        }


        Scatter(map, lightPoints);
    }