forked from space-wizards/RobustToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into 2024-08-19-reloads
# Conflicts: # RELEASE-NOTES.md
- Loading branch information
Showing
126 changed files
with
1,484 additions
and
1,058 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Numerics; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.Extensions.Configuration; | ||
using Robust.Shared.Analyzers; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Physics; | ||
using Robust.Shared.Physics.Collision.Shapes; | ||
using Robust.Shared.Physics.Components; | ||
using Robust.Shared.Physics.Dynamics; | ||
using Robust.Shared.Physics.Systems; | ||
using Robust.UnitTesting.Server; | ||
|
||
namespace Robust.Benchmarks.Physics; | ||
|
||
[Virtual] | ||
[MediumRunJob] | ||
public class PhysicsBoxStackBenchmark | ||
{ | ||
private ISimulation _sim = default!; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_sim = RobustServerSimulation.NewSimulation().InitializeInstance(); | ||
|
||
var entManager = _sim.Resolve<IEntityManager>(); | ||
entManager.System<SharedMapSystem>().CreateMap(out var mapId); | ||
SetupTumbler(entManager, mapId); | ||
|
||
for (var i = 0; i < 30; i++) | ||
{ | ||
entManager.TickUpdate(0.016f, false); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void BoxStack() | ||
{ | ||
var entManager = _sim.Resolve<IEntityManager>(); | ||
|
||
for (var i = 0; i < 10000; i++) | ||
{ | ||
entManager.TickUpdate(0.016f, false); | ||
} | ||
} | ||
|
||
private void SetupTumbler(IEntityManager entManager, MapId mapId) | ||
{ | ||
var physics = entManager.System<SharedPhysicsSystem>(); | ||
var fixtures = entManager.System<FixtureSystem>(); | ||
|
||
var groundUid = entManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); | ||
var ground = entManager.AddComponent<PhysicsComponent>(groundUid); | ||
|
||
var horizontal = new EdgeShape(new Vector2(-40, 0), new Vector2(40, 0)); | ||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 2, 2, true), body: ground); | ||
|
||
var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10)); | ||
fixtures.CreateFixture(groundUid, "fix2", new Fixture(vertical, 2, 2, true), body: ground); | ||
|
||
var xs = new[] | ||
{ | ||
0.0f, -10.0f, -5.0f, 5.0f, 10.0f | ||
}; | ||
|
||
var columnCount = 1; | ||
var rowCount = 15; | ||
PolygonShape shape; | ||
|
||
for (var j = 0; j < columnCount; j++) | ||
{ | ||
for (var i = 0; i < rowCount; i++) | ||
{ | ||
var x = 0.0f; | ||
|
||
var boxUid = entManager.SpawnEntity(null, | ||
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 1.1f * i), mapId)); | ||
var box = entManager.AddComponent<PhysicsComponent>(boxUid); | ||
|
||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box); | ||
|
||
shape = new PolygonShape(); | ||
shape.SetAsBox(0.5f, 0.5f); | ||
physics.SetFixedRotation(boxUid, false, body: box); | ||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true), body: box); | ||
|
||
physics.WakeBody(boxUid, body: box); | ||
physics.SetSleepingAllowed(boxUid, box, false); | ||
} | ||
} | ||
|
||
physics.WakeBody(groundUid, body: ground); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.Numerics; | ||
using BenchmarkDotNet.Attributes; | ||
using Robust.Shared.Analyzers; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Physics; | ||
using Robust.Shared.Physics.Collision.Shapes; | ||
using Robust.Shared.Physics.Components; | ||
using Robust.Shared.Physics.Dynamics; | ||
using Robust.Shared.Physics.Systems; | ||
using Robust.UnitTesting.Server; | ||
|
||
namespace Robust.Benchmarks.Physics; | ||
|
||
[Virtual] | ||
public class PhysicsCircleStackBenchmark | ||
{ | ||
private ISimulation _sim = default!; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_sim = RobustServerSimulation.NewSimulation().InitializeInstance(); | ||
|
||
var entManager = _sim.Resolve<IEntityManager>(); | ||
entManager.System<SharedMapSystem>().CreateMap(out var mapId); | ||
SetupTumbler(entManager, mapId); | ||
|
||
for (var i = 0; i < 30; i++) | ||
{ | ||
entManager.TickUpdate(0.016f, false); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void CircleStack() | ||
{ | ||
var entManager = _sim.Resolve<IEntityManager>(); | ||
|
||
for (var i = 0; i < 10000; i++) | ||
{ | ||
entManager.TickUpdate(0.016f, false); | ||
} | ||
} | ||
|
||
private void SetupTumbler(IEntityManager entManager, MapId mapId) | ||
{ | ||
var physics = entManager.System<SharedPhysicsSystem>(); | ||
var fixtures = entManager.System<FixtureSystem>(); | ||
|
||
var groundUid = entManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); | ||
var ground = entManager.AddComponent<PhysicsComponent>(groundUid); | ||
|
||
var horizontal = new EdgeShape(new Vector2(-40, 0), new Vector2(40, 0)); | ||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 2, 2, true), body: ground); | ||
|
||
var vertical = new EdgeShape(new Vector2(20, 0), new Vector2(20, 20)); | ||
fixtures.CreateFixture(groundUid, "fix2", new Fixture(vertical, 2, 2, true), body: ground); | ||
|
||
var xs = new[] | ||
{ | ||
0.0f, -10.0f, -5.0f, 5.0f, 10.0f | ||
}; | ||
|
||
var columnCount = 1; | ||
var rowCount = 15; | ||
PhysShapeCircle shape; | ||
|
||
for (var j = 0; j < columnCount; j++) | ||
{ | ||
for (var i = 0; i < rowCount; i++) | ||
{ | ||
var x = 0.0f; | ||
|
||
var boxUid = entManager.SpawnEntity(null, | ||
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)); | ||
var box = entManager.AddComponent<PhysicsComponent>(boxUid); | ||
|
||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box); | ||
shape = new PhysShapeCircle(0.5f); | ||
physics.SetFixedRotation(boxUid, false, body: box); | ||
// TODO: Need to detect shape and work out if we need to use fixedrotation | ||
|
||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true, 5f)); | ||
physics.WakeBody(boxUid, body: box); | ||
physics.SetSleepingAllowed(boxUid, box, false); | ||
} | ||
} | ||
|
||
physics.WakeBody(groundUid, body: ground); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Numerics; | ||
using BenchmarkDotNet.Attributes; | ||
using Robust.Shared.Analyzers; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Physics; | ||
using Robust.Shared.Physics.Collision.Shapes; | ||
using Robust.Shared.Physics.Components; | ||
using Robust.Shared.Physics.Dynamics; | ||
using Robust.Shared.Physics.Systems; | ||
using Robust.UnitTesting.Server; | ||
|
||
namespace Robust.Benchmarks.Physics; | ||
|
||
[Virtual] | ||
public class PhysicsPyramidBenchmark | ||
{ | ||
private ISimulation _sim = default!; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_sim = RobustServerSimulation.NewSimulation().InitializeInstance(); | ||
|
||
var entManager = _sim.Resolve<IEntityManager>(); | ||
entManager.System<SharedMapSystem>().CreateMap(out var mapId); | ||
SetupTumbler(entManager, mapId); | ||
|
||
for (var i = 0; i < 300; i++) | ||
{ | ||
entManager.TickUpdate(0.016f, false); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Pyramid() | ||
{ | ||
var entManager = _sim.Resolve<IEntityManager>(); | ||
|
||
for (var i = 0; i < 5000; i++) | ||
{ | ||
entManager.TickUpdate(0.016f, false); | ||
} | ||
} | ||
|
||
private void SetupTumbler(IEntityManager entManager, MapId mapId) | ||
{ | ||
const byte count = 20; | ||
|
||
// Setup ground | ||
var physics = entManager.System<SharedPhysicsSystem>(); | ||
var fixtures = entManager.System<FixtureSystem>(); | ||
var groundUid = entManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); | ||
var ground = entManager.AddComponent<PhysicsComponent>(groundUid); | ||
|
||
var horizontal = new EdgeShape(new Vector2(40, 0), new Vector2(-40, 0)); | ||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 2, 2, true), body: ground); | ||
physics.WakeBody(groundUid, body: ground); | ||
|
||
// 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 boxUid = entManager.SpawnEntity(null, new MapCoordinates(y, mapId)); | ||
var box = entManager.AddComponent<PhysicsComponent>(boxUid); | ||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box); | ||
|
||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true, 5f), body: box); | ||
y += deltaY; | ||
|
||
physics.WakeBody(boxUid, body: box); | ||
physics.SetSleepingAllowed(boxUid, box, false); | ||
} | ||
|
||
x += deltaX; | ||
} | ||
} | ||
} |
Oops, something went wrong.