Replace obsolete map functions in IconSmoothSystem (#30958)
* first part * second part
This commit is contained in:
@@ -16,6 +16,8 @@ namespace Content.Client.IconSmoothing
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed partial class IconSmoothSystem : EntitySystem
|
public sealed partial class IconSmoothSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
||||||
|
|
||||||
private readonly Queue<EntityUid> _dirtyEntities = new();
|
private readonly Queue<EntityUid> _dirtyEntities = new();
|
||||||
private readonly Queue<EntityUid> _anchorChangedEntities = new();
|
private readonly Queue<EntityUid> _anchorChangedEntities = new();
|
||||||
|
|
||||||
@@ -46,7 +48,7 @@ namespace Content.Client.IconSmoothing
|
|||||||
if (xform.Anchored)
|
if (xform.Anchored)
|
||||||
{
|
{
|
||||||
component.LastPosition = TryComp<MapGridComponent>(xform.GridUid, out var grid)
|
component.LastPosition = TryComp<MapGridComponent>(xform.GridUid, out var grid)
|
||||||
? (xform.GridUid.Value, grid.TileIndicesFor(xform.Coordinates))
|
? (xform.GridUid.Value, _mapSystem.TileIndicesFor(xform.GridUid.Value, grid, xform.Coordinates))
|
||||||
: (null, new Vector2i(0, 0));
|
: (null, new Vector2i(0, 0));
|
||||||
|
|
||||||
DirtyNeighbours(uid, component);
|
DirtyNeighbours(uid, component);
|
||||||
@@ -151,9 +153,12 @@ namespace Content.Client.IconSmoothing
|
|||||||
|
|
||||||
Vector2i pos;
|
Vector2i pos;
|
||||||
|
|
||||||
|
EntityUid entityUid;
|
||||||
|
|
||||||
if (transform.Anchored && TryComp<MapGridComponent>(transform.GridUid, out var grid))
|
if (transform.Anchored && TryComp<MapGridComponent>(transform.GridUid, out var grid))
|
||||||
{
|
{
|
||||||
pos = grid.CoordinatesToTile(transform.Coordinates);
|
entityUid = transform.GridUid.Value;
|
||||||
|
pos = _mapSystem.CoordinatesToTile(transform.GridUid.Value, grid, transform.Coordinates);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -164,21 +169,22 @@ namespace Content.Client.IconSmoothing
|
|||||||
if (!TryComp(gridId, out grid))
|
if (!TryComp(gridId, out grid))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
entityUid = gridId;
|
||||||
pos = oldPos;
|
pos = oldPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yes, we updates ALL smoothing entities surrounding us even if they would never smooth with us.
|
// Yes, we updates ALL smoothing entities surrounding us even if they would never smooth with us.
|
||||||
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(1, 0)));
|
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(1, 0)));
|
||||||
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(-1, 0)));
|
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(-1, 0)));
|
||||||
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(0, 1)));
|
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(0, 1)));
|
||||||
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(0, -1)));
|
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(0, -1)));
|
||||||
|
|
||||||
if (comp.Mode is IconSmoothingMode.Corners or IconSmoothingMode.NoSprite or IconSmoothingMode.Diagonal)
|
if (comp.Mode is IconSmoothingMode.Corners or IconSmoothingMode.NoSprite or IconSmoothingMode.Diagonal)
|
||||||
{
|
{
|
||||||
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(1, 1)));
|
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(1, 1)));
|
||||||
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(-1, -1)));
|
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(-1, -1)));
|
||||||
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(-1, 1)));
|
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(-1, 1)));
|
||||||
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(1, -1)));
|
DirtyEntities(_mapSystem.GetAnchoredEntitiesEnumerator(entityUid, grid, pos + new Vector2i(1, -1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +212,7 @@ namespace Content.Client.IconSmoothing
|
|||||||
IconSmoothComponent? smooth = null)
|
IconSmoothComponent? smooth = null)
|
||||||
{
|
{
|
||||||
TransformComponent? xform;
|
TransformComponent? xform;
|
||||||
MapGridComponent? grid = null;
|
Entity<MapGridComponent>? gridEntity = null;
|
||||||
|
|
||||||
// The generation check prevents updating an entity multiple times per tick.
|
// The generation check prevents updating an entity multiple times per tick.
|
||||||
// As it stands now, it's totally possible for something to get queued twice.
|
// As it stands now, it's totally possible for something to get queued twice.
|
||||||
@@ -223,17 +229,20 @@ namespace Content.Client.IconSmoothing
|
|||||||
{
|
{
|
||||||
var directions = DirectionFlag.None;
|
var directions = DirectionFlag.None;
|
||||||
|
|
||||||
if (TryComp(xform.GridUid, out grid))
|
if (TryComp(xform.GridUid, out MapGridComponent? grid))
|
||||||
{
|
{
|
||||||
var pos = grid.TileIndicesFor(xform.Coordinates);
|
var gridUid = xform.GridUid.Value;
|
||||||
|
var pos = _mapSystem.TileIndicesFor(gridUid, grid, xform.Coordinates);
|
||||||
|
|
||||||
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.North)), smoothQuery))
|
gridEntity = (gridUid, grid);
|
||||||
|
|
||||||
|
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.North)), smoothQuery))
|
||||||
directions |= DirectionFlag.North;
|
directions |= DirectionFlag.North;
|
||||||
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.South)), smoothQuery))
|
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.South)), smoothQuery))
|
||||||
directions |= DirectionFlag.South;
|
directions |= DirectionFlag.South;
|
||||||
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.East)), smoothQuery))
|
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.East)), smoothQuery))
|
||||||
directions |= DirectionFlag.East;
|
directions |= DirectionFlag.East;
|
||||||
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.West)), smoothQuery))
|
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.West)), smoothQuery))
|
||||||
directions |= DirectionFlag.West;
|
directions |= DirectionFlag.West;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +266,11 @@ namespace Content.Client.IconSmoothing
|
|||||||
|
|
||||||
if (xform.Anchored)
|
if (xform.Anchored)
|
||||||
{
|
{
|
||||||
if (!TryComp(xform.GridUid, out grid))
|
if (TryComp(xform.GridUid, out MapGridComponent? grid))
|
||||||
|
{
|
||||||
|
gridEntity = (xform.GridUid.Value, grid);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Log.Error($"Failed to calculate IconSmoothComponent sprite in {uid} because grid {xform.GridUid} was missing.");
|
Log.Error($"Failed to calculate IconSmoothComponent sprite in {uid} because grid {xform.GridUid} was missing.");
|
||||||
return;
|
return;
|
||||||
@@ -267,28 +280,31 @@ namespace Content.Client.IconSmoothing
|
|||||||
switch (smooth.Mode)
|
switch (smooth.Mode)
|
||||||
{
|
{
|
||||||
case IconSmoothingMode.Corners:
|
case IconSmoothingMode.Corners:
|
||||||
CalculateNewSpriteCorners(grid, smooth, spriteEnt, xform, smoothQuery);
|
CalculateNewSpriteCorners(gridEntity, smooth, spriteEnt, xform, smoothQuery);
|
||||||
break;
|
break;
|
||||||
case IconSmoothingMode.CardinalFlags:
|
case IconSmoothingMode.CardinalFlags:
|
||||||
CalculateNewSpriteCardinal(grid, smooth, spriteEnt, xform, smoothQuery);
|
CalculateNewSpriteCardinal(gridEntity, smooth, spriteEnt, xform, smoothQuery);
|
||||||
break;
|
break;
|
||||||
case IconSmoothingMode.Diagonal:
|
case IconSmoothingMode.Diagonal:
|
||||||
CalculateNewSpriteDiagonal(grid, smooth, spriteEnt, xform, smoothQuery);
|
CalculateNewSpriteDiagonal(gridEntity, smooth, spriteEnt, xform, smoothQuery);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CalculateNewSpriteDiagonal(MapGridComponent? grid, IconSmoothComponent smooth,
|
private void CalculateNewSpriteDiagonal(Entity<MapGridComponent>? gridEntity, IconSmoothComponent smooth,
|
||||||
Entity<SpriteComponent> sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
Entity<SpriteComponent> sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
||||||
{
|
{
|
||||||
if (grid == null)
|
if (gridEntity == null)
|
||||||
{
|
{
|
||||||
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}0");
|
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gridUid = gridEntity.Value.Owner;
|
||||||
|
var grid = gridEntity.Value.Comp;
|
||||||
|
|
||||||
var neighbors = new Vector2[]
|
var neighbors = new Vector2[]
|
||||||
{
|
{
|
||||||
new(1, 0),
|
new(1, 0),
|
||||||
@@ -296,14 +312,14 @@ namespace Content.Client.IconSmoothing
|
|||||||
new(0, -1),
|
new(0, -1),
|
||||||
};
|
};
|
||||||
|
|
||||||
var pos = grid.TileIndicesFor(xform.Coordinates);
|
var pos = _mapSystem.TileIndicesFor(gridUid, grid, xform.Coordinates);
|
||||||
var rotation = xform.LocalRotation;
|
var rotation = xform.LocalRotation;
|
||||||
var matching = true;
|
var matching = true;
|
||||||
|
|
||||||
for (var i = 0; i < neighbors.Length; i++)
|
for (var i = 0; i < neighbors.Length; i++)
|
||||||
{
|
{
|
||||||
var neighbor = (Vector2i) rotation.RotateVec(neighbors[i]);
|
var neighbor = (Vector2i)rotation.RotateVec(neighbors[i]);
|
||||||
matching = matching && MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos + neighbor), smoothQuery);
|
matching = matching && MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos + neighbor), smoothQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matching)
|
if (matching)
|
||||||
@@ -316,27 +332,30 @@ namespace Content.Client.IconSmoothing
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CalculateNewSpriteCardinal(MapGridComponent? grid, IconSmoothComponent smooth, Entity<SpriteComponent> sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
private void CalculateNewSpriteCardinal(Entity<MapGridComponent>? gridEntity, IconSmoothComponent smooth, Entity<SpriteComponent> sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
||||||
{
|
{
|
||||||
var dirs = CardinalConnectDirs.None;
|
var dirs = CardinalConnectDirs.None;
|
||||||
|
|
||||||
if (grid == null)
|
if (gridEntity == null)
|
||||||
{
|
{
|
||||||
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}{(int) dirs}");
|
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}{(int)dirs}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pos = grid.TileIndicesFor(xform.Coordinates);
|
var gridUid = gridEntity.Value.Owner;
|
||||||
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.North)), smoothQuery))
|
var grid = gridEntity.Value.Comp;
|
||||||
|
|
||||||
|
var pos = _mapSystem.TileIndicesFor(gridUid, grid, xform.Coordinates);
|
||||||
|
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.North)), smoothQuery))
|
||||||
dirs |= CardinalConnectDirs.North;
|
dirs |= CardinalConnectDirs.North;
|
||||||
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.South)), smoothQuery))
|
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.South)), smoothQuery))
|
||||||
dirs |= CardinalConnectDirs.South;
|
dirs |= CardinalConnectDirs.South;
|
||||||
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.East)), smoothQuery))
|
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.East)), smoothQuery))
|
||||||
dirs |= CardinalConnectDirs.East;
|
dirs |= CardinalConnectDirs.East;
|
||||||
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.West)), smoothQuery))
|
if (MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.West)), smoothQuery))
|
||||||
dirs |= CardinalConnectDirs.West;
|
dirs |= CardinalConnectDirs.West;
|
||||||
|
|
||||||
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}{(int) dirs}");
|
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}{(int)dirs}");
|
||||||
|
|
||||||
var directions = DirectionFlag.None;
|
var directions = DirectionFlag.None;
|
||||||
|
|
||||||
@@ -367,11 +386,11 @@ namespace Content.Client.IconSmoothing
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CalculateNewSpriteCorners(MapGridComponent? grid, IconSmoothComponent smooth, Entity<SpriteComponent> spriteEnt, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
private void CalculateNewSpriteCorners(Entity<MapGridComponent>? gridEntity, IconSmoothComponent smooth, Entity<SpriteComponent> spriteEnt, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
||||||
{
|
{
|
||||||
var (cornerNE, cornerNW, cornerSW, cornerSE) = grid == null
|
var (cornerNE, cornerNW, cornerSW, cornerSE) = gridEntity == null
|
||||||
? (CornerFill.None, CornerFill.None, CornerFill.None, CornerFill.None)
|
? (CornerFill.None, CornerFill.None, CornerFill.None, CornerFill.None)
|
||||||
: CalculateCornerFill(grid, smooth, xform, smoothQuery);
|
: CalculateCornerFill(gridEntity.Value, smooth, xform, smoothQuery);
|
||||||
|
|
||||||
// TODO figure out a better way to set multiple sprite layers.
|
// TODO figure out a better way to set multiple sprite layers.
|
||||||
// This will currently re-calculate the sprite bounding box 4 times.
|
// This will currently re-calculate the sprite bounding box 4 times.
|
||||||
@@ -379,10 +398,10 @@ namespace Content.Client.IconSmoothing
|
|||||||
// At the very least each event currently only queues a sprite for updating.
|
// At the very least each event currently only queues a sprite for updating.
|
||||||
// Oh god sprite component is a mess.
|
// Oh god sprite component is a mess.
|
||||||
var sprite = spriteEnt.Comp;
|
var sprite = spriteEnt.Comp;
|
||||||
sprite.LayerSetState(CornerLayers.NE, $"{smooth.StateBase}{(int) cornerNE}");
|
sprite.LayerSetState(CornerLayers.NE, $"{smooth.StateBase}{(int)cornerNE}");
|
||||||
sprite.LayerSetState(CornerLayers.SE, $"{smooth.StateBase}{(int) cornerSE}");
|
sprite.LayerSetState(CornerLayers.SE, $"{smooth.StateBase}{(int)cornerSE}");
|
||||||
sprite.LayerSetState(CornerLayers.SW, $"{smooth.StateBase}{(int) cornerSW}");
|
sprite.LayerSetState(CornerLayers.SW, $"{smooth.StateBase}{(int)cornerSW}");
|
||||||
sprite.LayerSetState(CornerLayers.NW, $"{smooth.StateBase}{(int) cornerNW}");
|
sprite.LayerSetState(CornerLayers.NW, $"{smooth.StateBase}{(int)cornerNW}");
|
||||||
|
|
||||||
var directions = DirectionFlag.None;
|
var directions = DirectionFlag.None;
|
||||||
|
|
||||||
@@ -401,17 +420,20 @@ namespace Content.Client.IconSmoothing
|
|||||||
CalculateEdge(spriteEnt, directions, sprite);
|
CalculateEdge(spriteEnt, directions, sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
private (CornerFill ne, CornerFill nw, CornerFill sw, CornerFill se) CalculateCornerFill(MapGridComponent grid, IconSmoothComponent smooth, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
private (CornerFill ne, CornerFill nw, CornerFill sw, CornerFill se) CalculateCornerFill(Entity<MapGridComponent> gridEntity, IconSmoothComponent smooth, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
||||||
{
|
{
|
||||||
var pos = grid.TileIndicesFor(xform.Coordinates);
|
var gridUid = gridEntity.Owner;
|
||||||
var n = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.North)), smoothQuery);
|
var grid = gridEntity.Comp;
|
||||||
var ne = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.NorthEast)), smoothQuery);
|
|
||||||
var e = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.East)), smoothQuery);
|
var pos = _mapSystem.TileIndicesFor(gridUid, grid, xform.Coordinates);
|
||||||
var se = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.SouthEast)), smoothQuery);
|
var n = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.North)), smoothQuery);
|
||||||
var s = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.South)), smoothQuery);
|
var ne = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.NorthEast)), smoothQuery);
|
||||||
var sw = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.SouthWest)), smoothQuery);
|
var e = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.East)), smoothQuery);
|
||||||
var w = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.West)), smoothQuery);
|
var se = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.SouthEast)), smoothQuery);
|
||||||
var nw = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.NorthWest)), smoothQuery);
|
var s = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.South)), smoothQuery);
|
||||||
|
var sw = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.SouthWest)), smoothQuery);
|
||||||
|
var w = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.West)), smoothQuery);
|
||||||
|
var nw = MatchingEntity(smooth, _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, pos.Offset(Direction.NorthWest)), smoothQuery);
|
||||||
|
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
var cornerNE = CornerFill.None;
|
var cornerNE = CornerFill.None;
|
||||||
|
|||||||
Reference in New Issue
Block a user