Replace MapIndices with Vector2i (#2228)

* Replace MapIndices with Vector2i

* Update da submodule

* AA EE II OO U U

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
DrSmugleaf
2020-10-11 15:21:21 +02:00
committed by GitHub
parent 5127824716
commit 753ca81865
35 changed files with 224 additions and 211 deletions

View File

@@ -11,6 +11,7 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.Atmos
{
@@ -176,7 +177,7 @@ namespace Content.Server.Atmos
}
var gam = grid.GetComponent<GridAtmosphereComponent>();
var indices = new MapIndices(x, y);
var indices = new Vector2i(x, y);
var tile = gam.GetTile(indices);
if (tile == null)
@@ -300,7 +301,7 @@ namespace Content.Server.Atmos
}
var gam = grid.GetComponent<GridAtmosphereComponent>();
var indices = new MapIndices(x, y);
var indices = new Vector2i(x, y);
var tile = gam.GetTile(indices);
if (tile == null)
@@ -368,7 +369,7 @@ namespace Content.Server.Atmos
}
var gam = grid.GetComponent<GridAtmosphereComponent>();
var indices = new MapIndices(x, y);
var indices = new Vector2i(x, y);
var tile = gam.GetTile(indices);
if (tile == null)

View File

@@ -5,6 +5,7 @@ using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.Atmos
{
@@ -36,26 +37,26 @@ namespace Content.Server.Atmos
return !Equals(air = coordinates.GetTileAir(entityManager)!, default);
}
public static TileAtmosphere? GetTileAtmosphere(this MapIndices indices, GridId gridId)
public static TileAtmosphere? GetTileAtmosphere(this Vector2i indices, GridId gridId)
{
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
return gridAtmos?.GetTile(indices);
}
public static GasMixture? GetTileAir(this MapIndices indices, GridId gridId)
public static GasMixture? GetTileAir(this Vector2i indices, GridId gridId)
{
return indices.GetTileAtmosphere(gridId)?.Air;
}
public static bool TryGetTileAtmosphere(this MapIndices indices, GridId gridId,
public static bool TryGetTileAtmosphere(this Vector2i indices, GridId gridId,
[MaybeNullWhen(false)] out TileAtmosphere atmosphere)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId)!, default);
}
public static bool TryGetTileAir(this MapIndices indices, GridId gridId, [MaybeNullWhen(false)] out GasMixture air)
public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [MaybeNullWhen(false)] out GasMixture air)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(air = indices.GetTileAir(gridId)!, default);

View File

@@ -23,9 +23,9 @@ namespace Content.Server.Atmos
}
}
public static MapIndices Offset(this MapIndices pos, Direction dir)
public static Vector2i Offset(this Vector2i pos, Direction dir)
{
return pos + (MapIndices) dir.CardinalToIntVec();
return pos + (Vector2i) dir.CardinalToIntVec();
}
}
}

View File

@@ -25,31 +25,31 @@ namespace Content.Server.Atmos
/// Attemps to pry a tile.
/// </summary>
/// <param name="indices"></param>
void PryTile(MapIndices indices);
void PryTile(Vector2i indices);
/// <summary>
/// Burns a tile.
/// </summary>
/// <param name="gridIndices"></param>
void BurnTile(MapIndices gridIndices);
void BurnTile(Vector2i gridIndices);
/// <summary>
/// Invalidates a coordinate to be revalidated again.
/// Use this after changing a tile's gas contents, or when the tile becomes space, etc.
/// </summary>
/// <param name="indices"></param>
void Invalidate(MapIndices indices);
void Invalidate(Vector2i indices);
/// <summary>
/// Attempts to fix a sudden vacuum by creating gas.
/// </summary>
void FixVacuum(MapIndices indices);
void FixVacuum(Vector2i indices);
/// <summary>
/// Revalidates indices immediately.
/// </summary>
/// <param name="indices"></param>
void UpdateAdjacentBits(MapIndices indices);
void UpdateAdjacentBits(Vector2i indices);
/// <summary>
/// Adds an active tile so it becomes processed every update until it becomes inactive.
@@ -120,7 +120,7 @@ namespace Content.Server.Atmos
/// <param name="indices"></param>
/// <param name="createSpace"></param>
/// <returns></returns>
TileAtmosphere GetTile(MapIndices indices, bool createSpace = true);
TileAtmosphere GetTile(Vector2i indices, bool createSpace = true);
/// <summary>
/// Returns a tile.
@@ -138,14 +138,14 @@ namespace Content.Server.Atmos
/// <param name="indices"></param>
/// <param name="direction"></param>
/// <returns></returns>
bool IsAirBlocked(MapIndices indices, AtmosDirection direction);
bool IsAirBlocked(Vector2i indices, AtmosDirection direction);
/// <summary>
/// Returns if the tile in question is space.
/// </summary>
/// <param name="indices"></param>
/// <returns></returns>
bool IsSpace(MapIndices indices);
bool IsSpace(Vector2i indices);
/// <summary>
/// Returns the volume in liters for a number of cells/tiles.
@@ -157,7 +157,7 @@ namespace Content.Server.Atmos
/// <summary>
/// Returns a dictionary of adjacent TileAtmospheres.
/// </summary>
Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(MapIndices indices, bool includeAirBlocked = false);
Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(Vector2i indices, bool includeAirBlocked = false);
void Update(float frameTime);

