예제 #1
0
        public ChunkManager(IServiceProvider serviceProvider, GraphicsDevice graphics, World world)
        {
            Graphics = graphics;
            World    = world;

            Options   = serviceProvider.GetRequiredService <IOptionsProvider>().AlexOptions;
            Resources = serviceProvider.GetRequiredService <ResourceManager>();

            var stillAtlas = Resources.Atlas.GetStillAtlas();

            var fogStart = 0;

            Shaders = new RenderingShaders(Graphics);
            Shaders.SetTextures(stillAtlas);
            Shaders.SetAnimatedTextures(Resources.Atlas.GetAtlas(0));

            RenderDistance = Options.VideoOptions.RenderDistance;

            Options.VideoOptions.RenderDistance.Bind(
                (value, newValue) =>
            {
                RenderDistance = newValue;
            });

            Chunks            = new ConcurrentDictionary <ChunkCoordinates, ChunkColumn>();
            CancellationToken = new CancellationTokenSource();

            BlockLightCalculations = new BlockLightCalculations((World)world);
            SkyLightCalculator     = new SkyLightCalculations();

            Func <ChunkCoordinates, ChunkCoordinates, int> orderingTool = (a, b) =>
            {
                var pos       = new ChunkCoordinates(World.Camera.Position);
                var aDistance = a.DistanceTo(pos);
                var bDistance = b.DistanceTo(pos);

                if (aDistance < bDistance)
                {
                    return(-1);
                }

                if (bDistance > aDistance)
                {
                    return(1);
                }

                return(0);
            };

            UpdateQueue       = new FancyQueue <ChunkCoordinates>();
            UpdateBorderQueue = new FancyQueue <ChunkCoordinates>();
            FastUpdateQueue   = new FancyQueue <ChunkCoordinates>();
        }
예제 #2
0
        public ChunkManager(IServiceProvider serviceProvider, GraphicsDevice graphics, World world)
        {
            Graphics = graphics;
            World    = world;

            Options   = serviceProvider.GetRequiredService <IOptionsProvider>().AlexOptions;
            Resources = serviceProvider.GetRequiredService <ResourceManager>();

            var stillAtlas = Resources.Atlas.GetStillAtlas();

            var fogStart = 0;

            Shaders = new RenderingShaders(Graphics);
            Shaders.SetTextures(stillAtlas);
            Shaders.SetAnimatedTextures(Resources.Atlas.GetAtlas(0));

            _renderSampler.MaxMipLevel = stillAtlas.LevelCount;

            RenderDistance = Options.VideoOptions.RenderDistance;

            Options.VideoOptions.RenderDistance.Bind(
                (value, newValue) =>
            {
                RenderDistance = newValue;
            });

            Chunks            = new ConcurrentDictionary <ChunkCoordinates, ChunkColumn>();
            CancellationToken = new CancellationTokenSource();

            BlockLightCalculations = new BlockLightCalculations(world, CancellationToken.Token);
            SkyLightCalculator     = new SkyLightCalculations(CancellationToken.Token);

            UpdateQueue       = new FancyQueue <ChunkCoordinates>();
            UpdateBorderQueue = new FancyQueue <ChunkCoordinates>();
            FastUpdateQueue   = new FancyQueue <ChunkCoordinates>();
        }
예제 #3
0
        private void DrawStaged(IRenderArgs args, out int chunksRendered, out int drawnVertices,
                                Effect forceEffect = null, params RenderStage[] stages)
        {
            var originalBlendState = args.GraphicsDevice.BlendState;

            if (stages == null || stages.Length == 0)
            {
                stages = RenderStages;
            }

            var tempVertices = 0;

            ChunkData[]      chunks  = _renderedChunks;
            RenderingShaders shaders = Shaders;

            //	Effect transparentEffect = shaders.TransparentEffect;

            //if (!Block.FancyGraphics)
            //{
            //	transparentEffect = shaders.OpaqueEffect;
            //}

            foreach (var stage in stages)
            {
                args.GraphicsDevice.BlendState = originalBlendState;

                Effect effect = forceEffect;
                if (forceEffect == null)
                {
                    switch (stage)
                    {
                    case RenderStage.OpaqueFullCube:
                        if (Block.FancyGraphics)
                        {
                            effect = shaders.TransparentEffect;
                        }
                        else
                        {
                            effect = shaders.OpaqueEffect;
                        }
                        break;

                    case RenderStage.Opaque:
                        if (Block.FancyGraphics)
                        {
                            effect = shaders.TransparentEffect;
                        }
                        else
                        {
                            effect = shaders.OpaqueEffect;
                        }
                        //effect = shaders.TransparentEffect;
                        break;

                    case RenderStage.Transparent:
                        effect = shaders.TransparentEffect;
                        break;

                    case RenderStage.Translucent:
                        args.GraphicsDevice.BlendState = TranslucentBlendState;
                        effect = shaders.TranslucentEffect;
                        break;

                    case RenderStage.Animated:
                        effect = shaders.AnimatedEffect;
                        break;

                    case RenderStage.Liquid:
                        //	case RenderStage.AnimatedTranslucent:
                        effect = shaders.AnimatedEffect;

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }


                tempVertices += DrawChunks(args.GraphicsDevice, chunks, effect, stage);
            }

            //	tempChunks = chunks.Count(x => x != null && x.RenderStages != null && x.RenderStages.Count > 0);

            chunksRendered = chunks.Length;
            drawnVertices  = tempVertices;

            args.GraphicsDevice.BlendState = originalBlendState;
        }
예제 #4
0
        private void DrawStaged(IRenderArgs args,
                                Effect forceEffect = null, params RenderStage[] stages)
        {
            var originalBlendState = args.GraphicsDevice.BlendState;

            if (stages == null || stages.Length == 0)
            {
                stages = RenderStages;
            }

            ChunkData[] chunks = _renderedChunks;

            if (CancellationToken.IsCancellationRequested || chunks == null)
            {
                return;
            }

            RenderingShaders shaders = Shaders;

            foreach (var stage in stages)
            {
                args.GraphicsDevice.BlendState = originalBlendState;

                Effect effect = forceEffect;
                if (forceEffect == null)
                {
                    switch (stage)
                    {
                    case RenderStage.OpaqueFullCube:
                        if (Block.FancyGraphics)
                        {
                            effect = shaders.TransparentEffect;
                        }
                        else
                        {
                            effect = shaders.OpaqueEffect;
                        }
                        break;

                    case RenderStage.Opaque:
                        if (Block.FancyGraphics)
                        {
                            effect = shaders.TransparentEffect;
                        }
                        else
                        {
                            effect = shaders.OpaqueEffect;
                        }
                        //effect = shaders.TransparentEffect;
                        break;

                    case RenderStage.Transparent:
                        effect = shaders.TransparentEffect;
                        break;

                    case RenderStage.Translucent:
                        args.GraphicsDevice.BlendState = TranslucentBlendState;
                        effect = shaders.TranslucentEffect;
                        break;

                    case RenderStage.Animated:
                        effect = shaders.AnimatedEffect;
                        break;

                    case RenderStage.Liquid:
                        //	case RenderStage.AnimatedTranslucent:
                        effect = shaders.AnimatedEffect;

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                DrawChunks(args.GraphicsDevice, chunks, effect, stage);
            }

            args.GraphicsDevice.BlendState = originalBlendState;
        }