public void RenderScene_ShouldApplyViewRectangleOfCameraWithOverscanMatchedByWidth_WhenCameraAndScreenAspectRatioDiffers()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            var cameraTransform = new Transform2DComponent
            {
                Translation = new Vector2(10, -10),
                Rotation    = 0,
                Scale       = Vector2.One
            };
            var cameraEntity = renderingSceneBuilder.AddCamera(cameraTransform);
            var camera       = cameraEntity.GetComponent <CameraComponent>();

            camera.AspectRatioBehavior = AspectRatioBehavior.Overscan;

            // Camera view rectangle 2xScreenWidth and 4xScreenHeight
            // Camera view rectangle is 1:1 ratio while screen is 2:1 ratio
            camera.ViewRectangle = new Vector2(ScreenWidth * 2, ScreenHeight * 4);

            var entity = renderingSceneBuilder.AddSprite(Transform2DComponent.CreateDefault());
            var scene  = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            _renderer2D.Received(1).RenderSprite(entity.GetSprite(),
                                                 // Sprite transform is half the scale and translation due to camera view rectangle being scaled by width to match
                                                 new Matrix3x3(m11: 0.5, m12: 0, m13: -5, m21: 0, m22: 0.5, m23: 5, m31: 0, m32: 0, m33: 1));
        }
        public void RenderScene_ShouldRenderDiagnosticInfo_AfterRenderingScene()
        {
            // Arrange
            var diagnosticInfo1 = GetRandomDiagnosticInfo();
            var diagnosticInfo2 = GetRandomDiagnosticInfo();
            var diagnosticInfo3 = GetRandomDiagnosticInfo();

            _aggregatedDiagnosticInfoProvider.GetAllDiagnosticInfo().Returns(new[] { diagnosticInfo1, diagnosticInfo2, diagnosticInfo3 });

            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity1 = renderingSceneBuilder.AddSprite(orderInLayer: 0);
            var entity2 = renderingSceneBuilder.AddSprite(orderInLayer: 1);
            var entity3 = renderingSceneBuilder.AddSprite(orderInLayer: 2);
            var scene   = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            Received.InOrder(() =>
            {
                _renderer2D.RenderSprite(entity1.GetSprite(), entity1.Get2DTransformationMatrix());
                _renderer2D.RenderSprite(entity2.GetSprite(), entity2.Get2DTransformationMatrix());
                _renderer2D.RenderSprite(entity3.GetSprite(), entity3.Get2DTransformationMatrix());

                _renderer2D.RenderText(diagnosticInfo1.ToString(), Arg.Any <FontSize>(), Arg.Any <Color>(), Arg.Any <Matrix3x3>());
                _renderer2D.RenderText(diagnosticInfo2.ToString(), Arg.Any <FontSize>(), Arg.Any <Color>(), Arg.Any <Matrix3x3>());
                _renderer2D.RenderText(diagnosticInfo3.ToString(), Arg.Any <FontSize>(), Arg.Any <Color>(), Arg.Any <Matrix3x3>());
            });
        }
        public void RenderScene_ShouldApplyViewRectangleOfCamera_WhenSceneContainsEntityAndCamera()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            var cameraTransform = new Transform2DComponent
            {
                Translation = new Vector2(10, -10),
                Rotation    = 0,
                Scale       = Vector2.One
            };
            var cameraEntity = renderingSceneBuilder.AddCamera(cameraTransform);
            var camera       = cameraEntity.GetComponent <CameraComponent>();

            // Camera view rectangle is twice the screen resolution
            camera.ViewRectangle = new Vector2(ScreenWidth * 2, ScreenHeight * 2);

            var entity = renderingSceneBuilder.AddSprite(Transform2DComponent.CreateDefault());
            var scene  = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            _renderer2D.Received(1).RenderSprite(entity.GetSprite(),
                                                 // Sprite transform is half the scale and translation due to camera view rectangle
                                                 new Matrix3x3(m11: 0.5, m12: 0, m13: -5, m21: 0, m22: 0.5, m23: 5, m31: 0, m32: 0, m33: 1));
        }
        public void RenderScene_ShouldRenderEntityTransformedWithParentTransform_WhenEntityHasParentWithTransform2DComponent()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var(parentEntity, childEntity) = renderingSceneBuilder.AddParentEllipseWithChildEllipse();
            var scene = renderingSceneBuilder.Build();

            var parentExpectedTransform = parentEntity.Get2DTransformationMatrix();
            var childExpectedTransform  = parentExpectedTransform * childEntity.Get2DTransformationMatrix();


            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            var parentEllipseRenderer = parentEntity.GetComponent <EllipseRendererComponent>();

            _renderer2D.Received(1).RenderEllipse(new Ellipse(parentEllipseRenderer.RadiusX, parentEllipseRenderer.RadiusY), parentEllipseRenderer.Color,
                                                  parentEllipseRenderer.FillInterior, parentExpectedTransform);

            var childEllipseRenderer = childEntity.GetComponent <EllipseRendererComponent>();

            _renderer2D.Received(1).RenderEllipse(new Ellipse(childEllipseRenderer.RadiusX, childEllipseRenderer.RadiusY), childEllipseRenderer.Color,
                                                  childEllipseRenderer.FillInterior, childExpectedTransform);
        }
        public void RenderScene_ShouldRenderInSortingLayersOrder_Foreground_Background_Default()
        {
            // Arrange
            const string backgroundSortingLayerName = "Background";
            const string foregroundSortingLayerName = "Foreground";

            SetupSortingLayers(foregroundSortingLayerName, backgroundSortingLayerName, RenderingConfiguration.DefaultSortingLayerName);

            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity1 = renderingSceneBuilder.AddSprite(sortingLayerName: foregroundSortingLayerName);
            var entity2 = renderingSceneBuilder.AddSprite(sortingLayerName: RenderingConfiguration.DefaultSortingLayerName);
            var entity3 = renderingSceneBuilder.AddSprite(sortingLayerName: backgroundSortingLayerName);
            var scene   = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            Received.InOrder(() =>
            {
                _renderer2D.RenderSprite(entity1.GetSprite(), entity1.Get2DTransformationMatrix());
                _renderer2D.RenderSprite(entity3.GetSprite(), entity3.Get2DTransformationMatrix());
                _renderer2D.RenderSprite(entity2.GetSprite(), entity2.Get2DTransformationMatrix());
            });
        }
        public void RenderScene_ShouldIgnoreOrderInLayer_WhenEntitiesAreInDifferentSortingLayers()
        {
            // Arrange
            const string otherSortingLayer = "Other";

            SetupSortingLayers(RenderingConfiguration.DefaultSortingLayerName, otherSortingLayer);

            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity1 = renderingSceneBuilder.AddSprite(orderInLayer: 0, sortingLayerName: otherSortingLayer);
            var entity2 = renderingSceneBuilder.AddSprite(orderInLayer: 1);
            var scene   = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            Received.InOrder(() =>
            {
                _renderer2D.RenderSprite(entity2.GetSprite(), entity2.Get2DTransformationMatrix());
                _renderer2D.RenderSprite(entity1.GetSprite(), entity1.Get2DTransformationMatrix());
            });
        }
        public void RenderScene_ShouldNotRenderSprite_WhenSceneContainsEntityWithSpriteRendererAndTransformButDoesNotContainCamera()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddSprite();
            var scene = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            _renderer2D.DidNotReceive().RenderSprite(Arg.Any <Sprite>(), Arg.Any <Matrix3x3>());
        }
        public void RenderScene_ShouldRenderSprite_WhenSceneContainsEntityWithSpriteRendererAndTransform()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity = renderingSceneBuilder.AddSprite();
            var scene  = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            _renderer2D.Received(1).RenderSprite(entity.GetSprite(), entity.Get2DTransformationMatrix());
        }
        public void RenderScene_ShouldRenderOnlyEntities_ThatHaveVisibleSpriteRenderer()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity1 = renderingSceneBuilder.AddSprite(visible: true);
            var entity2 = renderingSceneBuilder.AddSprite(visible: false);
            var scene   = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            _renderer2D.Received(1).RenderSprite(entity1.GetSprite(), entity1.Get2DTransformationMatrix());
            _renderer2D.DidNotReceive().RenderSprite(entity2.GetSprite(), entity2.Get2DTransformationMatrix());
        }
