示例#1
0
        public IPlotOperation CreateCityBarRenderer()
        {
            var map = GameData.Terrain;

            bool CityMapper(byte index, out ISettlement s, out Nothing context)
            {
                if (index == 0)
                {
                    s       = null;
                    context = null;
                    return(false);
                }

                s       = GameData.Settlements[index];
                context = null;
                return(true);
            }

            var settlementMatcher =
                new DirectMappingTileMatcher <byte, ISettlement, Nothing>((x, y) => map[x, y].City, CityMapper);

            return(PlotOperations.FromContext(RenderingConfig)
                   .Create(settlementMatcher)
                   .ForViewport()
                   .WithRenderer(CreateRenderer())
                   .Build());
        }
示例#2
0
        public void RenderAccess_With_Cache_ViewPort_then_Conversion()
        {
            var rc       = new GameRenderingConfig(RenderType.Grid);
            var renderer = new RendererSubstitute <RenderedTile, RenderedContext>();
            var conv     = new ConverterProxy();
            var matcher  = new DummyTileMatcher <MatchedTile, MatchedContext>();

            var sourceFactory = PlotOperations.FromContext(rc).Create(matcher);
            var cachedFactory = sourceFactory.WithCache();
            var vpFactory     = cachedFactory.ForViewport();
            var convRend      = vpFactory.WithConversion(conv).Build();

            var sourcePo = sourceFactory.BuildUnsafe();
            var cached   = cachedFactory.BuildUnsafe();
            var vp       = vpFactory.Build();

            sourcePo.Renderer.Should().Be(cached.ActiveRenderer);
            sourcePo.ActiveRenderer.Should().Be(cached.ActiveRenderer);

            convRend.Renderer = renderer;

            Assert.AreEqual(vp.ActiveRenderer, cached.Renderer);
            Assert.AreEqual(vp.Renderer, conv);

            sourcePo.Renderer.Should().Be(cached.ActiveRenderer);
            sourcePo.ActiveRenderer.Should().Be(cached.ActiveRenderer);

            vp.ActiveRenderer.Should().BeAssignableTo <ViewportRenderer <MatchedTile, MatchedContext> >();
        }
示例#3
0
        IPlotOperation CreateNonCachedFromMatchControl(TileMatchControl tm, IRenderCallbackFactory <Nothing, TTile> r)
        {
            var po = PlotOperations.FromContext(RenderingConfig)
                     .Create(tm.Matcher)
                     .ForViewport()
                     .WithRenderer(r.CreateRenderer <Nothing>(this, Nothing.Instance))
                     .Build();

            return(po);
        }
        public void AsEffOneBinPlotReverse()
        {
            var h = new ROOTNET.NTH2F("hi", "there", 1, 0.0, 10.0, 1, 0.0, 10.0);

            h.SetBinContent(1, 1, 10.0);

            var r = PlotOperations.asEfficiency(new RootContext(), h, false, false);

            Assert.AreEqual(1.0, r.GetBinContent(1, 1));
        }
示例#5
0
        protected IPlotOperation CreatePlot <TContext, TRenderParameter>(IRenderCallbackFactory <TRenderParameter, TTile> renderer,
                                                                         ITileMatcher <TTile, TContext> matcher,
                                                                         TRenderParameter sortingLayer)
        {
            var p = PlotOperations.FromContext(RenderingConfig)
                    .Create(matcher)
                    .WithCache()
                    .ForViewport()
                    .WithRenderer(renderer.CreateRenderer <TContext>(this, sortingLayer));

            return(p.Build());
        }
        public void TwoBinsOneRowBothFilled()
        {
            var h = new ROOTNET.NTH2F("hi", "there", 2, 0.0, 10.0, 1, 0.0, 10.0);

            h.SetBinContent(1, 1, 10.0);
            h.SetBinContent(2, 1, 10.0);

            var r = PlotOperations.asEfficiency(new RootContext(), h, true, true);

            Assert.AreEqual(1.0, r.GetBinContent(1, 1));
            Assert.AreEqual(0.5, r.GetBinContent(2, 1));
        }
示例#7
0
        public void RenderSetUp_With_Cache()
        {
            var rc       = new GameRenderingConfig(RenderType.Grid);
            var renderer = new RendererSubstitute <MatchedTile, MatchedContext>();

            var matcher = new DummyTileMatcher <MatchedTile, MatchedContext>();
            var plot    = PlotOperations.FromContext(rc).Create(matcher).WithCache().BuildUnsafe();

            Assert.IsTrue(CachingPlotOperation <MatchedTile, MatchedContext> .IsRecordingRenderer(plot.ActiveRenderer));

            plot.Renderer = renderer;

            Assert.IsTrue(CachingPlotOperation <MatchedTile, MatchedContext> .IsRecordingRenderer(plot.ActiveRenderer));
            Assert.AreEqual(plot.Renderer, renderer);
        }
        public void FourBinsOneRowBothFilledReverse()
        {
            var h = new ROOTNET.NTH2F("hi", "there", 4, 0.0, 10.0, 1, 0.0, 10.0);

            h.SetBinContent(1, 1, 10.0);
            h.SetBinContent(2, 1, 10.0);
            h.SetBinContent(3, 1, 10.0);
            h.SetBinContent(4, 1, 10.0);

            var r = PlotOperations.asEfficiency(new RootContext(), h, false, true);

            Assert.AreEqual(0.25, r.GetBinContent(1, 1));
            Assert.AreEqual(0.50, r.GetBinContent(2, 1));
            Assert.AreEqual(0.75, r.GetBinContent(3, 1));
            Assert.AreEqual(1.0, r.GetBinContent(4, 1));
        }
