Files
RobustToolbox/Robust.UnitTesting/Client/GameObjects/Components/Transform_Test.cs
T
fefcc7cba3 Physics (#1602)
* Physics worlds

* Paul's a good boy

* Build working

* Ingame and not lagging to hell

* Why didn't you commit ahhhhh

* Hard collisions working

* Solver parity

* Decent broadphase work done

* BroadPhase outline done

* BroadPhase working

* waiting for pvs

* Fix static PVS AABB

* Stop static bodies from awakening

* Optimise a bunch of stuff

* Even more broadphase stuff

* I'm fucking stupid

* Optimise fixture updates

* Collision solver start

* Building

* A is for Argumentative

* Fix contact caching island flags

* Circle shapes actually workeded

* Damping

* DS2 consumables only

* Slightly more stable

* Even slightlier more stablier

* VV your heart out

* Initial joint support

* 90% of joints I just wanted to push as I'd scream if I lost progress

* JOINT PURGATORY

* Joints barely functional lmao

* Okay these joints slightly more functional

* Remove station FrictionJoint

* Also that

* Some Box2D ports

* Cleanup mass

* Edge shape

* Active contacts

* Fix active contacts

* Optimise active contacts even more

* Boxes be stacking

* I would die for smug oh my fucking god

* In which everything is fixed

* Distance joints working LETS GO

* Remove frequency on distancejoint

* Fix some stuff and break joints

* Crashing fixed mehbeh

* ICollideSpecial and more resilience

* auto-clear

* showbb vera

* Slap that TODO in there

* Fix restartround crash

* Random fixes

* Fix fixture networking

* Add intersection method for broadphase

* Fix contacts

* Licenses done

* Optimisations

* Fix wall clips

* Config caching for island

* allocations optimisations

* Optimise casts

* Optimise events queue for physics

* Contact manager optimisations

* Optimise controllers

* Sloth joint or something idk

* Controller graph

* Remove content cvar

* Random cleanup

* Finally remove VirtualController

* Manifold structs again

* Optimise this absolute retardation

* Optimise

* fix license

* Cleanup physics interface

* AHHHHHHHHHHHHH

* Fix collisions again

* snivybus

* Fix potential nasty manifold bug

* Tests go snivy

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
2021-03-01 03:09:36 +11:00

141 lines
5.2 KiB
C#

using System.IO;
using Moq;
using NUnit.Framework;
using Robust.Client.GameObjects;
using Robust.Client.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Prototypes;
namespace Robust.UnitTesting.Client.GameObjects.Components
{
[TestFixture]
[TestOf(typeof(TransformComponent))]
class Transform_Test : RobustUnitTest
{
public override UnitTestProject Project => UnitTestProject.Client;
private IClientEntityManager EntityManager = default!;
private IMapManager MapManager = default!;
const string PROTOTYPES = @"
- type: entity
name: dummy
id: dummy
components:
- type: Transform
";
private MapId MapA;
private IMapGrid GridA = default!;
private MapId MapB;
private IMapGrid GridB = default!;
protected override void OverrideIoC()
{
base.OverrideIoC();
var mock = new Mock<IEntitySystemManager>();
var system = new SharedTransformSystem();
var broady = new BroadPhaseSystem();
var physics = new PhysicsSystem();
mock.Setup(m => m.GetEntitySystem<SharedTransformSystem>()).Returns(system);
mock.Setup(m => m.GetEntitySystem<SharedBroadPhaseSystem>()).Returns(broady);
mock.Setup(m => m.GetEntitySystem<SharedPhysicsSystem>()).Returns(physics);
IoCManager.RegisterInstance<IEntitySystemManager>(mock.Object, true);
}
[OneTimeSetUp]
public void Setup()
{
var compMan = IoCManager.Resolve<IComponentManager>();
compMan.Initialize();
EntityManager = IoCManager.Resolve<IClientEntityManager>();
MapManager = IoCManager.Resolve<IMapManager>();
MapManager.Initialize();
MapManager.Startup();
var manager = IoCManager.Resolve<IPrototypeManager>();
manager.LoadFromStream(new StringReader(PROTOTYPES));
manager.Resync();
// build the net dream
MapA = MapManager.CreateMap();
GridA = MapManager.CreateGrid(MapA);
MapB = MapManager.CreateMap();
GridB = MapManager.CreateGrid(MapB);
//NOTE: The grids have not moved, so we can assert worldpos == localpos for the tests
}
/// <summary>
/// Make sure that component state locations are RELATIVE.
/// </summary>
[Test]
public void ComponentStatePositionTest()
{
// Arrange
var initialPos = new EntityCoordinates(GridA.GridEntityId, (0, 0));
var parent = EntityManager.SpawnEntity("dummy", initialPos);
var child = EntityManager.SpawnEntity("dummy", initialPos);
var parentTrans = parent.Transform;
var childTrans = child.Transform;
var compState = new TransformComponent.TransformComponentState(new Vector2(5, 5), new Angle(0), GridB.GridEntityId, false);
parentTrans.HandleComponentState(compState, null);
compState = new TransformComponent.TransformComponentState(new Vector2(6, 6), new Angle(0), GridB.GridEntityId, false);
childTrans.HandleComponentState(compState, null);
// World pos should be 6, 6 now.
// Act
var oldWpos = childTrans.WorldPosition;
compState = new TransformComponent.TransformComponentState(new Vector2(1, 1), new Angle(0), parent.Uid, false);
childTrans.HandleComponentState(compState, null);
var newWpos = childTrans.WorldPosition;
// Assert
Assert.That(newWpos, Is.EqualTo(oldWpos));
}
/// <summary>
/// Tests that world rotation is built properly
/// </summary>
[Test]
public void WorldRotationTest()
{
// Arrange
var initalPos = new EntityCoordinates(GridA.GridEntityId, (0, 0));
var node1 = EntityManager.SpawnEntity("dummy", initalPos);
var node2 = EntityManager.SpawnEntity("dummy", initalPos);
var node3 = EntityManager.SpawnEntity("dummy", initalPos);
node1.Name = "node1_dummy";
node2.Name = "node2_dummy";
node3.Name = "node3_dummy";
var node1Trans = node1.Transform;
var node2Trans = node2.Transform;
var node3Trans = node3.Transform;
var compState = new TransformComponent.TransformComponentState(new Vector2(6, 6), Angle.FromDegrees(135), GridB.GridEntityId, false);
node1Trans.HandleComponentState(compState, null);
compState = new TransformComponent.TransformComponentState(new Vector2(1, 1), Angle.FromDegrees(45), node1.Uid, false);
node2Trans.HandleComponentState(compState, null);
compState = new TransformComponent.TransformComponentState(new Vector2(0, 0), Angle.FromDegrees(45), node2.Uid, false);
node3Trans.HandleComponentState(compState, null);
// Act
var result = node3Trans.WorldRotation;
// Assert (135 + 45 + 45 = 225)
Assert.That(result, new ApproxEqualityConstraint(Angle.FromDegrees(225)));
}
}
}