Exemplo n.º 10
0
        public void RenderScene_ShouldRenderEllipse_WhenSceneContainsEntityWithEllipseRendererAndTransform()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity = renderingSceneBuilder.AddEllipse();
            var scene  = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            var ellipseRenderer = entity.GetComponent <EllipseRendererComponent>();

            _renderer2D.Received(1).RenderEllipse(new Ellipse(ellipseRenderer.RadiusX, ellipseRenderer.RadiusY), ellipseRenderer.Color,
                                                  ellipseRenderer.FillInterior, entity.Get2DTransformationMatrix());
        }
Exemplo n.º 11
0
        public void RenderScene_ShouldRenderText_WhenSceneContainsEntityWithTextRendererAndTransform()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity = renderingSceneBuilder.AddText();
            var scene  = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            var textRenderer = entity.GetComponent <TextRendererComponent>();

            Debug.Assert(textRenderer.Text != null, "textRenderer.Text != null");
            _renderer2D.Received(1).RenderText(textRenderer.Text, textRenderer.FontSize, textRenderer.Color, entity.Get2DTransformationMatrix());
        }
Exemplo n.º 12
0
        public void RenderScene_ShouldDrawDebugInformation()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity = renderingSceneBuilder.AddSprite();
            var scene  = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            Received.InOrder(() =>
            {
                _renderer2D.RenderSprite(entity.GetSprite(), entity.Get2DTransformationMatrix());
                _debugRendererForRenderingSystem.Received(1).DrawDebugInformation(_renderer2D, Matrix3x3.Identity);
            });
        }
