public FramerateControl(SpaceTimePanel scene) { this.scene = scene; this.AutoSize = true; nowControl = Add(new Label() { Text = "".ToConsoleString() }).FillHorizontally(); elementsControl = Add(new Label() { Text = "".ToConsoleString() }).FillHorizontally(); functionsControl = Add(new Label() { Text = "".ToConsoleString() }).FillHorizontally(); renderFPSLabel = Add(new Label() { Text = "".ToConsoleString() }).FillHorizontally(); paintFPSLabel = Add(new Label() { Text = "".ToConsoleString() }).FillHorizontally(); sleepTimeLabel = Add(new Label() { Text = "".ToConsoleString() }).FillHorizontally(); zeroSpinsLabel = Add(new Label() { Text = "".ToConsoleString() }).FillHorizontally(); nonZeroSpinsLabel = Add(new Label() { Text = "".ToConsoleString() }).FillHorizontally(); AddedToVisualTree.SubscribeForLifetime(SetupPolling, this); }
private async Task TestCantGoThroughWalls(Direction d, CliTestHarness app, SpaceTimePanel stPanel) { SpacialAwareness.OnNudge.SubscribeForLifetime((ev) => Assert.Fail("Nudging not allowed"), app); var st = stPanel.SpaceTime; var wall = st.Add(new SpacialElement() { BackgroundColor = RGB.DarkRed }); ILocationF movingObjectLocation; float movementAngle; float expected; Func <SpacialElement, float> actual; if (d == Direction.Right) { movingObjectLocation = LocationF.Create((int)(st.Width * .25f), st.Height * .5f - .5f); movementAngle = 0; wall.ResizeTo(.1f, st.Height); wall.MoveTo((int)(st.Width * .75f), 0); expected = wall.Left; actual = m => m.Right(); } else if (d == Direction.Left) { movingObjectLocation = LocationF.Create((int)(st.Width * .75f), st.Height * .5f - .5f); movementAngle = 180; wall.ResizeTo(.1f, st.Height); wall.MoveTo((int)(st.Width * .25f) - .1f, 0); expected = wall.Right(); actual = m => m.Left; } else if (d == Direction.Up) { movingObjectLocation = LocationF.Create(st.Width * .5f - .5f, (int)(st.Height * .75f)); movementAngle = 270; wall.ResizeTo(st.Width, .1f); wall.MoveTo(0, (int)(st.Height * .25f) - .1f); expected = wall.Bottom(); actual = m => m.Top; } else if (d == Direction.Down) { movingObjectLocation = LocationF.Create(st.Width * .5f - .5f, (int)(st.Height * .25f)); movementAngle = 90; wall.ResizeTo(st.Width, .1f); wall.MoveTo(0, (int)(st.Height * .75f)); expected = wall.Top; actual = m => m.Bottom(); } else { throw new NotSupportedException(); } for (var speed = 5; speed < 1000; speed *= 2) { Console.WriteLine($"Speed: {speed}"); var movingObject = st.Add(new SpacialElement(1, 1, movingObjectLocation.Left, movingObjectLocation.Top) { BackgroundColor = RGB.Blue }); var v = new Velocity(movingObject); await st.DelayAsync(500); v.Angle = movementAngle; v.Speed = speed; await st.DelayAsync(20000); PhysicsTest.AssertClose(expected, actual(movingObject), .2f); Console.WriteLine($"Wall.Left == {expected}, movingObject.Right() == {actual(movingObject)}"); movingObject.Lifetime.Dispose(); } }