Skip to content

Commit

Permalink
FixMerge
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonsant committed Aug 9, 2024
2 parents 3a81dcc + 3256dde commit a5ee991
Show file tree
Hide file tree
Showing 36 changed files with 164 additions and 55 deletions.
7 changes: 7 additions & 0 deletions Content.Client/IconSmoothing/IconSmoothComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,12 @@ public enum IconSmoothingMode : byte
/// Where this component contributes to our neighbors being calculated but we do not update our own sprite.
/// </summary>
NoSprite,

// Frontier: pretty diagonal windows
/// <summary>
/// The icon represents a triangular sprite with 5 states, representing which combinations of South and East are being occupied or not.
/// </summary>
DiagonalNF,
// End Frontier
}
}
108 changes: 88 additions & 20 deletions Content.Client/IconSmoothing/IconSmoothSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Numerics;
using Content.Client.Anomaly.Ui;
using Content.Client.Overlays;
using Content.Shared.IconSmoothing;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
Expand Down Expand Up @@ -154,7 +156,7 @@ public void DirtyNeighbours(EntityUid uid, IconSmoothComponent? comp = null, Tra
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(0, 1)));
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(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 or IconSmoothingMode.DiagonalNF) // Frontier: add DiagonalNF
{
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(1, 1)));
DirtyEntities(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(-1, -1)));
Expand Down Expand Up @@ -208,13 +210,13 @@ private void CalculateNewSprite(EntityUid uid,
{
var pos = grid.TileIndicesFor(xform.Coordinates);

if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.North)), smoothQuery))
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.North)), smoothQuery, new(0, 1))) // Frontier: added (0, 1) vector
directions |= DirectionFlag.North;
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.South)), smoothQuery))
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.South)), smoothQuery, new(0, -1))) // Frontier: added (0, -1) vector
directions |= DirectionFlag.South;
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.East)), smoothQuery))
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.East)), smoothQuery, new(1, 0))) // Frontier: added (1, 0) vector
directions |= DirectionFlag.East;
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.West)), smoothQuery))
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.West)), smoothQuery, new(-1, 0))) // Frontier: added (-1, 0) vector
directions |= DirectionFlag.West;
}

Expand Down Expand Up @@ -256,6 +258,9 @@ private void CalculateNewSprite(EntityUid uid,
case IconSmoothingMode.Diagonal:
CalculateNewSpriteDiagonal(grid, smooth, spriteEnt, xform, smoothQuery);
break;
case IconSmoothingMode.DiagonalNF: // Frontier
CalculateNewSpriteDiagonalNF(grid, smooth, spriteEnt, xform, smoothQuery); // Frontier
break; // Frontier
default:
throw new ArgumentOutOfRangeException();
}
Expand Down Expand Up @@ -284,7 +289,7 @@ private void CalculateNewSpriteDiagonal(MapGridComponent? grid, IconSmoothCompon
for (var i = 0; i < neighbors.Length; i++)
{
var neighbor = (Vector2i) rotation.RotateVec(neighbors[i]);
matching = matching && MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos + neighbor), smoothQuery);
matching = matching && MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos + neighbor), smoothQuery, pos); // Frontier: add pos
}

if (matching)
Expand All @@ -297,6 +302,68 @@ private void CalculateNewSpriteDiagonal(MapGridComponent? grid, IconSmoothCompon
}
}

// New Frontiers - Better icon smoothing - icon smoothing that supports more diagonal window states
// and respects the empty sides of diagonal walls/windows
// This code is licensed under AGPLv3. See AGPLv3.txt

// Frontier: 5-state diagonal windows
private void CalculateNewSpriteDiagonalNF(MapGridComponent? grid, IconSmoothComponent smooth,
Entity<SpriteComponent> sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
{
if (grid == null)
{
sprite.Comp.LayerSetState(0, $"{smooth.StateBase}0");
return;
}

var neighbors = new Vector2[]
{
new(1, 0),
new(0, -1),
};

var pos = grid.TileIndicesFor(xform.Coordinates);
var rotation = xform.LocalRotation;
int value = 0;

for (var i = 0; i < neighbors.Length; i++)
{
var neighbor = (Vector2i) rotation.RotateVec(neighbors[i]);
if(MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos + neighbor), smoothQuery, neighbor))
value |= 1 << i;
}

