From bc6a93fa024c86d3d8cc8ba12fa7e6d60d1d8f99 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 28 Mar 2021 13:41:49 +1100 Subject: [PATCH] Add pyramid physics testbed (#3710) * Add pyramid physics testbed From Box2D (licence is already on the file). Useful for testing solver performance for large islands. * nulls Co-authored-by: Metal Gear Sloth --- .../Tests/Physics/PhysicsTestBedTest.cs | 10 ++- .../Commands/Physics/TestbedCommand.cs | 63 +++++++++++++++++-- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/Content.IntegrationTests/Tests/Physics/PhysicsTestBedTest.cs b/Content.IntegrationTests/Tests/Physics/PhysicsTestBedTest.cs index 1396e346af..e60d74f974 100644 --- a/Content.IntegrationTests/Tests/Physics/PhysicsTestBedTest.cs +++ b/Content.IntegrationTests/Tests/Physics/PhysicsTestBedTest.cs @@ -64,8 +64,7 @@ namespace Content.IntegrationTests.Tests.Physics var entityManager = IoCManager.Resolve(); - // TODO: Need a blank entity we can spawn for testbed. - var ground = entityManager.SpawnEntity("BlankEntity", new MapCoordinates(0, 0, mapId)).AddComponent(); + var ground = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)).AddComponent(); var horizontal = new EdgeShape(new Vector2(-20, 0), new Vector2(20, 0)); var horizontalFixture = new Fixture(ground, horizontal) @@ -98,7 +97,7 @@ namespace Content.IntegrationTests.Tests.Physics { var x = 0.0f; - var box = entityManager.SpawnEntity("BlankEntity", + var box = entityManager.SpawnEntity(null, new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent(); box.BodyType = BodyType.Dynamic; @@ -181,8 +180,7 @@ namespace Content.IntegrationTests.Tests.Physics var entityManager = IoCManager.Resolve(); - // TODO: Need a blank entity we can spawn for testbed. - var ground = entityManager.SpawnEntity("BlankEntity", new MapCoordinates(0, 0, mapId)).AddComponent(); + var ground = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)).AddComponent(); var horizontal = new EdgeShape(new Vector2(-20, 0), new Vector2(20, 0)); var horizontalFixture = new Fixture(ground, horizontal) @@ -215,7 +213,7 @@ namespace Content.IntegrationTests.Tests.Physics { var x = 0.0f; - var circle = entityManager.SpawnEntity("BlankEntity", + var circle = entityManager.SpawnEntity(null, new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent(); circle.BodyType = BodyType.Dynamic; diff --git a/Content.Server/Commands/Physics/TestbedCommand.cs b/Content.Server/Commands/Physics/TestbedCommand.cs index aaeb6f2912..f57fdfed15 100644 --- a/Content.Server/Commands/Physics/TestbedCommand.cs +++ b/Content.Server/Commands/Physics/TestbedCommand.cs @@ -94,6 +94,10 @@ namespace Content.Server.Commands.Physics SetupPlayer(mapId, shell, player, mapManager); CreateCircleStack(mapId); break; + case "pyramid": + SetupPlayer(mapId, shell, player, mapManager); + CreatePyramid(mapId); + break; default: shell.WriteLine($"testbed {args[0]} not found!"); return; @@ -115,7 +119,7 @@ namespace Content.Server.Commands.Physics { var entityManager = IoCManager.Resolve(); - var ground = entityManager.SpawnEntity("BlankEntity", new MapCoordinates(0, 0, mapId)).AddComponent(); + var ground = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)).AddComponent(); var horizontal = new EdgeShape(new Vector2(-20, 0), new Vector2(20, 0)); var horizontalFixture = new Fixture(ground, horizontal) @@ -150,7 +154,7 @@ namespace Content.Server.Commands.Physics { var x = 0.0f; - var box = entityManager.SpawnEntity("BlankEntity", + var box = entityManager.SpawnEntity(null, new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent(); box.BodyType = BodyType.Dynamic; @@ -175,8 +179,7 @@ namespace Content.Server.Commands.Physics { var entityManager = IoCManager.Resolve(); - // TODO: Need a blank entity we can spawn for testbed. - var ground = entityManager.SpawnEntity("BlankEntity", new MapCoordinates(0, 0, mapId)).AddComponent(); + var ground = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)).AddComponent(); var horizontal = new EdgeShape(new Vector2(-20, 0), new Vector2(20, 0)); var horizontalFixture = new Fixture(ground, horizontal) @@ -211,7 +214,7 @@ namespace Content.Server.Commands.Physics { var x = 0.0f; - var box = entityManager.SpawnEntity("BlankEntity", + var box = entityManager.SpawnEntity(null, new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent(); box.BodyType = BodyType.Dynamic; @@ -230,5 +233,55 @@ namespace Content.Server.Commands.Physics } } } + + private void CreatePyramid(MapId mapId) + { + const byte count = 20; + + // Setup ground + var entityManager = IoCManager.Resolve(); + var ground = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)).AddComponent(); + + var horizontal = new EdgeShape(new Vector2(-40, 0), new Vector2(40, 0)); + var horizontalFixture = new Fixture(ground, horizontal) + { + CollisionLayer = (int) CollisionGroup.Impassable, + CollisionMask = (int) CollisionGroup.Impassable, + Hard = true + }; + + ground.AddFixture(horizontalFixture); + + // Setup boxes + float a = 0.5f; + PolygonShape shape = new(); + shape.SetAsBox(a, a); + + var x = new Vector2(-7.0f, 0.75f); + Vector2 y; + Vector2 deltaX = new Vector2(0.5625f, 1.25f); + Vector2 deltaY = new Vector2(1.125f, 0.0f); + + for (var i = 0; i < count; ++i) + { + y = x; + + for (var j = i; j < count; ++j) + { + var box = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)).AddComponent(); + box.BodyType = BodyType.Dynamic; + box.Owner.Transform.WorldPosition = y; + box.AddFixture( + new Fixture(box, shape) { + CollisionLayer = (int) CollisionGroup.Impassable, + CollisionMask = (int) CollisionGroup.Impassable, + Hard = true}); + box.Mass = 5.0f; + y += deltaY; + } + + x += deltaX; + } + } } }