Exemplo n.º 13
0
        public void RenderScene_ShouldRenderRectangle_WhenSceneContainsEntityWithRectangleRendererAndTransform()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity = renderingSceneBuilder.AddRectangle();
            var scene  = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            var rectangleRenderer = entity.GetComponent <RectangleRendererComponent>();

            _renderer2D.Received(1).RenderRectangle(Arg.Is <AxisAlignedRectangle>(r =>
                                                                                  Math.Abs(r.Width - rectangleRenderer.Dimension.X) < 0.001 && Math.Abs(r.Height - rectangleRenderer.Dimension.Y) < 0.001),
                                                    rectangleRenderer.Color, rectangleRenderer.FillInterior,
                                                    entity.Get2DTransformationMatrix());
        }
Exemplo n.º 14
0
        public void RenderScene_ShouldApplyViewRectangleOfCameraWithUnderscanMatchedByHeight_WhenCameraAndScreenAspectRatioDiffers()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            var cameraTransform = new Transform2DComponent
            {
                Translation = new Vector2(10, -10),
                Rotation    = 0,
                Scale       = Vector2.One
            };
            var cameraEntity = renderingSceneBuilder.AddCamera(cameraTransform);
            var camera       = cameraEntity.GetComponent <CameraComponent>();

            camera.AspectRatioBehavior = AspectRatioBehavior.Underscan;

            // Camera view rectangle 1xScreenWidth and 2xScreenHeight
            // Camera view rectangle is 1:1 ratio while screen is 2:1 ratio
            camera.ViewRectangle = new Vector2(ScreenWidth, ScreenHeight * 2);

            var entity = renderingSceneBuilder.AddSprite(Transform2DComponent.CreateDefault());
            var scene  = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            Received.InOrder(() =>
            {
                _renderer2D.Clear(Color.FromArgb(255, 255, 255, 255));
                _renderer2D.Clear(Color.FromArgb(255, 0, 0, 0));
                _renderer2D.SetClippingRectangle(new AxisAlignedRectangle(ScreenHeight, ScreenHeight));
                _renderer2D.Clear(Color.FromArgb(255, 255, 255, 255));
                _renderer2D.Received(1).RenderSprite(entity.GetSprite(),
                                                     // Sprite transform is half the scale and translation due to camera view rectangle being scaled by height to match
                                                     new Matrix3x3(m11: 0.5, m12: 0, m13: -5, m21: 0, m22: 0.5, m23: 5, m31: 0, m32: 0, m33: 1));
                _renderer2D.ClearClipping();
            });
        }