// both walls checked, check the corner
if (value == 3)
{
var neighbor = (Vector2i) rotation.RotateVec(new(1, -1));
if(MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos + neighbor), smoothQuery, neighbor))
value = 4;
}

sprite.Comp.LayerSetState(0, $"{smooth.StateBase}{value}");
}

// Check if a particular window/wall allows smoothing on a given edge
private bool EntityIsSmoothOnEdge(EntityUid? target, IconSmoothComponent targetComp, Vector2 sourceDir)
{
var xformQuery = GetEntityQuery<TransformComponent>();
xformQuery.TryGetComponent(target, out var xform);
if (xform is null)
return false;

if (targetComp.Mode is IconSmoothingMode.Diagonal or IconSmoothingMode.DiagonalNF)
{
var rot = -xform.LocalRotation; // Source direction must be transformed into our reference.
var angle = new Angle(rot.RotateVec(-sourceDir)); // Direction is given from sourge to target, we need the direction from target to source.
angle += Math.PI / 2; // Cardinal directions start at north(?), but positive X angle is 0.
var dir = angle.GetCardinalDir();
return dir is Direction.South or Direction.SouthEast or Direction.East;
}
return true; // All other target components use all sides
}
// End of modified code

private void CalculateNewSpriteCardinal(MapGridComponent? grid, IconSmoothComponent smooth, Entity<SpriteComponent> sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
{
var dirs = CardinalConnectDirs.None;
Expand All @@ -308,13 +375,13 @@ private void CalculateNewSpriteCardinal(MapGridComponent? grid, IconSmoothCompon
}

var pos = grid.TileIndicesFor(xform.Coordinates);
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.North)), smoothQuery))
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.North)), smoothQuery, new(0, 1))) // Frontier: add vector
dirs |= CardinalConnectDirs.North;
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.South)), smoothQuery))
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.South)), smoothQuery, new(0, -1))) // Frontier: add vector
dirs |= CardinalConnectDirs.South;
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.East)), smoothQuery))
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.East)), smoothQuery, new(1, 0))) // Frontier: add vector
dirs |= CardinalConnectDirs.East;
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.West)), smoothQuery))
if (MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.West)), smoothQuery, new(-1, 0))) // Frontier: add vector
dirs |= CardinalConnectDirs.West;

sprite.Comp.LayerSetState(0, $"{smooth.StateBase}{(int) dirs}");
Expand All @@ -333,13 +400,14 @@ private void CalculateNewSpriteCardinal(MapGridComponent? grid, IconSmoothCompon
CalculateEdge(sprite, directions, sprite);
}

private bool MatchingEntity(IconSmoothComponent smooth, AnchoredEntitiesEnumerator candidates, EntityQuery<IconSmoothComponent> smoothQuery)
private bool MatchingEntity(IconSmoothComponent smooth, AnchoredEntitiesEnumerator candidates, EntityQuery<IconSmoothComponent> smoothQuery, Vector2 offset)
{
while (candidates.MoveNext(out var entity))
{
if (smoothQuery.TryGetComponent(entity, out var other) &&
other.SmoothKey == smooth.SmoothKey &&
other.Enabled)
other.Enabled &&
EntityIsSmoothOnEdge(entity, other, offset)) // Frontier: added EntityIsSmo
{
return true;
}
Expand Down Expand Up @@ -385,14 +453,14 @@ private void CalculateNewSpriteCorners(MapGridComponent? grid, IconSmoothCompone
private (CornerFill ne, CornerFill nw, CornerFill sw, CornerFill se) CalculateCornerFill(MapGridComponent grid, IconSmoothComponent smooth, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
{
var pos = grid.TileIndicesFor(xform.Coordinates);
var n = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.North)), smoothQuery);
var ne = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.NorthEast)), smoothQuery);
var e = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.East)), smoothQuery);
var se = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.SouthEast)), smoothQuery);
var s = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.South)), smoothQuery);
var sw = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.SouthWest)), smoothQuery);
var w = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.West)), smoothQuery);
var nw = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.NorthWest)), smoothQuery);
var n = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.North)), smoothQuery, new(0, 1)); // Frontier: add vector
var ne = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.NorthEast)), smoothQuery, new(1, 1)); // Frontier: add vector
var e = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.East)), smoothQuery, new(1, 0)); // Frontier: add vector
var se = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.SouthEast)), smoothQuery, new(1, -1)); // Frontier: add vector
var s = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.South)), smoothQuery, new(0, -1)); // Frontier: add vector
var sw = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.SouthWest)), smoothQuery, new(-1, -1)); // Frontier: add vector
var w = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.West)), smoothQuery, new(-1, 0)); // Frontier: add vector
var nw = MatchingEntity(smooth, grid.GetAnchoredEntitiesEnumerator(pos.Offset(Direction.NorthWest)), smoothQuery, new(-1, 1)); // Frontier: add vector

