diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 38b2d75884..c6a5fa90c2 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -59,6 +59,7 @@ END TEMPLATE--> ### Breaking changes * Remove the duplicate serialization copy of components kept on ComponentRegistryEntry; now it only stores the deserialized component. To get the raw MappingDataNode for EntityPrototypes use PrototypeManager. This is expected to significantly reduce memory usage. +* Obsolete LocalRotation in favor of the system method. The angle is now also normalized to 2PI and no longer grows indefinitely. ### New features diff --git a/Robust.Server.IntegrationTests/GameObjects/Components/Transform_Test.cs b/Robust.Server.IntegrationTests/GameObjects/Components/Transform_Test.cs index 95b857bb95..14f54d4647 100644 --- a/Robust.Server.IntegrationTests/GameObjects/Components/Transform_Test.cs +++ b/Robust.Server.IntegrationTests/GameObjects/Components/Transform_Test.cs @@ -439,6 +439,21 @@ namespace Robust.Server.IntegrationTests.GameObjects.Components Assert.That(result, new ApproxEqualityConstraint(Angle.FromDegrees(225))); } + [Test] + public void LocalRotationNormalizesTest() + { + var entity = EntityManager.SpawnEntity(null, InitialPos); + var transform = EntityManager.GetComponent(entity); + + XformSystem.SetLocalRotation(entity, Angle.FromDegrees(90), transform); + + Assert.That(transform.LocalRotation, NUnit.Framework.Is.EqualTo(Angle.FromDegrees(90))); + + XformSystem.SetWorldRotation(transform, Angle.FromDegrees(810)); + + Assert.That(transform.LocalRotation, NUnit.Framework.Is.EqualTo(Angle.FromDegrees(90))); + } + /// /// Test that, in a chain A -> B -> C, if A is moved C's world position correctly updates. /// diff --git a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs index f2e132d06c..bb0d20aa20 100644 --- a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs +++ b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs @@ -153,11 +153,14 @@ namespace Robust.Shared.GameObjects public Angle LocalRotation { get => _localRotation; + [Obsolete("Use SharedTransformSystem.SetLocalRotation")] set { if(_noLocalRotation) return; + value = SharedTransformSystem.NormalizeRotation(value); + if (_localRotation.EqualsApprox(value)) return; diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs index 2fa10c984a..cdeeaf29c8 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs @@ -45,7 +45,7 @@ public abstract partial class SharedTransformSystem var oldRot = xform._localRotation; var oldMap = xform.MapUid; xform._localPosition = tilePos + newGrid.TileSizeHalfVector; - xform._localRotation += rotation; + xform._localRotation = NormalizeRotation(xform._localRotation + rotation); var meta = MetaData(uid); SetGridId((uid, xform, meta), newGridUid); @@ -437,6 +437,11 @@ public abstract partial class SharedTransformSystem #region Local Rotation + internal static Angle NormalizeRotation(Angle rotation) + { + return rotation.Reduced(); + } + public void SetLocalRotationNoLerp(EntityUid uid, Angle value, TransformComponent? xform = null) { if (!XformQuery.Resolve(uid, ref xform)) @@ -457,6 +462,27 @@ public abstract partial class SharedTransformSystem #endregion + #region No Local Rotation + + public void SetNoLocalRotation(EntityUid uid, bool value, TransformComponent? xform = null) + { + if (!XformQuery.Resolve(uid, ref xform)) + return; + + SetNoLocalRotation((uid, xform), value); + } + + public void SetNoLocalRotation(Entity entity, bool value) + { + if (value) + SetLocalRotation(entity.Owner, Angle.Zero, entity.Comp); + + entity.Comp._noLocalRotation = value; + Dirty(entity); + } + + #endregion + #region Coordinates public void SetCoordinates(EntityUid uid, EntityCoordinates value) @@ -519,7 +545,7 @@ public abstract partial class SharedTransformSystem xform._localPosition = value.Position; if (rotation != null && !xform.NoLocalRotation) - xform._localRotation = rotation.Value; + xform._localRotation = NormalizeRotation(rotation.Value); DebugTools.Assert(!xform.NoLocalRotation || xform.LocalRotation == 0); @@ -621,7 +647,7 @@ public abstract partial class SharedTransformSystem { // preserve world rotation if (rotation == null && oldParent != null && newParent != null && !xform.NoLocalRotation) - xform._localRotation += GetWorldRotation(oldParent) - GetWorldRotation(newParent); + xform._localRotation = NormalizeRotation(xform._localRotation + GetWorldRotation(oldParent) - GetWorldRotation(newParent)); DebugTools.Assert(!xform.NoLocalRotation || xform.LocalRotation == 0); } @@ -1277,7 +1303,7 @@ public abstract partial class SharedTransformSystem xform._localPosition = pos; if (!xform.NoLocalRotation) - xform._localRotation = rot; + xform._localRotation = NormalizeRotation(rot); DebugTools.Assert(!xform.NoLocalRotation || xform.LocalRotation == 0);