Exemplo n.º 15
0
        public void RenderScene_ShouldCallInFollowingOrder_BeginRendering_Clear_RenderSprite_EndRendering()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            renderingSceneBuilder.AddSprite();
            var scene = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            Received.InOrder(() =>
            {
                _renderer2D.BeginRendering();
                _renderer2D.Clear(Color.FromArgb(255, 255, 255, 255));
                _renderer2D.RenderSprite(Arg.Any <Sprite>(), Arg.Any <Matrix3x3>());
                _renderer2D.EndRendering(false);
            });
        }
Exemplo n.º 16
0
        public void RenderScene_ShouldPerformCameraTransformationOnEntity_WhenSceneContainsEntityAndCamera()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            var cameraTransform = new Transform2DComponent
            {
                Translation = new Vector2(10, -10),
                Rotation    = 0,
                Scale       = Vector2.One
            };

            renderingSceneBuilder.AddCamera(cameraTransform);
            var entity = renderingSceneBuilder.AddSprite(Transform2DComponent.CreateDefault());
            var scene  = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            _renderer2D.Received(1).RenderSprite(entity.GetSprite(), Matrix3x3.CreateTranslation(new Vector2(-10, 10)));
        }
Exemplo n.º 17
0
        public void RenderScene_ShouldSetScreenWidthAndScreenHeightOnCameraComponent()
        {
            // Arrange
            const int screenWidth  = 123;
            const int screenHeight = 456;

            _renderer2D.ScreenWidth.Returns(screenWidth);
            _renderer2D.ScreenHeight.Returns(screenHeight);

            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();
            var cameraEntity          = renderingSceneBuilder.AddCamera();
            var scene = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            var cameraComponent = cameraEntity.GetComponent <CameraComponent>();

            Assert.That(cameraComponent.ScreenWidth, Is.EqualTo(screenWidth));
            Assert.That(cameraComponent.ScreenHeight, Is.EqualTo(screenHeight));
        }
Exemplo n.º 18
0
        public void RenderScene_ShouldRenderInOrderOf_OrderInLayer_WhenEntitiesAreInTheSameSortingLayer()
        {
            // Arrange
            var renderingSystem       = GetRenderingSystem();
            var renderingSceneBuilder = new RenderingSceneBuilder();

            renderingSceneBuilder.AddCamera();
            var entity1 = renderingSceneBuilder.AddSprite(orderInLayer: 1);
            var entity2 = renderingSceneBuilder.AddSprite(orderInLayer: -1);
            var entity3 = renderingSceneBuilder.AddSprite(orderInLayer: 0);
            var scene   = renderingSceneBuilder.Build();

            // Act
            renderingSystem.RenderScene(scene);

            // Assert
            Received.InOrder(() =>
            {
                _renderer2D.RenderSprite(entity2.GetSprite(), entity2.Get2DTransformationMatrix());
                _renderer2D.RenderSprite(entity3.GetSprite(), entity3.Get2DTransformationMatrix());
                _renderer2D.RenderSprite(entity1.GetSprite(), entity1.Get2DTransformationMatrix());
            });
        }