View File

@@ -106,7 +106,7 @@ namespace Content.Server.Atmos
public TileRef? Tile => GridIndices.GetTileRef(GridIndex);
[ViewVariables]
public MapIndices GridIndices { get; }
public Vector2i GridIndices { get; }
[ViewVariables]
public ExcitedGroup ExcitedGroup { get; set; }
@@ -122,7 +122,7 @@ namespace Content.Server.Atmos
[ViewVariables]
public bool BlocksAllAir => BlockedAirflow == AtmosDirection.All;
public TileAtmosphere(GridAtmosphereComponent atmosphereComponent, GridId gridIndex, MapIndices gridIndices, GasMixture mixture = null, bool immutable = false)
public TileAtmosphere(GridAtmosphereComponent atmosphereComponent, GridId gridIndex, Vector2i gridIndices, GasMixture mixture = null, bool immutable = false)
{
IoCManager.InjectDependencies(this);
_gridAtmosphereComponent = atmosphereComponent;
@@ -197,7 +197,7 @@ namespace Content.Server.Atmos
{
if(_soundCooldown == 0)
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Effects/space_wind.ogg",
GridIndices.ToEntityCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(PressureDifference / 10, 10, 100)));
GridIndices.ToEntityCoordinates(GridIndex, _mapManager), AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(PressureDifference / 10, 10, 100)));
}
foreach (var entity in _gridTileLookupSystem.GetEntitiesIntersecting(GridIndex, GridIndices))
@@ -212,7 +212,7 @@ namespace Content.Server.Atmos
var pressureMovements = physics.EnsureController<HighPressureMovementController>();
if (pressure.LastHighPressureMovementAirCycle < _gridAtmosphereComponent.UpdateCounter)
{
pressureMovements.ExperiencePressureDifference(_gridAtmosphereComponent.UpdateCounter, PressureDifference, _pressureDirection, 0, PressureSpecificTarget?.GridIndices.ToEntityCoordinates(_mapManager, GridIndex) ?? EntityCoordinates.Invalid);
pressureMovements.ExperiencePressureDifference(_gridAtmosphereComponent.UpdateCounter, PressureDifference, _pressureDirection, 0, PressureSpecificTarget?.GridIndices.ToEntityCoordinates(GridIndex, _mapManager) ?? EntityCoordinates.Invalid);
}
}

View File

@@ -46,7 +46,7 @@ namespace Content.Server.Construction.Conditions
var type = _componentFactory.GetRegistration(Component).Type;
var indices = entity.Transform.Coordinates.ToMapIndices(entity.EntityManager, _mapManager);
var indices = entity.Transform.Coordinates.ToVector2i(entity.EntityManager, _mapManager);
var entities = indices.GetEntitiesInTile(entity.Transform.GridID, true, entity.EntityManager);
foreach (var ent in entities)

View File

