mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Fix transform test warnings (#4558)
This commit is contained in:
@@ -21,6 +21,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
|
||||
private IServerEntityManagerInternal EntityManager = default!;
|
||||
private IMapManager MapManager = default!;
|
||||
private SharedTransformSystem XformSystem => EntityManager.System<SharedTransformSystem>();
|
||||
|
||||
const string Prototypes = @"
|
||||
- type: entity
|
||||
@@ -35,9 +36,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
";
|
||||
|
||||
private MapId MapA;
|
||||
private Entity<MapGridComponent> GridA = default!;
|
||||
private Entity<MapGridComponent> GridA;
|
||||
private MapId MapB;
|
||||
private Entity<MapGridComponent> GridB = default!;
|
||||
private Entity<MapGridComponent> GridB;
|
||||
|
||||
private static readonly EntityCoordinates InitialPos = new(new EntityUid(1), new Vector2(0, 0));
|
||||
|
||||
@@ -84,39 +85,38 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var childTrans = EntityManager.GetComponent<TransformComponent>(child);
|
||||
|
||||
// that are not on the same map
|
||||
parentTrans.Coordinates = new EntityCoordinates(GridA, new Vector2(5, 5));
|
||||
childTrans.Coordinates = new EntityCoordinates(GridB, new Vector2(4, 4));
|
||||
XformSystem.SetCoordinates(parent, parentTrans, new EntityCoordinates(GridA, new Vector2(5, 5)));
|
||||
XformSystem.SetCoordinates(child, childTrans, new EntityCoordinates(GridB, new Vector2(4, 4)));
|
||||
|
||||
// if they are parented, the child keeps its world position, but moves to the parents map
|
||||
childTrans.AttachParent(parentTrans);
|
||||
|
||||
XformSystem.SetParent(child, childTrans, parent, parentXform: parentTrans);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(childTrans.MapID, Is.EqualTo(parentTrans.MapID));
|
||||
Assert.That(childTrans.GridUid, Is.EqualTo(parentTrans.GridUid));
|
||||
Assert.That(childTrans.Coordinates, Is.EqualTo(new EntityCoordinates(parent, new Vector2(-1, -1))));
|
||||
Assert.That(childTrans.WorldPosition, Is.EqualTo(new Vector2(4, 4)));
|
||||
Assert.That(childTrans.MapID, NUnit.Framework.Is.EqualTo(parentTrans.MapID));
|
||||
Assert.That(childTrans.GridUid, NUnit.Framework.Is.EqualTo(parentTrans.GridUid));
|
||||
Assert.That(childTrans.Coordinates, NUnit.Framework.Is.EqualTo(new EntityCoordinates(parent, new Vector2(-1, -1))));
|
||||
Assert.That(XformSystem.GetWorldPosition(childTrans), NUnit.Framework.Is.EqualTo(new Vector2(4, 4)));
|
||||
});
|
||||
|
||||
// move the parent, and the child should move with it
|
||||
childTrans.LocalPosition = new Vector2(6, 6);
|
||||
parentTrans.WorldPosition = new Vector2(-8, -8);
|
||||
XformSystem.SetLocalPosition(child, new Vector2(6, 6), childTrans);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(-8, -8));
|
||||
|
||||
Assert.That(childTrans.WorldPosition, Is.EqualTo(new Vector2(-2, -2)));
|
||||
Assert.That(XformSystem.GetWorldPosition(childTrans), NUnit.Framework.Is.EqualTo(new Vector2(-2, -2)));
|
||||
|
||||
// if we detach parent, the child should be left where it was, still relative to parents grid
|
||||
var oldLpos = new Vector2(-2, -2);
|
||||
var oldWpos = childTrans.WorldPosition;
|
||||
var oldWpos = XformSystem.GetWorldPosition(childTrans);
|
||||
|
||||
childTrans.AttachToGridOrMap();
|
||||
XformSystem.AttachToGridOrMap(child, childTrans);
|
||||
|
||||
// the gridId won't match, because we just detached from the grid entity
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(childTrans.Coordinates.Position, Is.EqualTo(oldLpos));
|
||||
Assert.That(childTrans.WorldPosition, Is.EqualTo(oldWpos));
|
||||
Assert.That(childTrans.Coordinates.Position, NUnit.Framework.Is.EqualTo(oldLpos));
|
||||
Assert.That(XformSystem.GetWorldPosition(childTrans), NUnit.Framework.Is.EqualTo(oldWpos));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -131,16 +131,16 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var child = EntityManager.SpawnEntity(null, InitialPos);
|
||||
var parentTrans = EntityManager.GetComponent<TransformComponent>(parent);
|
||||
var childTrans = EntityManager.GetComponent<TransformComponent>(child);
|
||||
parentTrans.WorldPosition = new Vector2(5, 5);
|
||||
childTrans.WorldPosition = new Vector2(6, 6);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(5, 5));
|
||||
XformSystem.SetWorldPosition(childTrans, new Vector2(6, 6));
|
||||
|
||||
// Act
|
||||
var oldWpos = childTrans.WorldPosition;
|
||||
childTrans.AttachParent(parentTrans);
|
||||
var newWpos = childTrans.WorldPosition;
|
||||
var oldWpos = XformSystem.GetWorldPosition(childTrans);
|
||||
XformSystem.SetParent(child, childTrans, parent, parentXform: parentTrans);
|
||||
var newWpos = XformSystem.GetWorldPosition(childTrans);
|
||||
|
||||
// Assert
|
||||
Assert.That(oldWpos == newWpos);
|
||||
Assert.That(oldWpos, NUnit.Framework.Is.EqualTo(newWpos));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -156,25 +156,25 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var parentTrans = EntityManager.GetComponent<TransformComponent>(parent);
|
||||
var childOneTrans = EntityManager.GetComponent<TransformComponent>(childOne);
|
||||
var childTwoTrans = EntityManager.GetComponent<TransformComponent>(childTwo);
|
||||
parentTrans.WorldPosition = new Vector2(1, 1);
|
||||
childOneTrans.WorldPosition = new Vector2(2, 2);
|
||||
childTwoTrans.WorldPosition = new Vector2(3, 3);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(childOneTrans, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(childTwoTrans, new Vector2(3, 3));
|
||||
|
||||
// Act
|
||||
var oldWpos = childOneTrans.WorldPosition;
|
||||
childOneTrans.AttachParent(parentTrans);
|
||||
var newWpos = childOneTrans.WorldPosition;
|
||||
Assert.That(oldWpos, Is.EqualTo(newWpos));
|
||||
var oldWpos = XformSystem.GetWorldPosition(childOneTrans);
|
||||
XformSystem.SetParent(childOne, childOneTrans, parent, parentXform: parentTrans);
|
||||
var newWpos = XformSystem.GetWorldPosition(childOneTrans);
|
||||
Assert.That(oldWpos, NUnit.Framework.Is.EqualTo(newWpos));
|
||||
|
||||
oldWpos = childTwoTrans.WorldPosition;
|
||||
childTwoTrans.AttachParent(parentTrans);
|
||||
newWpos = childTwoTrans.WorldPosition;
|
||||
Assert.That(oldWpos, Is.EqualTo(newWpos));
|
||||
oldWpos = XformSystem.GetWorldPosition(childTwoTrans);
|
||||
XformSystem.SetParent(childOne, childOneTrans, parent, parentXform: parentTrans);
|
||||
newWpos = XformSystem.GetWorldPosition(childTwoTrans);
|
||||
Assert.That(oldWpos, NUnit.Framework.Is.EqualTo(newWpos));
|
||||
|
||||
oldWpos = childTwoTrans.WorldPosition;
|
||||
childTwoTrans.AttachParent(childOneTrans);
|
||||
newWpos = childTwoTrans.WorldPosition;
|
||||
Assert.That(oldWpos, Is.EqualTo(newWpos));
|
||||
oldWpos = XformSystem.GetWorldPosition(childTwoTrans);
|
||||
XformSystem.SetParent(childTwo, childTwoTrans, childOne, parentXform: childOneTrans);
|
||||
newWpos = XformSystem.GetWorldPosition(childTwoTrans);
|
||||
Assert.That(oldWpos, NUnit.Framework.Is.EqualTo(newWpos));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -188,15 +188,15 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var child = EntityManager.SpawnEntity(null, InitialPos);
|
||||
var parentTrans = EntityManager.GetComponent<TransformComponent>(parent);
|
||||
var childTrans = EntityManager.GetComponent<TransformComponent>(child);
|
||||
parentTrans.WorldPosition = new Vector2(0, 0);
|
||||
childTrans.WorldPosition = new Vector2(2, 0);
|
||||
childTrans.AttachParent(parentTrans);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(childTrans, new Vector2(2, 0));
|
||||
XformSystem.SetParent(child, childTrans, parent, parentXform: parentTrans);
|
||||
|
||||
//Act
|
||||
parentTrans.LocalRotation = new Angle(MathHelper.Pi / 2);
|
||||
|
||||
//Assert
|
||||
var result = childTrans.WorldPosition;
|
||||
var result = XformSystem.GetWorldPosition(childTrans);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(MathHelper.CloseToPercent(result.X, 0));
|
||||
@@ -215,15 +215,15 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var child = EntityManager.SpawnEntity(null, InitialPos);
|
||||
var parentTrans = EntityManager.GetComponent<TransformComponent>(parent);
|
||||
var childTrans = EntityManager.GetComponent<TransformComponent>(child);
|
||||
parentTrans.WorldPosition = new Vector2(1, 1);
|
||||
childTrans.WorldPosition = new Vector2(2, 1);
|
||||
childTrans.AttachParent(parentTrans);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(childTrans, new Vector2(2, 1));
|
||||
XformSystem.SetParent(child, childTrans, parent, parentXform: parentTrans);
|
||||
|
||||
//Act
|
||||
parentTrans.LocalRotation = new Angle(MathHelper.Pi / 2);
|
||||
|
||||
//Assert
|
||||
var result = childTrans.WorldPosition;
|
||||
var result = XformSystem.GetWorldPosition(childTrans);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(MathHelper.CloseToPercent(result.X, 1));
|
||||
@@ -248,20 +248,20 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
var node4Trans = EntityManager.GetComponent<TransformComponent>(node4);
|
||||
|
||||
node1Trans.WorldPosition = new Vector2(0, 0);
|
||||
node2Trans.WorldPosition = new Vector2(1, 1);
|
||||
node3Trans.WorldPosition = new Vector2(2, 2);
|
||||
node4Trans.WorldPosition = new Vector2(0, 2);
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2Trans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3Trans, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(node4Trans, new Vector2(0, 2));
|
||||
|
||||
node2Trans.AttachParent(node1Trans);
|
||||
node3Trans.AttachParent(node2Trans);
|
||||
node4Trans.AttachParent(node3Trans);
|
||||
XformSystem.SetParent(node2, node2Trans, node1, parentXform: node1Trans);
|
||||
XformSystem.SetParent(node3, node3Trans, node2, parentXform: node2Trans);
|
||||
XformSystem.SetParent(node4, node4Trans, node3, parentXform: node3Trans);
|
||||
|
||||
//Act
|
||||
node1Trans.LocalRotation = new Angle(MathHelper.Pi / 2);
|
||||
|
||||
//Assert
|
||||
var result = node4Trans.WorldPosition;
|
||||
var result = XformSystem.GetWorldPosition(node4Trans);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -285,25 +285,25 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node2Trans = EntityManager.GetComponent<TransformComponent>(node2);
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
|
||||
node1Trans.WorldPosition = new Vector2(0, 0);
|
||||
node2Trans.WorldPosition = new Vector2(1, 1);
|
||||
node3Trans.WorldPosition = new Vector2(2, 2);
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2Trans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3Trans, new Vector2(2, 2));
|
||||
|
||||
node2Trans.AttachParent(node1Trans);
|
||||
node3Trans.AttachParent(node2Trans);
|
||||
XformSystem.SetParent(node1, node1Trans, node2, parentXform: node2Trans);
|
||||
XformSystem.SetParent(node2, node2Trans, node3, parentXform: node3Trans);
|
||||
|
||||
// Act
|
||||
var oldWpos = node3Trans.WorldPosition;
|
||||
var oldWpos = XformSystem.GetWorldPosition(node3Trans);
|
||||
|
||||
for (var i = 0; i < 10000; i++)
|
||||
{
|
||||
var dx = i % 2 == 0 ? 5 : -5;
|
||||
node1Trans.LocalPosition += new Vector2(dx, dx);
|
||||
node2Trans.LocalPosition += new Vector2(dx, dx);
|
||||
node3Trans.LocalPosition += new Vector2(dx, dx);
|
||||
XformSystem.SetLocalPosition(node1, node1Trans.LocalPosition + new Vector2(dx, dx), node1Trans);
|
||||
XformSystem.SetLocalPosition(node2, node2Trans.LocalPosition + new Vector2(dx, dx), node2Trans);
|
||||
XformSystem.SetLocalPosition(node3, node3Trans.LocalPosition + new Vector2(dx, dx), node3Trans);
|
||||
}
|
||||
|
||||
var newWpos = node3Trans.WorldPosition;
|
||||
var newWpos = XformSystem.GetWorldPosition(node3Trans);
|
||||
|
||||
// Assert
|
||||
Assert.Multiple(() =>
|
||||
@@ -330,15 +330,15 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node2Trans = EntityManager.GetComponent<TransformComponent>(node2);
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
|
||||
node1Trans.WorldPosition = new Vector2(0, 0);
|
||||
node2Trans.WorldPosition = new Vector2(1, 1);
|
||||
node3Trans.WorldPosition = new Vector2(2, 2);
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2Trans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3Trans, new Vector2(2, 2));
|
||||
|
||||
node2Trans.AttachParent(node1Trans);
|
||||
node3Trans.AttachParent(node2Trans);
|
||||
XformSystem.SetParent(node2, node2Trans, node1, parentXform: node1Trans);
|
||||
XformSystem.SetParent(node3, node3Trans, node2, parentXform: node2Trans);
|
||||
|
||||
// Act
|
||||
var oldWpos = node3Trans.WorldPosition;
|
||||
var oldWpos = XformSystem.GetWorldPosition(node3Trans);
|
||||
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
@@ -347,7 +347,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
node3Trans.LocalRotation += new Angle(MathHelper.Pi);
|
||||
}
|
||||
|
||||
var newWpos = node3Trans.WorldPosition;
|
||||
var newWpos = XformSystem.GetWorldPosition(node3Trans);
|
||||
|
||||
//NOTE: Yes, this does cause a non-zero error
|
||||
|
||||
@@ -355,8 +355,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(MathHelper.CloseToPercent(oldWpos.X, newWpos.Y));
|
||||
Assert.That(MathHelper.CloseToPercent(oldWpos.Y, newWpos.Y));
|
||||
Assert.That(MathHelper.CloseToPercent(oldWpos.X, newWpos.Y, 0.0001f));
|
||||
Assert.That(MathHelper.CloseToPercent(oldWpos.Y, newWpos.Y, 0.0001f));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -379,21 +379,21 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
var node4Trans = EntityManager.GetComponent<TransformComponent>(node4);
|
||||
|
||||
node1Trans.WorldPosition = new Vector2(0, 0);
|
||||
node2Trans.WorldPosition = new Vector2(1, 1);
|
||||
node3Trans.WorldPosition = new Vector2(2, 2);
|
||||
node4Trans.WorldPosition = new Vector2(0, 2);
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2Trans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3Trans, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(node4Trans, new Vector2(0, 2));
|
||||
|
||||
node2Trans.AttachParent(node1Trans);
|
||||
node3Trans.AttachParent(node2Trans);
|
||||
node4Trans.AttachParent(node3Trans);
|
||||
XformSystem.SetParent(node2, node2Trans, node1, parentXform: node1Trans);
|
||||
XformSystem.SetParent(node3, node3Trans, node2, parentXform: node2Trans);
|
||||
XformSystem.SetParent(node4, node4Trans, node3, parentXform: node3Trans);
|
||||
|
||||
//Act
|
||||
node1Trans.LocalRotation = new Angle(MathHelper.Pi / 6.37);
|
||||
node1Trans.WorldPosition = new Vector2(1, 1);
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(1, 1));
|
||||
|
||||
var worldMat = node4Trans.WorldMatrix;
|
||||
var invWorldMat = node4Trans.InvWorldMatrix;
|
||||
var worldMat = XformSystem.GetWorldMatrix(node4Trans);
|
||||
var invWorldMat = XformSystem.GetInvWorldMatrix(node4Trans);
|
||||
|
||||
Matrix3.Multiply(in worldMat, in invWorldMat, out var leftVerifyMatrix);
|
||||
Matrix3.Multiply(in invWorldMat, in worldMat, out var rightVerifyMatrix);
|
||||
@@ -425,8 +425,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node2Trans = EntityManager.GetComponent<TransformComponent>(node2);
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
|
||||
node2Trans.AttachParent(node1Trans);
|
||||
node3Trans.AttachParent(node2Trans);
|
||||
XformSystem.SetParent(node2, node2Trans, node1, parentXform: node1Trans);
|
||||
XformSystem.SetParent(node3, node3Trans, node2, parentXform: node2Trans);
|
||||
|
||||
node1Trans.LocalRotation = Angle.FromDegrees(0);
|
||||
node2Trans.LocalRotation = Angle.FromDegrees(45);
|
||||
@@ -436,7 +436,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
node1Trans.LocalRotation = Angle.FromDegrees(135);
|
||||
|
||||
// Assert (135 + 45 + 45 = 225)
|
||||
var result = node3Trans.WorldRotation;
|
||||
var result = XformSystem.GetWorldRotation(node3Trans);
|
||||
Assert.That(result, new ApproxEqualityConstraint(Angle.FromDegrees(225)));
|
||||
}
|
||||
|
||||
@@ -454,14 +454,14 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node2Trans = EntityManager.GetComponent<TransformComponent>(node2);
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
|
||||
node2Trans.AttachParent(node1Trans);
|
||||
node3Trans.AttachParent(node2Trans);
|
||||
XformSystem.SetParent(node2, node2Trans, node1, parentXform: node1Trans);
|
||||
XformSystem.SetParent(node3, node3Trans, node2, parentXform: node2Trans);
|
||||
|
||||
node3Trans.LocalPosition = new Vector2(5, 5);
|
||||
node2Trans.LocalPosition = new Vector2(5, 5);
|
||||
node1Trans.LocalPosition = new Vector2(5, 5);
|
||||
XformSystem.SetLocalPosition(node3, new Vector2(5, 5), node3Trans);
|
||||
XformSystem.SetLocalPosition(node2, new Vector2(5, 5), node2Trans);
|
||||
XformSystem.SetLocalPosition(node1, new Vector2(5, 5), node1Trans);
|
||||
|
||||
Assert.That(node3Trans.WorldPosition, new ApproxEqualityConstraint(new Vector2(15, 15)));
|
||||
Assert.That(XformSystem.GetWorldPosition(node3Trans), new ApproxEqualityConstraint(new Vector2(15, 15)));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user