示例#9
0
        IPlotOperation CreateFromMatchControl(TileMatchControl tm, IRenderCallbackFactory <Nothing, TTile> r)
        {
            if (tm.Cachable)
            {
                var cache =
                    PlotOperations.FromContext(RenderingConfig)
                    .Create(tm.Matcher)
                    .WithCache()
                    .ForViewport()
                    .WithRenderer(r.CreateRenderer <Nothing>(this, Nothing.Instance))
                    .Build();
                tm.CacheControl(cache);
                return(cache);
            }

            return(CreateNonCachedFromMatchControl(tm, r));
        }
示例#10
0
        public void RenderAccess_With_Cache_ViewPort()
        {
            var rc       = new GameRenderingConfig(RenderType.Grid);
            var renderer = new RendererSubstitute <RenderedTile, RenderedContext>();
            var conv     = new ConverterProxy();
            var matcher  = new DummyTileMatcher <RenderedTile, RenderedContext>();

            var cache =
                PlotOperations.FromContext(rc)
                .Create(matcher)
                .WithCache()
                .ForViewport()
                .WithRenderer(renderer)
                .Build();

            var s = cache.ActiveRenderer.Should().BeAssignableTo <ViewportRenderer <RenderedTile, RenderedContext> >().Subject;
            //s.RenderTarget.Should().BeAssignableTo<ViewportRenderer<RenderedTile, RenderedContext>>();
        }
示例#11
0
        /// <summary>
        ///  Produces the rendering pipeline for rendering the wall and item layer.
        ///
        ///  This operation consists of three tile renderer operations per map
        ///  coordinate. Each operation must be executed as a single batch for each
        ///  map coordinate  so that later tiles can correctly paint over these
        ///  tiles if needed.
        /// </summary>
        /// <returns></returns>
        IPlotOperation CreateItemLayerPlotOperation <TRenderParameter>(IRenderCallbackFactory <TRenderParameter, TTile> rendererFactory,
                                                                       ITileRegistry <TTile> tiles,
                                                                       TRenderParameter sortingLayer)
        {
            IRenderPlotOperation <TTile, Nothing> CreateWallPlotter()
            {
                var matcher = new AggregateTileMatcher <TTile, Nothing>
                                  (CreateWallMatcher(tiles), CreateDecoMatcher(tiles));

                return(PlotOperations.FromContext(RenderingConfig)
                       .Create(matcher)
                       .WithCache()
                       .ForViewport()
                       .Build());
            }

            IRenderPlotOperation <TTile, Nothing> CreateItemPlotter()
            {
                // Selects all items stored at a give map location.
                // The item will be passed through to the renderer layer as context for post processing.
                var itemMatcher = new ItemListMatcher <TTile>(GameData, tiles);

                // Take the item context and update the rendered position of the item based on the item's location.
                // This converts the context from IItem to Nothing after adjusting the coordinates.
                var conv = new DungeonGameItemLocationResolver <TTile, Nothing>(GameData.ItemService,
                                                                                RenderingConfig.Viewport);

                return(PlotOperations.FromContext(RenderingConfig)
                       .Create(itemMatcher)
                       .ForViewport()
                       .WithConversion(conv)
                       .Build());
            }

            var renderer = new BatchedPositionedSpriteRenderer <TTile, Nothing>(rendererFactory.CreateRenderer <Nothing>(this, sortingLayer));
            var batch    = new BatchedPlotOperation <TTile, Nothing>(renderer, CreateWallPlotter(), CreateItemPlotter());

            return(batch);
        }
示例#12
0
        public void RenderAccess_With_Conversion()
        {
            var rc       = new GameRenderingConfig(RenderType.Grid);
            var renderer = new RendererSubstitute <RenderedTile, RenderedContext>();
            var conv     = new ConverterProxy();
            var matcher  = new DummyTileMatcher <MatchedTile, MatchedContext>();

            var sourceFactory = PlotOperations.FromContext(rc).Create(matcher);
            var plot          = sourceFactory.WithConversion(conv).BuildUnsafe();

            var sourcePo = sourceFactory.BuildUnsafe();

            sourcePo.Renderer.Should().Be(conv);
            sourcePo.ActiveRenderer.Should().Be(conv);
            plot.ActiveRenderer.Should().BeNull();

            plot.Renderer = renderer;
            Assert.AreEqual(plot.Renderer, renderer);
            Assert.AreEqual(plot.ActiveRenderer, renderer);
            sourcePo.Renderer.Should().Be(conv);
            sourcePo.ActiveRenderer.Should().Be(conv);
        }