@@ -20,7 +20,7 @@ namespace Content.Server.GameObjects.Components.Atmos
[RegisterComponent]
public class AirtightComponent : Component, IMapInit
{
private (GridId, MapIndices) _lastPosition;
private (GridId, Vector2i) _lastPosition;
private AtmosphereSystem _atmosphereSystem = default!;
public override string Name => "Airtight";
@@ -169,7 +169,7 @@ namespace Content.Server.GameObjects.Components.Atmos
UpdatePosition(Owner.Transform.GridID, snapGrid.Position);
}
private void UpdatePosition(GridId gridId, MapIndices pos)
private void UpdatePosition(GridId gridId, Vector2i pos)
{
var gridAtmos = _atmosphereSystem.GetGridAtmosphere(gridId);

View File

@@ -20,6 +20,7 @@ using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
@@ -78,7 +79,7 @@ namespace Content.Server.GameObjects.Components.Atmos
private double _excitedGroupLastProcess;
[ViewVariables]
protected readonly Dictionary<MapIndices, TileAtmosphere> Tiles = new Dictionary<MapIndices, TileAtmosphere>(1000);
protected readonly Dictionary<Vector2i, TileAtmosphere> Tiles = new Dictionary<Vector2i, TileAtmosphere>(1000);
[ViewVariables]
private readonly HashSet<TileAtmosphere> _activeTiles = new HashSet<TileAtmosphere>(1000);
@@ -108,7 +109,7 @@ namespace Content.Server.GameObjects.Components.Atmos
private double _superconductivityLastProcess;
[ViewVariables]
private readonly HashSet<MapIndices> _invalidatedCoords = new HashSet<MapIndices>(1000);
private readonly HashSet<Vector2i> _invalidatedCoords = new HashSet<Vector2i>(1000);
[ViewVariables]
private int InvalidatedCoordsCount => _invalidatedCoords.Count;
@@ -162,7 +163,7 @@ namespace Content.Server.GameObjects.Components.Atmos
}
/// <inheritdoc />
public virtual void PryTile(MapIndices indices)
public virtual void PryTile(Vector2i indices)
{
if (IsSpace(indices) || IsAirBlocked(indices)) return;
@@ -206,7 +207,7 @@ namespace Content.Server.GameObjects.Components.Atmos
}
/// <inheritdoc />
public virtual void Invalidate(MapIndices indices)
public virtual void Invalidate(Vector2i indices)
{
_invalidatedCoords.Add(indices);
}
@@ -264,13 +265,13 @@ namespace Content.Server.GameObjects.Components.Atmos
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void UpdateAdjacentBits(MapIndices indices)
public void UpdateAdjacentBits(Vector2i indices)
{
GetTile(indices)?.UpdateAdjacent();
}
/// <inheritdoc />
public virtual void FixVacuum(MapIndices indices)
public virtual void FixVacuum(Vector2i indices)
{
var tile = GetTile(indices);
if (tile?.GridIndex != _gridId) return;
@@ -387,11 +388,11 @@ namespace Content.Server.GameObjects.Components.Atmos
/// <inheritdoc />
public virtual TileAtmosphere? GetTile(EntityCoordinates coordinates, bool createSpace = true)
{
return GetTile(coordinates.ToMapIndices(_serverEntityManager, _mapManager), createSpace);
return GetTile(coordinates.ToVector2i(_serverEntityManager, _mapManager), createSpace);
}
/// <inheritdoc />
public virtual TileAtmosphere? GetTile(MapIndices indices, bool createSpace = true)
public virtual TileAtmosphere? GetTile(Vector2i indices, bool createSpace = true)
{
if (Tiles.TryGetValue(indices, out var tile)) return tile;
@@ -405,7 +406,7 @@ namespace Content.Server.GameObjects.Components.Atmos
}
/// <inheritdoc />
public bool IsAirBlocked(MapIndices indices, AtmosDirection direction = AtmosDirection.All)
public bool IsAirBlocked(Vector2i indices, AtmosDirection direction = AtmosDirection.All)
{
foreach (var obstructingComponent in GetObstructingComponents(indices))
{
@@ -420,7 +421,7 @@ namespace Content.Server.GameObjects.Components.Atmos
}
/// <inheritdoc />
public virtual bool IsSpace(MapIndices indices)
public virtual bool IsSpace(Vector2i indices)
{
// TODO ATMOS use ContentTileDefinition to define in YAML whether or not a tile is considered space
if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return default;
@@ -428,7 +429,7 @@ namespace Content.Server.GameObjects.Components.Atmos
return mapGrid.Grid.GetTileRef(indices).Tile.IsEmpty;
}
public Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(MapIndices indices, bool includeAirBlocked = false)
public Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(Vector2i indices, bool includeAirBlocked = false)
{
var sides = new Dictionary<AtmosDirection, TileAtmosphere>();
for (var i = 0; i < Atmospherics.Directions; i++)
@@ -780,7 +781,7 @@ namespace Content.Server.GameObjects.Components.Atmos
return true;
}
protected virtual IEnumerable<AirtightComponent> GetObstructingComponents(MapIndices indices)
protected virtual IEnumerable<AirtightComponent> GetObstructingComponents(Vector2i indices)
{
var gridLookup = EntitySystem.Get<GridTileLookupSystem>();
@@ -795,7 +796,7 @@ namespace Content.Server.GameObjects.Components.Atmos
return list;
}
private bool NeedsVacuumFixing(MapIndices indices)
private bool NeedsVacuumFixing(Vector2i indices)
{
var value = false;
@@ -807,7 +808,7 @@ namespace Content.Server.GameObjects.Components.Atmos
return value;
}
private AtmosDirection GetBlockedDirections(MapIndices indices)
private AtmosDirection GetBlockedDirections(Vector2i indices)
{
var value = AtmosDirection.Invalid;
@@ -833,7 +834,7 @@ namespace Content.Server.GameObjects.Components.Atmos
var gridId = mapGrid.Grid.Index;
if (!serializer.TryReadDataField("uniqueMixes", out List<GasMixture>? uniqueMixes) ||
!serializer.TryReadDataField("tiles", out Dictionary<MapIndices, int>? tiles))
!serializer.TryReadDataField("tiles", out Dictionary<Vector2i, int>? tiles))
return;
Tiles.Clear();
@@ -857,7 +858,7 @@ namespace Content.Server.GameObjects.Components.Atmos
{
var uniqueMixes = new List<GasMixture>();
var uniqueMixHash = new Dictionary<GasMixture, int>();
var tiles = new Dictionary<MapIndices, int>();
var tiles = new Dictionary<Vector2i, int>();
foreach (var (indices, tile) in Tiles)
{
if (tile.Air == null) continue;
@@ -875,7 +876,7 @@ namespace Content.Server.GameObjects.Components.Atmos
}
serializer.DataField(ref uniqueMixes, "uniqueMixes", new List<GasMixture>());
serializer.DataField(ref tiles, "tiles", new Dictionary<MapIndices, int>());
serializer.DataField(ref tiles, "tiles", new Dictionary<Vector2i, int>());
}
}
@@ -890,7 +891,7 @@ namespace Content.Server.GameObjects.Components.Atmos
}
/// <inheritdoc />
public virtual void BurnTile(MapIndices gridIndices)
public virtual void BurnTile(Vector2i gridIndices)
{
// TODO ATMOS
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Content.Server.Atmos;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.GameObjects.Components.Atmos
{
@@ -12,17 +13,17 @@ namespace Content.Server.GameObjects.Components.Atmos
public override void RepopulateTiles() { }
public override bool IsSpace(MapIndices indices)
public override bool IsSpace(Vector2i indices)
{
return true;
}
public override TileAtmosphere? GetTile(MapIndices indices, bool createSpace = true)
public override TileAtmosphere? GetTile(Vector2i indices, bool createSpace = true)
{
return new TileAtmosphere(this, GridId.Invalid, indices, new GasMixture(2500, AtmosphereSystem), true);
}
protected override IEnumerable<AirtightComponent> GetObstructingComponents(MapIndices indices)
protected override IEnumerable<AirtightComponent> GetObstructingComponents(Vector2i indices)
{
return Enumerable.Empty<AirtightComponent>();
}

View File

@@ -7,6 +7,7 @@ using Content.Shared.Atmos;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Map;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.GameObjects.Components.Atmos
{
@@ -18,7 +19,7 @@ namespace Content.Server.GameObjects.Components.Atmos
{
public override string Name => "UnsimulatedGridAtmosphere";
public override void PryTile(MapIndices indices) { }
public override void PryTile(Vector2i indices) { }
public override void RepopulateTiles()
{
@@ -31,11 +32,11 @@ namespace Content.Server.GameObjects.Components.Atmos
}
}
public override void Invalidate(MapIndices indices) { }
public override void Invalidate(Vector2i indices) { }
protected override void Revalidate() { }
public override void FixVacuum(MapIndices indices) { }
public override void FixVacuum(Vector2i indices) { }
public override void AddActiveTile(TileAtmosphere? tile) { }

View File

@@ -87,7 +87,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
_reactTimer = 0;
var mapGrid = _mapManager.GetGrid(Owner.Transform.GridID);
var tile = mapGrid.GetTileRef(Owner.Transform.Coordinates.ToMapIndices(Owner.EntityManager, _mapManager));
var tile = mapGrid.GetTileRef(Owner.Transform.Coordinates.ToVector2i(Owner.EntityManager, _mapManager));
foreach (var reagentQuantity in contents.ReagentList.ToArray())
{
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;

View File

@@ -16,6 +16,7 @@ using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -152,7 +153,7 @@ namespace Content.Server.GameObjects.Components.Items.RCD
}
private bool IsRCDStillValid(AfterInteractEventArgs eventArgs, IMapGrid mapGrid, TileRef tile, MapIndices snapPos, RcdMode startingMode)
private bool IsRCDStillValid(AfterInteractEventArgs eventArgs, IMapGrid mapGrid, TileRef tile, Vector2i snapPos, RcdMode startingMode)
{
//Less expensive checks first. Failing those ones, we need to check that the tile isn't obstructed.
if (_ammo <= 0)

View File

@@ -26,15 +26,15 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
public TimeSpan LastUpdate { get; private set; }
public GridId GridId { get; }
public MapIndices Indices => _indices;
private readonly MapIndices _indices;
public Vector2i Indices => _indices;
private readonly Vector2i _indices;
// Nodes per chunk row
public static int ChunkSize => 8;
public PathfindingNode[,] Nodes => _nodes;
private PathfindingNode[,] _nodes = new PathfindingNode[ChunkSize,ChunkSize];
public PathfindingChunk(GridId gridId, MapIndices indices)
public PathfindingChunk(GridId gridId, Vector2i indices)
{
GridId = gridId;
_indices = indices;
@@ -46,7 +46,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{
for (var y = 0; y < ChunkSize; y++)
{
var tileRef = mapGrid.GetTileRef(new MapIndices(x + _indices.X, y + _indices.Y));
var tileRef = mapGrid.GetTileRef(new Vector2i(x + _indices.X, y + _indices.Y));
CreateNode(tileRef);
}
}
@@ -75,7 +75,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{
if (x == 0 && y == 0) continue;
var (neighborX, neighborY) = (_indices.X + ChunkSize * x, _indices.Y + ChunkSize * y);
if (chunkGrid.TryGetValue(new MapIndices(neighborX, neighborY), out var neighbor))
if (chunkGrid.TryGetValue(new Vector2i(neighborX, neighborY), out var neighbor))
{
yield return neighbor;
}
@@ -83,10 +83,10 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
}
}
public bool InBounds(MapIndices mapIndices)
public bool InBounds(Vector2i Vector2i)
{
if (mapIndices.X < _indices.X || mapIndices.Y < _indices.Y) return false;
if (mapIndices.X >= _indices.X + ChunkSize || mapIndices.Y >= _indices.Y + ChunkSize) return false;
if (Vector2i.X < _indices.X || Vector2i.Y < _indices.Y) return false;
if (Vector2i.X >= _indices.X + ChunkSize || Vector2i.Y >= _indices.Y + ChunkSize) return false;
return true;
}

View File

@@ -199,7 +199,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
}
intermediate = pathfindingSystem.GetNode(grid.GetTileRef(
new MapIndices(intermediate.TileRef.X + xOffset, intermediate.TileRef.Y + yOffset)));
new Vector2i(intermediate.TileRef.X + xOffset, intermediate.TileRef.Y + yOffset)));
if (intermediate.TileRef != current.TileRef)
{

View File

@@ -69,7 +69,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
for (var y = -1; y <= 1; y++)
{
if (x == 0 && y == 0) continue;
var indices = new MapIndices(TileRef.X + x, TileRef.Y + y);
var indices = new Vector2i(TileRef.X + x, TileRef.Y + y);
if (ParentChunk.InBounds(indices))
{
var (relativeX, relativeY) = (indices.X - ParentChunk.Indices.X,
@@ -100,7 +100,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{
var chunkXOffset = TileRef.X - ParentChunk.Indices.X;
var chunkYOffset = TileRef.Y - ParentChunk.Indices.Y;
MapIndices neighborMapIndices;
Vector2i neighborVector2i;
switch (direction)
{
@@ -110,13 +110,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return ParentChunk.Nodes[chunkXOffset + 1, chunkYOffset];
}
neighborMapIndices = new MapIndices(TileRef.X + 1, TileRef.Y);
neighborVector2i = new Vector2i(TileRef.X + 1, TileRef.Y);
foreach (var neighbor in ParentChunk.GetNeighbors())
{
if (neighbor.InBounds(neighborMapIndices))
if (neighbor.InBounds(neighborVector2i))
{
return neighbor.Nodes[neighborMapIndices.X - neighbor.Indices.X,
neighborMapIndices.Y - neighbor.Indices.Y];
return neighbor.Nodes[neighborVector2i.X - neighbor.Indices.X,
neighborVector2i.Y - neighbor.Indices.Y];
}
}
@@ -127,13 +127,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return ParentChunk.Nodes[chunkXOffset + 1, chunkYOffset + 1];
}
neighborMapIndices = new MapIndices(TileRef.X + 1, TileRef.Y + 1);
neighborVector2i = new Vector2i(TileRef.X + 1, TileRef.Y + 1);
foreach (var neighbor in ParentChunk.GetNeighbors())
{
if (neighbor.InBounds(neighborMapIndices))
if (neighbor.InBounds(neighborVector2i))
{
return neighbor.Nodes[neighborMapIndices.X - neighbor.Indices.X,
neighborMapIndices.Y - neighbor.Indices.Y];
return neighbor.Nodes[neighborVector2i.X - neighbor.Indices.X,
neighborVector2i.Y - neighbor.Indices.Y];
}
}
@@ -144,13 +144,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return ParentChunk.Nodes[chunkXOffset, chunkYOffset + 1];
}
neighborMapIndices = new MapIndices(TileRef.X, TileRef.Y + 1);
neighborVector2i = new Vector2i(TileRef.X, TileRef.Y + 1);
foreach (var neighbor in ParentChunk.GetNeighbors())
{
if (neighbor.InBounds(neighborMapIndices))
if (neighbor.InBounds(neighborVector2i))
{
return neighbor.Nodes[neighborMapIndices.X - neighbor.Indices.X,
neighborMapIndices.Y - neighbor.Indices.Y];
return neighbor.Nodes[neighborVector2i.X - neighbor.Indices.X,
neighborVector2i.Y - neighbor.Indices.Y];
}
}
@@ -161,13 +161,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return ParentChunk.Nodes[chunkXOffset - 1, chunkYOffset + 1];
}
neighborMapIndices = new MapIndices(TileRef.X - 1, TileRef.Y + 1);
neighborVector2i = new Vector2i(TileRef.X - 1, TileRef.Y + 1);
foreach (var neighbor in ParentChunk.GetNeighbors())
{
if (neighbor.InBounds(neighborMapIndices))
if (neighbor.InBounds(neighborVector2i))
{
return neighbor.Nodes[neighborMapIndices.X - neighbor.Indices.X,
neighborMapIndices.Y - neighbor.Indices.Y];
return neighbor.Nodes[neighborVector2i.X - neighbor.Indices.X,
neighborVector2i.Y - neighbor.Indices.Y];
}
}
@@ -178,13 +178,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return ParentChunk.Nodes[chunkXOffset - 1, chunkYOffset];
}
neighborMapIndices = new MapIndices(TileRef.X - 1, TileRef.Y);
neighborVector2i = new Vector2i(TileRef.X - 1, TileRef.Y);
foreach (var neighbor in ParentChunk.GetNeighbors())
{
if (neighbor.InBounds(neighborMapIndices))
if (neighbor.InBounds(neighborVector2i))
{
return neighbor.Nodes[neighborMapIndices.X - neighbor.Indices.X,
neighborMapIndices.Y - neighbor.Indices.Y];
return neighbor.Nodes[neighborVector2i.X - neighbor.Indices.X,
neighborVector2i.Y - neighbor.Indices.Y];
}
}
@@ -195,13 +195,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return ParentChunk.Nodes[chunkXOffset - 1, chunkYOffset - 1];
}
neighborMapIndices = new MapIndices(TileRef.X - 1, TileRef.Y - 1);
neighborVector2i = new Vector2i(TileRef.X - 1, TileRef.Y - 1);
foreach (var neighbor in ParentChunk.GetNeighbors())
{
if (neighbor.InBounds(neighborMapIndices))
if (neighbor.InBounds(neighborVector2i))
{
return neighbor.Nodes[neighborMapIndices.X - neighbor.Indices.X,
neighborMapIndices.Y - neighbor.Indices.Y];
return neighbor.Nodes[neighborVector2i.X - neighbor.Indices.X,
neighborVector2i.Y - neighbor.Indices.Y];
}
}
@@ -212,13 +212,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return ParentChunk.Nodes[chunkXOffset, chunkYOffset - 1];
}
neighborMapIndices = new MapIndices(TileRef.X, TileRef.Y - 1);
neighborVector2i = new Vector2i(TileRef.X, TileRef.Y - 1);
foreach (var neighbor in ParentChunk.GetNeighbors())
{
if (neighbor.InBounds(neighborMapIndices))
if (neighbor.InBounds(neighborVector2i))
{
return neighbor.Nodes[neighborMapIndices.X - neighbor.Indices.X,
neighborMapIndices.Y - neighbor.Indices.Y];
return neighbor.Nodes[neighborVector2i.X - neighbor.Indices.X,
neighborVector2i.Y - neighbor.Indices.Y];
}
}
@@ -229,13 +229,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return ParentChunk.Nodes[chunkXOffset + 1, chunkYOffset - 1];
}
neighborMapIndices = new MapIndices(TileRef.X + 1, TileRef.Y - 1);
neighborVector2i = new Vector2i(TileRef.X + 1, TileRef.Y - 1);
foreach (var neighbor in ParentChunk.GetNeighbors())
{
if (neighbor.InBounds(neighborMapIndices))
if (neighbor.InBounds(neighborVector2i))
{
return neighbor.Nodes[neighborMapIndices.X - neighbor.Indices.X,
neighborMapIndices.Y - neighbor.Indices.Y];
return neighbor.Nodes[neighborVector2i.X - neighbor.Indices.X,
neighborVector2i.Y - neighbor.Indices.Y];
}
}

