Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup: Purge calls to obsolete EntityCoordinates methods #4983

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Robust.Client/GameObjects/EntitySystems/InputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed class InputSystem : SharedInputSystem, IPostInjectInit
[Dependency] private readonly IConsoleHost _conHost = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

private ISawmill _sawmillInputContext = default!;

Expand Down Expand Up @@ -151,7 +152,7 @@ private void GenerateInputCommand(IConsoleShell shell, string argstr, string[] a

var pxform = Transform(pent);
var wPos = pxform.WorldPosition + new Vector2(float.Parse(args[2]), float.Parse(args[3]));
var coords = EntityCoordinates.FromMap(EntityManager, pent, new MapCoordinates(wPos, pxform.MapID));
var coords = EntityCoordinates.FromMap(pent, new MapCoordinates(wPos, pxform.MapID), _transform, EntityManager);

var funcId = _inputManager.NetworkBindMap.KeyFunctionID(keyFunction);

Expand Down
2 changes: 1 addition & 1 deletion Robust.Client/Placement/Modes/AlignSimilar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void AlignPlacementMode(ScreenCoordinates mouseScreen)

var snapToEntities = EntitySystem.Get<EntityLookupSystem>().GetEntitiesInRange(MouseCoords, SnapToRange)
.Where(entity => pManager.EntityManager.GetComponent<MetaDataComponent>(entity).EntityPrototype == pManager.CurrentPrototype && pManager.EntityManager.GetComponent<TransformComponent>(entity).MapID == mapId)
.OrderBy(entity => (pManager.EntityManager.GetComponent<TransformComponent>(entity).WorldPosition - MouseCoords.ToMapPos(pManager.EntityManager)).LengthSquared())
.OrderBy(entity => (pManager.EntityManager.GetComponent<TransformComponent>(entity).WorldPosition - MouseCoords.ToMapPos(pManager.EntityManager, pManager.EntityManager.System<SharedTransformSystem>())).LengthSquared())
.ToList();

if (snapToEntities.Count == 0)
Expand Down
20 changes: 13 additions & 7 deletions Robust.Client/Placement/PlacementMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ public virtual void Render(DrawingHandleWorld handle)

var dirAng = pManager.Direction.ToAngle();
var spriteSys = pManager.EntityManager.System<SpriteSystem>();
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
foreach (var coordinate in locationcollection)
{
if (!coordinate.IsValid(pManager.EntityManager))
return; // Just some paranoia just in case
var worldPos = coordinate.ToMapPos(pManager.EntityManager);
var worldPos = coordinate.ToMapPos(pManager.EntityManager, transformSys);
var worldRot = pManager.EntityManager.GetComponent<TransformComponent>(coordinate.EntityId).WorldRotation + dirAng;

sprite.Color = IsValidPosition(coordinate) ? ValidPlaceColor : InvalidPlaceColor;
Expand All @@ -136,11 +137,12 @@ public IEnumerable<EntityCoordinates> LineCoordinates()
{
var mouseScreen = pManager.InputManager.MouseScreenPosition;
var mousePos = pManager.EyeManager.PixelToMap(mouseScreen);
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();

if (mousePos.MapId == MapId.Nullspace)
yield break;

var (_, (x, y)) = EntityCoordinates.FromMap(pManager.StartPoint.EntityId, mousePos, pManager.EntityManager) - pManager.StartPoint;
var (_, (x, y)) = EntityCoordinates.FromMap(pManager.StartPoint.EntityId, mousePos, transformSys, pManager.EntityManager) - pManager.StartPoint;
float iterations;
Vector2 distance;
if (Math.Abs(x) > Math.Abs(y))
Expand All @@ -167,11 +169,12 @@ public IEnumerable<EntityCoordinates> GridCoordinates()
{
var mouseScreen = pManager.InputManager.MouseScreenPosition;
var mousePos = pManager.EyeManager.PixelToMap(mouseScreen);
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();

if (mousePos.MapId == MapId.Nullspace)
yield break;

var placementdiff = EntityCoordinates.FromMap(pManager.StartPoint.EntityId, mousePos, pManager.EntityManager) - pManager.StartPoint;
var placementdiff = EntityCoordinates.FromMap(pManager.StartPoint.EntityId, mousePos, transformSys, pManager.EntityManager) - pManager.StartPoint;

var xSign = Math.Sign(placementdiff.X);
var ySign = Math.Sign(placementdiff.Y);
Expand All @@ -195,7 +198,7 @@ public TileRef GetTileRef(EntityCoordinates coordinates)
var gridUidOpt = coordinates.GetGridUid(pManager.EntityManager);
return gridUidOpt is EntityUid gridUid && gridUid.IsValid() ? pManager.MapManager.GetGrid(gridUid).GetTileRef(MouseCoords)
: new TileRef(gridUidOpt ?? EntityUid.Invalid,
MouseCoords.ToVector2i(pManager.EntityManager, pManager.MapManager), Tile.Empty);
MouseCoords.ToVector2i(pManager.EntityManager, pManager.MapManager, pManager.EntityManager.System<SharedTransformSystem>()), Tile.Empty);
}

public TextureResource GetSprite(string key)
Expand Down Expand Up @@ -223,15 +226,17 @@ public bool RangeCheck(EntityCoordinates coordinates)
}

var range = pManager.CurrentPermission!.Range;
if (range > 0 && !pManager.EntityManager.GetComponent<TransformComponent>(controlled).Coordinates.InRange(pManager.EntityManager, coordinates, range))
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
if (range > 0 && !pManager.EntityManager.GetComponent<TransformComponent>(controlled).Coordinates.InRange(pManager.EntityManager, transformSys, coordinates, range))
return false;
return true;
}

