using System.Numerics; using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; 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.UnitTesting.Shared.Physics; [TestFixture, TestOf(typeof(PhysicsMapComponent))] public sealed class PhysicsMap_Test { /// /// If a body has a child does its child's physicsmap get updated. /// [Test] public void RecursiveMapChange() { var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); var mapManager = sim.Resolve(); var system = entManager.EntitySysManager; var physSystem = system.GetEntitySystem(); var fixtureSystem = system.GetEntitySystem(); var xformSystem = system.GetEntitySystem(); var mapId = sim.CreateMap().MapId; var mapId2 = sim.CreateMap().MapId; var mapUid = mapManager.GetMapEntityId(mapId); var mapUid2 = mapManager.GetMapEntityId(mapId2); var physicsMap = entManager.GetComponent(mapUid); var physicsMap2 = entManager.GetComponent(mapUid2); var parent = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId)); var parentXform = entManager.GetComponent(parent); var parentBody = entManager.AddComponent(parent); physSystem.SetBodyType(parent, BodyType.Dynamic); physSystem.SetSleepingAllowed(parent, parentBody, false); fixtureSystem.CreateFixture(parent, "fix1", new Fixture(new PhysShapeCircle(0.5f), 0, 0, false), body: parentBody); physSystem.WakeBody(parent); Assert.That(physicsMap.AwakeBodies, Does.Contain(parentBody)); var child = entManager.SpawnEntity(null, new EntityCoordinates(parent, Vector2.Zero)); var childBody = entManager.AddComponent(child); physSystem.SetBodyType(child, BodyType.Dynamic); physSystem.SetSleepingAllowed(child, childBody, false); fixtureSystem.CreateFixture(child, "fix1", new Fixture(new PhysShapeCircle(0.5f), 0, 0, false), body: childBody); physSystem.WakeBody(child, body: childBody); Assert.That(physicsMap.AwakeBodies, Does.Contain(childBody)); xformSystem.SetParent(parent, parentXform, mapUid2); Assert.That(physicsMap.AwakeBodies, Is.Empty); Assert.That(physicsMap2.AwakeBodies, Has.Count.EqualTo(2)); xformSystem.SetParent(parent, parentXform, mapUid); Assert.That(physicsMap.AwakeBodies, Has.Count.EqualTo(2)); Assert.That(physicsMap2.AwakeBodies, Is.Empty); } }