// ReSharper disable InconsistentNaming
var cornerNE = CornerFill.None;
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Atmos/Atmospherics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static class Atmospherics
/// so it just applies this flat value).
/// </summary>
// Original value is 4, buff back when we have proper ways for players to deal with breaches.
public const int LowPressureDamage = 1;
public const int LowPressureDamage = 4; // Frontier: 1<4

public const float WindowHeatTransferCoefficient = 0.1f;

Expand Down
8 changes: 8 additions & 0 deletions Resources/Changelog/Changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6165,3 +6165,11 @@ Entries:
message: Public transit should now properly prioritize bus docks.
id: 5183
time: '2024-08-09T16:23:08.0000000+00:00'
- author: whatstone and whatstone
changes:
- type: Tweak
message: >-
Walls/windows/secret doors icons once again smoothly transition into
each other.
id: 5184
time: '2024-08-09T18:24:00.0000000+00:00'
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
key: walls # Frontier: windows<walls
base: state
- type: Icon
sprite: Structures/Windows/clockwork_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
key: walls # Frontier: windows<walls
base: state
- type: Icon
sprite: Structures/Windows/mining_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
key: walls # Frontier: windows<walls
base: state
- type: Icon
sprite: Structures/Windows/plasma_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
key: walls # Frontier: windows<walls
base: state
- type: Icon
sprite: Structures/Windows/plastitanium_window_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
key: walls # Frontier: windows<walls
base: state
- type: Icon
sprite: Structures/Windows/reinforced_window_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
key: walls # Frontier: windows<walls
base: state
- type: Icon
sprite: Structures/Windows/reinforced_plasma_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
key: walls # Frontier: windows<walls
base: state
- type: Icon
sprite: Structures/Windows/reinforced_uranium_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
key: walls # Frontier: windows<walls
base: state
- type: Icon
sprite: Structures/Windows/shuttle_window_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
key: walls # Frontier: windows<walls
base: state
- type: Icon
sprite: Structures/Windows/uranium_window_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: windows
base: state
- type: Icon
sprite: Structures/Windows/window_diagonal.rsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
state: state0
- type: IconSmooth
mode: Diagonal
key: walls
#key: walls
base: state
- type: Icon
state: state0
Expand Down Expand Up @@ -57,14 +57,14 @@
- type: Sprite
drawdepth: Walls
sprite: _NF/Structures/Walls/solid_reinforced_diagonal.rsi
state: state0
state: reinf0
- type: IconSmooth
mode: Diagonal
mode: DiagonalNF
key: walls
base: state
base: reinf
- type: Icon
sprite: _NF/Structures/Walls/solid_reinforced_diagonal.rsi
state: state0
state: reinf0
- type: Fixtures
fixtures:
fix1:
Expand Down Expand Up @@ -93,14 +93,14 @@
- type: Sprite
drawdepth: Walls
sprite: _NF/Structures/Walls/wood_diagonal.rsi
state: state0
state: wood0
- type: IconSmooth
mode: Diagonal
key: walls
base: state
mode: DiagonalNF
key: woods
base: wood
- type: Icon
sprite: _NF/Structures/Walls/wood_diagonal.rsi
state: state0
state: wood0
- type: Fixtures
fixtures:
fix1:
Expand Down Expand Up @@ -129,14 +129,14 @@
- type: Sprite
drawdepth: Walls
sprite: _NF/Structures/Walls/uranium_diagonal.rsi
state: state0
state: uranium0
- type: IconSmooth
mode: Diagonal
mode: DiagonalNF
key: walls
base: state
base: uranium
- type: Icon
sprite: _NF/Structures/Walls/uranium_diagonal.rsi
state: state0
state: uranium0
- type: Fixtures
fixtures:
fix1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- GlassLayer
- type: Airtight
- type: IconSmooth
key: windows
key: walls # Frontier: windows<walls
base: ptwindow
- type: InteractionPopup
interactSuccessString: comp-window-knock
Expand Down
Loading

0 comments on commit a5ee991

Please sign in to comment.