View File

@@ -13,6 +13,7 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
@@ -32,8 +33,8 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public IReadOnlyDictionary<GridId, Dictionary<MapIndices, PathfindingChunk>> Graph => _graph;
private readonly Dictionary<GridId, Dictionary<MapIndices, PathfindingChunk>> _graph = new Dictionary<GridId, Dictionary<MapIndices, PathfindingChunk>>();
public IReadOnlyDictionary<GridId, Dictionary<Vector2i, PathfindingChunk>> Graph => _graph;
private readonly Dictionary<GridId, Dictionary<Vector2i, PathfindingChunk>> _graph = new Dictionary<GridId, Dictionary<Vector2i, PathfindingChunk>>();
private readonly PathfindingJobQueue _pathfindingQueue = new PathfindingJobQueue();
@@ -144,28 +145,28 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{
var chunkX = (int) (Math.Floor((float) tile.X / PathfindingChunk.ChunkSize) * PathfindingChunk.ChunkSize);
var chunkY = (int) (Math.Floor((float) tile.Y / PathfindingChunk.ChunkSize) * PathfindingChunk.ChunkSize);
var mapIndices = new MapIndices(chunkX, chunkY);
var Vector2i = new Vector2i(chunkX, chunkY);
if (_graph.TryGetValue(tile.GridIndex, out var chunks))
{
if (!chunks.ContainsKey(mapIndices))
if (!chunks.ContainsKey(Vector2i))
{
CreateChunk(tile.GridIndex, mapIndices);
CreateChunk(tile.GridIndex, Vector2i);
}
return chunks[mapIndices];
return chunks[Vector2i];
}
var newChunk = CreateChunk(tile.GridIndex, mapIndices);
var newChunk = CreateChunk(tile.GridIndex, Vector2i);
return newChunk;
}
private PathfindingChunk CreateChunk(GridId gridId, MapIndices indices)
private PathfindingChunk CreateChunk(GridId gridId, Vector2i indices)
{
var newChunk = new PathfindingChunk(gridId, indices);
if (!_graph.ContainsKey(gridId))
{
_graph.Add(gridId, new Dictionary<MapIndices, PathfindingChunk>());
_graph.Add(gridId, new Dictionary<Vector2i, PathfindingChunk>());
}
_graph[gridId].Add(indices, newChunk);

View File

@@ -603,10 +603,10 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
return Vector2.Zero;
}
if (target.TryGetComponent(out ICollidableComponent physicsComponent))
if (target.TryGetComponent(out ICollidableComponent collidable))
{
var targetDistance = (targetPos.Position - entityPos.Position);
targetPos = targetPos.Offset(physicsComponent.LinearVelocity * targetDistance);
targetPos = targetPos.Offset(collidable.LinearVelocity * targetDistance);
}
return (targetPos.Position - entityPos.Position).Normalized;
@@ -662,8 +662,8 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
// if we're moving in the same direction then ignore
// So if 2 entities are moving towards each other and both detect a collision they'll both move in the same direction
// i.e. towards the right
if (physicsEntity.TryGetComponent(out ICollidableComponent physicsComponent) &&
Vector2.Dot(physicsComponent.LinearVelocity, direction) > 0)
if (physicsEntity.TryGetComponent(out ICollidableComponent collidable) &&
Vector2.Dot(collidable.LinearVelocity, direction) > 0)
{
continue;
}

