Code cleanup: puddles and spreaders (#26102)

* Removed obsolete MapManager calls

* More code cleanup

* EnsureComp

* Rerun tests
This commit is contained in:
Tayrtahn
2024-03-14 23:41:08 -04:00
committed by GitHub
parent 361092a40b
commit cf0da11eb7
6 changed files with 65 additions and 60 deletions

View File

@@ -13,9 +13,11 @@ public sealed class PuddleDebugDebugOverlaySystem : SharedPuddleDebugOverlaySyst
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly PuddleSystem _puddle = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
private readonly HashSet<ICommonSession> _playerObservers = new();
private List<Entity<MapGridComponent>> _grids = new();
private readonly HashSet<ICommonSession> _playerObservers = [];
private List<Entity<MapGridComponent>> _grids = [];
public bool ToggleObserver(ICommonSession observer)
{
@@ -55,7 +57,8 @@ public sealed class PuddleDebugDebugOverlaySystem : SharedPuddleDebugOverlaySyst
var transform = EntityManager.GetComponent<TransformComponent>(entity);
var worldBounds = Box2.CenteredAround(transform.WorldPosition,
var worldBounds = Box2.CenteredAround(_transform.GetWorldPosition(transform),
new Vector2(LocalViewRange, LocalViewRange));
_grids.Clear();
@@ -69,14 +72,14 @@ public sealed class PuddleDebugDebugOverlaySystem : SharedPuddleDebugOverlaySyst
if (!Exists(gridUid))
continue;
foreach (var uid in grid.Comp.GetAnchoredEntities(worldBounds))
foreach (var uid in _map.GetAnchoredEntities(gridUid, grid, worldBounds))
{
PuddleComponent? puddle = null;
TransformComponent? xform = null;
if (!Resolve(uid, ref puddle, ref xform, false))
continue;
var pos = xform.Coordinates.ToVector2i(EntityManager, _mapManager);
var pos = xform.Coordinates.ToVector2i(EntityManager, _mapManager, _transform);
var vol = _puddle.CurrentVolume(uid, puddle);
data.Add(new PuddleDebugOverlayData(pos, vol));
}

View File

@@ -41,7 +41,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefMan = default!;
@@ -124,7 +124,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
foreach (var neighbor in args.NeighborFreeTiles)
{
var split = overflow.SplitSolution(spillAmount);
TrySpillAt(neighbor.Grid.GridTileToLocal(neighbor.Tile), split, out _, false);
TrySpillAt(_map.GridTileToLocal(neighbor.Tile.GridUid, neighbor.Grid, neighbor.Tile.GridIndices), split, out _, false);
args.Updates--;
if (args.Updates <= 0)
@@ -612,13 +612,14 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
return false;
}
if (!_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var mapGrid))
var gridUid = coordinates.GetGridUid(EntityManager);
if (!TryComp<MapGridComponent>(gridUid, out var mapGrid))
{
puddleUid = EntityUid.Invalid;
return false;
}
return TrySpillAt(mapGrid.GetTileRef(coordinates), solution, out puddleUid, sound);
return TrySpillAt(_map.GetTileRef(gridUid.Value, mapGrid, coordinates), solution, out puddleUid, sound);
}
/// <summary>
@@ -657,7 +658,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
// Let's not spill to invalid grids.
var gridId = tileRef.GridUid;
if (!_mapManager.TryGetGrid(gridId, out var mapGrid))
if (!TryComp<MapGridComponent>(gridId, out var mapGrid))
{
puddleUid = EntityUid.Invalid;
return false;
@@ -678,7 +679,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
// Get normalized co-ordinate for spill location and spill it in the centre
// TODO: Does SnapGrid or something else already do this?
var anchored = mapGrid.GetAnchoredEntitiesEnumerator(tileRef.GridIndices);
var anchored = _map.GetAnchoredEntitiesEnumerator(gridId, mapGrid, tileRef.GridIndices);
var puddleQuery = GetEntityQuery<PuddleComponent>();
var sparklesQuery = GetEntityQuery<EvaporationSparkleComponent>();
@@ -703,7 +704,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
return true;
}
var coords = mapGrid.GridTileToLocal(tileRef.GridIndices);
var coords = _map.GridTileToLocal(gridId, mapGrid, tileRef.GridIndices);
puddleUid = EntityManager.SpawnEntity("Puddle", coords);
EnsureComp<PuddleComponent>(puddleUid);
if (TryAddSolution(puddleUid, solution, sound))
@@ -740,7 +741,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
if (!TryComp<MapGridComponent>(tile.GridUid, out var grid))
return false;
var anc = grid.GetAnchoredEntitiesEnumerator(tile.GridIndices);
var anc = _map.GetAnchoredEntitiesEnumerator(tile.GridUid, grid, tile.GridIndices);
var puddleQuery = GetEntityQuery<PuddleComponent>();
while (anc.MoveNext(out var ent))

View File

@@ -13,7 +13,7 @@ using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Content.Shared.Smoking;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
@@ -35,7 +35,7 @@ public sealed class SmokeSystem : EntitySystem
// If I could do it all again this could probably use a lot more of puddles.
[Dependency] private readonly IAdminLogManager _logger = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
@@ -45,7 +45,6 @@ public sealed class SmokeSystem : EntitySystem
[Dependency] private readonly SharedBroadphaseSystem _broadphase = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly TransformSystem _transform = default!;
private EntityQuery<SmokeComponent> _smokeQuery;
private EntityQuery<SmokeAffectedComponent> _smokeAffectedQuery;
@@ -137,7 +136,7 @@ public sealed class SmokeSystem : EntitySystem
return;
}
if (!args.NeighborFreeTiles.Any())
if (args.NeighborFreeTiles.Count == 0)
return;
TryComp<TimedDespawnComponent>(entity, out var timer);
@@ -146,10 +145,10 @@ public sealed class SmokeSystem : EntitySystem
var smokePerSpread = entity.Comp.SpreadAmount / Math.Max(1, args.NeighborFreeTiles.Count);
foreach (var neighbor in args.NeighborFreeTiles)
{
var coords = neighbor.Grid.GridTileToLocal(neighbor.Tile);
var coords = _map.GridTileToLocal(neighbor.Tile.GridUid, neighbor.Grid, neighbor.Tile.GridIndices);
var ent = Spawn(prototype.ID, coords);
var spreadAmount = Math.Max(0, smokePerSpread);
entity.Comp.SpreadAmount -= args.NeighborFreeTiles.Count();
entity.Comp.SpreadAmount -= args.NeighborFreeTiles.Count;
StartSmoke(ent, solution.Clone(), timer?.Lifetime ?? entity.Comp.Duration, spreadAmount);
@@ -305,10 +304,10 @@ public sealed class SmokeSystem : EntitySystem
if (!_solutionContainerSystem.ResolveSolution(uid, SmokeComponent.SolutionName, ref component.Solution, out var solution) || !solution.Any())
return;
if (!_mapManager.TryGetGrid(xform.GridUid, out var mapGrid))
if (!TryComp<MapGridComponent>(xform.GridUid, out var mapGrid))
return;
var tile = mapGrid.GetTileRef(xform.Coordinates.ToVector2i(EntityManager, _mapManager, _transform));
var tile = _map.GetTileRef(xform.GridUid.Value, mapGrid, xform.Coordinates);
foreach (var reagentQuantity in solution.Contents.ToArray())
{