Skip to content

Commit

Permalink
Code cleanup: Purge calls to obsolete EntityCoordinates methods (spac…
Browse files Browse the repository at this point in the history
…e-wizards#26292)

* Purge calls to obsolete EntityCoordinates methods

* Pizza defruited; rerun those tests!
  • Loading branch information
Tayrtahn committed Mar 21, 2024
1 parent b347771 commit f4cb02f
Show file tree
Hide file tree
Showing 34 changed files with 70 additions and 56 deletions.
3 changes: 2 additions & 1 deletion Content.Client/Construction/ConstructionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public sealed class ConstructionSystem : SharedConstructionSystem
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;

private readonly Dictionary<int, EntityUid> _ghosts = new();
Expand Down Expand Up @@ -195,7 +196,7 @@ public bool TrySpawnGhost(
return false;

// This InRangeUnobstructed should probably be replaced with "is there something blocking us in that tile?"
var predicate = GetPredicate(prototype.CanBuildInImpassable, loc.ToMap(EntityManager));
var predicate = GetPredicate(prototype.CanBuildInImpassable, loc.ToMap(EntityManager, _transformSystem));
if (!_interactionSystem.InRangeUnobstructed(user, loc, 20f, predicate: predicate))
return false;

Expand Down
2 changes: 1 addition & 1 deletion Content.Client/ContextMenu/UI/EntityMenuUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private bool HandleOpenEntityMenu(in PointerInputCmdHandler.PointerInputCmdArgs
if (_combatMode.IsInCombatMode(args.Session?.AttachedEntity))
return false;

var coords = args.Coordinates.ToMap(_entityManager);
var coords = args.Coordinates.ToMap(_entityManager, _xform);

if (_verbSystem.TryGetEntityMenuEntities(coords, out var entities))
OpenRootMenu(entities);
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Gameplay/GameplayStateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private bool HandleInspect(ICommonSession? session, EntityCoordinates coords, En

public IEnumerable<EntityUid> GetClickableEntities(EntityCoordinates coordinates)
{
return GetClickableEntities(coordinates.ToMap(_entityManager));
return GetClickableEntities(coordinates.ToMap(_entityManager, _entitySystemManager.GetEntitySystem<SharedTransformSystem>()));
}

public IEnumerable<EntityUid> GetClickableEntities(MapCoordinates coordinates)
Expand Down
10 changes: 7 additions & 3 deletions Content.Client/NPC/PathfindingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class PathfindingSystem : SharedPathfindingSystem
[Dependency] private readonly IResourceCache _cache = default!;
[Dependency] private readonly NPCSteeringSystem _steering = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;

public PathfindingDebugMode Modes
{
Expand All @@ -39,7 +40,7 @@ public PathfindingDebugMode Modes
}
else if (!overlayManager.HasOverlay<PathfindingOverlay>())
{
overlayManager.AddOverlay(new PathfindingOverlay(EntityManager, _eyeManager, _inputManager, _mapManager, _cache, this, _mapSystem));
overlayManager.AddOverlay(new PathfindingOverlay(EntityManager, _eyeManager, _inputManager, _mapManager, _cache, this, _mapSystem, _transformSystem));
}

if ((value & PathfindingDebugMode.Steering) != 0x0)
Expand Down Expand Up @@ -140,6 +141,7 @@ public sealed class PathfindingOverlay : Overlay
private readonly IMapManager _mapManager;
private readonly PathfindingSystem _system;
private readonly MapSystem _mapSystem;
private readonly SharedTransformSystem _transformSystem;

public override OverlaySpace Space => OverlaySpace.ScreenSpace | OverlaySpace.WorldSpace;

Expand All @@ -153,14 +155,16 @@ public PathfindingOverlay(
IMapManager mapManager,
IResourceCache cache,
PathfindingSystem system,
MapSystem mapSystem)
MapSystem mapSystem,
SharedTransformSystem transformSystem)
{
_entManager = entManager;
_eyeManager = eyeManager;
_inputManager = inputManager;
_mapManager = mapManager;
_system = system;
_mapSystem = mapSystem;
_transformSystem = transformSystem;
_font = new VectorFont(cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
}

Expand Down Expand Up @@ -480,7 +484,7 @@ private void DrawWorld(OverlayDrawArgs args, DrawingHandleWorld worldHandle)
if (neighborPoly.NetEntity != poly.GraphUid)
{
color = Color.Green;
var neighborMap = _entManager.GetCoordinates(neighborPoly).ToMap(_entManager);
var neighborMap = _entManager.GetCoordinates(neighborPoly).ToMap(_entManager, _transformSystem);

if (neighborMap.MapId != args.MapId)
continue;
Expand Down
6 changes: 4 additions & 2 deletions Content.Client/Popups/PopupOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class PopupOverlay : Overlay
private readonly PopupSystem _popup;
private readonly PopupUIController _controller;
private readonly ExamineSystemShared _examine;

private readonly SharedTransformSystem _transform;
private readonly ShaderInstance _shader;

public override OverlaySpace Space => OverlaySpace.ScreenSpace;
Expand All @@ -35,13 +35,15 @@ public PopupOverlay(
IUserInterfaceManager uiManager,
PopupUIController controller,
ExamineSystemShared examine,
SharedTransformSystem transform,
PopupSystem popup)
{
_configManager = configManager;
_entManager = entManager;
_playerMgr = playerMgr;
_uiManager = uiManager;
_examine = examine;
_transform = transform;
_popup = popup;
_controller = controller;

Expand Down Expand Up @@ -76,7 +78,7 @@ private void DrawWorld(DrawingHandleScreen worldHandle, OverlayDrawArgs args, fl

foreach (var popup in _popup.WorldLabels)
{
var mapPos = popup.InitialPos.ToMap(_entManager);
var mapPos = popup.InitialPos.ToMap(_entManager, _transform);

if (mapPos.MapId != args.MapId)
continue;
Expand Down
2 changes: 2 additions & 0 deletions Content.Client/Popups/PopupSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class PopupSystem : SharedPopupSystem
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
[Dependency] private readonly IReplayRecordingManager _replayRecording = default!;
[Dependency] private readonly ExamineSystemShared _examine = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

public IReadOnlyList<WorldPopupLabel> WorldLabels => _aliveWorldLabels;
public IReadOnlyList<CursorPopupLabel> CursorLabels => _aliveCursorLabels;
Expand All @@ -54,6 +55,7 @@ public override void Initialize()
_uiManager,
_uiManager.GetUIController<PopupUIController>(),
_examine,
_transform,
this));
}

Expand Down
5 changes: 4 additions & 1 deletion Content.Client/Radiation/Overlays/RadiationPulseOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ private void RadiationQuery(IEye? currentEye)

private bool PulseQualifies(EntityUid pulseEntity, MapCoordinates currentEyeLoc)
{
return _entityManager.GetComponent<TransformComponent>(pulseEntity).MapID == currentEyeLoc.MapId && _entityManager.GetComponent<TransformComponent>(pulseEntity).Coordinates.InRange(_entityManager, EntityCoordinates.FromMap(_entityManager, _entityManager.GetComponent<TransformComponent>(pulseEntity).ParentUid, currentEyeLoc), MaxDist);
var transformComponent = _entityManager.GetComponent<TransformComponent>(pulseEntity);
var transformSystem = _entityManager.System<SharedTransformSystem>();
return transformComponent.MapID == currentEyeLoc.MapId
&& transformComponent.Coordinates.InRange(_entityManager, transformSystem, EntityCoordinates.FromMap(transformComponent.ParentUid, currentEyeLoc, transformSystem, _entityManager), MaxDist);
}

private sealed record RadiationShaderInstance(MapCoordinates CurrentMapCoords, float Range, TimeSpan Start, float Duration)
Expand Down
3 changes: 2 additions & 1 deletion Content.Client/Sandbox/SandboxSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed class SandboxSystem : SharedSandboxSystem
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IPlacementManager _placement = default!;
[Dependency] private readonly ContentEyeSystem _contentEye = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

private bool _sandboxEnabled;
public bool SandboxAllowed { get; private set; }
Expand Down Expand Up @@ -108,7 +109,7 @@ public bool Copy(ICommonSession? session, EntityCoordinates coords, EntityUid ui
}

// Try copy tile.
if (!_map.TryFindGridAt(coords.ToMap(EntityManager), out _, out var grid) || !grid.TryGetTileRef(coords, out var tileRef))
if (!_map.TryFindGridAt(coords.ToMap(EntityManager, _transform), out _, out var grid) || !grid.TryGetTileRef(coords, out var tileRef))
return false;

if (_placement.Eraser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void ExperiencePressureDifference(
// TODO: Technically these directions won't be correct but uhh I'm just here for optimisations buddy not to fix my old bugs.
if (throwTarget != EntityCoordinates.Invalid)
{
var pos = ((throwTarget.ToMap(EntityManager).Position - xform.WorldPosition).Normalized() + dirVec).Normalized();
var pos = ((throwTarget.ToMap(EntityManager, _transformSystem).Position - xform.WorldPosition).Normalized() + dirVec).Normalized();
_physics.ApplyLinearImpulse(uid, pos * moveForce, body: physics);
}
else
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Chemistry/EntitySystems/VaporSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace Content.Server.Chemistry.EntitySystems
[UsedImplicitly]
internal sealed class VaporSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly ThrowingSystem _throwing = default!;
Expand Down Expand Up @@ -115,7 +115,7 @@ private void Update(float frameTime, Entity<VaporComponent> ent, Entity<Solution
{
vapor.ReactTimer = 0;

var tile = gridComp.GetTileRef(xform.Coordinates.ToVector2i(EntityManager, _mapManager));
var tile = _map.GetTileRef(xform.GridUid.Value, gridComp, xform.Coordinates);
foreach (var reagentQuantity in contents.Contents.ToArray())
{
if (reagentQuantity.Quantity == FixedPoint2.Zero) continue;
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Construction/Conditions/ComponentInTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public bool Condition(EntityUid uid, IEntityManager entityManager)
if (transform.GridUid == null)
return false;

var indices = transform.Coordinates.ToVector2i(entityManager, IoCManager.Resolve<IMapManager>());
var transformSys = entityManager.System<SharedTransformSystem>();
var indices = transform.Coordinates.ToVector2i(entityManager, IoCManager.Resolve<IMapManager>(), transformSys);
var lookup = entityManager.EntitySysManager.GetEntitySystem<EntityLookupSystem>();
var entities = indices.GetEntitiesInTile(transform.GridUid.Value, LookupFlags.Approximate | LookupFlags.Static, lookup);

Expand Down
7 changes: 2 additions & 5 deletions Content.Server/Construction/ConstructionSystem.Initial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using System.Threading.Tasks;
using Content.Server.Construction.Components;
using Content.Server.Storage.EntitySystems;
using Content.Shared.ActionBlocker;
using Content.Shared.Construction;
using Content.Shared.Construction.Prototypes;
Expand All @@ -15,7 +14,6 @@
using Content.Shared.Interaction;
using Content.Shared.Inventory;
using Content.Shared.Storage;
using Content.Shared.Tag;
using Robust.Shared.Containers;
using Robust.Shared.Player;
using Robust.Shared.Timing;
Expand All @@ -30,8 +28,7 @@ public sealed partial class ConstructionSystem
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly EntityLookupSystem _lookupSystem = default!;
[Dependency] private readonly StorageSystem _storageSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;

// --- WARNING! LEGACY CODE AHEAD! ---
// This entire file contains the legacy code for initial construction.
Expand Down Expand Up @@ -465,7 +462,7 @@ void Cleanup()
return;
}

var mapPos = location.ToMap(EntityManager);
var mapPos = location.ToMap(EntityManager, _transformSystem);
var predicate = GetPredicate(constructionPrototype.CanBuildInImpassable, mapPos);

if (!_interactionSystem.InRangeUnobstructed(user, mapPos, predicate: predicate))
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Dragon/DragonSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public sealed partial class DragonSystem : EntitySystem
[Dependency] private readonly RoleSystem _role = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

private EntityQuery<CarpRiftsConditionComponent> _objQuery;

Expand Down Expand Up @@ -150,7 +151,7 @@ private void OnSpawnRift(EntityUid uid, DragonComponent component, DragonSpawnRi
// cant stack rifts near eachother
foreach (var (_, riftXform) in EntityQuery<DragonRiftComponent, TransformComponent>(true))
{
if (riftXform.Coordinates.InRange(EntityManager, xform.Coordinates, RiftRange))
if (riftXform.Coordinates.InRange(EntityManager, _transform, xform.Coordinates, RiftRange))
{
_popup.PopupEntity(Loc.GetString("carp-rift-proximity", ("proximity", RiftRange)), uid, uid);
return;
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Explosion/EntitySystems/ExplosionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public void QueueExplosion(MapCoordinates epicenter,
CameraShake(iterationIntensity.Count * 4f, epicenter, totalIntensity);

//For whatever bloody reason, sound system requires ENTITY coordinates.
var mapEntityCoords = EntityCoordinates.FromMap(EntityManager, _mapManager.GetMapEntityId(epicenter.MapId), epicenter);
var mapEntityCoords = EntityCoordinates.FromMap(_mapManager.GetMapEntityId(epicenter.MapId), epicenter, _transformSystem, EntityManager);

// play sound.
// for the normal audio, we want everyone in pvs range
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/GameTicking/GameTicker.Spawning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public EntityCoordinates GetObserverSpawnPoint()
// Ideally engine would just spawn them on grid directly I guess? Right now grid traversal is handling it during
// update which means we need to add a hack somewhere around it.
var spawn = _robustRandom.Pick(_possiblePositions);
var toMap = spawn.ToMap(EntityManager);
var toMap = spawn.ToMap(EntityManager, _transform);

if (_mapManager.TryFindGridAt(toMap, out var gridUid, out _))
{
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Guardian/GuardianSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public sealed class GuardianSystem : EntitySystem
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -324,7 +325,7 @@ private void CheckGuardianMove(
if (!guardianComponent.GuardianLoose)
return;

if (!guardianXform.Coordinates.InRange(EntityManager, hostXform.Coordinates, guardianComponent.DistanceAllowed))
if (!guardianXform.Coordinates.InRange(EntityManager, _transform, hostXform.Coordinates, guardianComponent.DistanceAllowed))
RetractGuardian(hostUid, hostComponent, guardianUid, guardianComponent);
}

Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Hands/Systems/HandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public sealed class HandsSystem : SharedHandsSystem
[Dependency] private readonly VirtualItemSystem _virtualItemSystem = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly PullingSystem _pullingSystem = default!;
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;

Expand Down Expand Up @@ -198,7 +199,7 @@ hands.ActiveHandEntity is not { } throwEnt ||
throwEnt = splitStack.Value;
}

var direction = coordinates.ToMapPos(EntityManager) - Transform(player).WorldPosition;
var direction = coordinates.ToMapPos(EntityManager, _transformSystem) - Transform(player).WorldPosition;
if (direction == Vector2.Zero)
return true;

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Implants/SubdermalImplantSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void OnScramImplant(EntityUid uid, SubdermalImplantComponent component,
return;

var xform = Transform(ent);
var entityCoords = xform.Coordinates.ToMap(EntityManager);
var entityCoords = xform.Coordinates.ToMap(EntityManager, _xform);

// try to find a valid position to teleport to, teleport to whatever works if we can't
var targetCoords = new MapCoordinates();
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Magic/MagicSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void OnProjectileSpell(ProjectileSpellEvent ev)
foreach (var pos in GetSpawnPositions(xform, ev.Pos))
{
// If applicable, this ensures the projectile is parented to grid on spawn, instead of the map.
var mapPos = pos.ToMap(EntityManager);
var mapPos = pos.ToMap(EntityManager, _transformSystem);
var spawnCoords = _mapManager.TryFindGridAt(mapPos, out var gridUid, out _)
? pos.WithEntityId(gridUid, EntityManager)
: new(_mapManager.GetMapEntityId(mapPos.MapId), mapPos.Position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public override bool IsMet(NPCBlackboard blackboard)
if (!blackboard.TryGetValue<EntityCoordinates>(TargetKey, out var target, _entManager))
return false;

return coordinates.InRange(_entManager, target, blackboard.GetValueOrDefault<float>(RangeKey, _entManager));
return coordinates.InRange(_entManager, _entManager.System<SharedTransformSystem>(), target, blackboard.GetValueOrDefault<float>(RangeKey, _entManager));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override bool IsMet(NPCBlackboard blackboard)
if (!blackboard.TryGetValue<EntityCoordinates>(TargetKey, out var target, _entManager))
return false;

return !coordinates.InRange(_entManager, target, blackboard.GetValueOrDefault<float>(RangeKey, _entManager));
return !coordinates.InRange(_entManager, _entManager.System<SharedTransformSystem>(), target, blackboard.GetValueOrDefault<float>(RangeKey, _entManager));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public override bool IsMet(NPCBlackboard blackboard)
!_entManager.TryGetComponent<TransformComponent>(target, out var targetXform))
return false;

return coordinates.InRange(_entManager, targetXform.Coordinates, blackboard.GetValueOrDefault<float>(RangeKey, _entManager));
return coordinates.InRange(_entManager, _entManager.System<SharedTransformSystem>(), targetXform.Coordinates, blackboard.GetValueOrDefault<float>(RangeKey, _entManager));
}
}
Loading

0 comments on commit f4cb02f

Please sign in to comment.