View File

@@ -120,7 +120,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
if (!gridEnt.TryGetComponent<GridAtmosphereComponent>(out var gam)) continue;
var entityTile = grid.GetTileRef(entity.Transform.Coordinates).GridIndices;
var baseTile = new MapIndices(entityTile.X - (LocalViewRange / 2), entityTile.Y - (LocalViewRange / 2));
var baseTile = new Vector2i(entityTile.X - (LocalViewRange / 2), entityTile.Y - (LocalViewRange / 2));
var debugOverlayContent = new AtmosDebugOverlayData[LocalViewRange * LocalViewRange];
var index = 0;
@@ -128,8 +128,8 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
{
for (var x = 0; x < LocalViewRange; x++)
{
var mapIndices = new MapIndices(baseTile.X + x, baseTile.Y + y);
debugOverlayContent[index++] = ConvertTileToData(gam.GetTile(mapIndices));
var Vector2i = new Vector2i(baseTile.X + x, baseTile.Y + y);
debugOverlayContent[index++] = ConvertTileToData(gam.GetTile(Vector2i));
}
}

View File

@@ -31,7 +31,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
/// <summary>
/// The tiles that have had their atmos data updated since last tick
/// </summary>
private Dictionary<GridId, HashSet<MapIndices>> _invalidTiles = new Dictionary<GridId, HashSet<MapIndices>>();
private Dictionary<GridId, HashSet<Vector2i>> _invalidTiles = new Dictionary<GridId, HashSet<Vector2i>>();
private Dictionary<IPlayerSession, PlayerGasOverlay> _knownPlayerChunks =
new Dictionary<IPlayerSession, PlayerGasOverlay>();
@@ -39,8 +39,8 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
/// <summary>
/// Gas data stored in chunks to make PVS / bubbling easier.
/// </summary>
private Dictionary<GridId, Dictionary<MapIndices, GasOverlayChunk>> _overlay =
new Dictionary<GridId, Dictionary<MapIndices, GasOverlayChunk>>();
private Dictionary<GridId, Dictionary<Vector2i, GasOverlayChunk>> _overlay =
new Dictionary<GridId, Dictionary<Vector2i, GasOverlayChunk>>();
/// <summary>
/// How far away do we update gas overlays (minimum; due to chunking further away tiles may also be updated).
@@ -75,22 +75,22 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Invalidate(GridId gridIndex, MapIndices indices)
public void Invalidate(GridId gridIndex, Vector2i indices)
{
if (!_invalidTiles.TryGetValue(gridIndex, out var existing))
{
existing = new HashSet<MapIndices>();
existing = new HashSet<Vector2i>();
_invalidTiles[gridIndex] = existing;
}
existing.Add(indices);
}
private GasOverlayChunk GetOrCreateChunk(GridId gridIndex, MapIndices indices)
private GasOverlayChunk GetOrCreateChunk(GridId gridIndex, Vector2i indices)
{
if (!_overlay.TryGetValue(gridIndex, out var chunks))
{
chunks = new Dictionary<MapIndices, GasOverlayChunk>();
chunks = new Dictionary<Vector2i, GasOverlayChunk>();
_overlay[gridIndex] = chunks;
}
@@ -150,7 +150,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
/// <param name="indices"></param>
/// <param name="overlayData"></param>
/// <returns>true if updated</returns>
private bool TryRefreshTile(GridAtmosphereComponent gam, GasOverlayData oldTile, MapIndices indices, out GasOverlayData overlayData)
private bool TryRefreshTile(GridAtmosphereComponent gam, GasOverlayData oldTile, Vector2i indices, out GasOverlayData overlayData)
{
var tile = gam.GetTile(indices);
@@ -214,7 +214,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
{
for (var y = -maxYDiff; y <= maxYDiff; y++)
{
var chunkIndices = GetGasChunkIndices(new MapIndices(entityTile.X + x * ChunkSize, entityTile.Y + y * ChunkSize));
var chunkIndices = GetGasChunkIndices(new Vector2i(entityTile.X + x * ChunkSize, entityTile.Y + y * ChunkSize));
if (!chunks.TryGetValue(chunkIndices, out var chunk)) continue;
@@ -261,7 +261,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
AccumulatedFrameTime -= _updateCooldown;
var gridAtmosComponents = new Dictionary<GridId, GridAtmosphereComponent>();
var updatedTiles = new Dictionary<GasOverlayChunk, HashSet<MapIndices>>();
var updatedTiles = new Dictionary<GasOverlayChunk, HashSet<Vector2i>>();
// So up to this point we've been caching the updated tiles for multiple ticks.
// Now we'll go through and check whether the update actually matters for the overlay or not,
@@ -295,7 +295,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
if (!updatedTiles.TryGetValue(chunk, out var tiles))
{
tiles = new HashSet<MapIndices>();
tiles = new HashSet<Vector2i>();
updatedTiles[chunk] = tiles;
}
@@ -355,7 +355,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
overlay.RemoveChunk(chunk);
}
var clientInvalids = new Dictionary<GridId, List<(MapIndices, GasOverlayData)>>();
var clientInvalids = new Dictionary<GridId, List<(Vector2i, GasOverlayData)>>();
// Check for any dirty chunks in range and bundle the data to send to the client.
foreach (var chunk in chunksInRange)
@@ -364,7 +364,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
if (!clientInvalids.TryGetValue(chunk.GridIndices, out var existingData))
{
existingData = new List<(MapIndices, GasOverlayData)>();
existingData = new List<(Vector2i, GasOverlayData)>();
clientInvalids[chunk.GridIndices] = existingData;
}
@@ -382,13 +382,13 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
}
private sealed class PlayerGasOverlay
{
private readonly Dictionary<GridId, Dictionary<MapIndices, GasOverlayChunk>> _data =
new Dictionary<GridId, Dictionary<MapIndices, GasOverlayChunk>>();
private readonly Dictionary<GridId, Dictionary<Vector2i, GasOverlayChunk>> _data =
new Dictionary<GridId, Dictionary<Vector2i, GasOverlayChunk>>();
private readonly Dictionary<GasOverlayChunk, GameTick> _lastSent =
new Dictionary<GasOverlayChunk, GameTick>();
public GasOverlayMessage UpdateClient(GridId grid, List<(MapIndices, GasOverlayData)> data)
public GasOverlayMessage UpdateClient(GridId grid, List<(Vector2i, GasOverlayData)> data)
{
return new GasOverlayMessage(grid, data);
}
@@ -418,7 +418,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
{
if (!_data.TryGetValue(chunk.GridIndices, out var chunks))
{
chunks = new Dictionary<MapIndices, GasOverlayChunk>();
chunks = new Dictionary<Vector2i, GasOverlayChunk>();
_data[chunk.GridIndices] = chunks;
}
@@ -441,9 +441,9 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
return;
}
if (chunks.ContainsKey(chunk.MapIndices))
if (chunks.ContainsKey(chunk.Vector2i))
{
chunks.Remove(chunk.MapIndices);
chunks.Remove(chunk.Vector2i);
}
}
@@ -457,7 +457,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
// Chunk data should already be up to date.
// Only send relevant tiles to client.
var tileData = new List<(MapIndices, GasOverlayData)>();
var tileData = new List<(Vector2i, GasOverlayData)>();
for (var x = 0; x < ChunkSize; x++)
{
@@ -470,7 +470,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
continue;
}
var indices = new MapIndices(chunk.MapIndices.X + x, chunk.MapIndices.Y + y);
var indices = new Vector2i(chunk.Vector2i.X + x, chunk.Vector2i.Y + y);
tileData.Add((indices, data));
}
}

View File

@@ -139,9 +139,9 @@ namespace Content.Server.Throw
var throwDuration = ThrownItemComponent.DefaultThrowTime;
var mass = 1f;
if (thrownEnt.TryGetComponent(out ICollidableComponent physicsComponent))
if (thrownEnt.TryGetComponent(out ICollidableComponent collidable))
{
mass = physicsComponent.Mass;
mass = collidable.Mass;
}
var velocityNecessary = distance / throwDuration;

View File

@@ -8,6 +8,7 @@ using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.Utility
{
@@ -28,7 +29,7 @@ namespace Content.Server.Utility
/// Helper that returns all entities in a turf.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IEntity> GetEntitiesInTileFast(this MapIndices indices, GridId gridId, GridTileLookupSystem? gridTileLookup = null)
public static IEnumerable<IEntity> GetEntitiesInTileFast(this Vector2i indices, GridId gridId, GridTileLookupSystem? gridTileLookup = null)
{
gridTileLookup ??= EntitySystem.Get<GridTileLookupSystem>();
return gridTileLookup.GetEntitiesIntersecting(gridId, indices);