Exemple #1
0
        public static void Expand(Block to, BlockLightSource source, sbyte light, Block from, BlockFace fromFace)
        {
            var queue = new Queue <Block>();

            Expand(queue, to, source, light, from, fromFace);
            UpdateRender(queue);
        }
Exemple #2
0
        public static void RemoveLightSource(BlockLightSource source)
        {
            var queue = new Queue <Block>();
            var list  = new ELinkedQueue <Block>();

            RemoveLight(list, source.Block, source);
            GetNearbyLights(queue, list);
            ExpandNearbyLights(list, null);
            UpdateRender(queue);
        }
Exemple #3
0
        public static void ExpandFrom(Block from, BlockLightSource source, sbyte light)
        {
            var queue = new Queue <Block>();

            for (var i = 0; i < Faces; i++)
            {
                var face = (BlockFace)i;
                if (!from.CanLightPassThrough(face))
                {
                    continue;
                }
                var opposite  = BlockFaceMethods.GetOpposite(face);
                var neighbour = from.GetNeighbour((BlockFace)i);
                Expand(queue, neighbour, source, light, from, opposite);
            }

            UpdateRender(queue);
        }
Exemple #4
0
        private static void Expand(Queue <Block> updatedBlocks, Block to, BlockLightSource source,
                                   sbyte light, Block from, BlockFace fromFace)
        {
            if (to == null || !to.CanLightBePassedFrom(fromFace, from))
            {
                return;
            }
            var blockLight = to.BlockLight;

            if (blockLight.Light >= light)
            {
                return;
            }

            blockLight.Light  = light;
            blockLight.Source = source;
            updatedBlocks?.Enqueue(to);

            var toLight = (sbyte)(light - to.StaticData.BlockLightPassReduction);

            if (toLight < 1)
            {
                return;
            }

            for (var i = 0; i < Faces; i++)
            {
                var face = (BlockFace)i;

                if (!to.CanLightPassThrough(face))
                {
                    continue;
                }
                var opposite  = BlockFaceMethods.GetOpposite(face);
                var neighbour = to.GetNeighbour((BlockFace)i);
                if (neighbour == null)
                {
                    continue;
                }


                Expand(updatedBlocks, neighbour, source, toLight, to, opposite);
            }
        }
Exemple #5
0
        public Block(BlockStaticData staticData, Chunk chunk, Vector3i position, Rgba32I textureFilter)
        {
            _weakReference = new WeakReference <Block>(this);

            _staticData      = staticData;
            _chunk           = chunk;
            _position        = position;
            _collidableFaces = new bool[6];
            _textureFilter   = textureFilter;
            _neighbours      = new WeakReference <Block> [6];

            _blockLight = new BlockLight();
            var lightSource = staticData.LightSource;

            _blockLightSource = lightSource ? new BlockLightSource(this, staticData.LightSourceLight) : null;
            if (!lightSource)
            {
                return;
            }
            _blockLight.Light  = _blockLightSource.SourceLight;
            _blockLight.Source = _blockLightSource;
        }
Exemple #6
0
 protected bool Equals(BlockLightSource other)
 {
     return(_block.Position.Equals(other.Block.Position));
 }
Exemple #7
0
        private static void RemoveLight(ELinkedList <Block> removedBlocksList, Block block, BlockLightSource source)
        {
            var light = block.BlockLight;

            if (!source.Equals(light.Source))
            {
                return;
            }
            var oldLight = Equals(block.BlockLightSource, source) ? Block.MaxBlockLight : light.Light;

            light.Light  = 0;
            light.Source = null;
            removedBlocksList.Add(block);

            for (var i = 0; i < Faces; i++)
            {
                var face      = (BlockFace)i;
                var opposite  = BlockFaceMethods.GetOpposite(face);
                var neighbour = block.GetNeighbour((BlockFace)i);
                if (neighbour == null)
                {
                    continue;
                }


                if (!block.CanLightPassThrough(face) || !neighbour.CanLightBePassedFrom(opposite, block))
                {
                    continue;
                }
                if (oldLight < neighbour.BlockLight.Light || !Equals(neighbour.BlockLight.Source, source))
                {
                    continue;
                }
                RemoveLight(removedBlocksList, neighbour, source);
            }
        }