public bool IsColliding(EntityCoordinates coordinates)
{
var bounds = pManager.ColliderAABB;
var mapCoords = coordinates.ToMap(pManager.EntityManager);
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
var mapCoords = coordinates.ToMap(pManager.EntityManager, transformSys);
var (x, y) = mapCoords.Position;

var collisionBox = Box2.FromDimensions(
Expand Down Expand Up @@ -261,7 +266,8 @@ protected EntityCoordinates ScreenToCursorGrid(ScreenCoordinates coords)
return EntityCoordinates.FromMap(pManager.MapManager, mapCoords);
}

return EntityCoordinates.FromMap(pManager.EntityManager, gridUid, mapCoords);
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
return EntityCoordinates.FromMap(gridUid, mapCoords, transformSys, pManager.EntityManager);
}
}
}
3 changes: 2 additions & 1 deletion Robust.Shared/Map/CoordinatesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static EntityCoordinates AlignWithClosestGridTile(this EntityCoordinates
return mapSystem.GridTileToLocal(gridId.Value, mapGrid, mapSystem.CoordinatesToTile(gridId.Value, mapGrid, coords));
}

var mapCoords = coords.ToMap(entityManager);
var transformSystem = entityManager.System<SharedTransformSystem>();
var mapCoords = coords.ToMap(entityManager, transformSystem);

if (mapManager.TryFindGridAt(mapCoords, out var gridUid, out mapGrid))
{
Expand Down
4 changes: 2 additions & 2 deletions Robust.Shared/Map/EntityCoordinates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public MapCoordinates ToMap(IEntityManager entityManager, SharedTransformSystem
[Obsolete("Use ToMapPos() with TransformSystem overload")]
public Vector2 ToMapPos(IEntityManager entityManager)
{
return ToMap(entityManager).Position;
return ToMap(entityManager, entityManager.System<SharedTransformSystem>()).Position;
}

/// <summary>
Expand Down Expand Up @@ -160,7 +160,7 @@ public static EntityCoordinates FromMap(EntityUid entity, MapCoordinates coordin
[Obsolete("Use overload with other parameter order.")]
public static EntityCoordinates FromMap(IEntityManager entityManager, EntityUid entityUid, MapCoordinates coordinates)
{
return FromMap(entityUid, coordinates, entityManager);
return FromMap(entityUid, coordinates, entityManager.System<SharedTransformSystem>(), entityManager);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Robust.Shared/Player/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Filter AddPlayersByPvs(TransformComponent origin, float rangeMultiplier =
public Filter AddPlayersByPvs(EntityCoordinates origin, float rangeMultiplier = 2f, IEntityManager? entityMan = null, ISharedPlayerManager? playerMan = null)
{
IoCManager.Resolve(ref entityMan, ref playerMan);
return AddPlayersByPvs(origin.ToMap(entityMan), rangeMultiplier, entityMan, playerMan);
return AddPlayersByPvs(origin.ToMap(entityMan, entityMan.System<SharedTransformSystem>()), rangeMultiplier, entityMan, playerMan);
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions Robust.UnitTesting/Shared/Map/EntityCoordinates_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,18 @@ public void ToMap_MoveGrid(float x1, float y1, float x2, float y2)
var entityManager = IoCManager.Resolve<IEntityManager>();
var mapManager = IoCManager.Resolve<IMapManager>();

var transformSystem = entityManager.System<SharedTransformSystem>();

var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGridEntity(mapId);
var gridEnt = grid.Owner;
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, entPos));

Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.ToMap(entityManager), Is.EqualTo(new MapCoordinates(entPos, mapId)));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.ToMap(entityManager, transformSystem), Is.EqualTo(new MapCoordinates(entPos, mapId)));

IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(gridEnt).LocalPosition += gridPos;

Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.ToMap(entityManager), Is.EqualTo(new MapCoordinates(entPos + gridPos, mapId)));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.ToMap(entityManager, transformSystem), Is.EqualTo(new MapCoordinates(entPos + gridPos, mapId)));
}

[Test]
Expand Down
Loading