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

@@ -35,7 +35,7 @@ namespace Content.Client.GameObjects.Components.IconSmoothing
internal ISpriteComponent Sprite { get; private set; } internal ISpriteComponent Sprite { get; private set; }
internal SnapGridComponent SnapGrid { get; private set; } internal SnapGridComponent SnapGrid { get; private set; }
private (GridId, MapIndices) _lastPosition; private (GridId, Vector2i) _lastPosition;
/// <summary> /// <summary>
/// We will smooth with other objects with the same key. /// We will smooth with other objects with the same key.

View File

@@ -69,7 +69,7 @@ namespace Content.Client.GameObjects.EntitySystems
return _tileData.ContainsKey(gridId); return _tileData.ContainsKey(gridId);
} }
public AtmosDebugOverlayData? GetData(GridId gridIndex, MapIndices indices) public AtmosDebugOverlayData? GetData(GridId gridIndex, Vector2i indices)
{ {
if (!_tileData.TryGetValue(gridIndex, out var srcMsg)) if (!_tileData.TryGetValue(gridIndex, out var srcMsg))
return null; return null;

View File

@@ -41,8 +41,8 @@ namespace Content.Client.GameObjects.EntitySystems
private readonly int[] _fireFrameCounter = new int[FireStates]; private readonly int[] _fireFrameCounter = new int[FireStates];
private readonly Texture[][] _fireFrames = new Texture[FireStates][]; private readonly Texture[][] _fireFrames = new Texture[FireStates][];
private Dictionary<GridId, Dictionary<MapIndices, GasOverlayChunk>> _tileData = private Dictionary<GridId, Dictionary<Vector2i, GasOverlayChunk>> _tileData =
new Dictionary<GridId, Dictionary<MapIndices, GasOverlayChunk>>(); new Dictionary<GridId, Dictionary<Vector2i, GasOverlayChunk>>();
private AtmosphereSystem _atmosphereSystem = default!; private AtmosphereSystem _atmosphereSystem = default!;
@@ -107,11 +107,11 @@ namespace Content.Client.GameObjects.EntitySystems
} }
// Slightly different to the server-side system version // Slightly different to the server-side system version
private GasOverlayChunk GetOrCreateChunk(GridId gridId, MapIndices indices) private GasOverlayChunk GetOrCreateChunk(GridId gridId, Vector2i indices)
{ {
if (!_tileData.TryGetValue(gridId, out var chunks)) if (!_tileData.TryGetValue(gridId, out var chunks))
{ {
chunks = new Dictionary<MapIndices, GasOverlayChunk>(); chunks = new Dictionary<Vector2i, GasOverlayChunk>();
_tileData[gridId] = chunks; _tileData[gridId] = chunks;
} }
@@ -148,7 +148,7 @@ namespace Content.Client.GameObjects.EntitySystems
return _tileData.ContainsKey(gridId); return _tileData.ContainsKey(gridId);
} }
public (Texture, Color color)[] GetOverlays(GridId gridIndex, MapIndices indices) public (Texture, Color color)[] GetOverlays(GridId gridIndex, Vector2i indices)
{ {
if (!_tileData.TryGetValue(gridIndex, out var chunks)) if (!_tileData.TryGetValue(gridIndex, out var chunks))
return Array.Empty<(Texture, Color)>(); return Array.Empty<(Texture, Color)>();

View File

@@ -82,16 +82,16 @@ namespace Content.Client.GameObjects.EntitySystems
{ {
var pos = ev.LastPosition.Value.pos; var pos = ev.LastPosition.Value.pos;
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(1, 0), ev.Offset)); AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(1, 0), ev.Offset));
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-1, 0), ev.Offset)); AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(-1, 0), ev.Offset));
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(0, 1), ev.Offset)); AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(0, 1), ev.Offset));
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(0, -1), ev.Offset)); AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(0, -1), ev.Offset));
if (ev.Mode == IconSmoothingMode.Corners) if (ev.Mode == IconSmoothingMode.Corners)
{ {
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(1, 1), ev.Offset)); AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(1, 1), ev.Offset));
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-1, -1), ev.Offset)); AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(-1, -1), ev.Offset));
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-1, 1), ev.Offset)); AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(-1, 1), ev.Offset));
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(1, -1), ev.Offset)); AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(1, -1), ev.Offset));
} }
} }
} }
@@ -135,7 +135,7 @@ namespace Content.Client.GameObjects.EntitySystems
/// </summary> /// </summary>
public sealed class IconSmoothDirtyEvent : EntitySystemMessage public sealed class IconSmoothDirtyEvent : EntitySystemMessage
{ {
public IconSmoothDirtyEvent(IEntity sender, (GridId grid, MapIndices pos)? lastPosition, SnapGridOffset offset, IconSmoothingMode mode) public IconSmoothDirtyEvent(IEntity sender, (GridId grid, Vector2i pos)? lastPosition, SnapGridOffset offset, IconSmoothingMode mode)
{ {
LastPosition = lastPosition; LastPosition = lastPosition;
Offset = offset; Offset = offset;
@@ -143,7 +143,7 @@ namespace Content.Client.GameObjects.EntitySystems
Sender = sender; Sender = sender;
} }
public (GridId grid, MapIndices pos)? LastPosition { get; } public (GridId grid, Vector2i pos)? LastPosition { get; }
public SnapGridOffset Offset { get; } public SnapGridOffset Offset { get; }
public IconSmoothingMode Mode { get; } public IconSmoothingMode Mode { get; }
public IEntity Sender { get; } public IEntity Sender { get; }

View File

@@ -6,6 +6,7 @@ using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.EntitySystems namespace Content.Client.GameObjects.EntitySystems
@@ -80,7 +81,7 @@ namespace Content.Client.GameObjects.EntitySystems
} }
} }
private void UpdateTile(IMapGrid grid, MapIndices position) private void UpdateTile(IMapGrid grid, Vector2i position)
{ {
var tile = grid.GetTileRef(position); var tile = grid.GetTileRef(position);
var tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId]; var tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId];

View File

@@ -3,6 +3,7 @@ using Content.Server.Atmos;
using NUnit.Framework; using NUnit.Framework;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.Atmos namespace Content.IntegrationTests.Tests.Atmos
{ {
@@ -91,7 +92,7 @@ namespace Content.IntegrationTests.Tests.Atmos
} }
[Test] [Test]
public async Task GetTileAtmosphereMapIndicesNotNullTest() public async Task GetTileAtmosphereVector2iNotNullTest()
{ {
var server = StartServerDummyTicker(); var server = StartServerDummyTicker();
@@ -99,7 +100,7 @@ namespace Content.IntegrationTests.Tests.Atmos
{ {
Assert.DoesNotThrow(() => Assert.DoesNotThrow(() =>
{ {
var atmosphere = default(MapIndices).GetTileAtmosphere(default); var atmosphere = default(Vector2i).GetTileAtmosphere(default);
Assert.NotNull(atmosphere); Assert.NotNull(atmosphere);
}); });
@@ -109,7 +110,7 @@ namespace Content.IntegrationTests.Tests.Atmos
} }
[Test] [Test]
public async Task GetTileAirMapIndicesNotNullTest() public async Task GetTileAirVector2iNotNullTest()
{ {
var server = StartServerDummyTicker(); var server = StartServerDummyTicker();
@@ -117,7 +118,7 @@ namespace Content.IntegrationTests.Tests.Atmos
{ {
Assert.DoesNotThrow(() => Assert.DoesNotThrow(() =>
{ {
var air = default(MapIndices).GetTileAir(default); var air = default(Vector2i).GetTileAir(default);
Assert.NotNull(air); Assert.NotNull(air);
}); });
@@ -127,7 +128,7 @@ namespace Content.IntegrationTests.Tests.Atmos
} }
[Test] [Test]
public async Task TryGetTileAtmosphereMapIndicesNotNullTest() public async Task TryGetTileAtmosphereVector2iNotNullTest()
{ {
var server = StartServerDummyTicker(); var server = StartServerDummyTicker();
@@ -135,7 +136,7 @@ namespace Content.IntegrationTests.Tests.Atmos
{ {
Assert.DoesNotThrow(() => Assert.DoesNotThrow(() =>
{ {
var hasAtmosphere = default(MapIndices).TryGetTileAtmosphere(default, out var atmosphere); var hasAtmosphere = default(Vector2i).TryGetTileAtmosphere(default, out var atmosphere);
Assert.True(hasAtmosphere); Assert.True(hasAtmosphere);
Assert.NotNull(atmosphere); Assert.NotNull(atmosphere);
@@ -146,7 +147,7 @@ namespace Content.IntegrationTests.Tests.Atmos
} }
[Test] [Test]
public async Task TryGetTileAirMapIndicesNotNullTest() public async Task TryGetTileAirVector2iNotNullTest()
{ {
var server = StartServerDummyTicker(); var server = StartServerDummyTicker();
@@ -154,7 +155,7 @@ namespace Content.IntegrationTests.Tests.Atmos
{ {
Assert.DoesNotThrow(() => Assert.DoesNotThrow(() =>
{ {
var hasAir = default(MapIndices).TryGetTileAir(default, out var air); var hasAir = default(Vector2i).TryGetTileAir(default, out var air);
Assert.True(hasAir); Assert.True(hasAir);
Assert.NotNull(air); Assert.NotNull(air);

View File

@@ -32,15 +32,15 @@ namespace Content.IntegrationTests.Tests
var tileDefinition = tileDefinitionManager["underplating"]; var tileDefinition = tileDefinitionManager["underplating"];
var underplating = new Tile(tileDefinition.TileId); var underplating = new Tile(tileDefinition.TileId);
gridOne.SetTile(new MapIndices(0, 0), underplating); gridOne.SetTile(new Vector2i(0, 0), underplating);
gridOne.SetTile(new MapIndices(-1, -1), underplating); gridOne.SetTile(new Vector2i(-1, -1), underplating);
entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new MapIndices(0, 0)).ToList(); entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new Vector2i(0, 0)).ToList();
Assert.That(entities.Count, Is.EqualTo(0)); Assert.That(entities.Count, Is.EqualTo(0));
// Space entity, check that nothing intersects it and that also it doesn't throw. // Space entity, check that nothing intersects it and that also it doesn't throw.
entityManager.SpawnEntity("HumanMob_Content", new MapCoordinates(Vector2.One * 1000, mapOne)); entityManager.SpawnEntity("HumanMob_Content", new MapCoordinates(Vector2.One * 1000, mapOne));
entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new MapIndices(1000, 1000)).ToList(); entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new Vector2i(1000, 1000)).ToList();
Assert.That(entities.Count, Is.EqualTo(0)); Assert.That(entities.Count, Is.EqualTo(0));
var entityOne = entityManager.SpawnEntity("Food4NoRaisins", new EntityCoordinates(gridOne.GridEntityId, Vector2.Zero)); var entityOne = entityManager.SpawnEntity("Food4NoRaisins", new EntityCoordinates(gridOne.GridEntityId, Vector2.Zero));
@@ -54,10 +54,10 @@ namespace Content.IntegrationTests.Tests
Assert.That(entities.Count, Is.EqualTo(3)); Assert.That(entities.Count, Is.EqualTo(3));
// Both dummies should be in each corner of the 0,0 tile but only one dummy intersects -1,-1 // Both dummies should be in each corner of the 0,0 tile but only one dummy intersects -1,-1
entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new MapIndices(-1, -1)).ToList(); entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new Vector2i(-1, -1)).ToList();
Assert.That(entities.Count, Is.EqualTo(1)); Assert.That(entities.Count, Is.EqualTo(1));
entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new MapIndices(0, 0)).ToList(); entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new Vector2i(0, 0)).ToList();
Assert.That(entities.Count, Is.EqualTo(2)); Assert.That(entities.Count, Is.EqualTo(2));
}); });

View File

@@ -28,14 +28,14 @@ namespace Content.IntegrationTests.Tests.Pathfinding
var mapId = mapMan.CreateMap(new MapId(1)); var mapId = mapMan.CreateMap(new MapId(1));
var gridId = new GridId(2); var gridId = new GridId(2);
mapMan.CreateGrid(mapId, gridId); mapMan.CreateGrid(mapId, gridId);
var chunkTile = mapMan.GetGrid(gridId).GetTileRef(new MapIndices(0, 0)); var chunkTile = mapMan.GetGrid(gridId).GetTileRef(new Vector2i(0, 0));
var chunk = pathfindingSystem.GetChunk(chunkTile); var chunk = pathfindingSystem.GetChunk(chunkTile);
Assert.That(chunk.Nodes.Length == PathfindingChunk.ChunkSize * PathfindingChunk.ChunkSize); Assert.That(chunk.Nodes.Length == PathfindingChunk.ChunkSize * PathfindingChunk.ChunkSize);
// Neighbors // Neighbors
var chunkNeighbors = chunk.GetNeighbors().ToList(); var chunkNeighbors = chunk.GetNeighbors().ToList();
Assert.That(chunkNeighbors.Count == 0); Assert.That(chunkNeighbors.Count == 0);
var neighborChunkTile = mapMan.GetGrid(gridId).GetTileRef(new MapIndices(PathfindingChunk.ChunkSize, PathfindingChunk.ChunkSize)); var neighborChunkTile = mapMan.GetGrid(gridId).GetTileRef(new Vector2i(PathfindingChunk.ChunkSize, PathfindingChunk.ChunkSize));
var neighborChunk = pathfindingSystem.GetChunk(neighborChunkTile); var neighborChunk = pathfindingSystem.GetChunk(neighborChunkTile);
chunkNeighbors = chunk.GetNeighbors().ToList(); chunkNeighbors = chunk.GetNeighbors().ToList();
Assert.That(chunkNeighbors.Count == 1); Assert.That(chunkNeighbors.Count == 1);

View File

@@ -37,13 +37,13 @@ namespace Content.IntegrationTests.Tests
var mapGrid = mapManager.CreateGrid(mapId); var mapGrid = mapManager.CreateGrid(mapId);
var mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId); var mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId);
mapGridEnt.Transform.WorldPosition = new Vector2(10, 10); mapGridEnt.Transform.WorldPosition = new Vector2(10, 10);
mapGrid.SetTile(new MapIndices(0,0), new Tile(1, 512)); mapGrid.SetTile(new Vector2i(0,0), new Tile(1, 512));
} }
{ {
var mapGrid = mapManager.CreateGrid(mapId); var mapGrid = mapManager.CreateGrid(mapId);
var mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId); var mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId);
mapGridEnt.Transform.WorldPosition = new Vector2(-8, -8); mapGridEnt.Transform.WorldPosition = new Vector2(-8, -8);
mapGrid.SetTile(new MapIndices(0, 0), new Tile(2, 511)); mapGrid.SetTile(new Vector2i(0, 0), new Tile(2, 511));
} }
mapLoader.SaveMap(mapId, mapPath); mapLoader.SaveMap(mapId, mapPath);
@@ -63,14 +63,14 @@ namespace Content.IntegrationTests.Tests
Assert.Fail(); Assert.Fail();
Assert.That(mapGrid.WorldPosition, Is.EqualTo(new Vector2(10, 10))); Assert.That(mapGrid.WorldPosition, Is.EqualTo(new Vector2(10, 10)));
Assert.That(mapGrid.GetTileRef(new MapIndices(0, 0)).Tile, Is.EqualTo(new Tile(1, 512))); Assert.That(mapGrid.GetTileRef(new Vector2i(0, 0)).Tile, Is.EqualTo(new Tile(1, 512)));
} }
{ {
if (!mapManager.TryFindGridAt(new MapId(10), new Vector2(-8, -8), out var mapGrid)) if (!mapManager.TryFindGridAt(new MapId(10), new Vector2(-8, -8), out var mapGrid))
Assert.Fail(); Assert.Fail();
Assert.That(mapGrid.WorldPosition, Is.EqualTo(new Vector2(-8, -8))); Assert.That(mapGrid.WorldPosition, Is.EqualTo(new Vector2(-8, -8)));
Assert.That(mapGrid.GetTileRef(new MapIndices(0, 0)).Tile, Is.EqualTo(new Tile(2, 511))); Assert.That(mapGrid.GetTileRef(new Vector2i(0, 0)).Tile, Is.EqualTo(new Tile(2, 511)));
} }
} }

View File

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

View File

@@ -5,6 +5,7 @@ using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.Atmos namespace Content.Server.Atmos
{ {
@@ -36,26 +37,26 @@ namespace Content.Server.Atmos
return !Equals(air = coordinates.GetTileAir(entityManager)!, default); 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); var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
return gridAtmos?.GetTile(indices); 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; 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) [MaybeNullWhen(false)] out TileAtmosphere atmosphere)
{ {
// ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId)!, default); 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 // ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(air = indices.GetTileAir(gridId)!, default); 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. /// Attemps to pry a tile.
/// </summary> /// </summary>
/// <param name="indices"></param> /// <param name="indices"></param>
void PryTile(MapIndices indices); void PryTile(Vector2i indices);
/// <summary> /// <summary>
/// Burns a tile. /// Burns a tile.
/// </summary> /// </summary>
/// <param name="gridIndices"></param> /// <param name="gridIndices"></param>
void BurnTile(MapIndices gridIndices); void BurnTile(Vector2i gridIndices);
/// <summary> /// <summary>
/// Invalidates a coordinate to be revalidated again. /// Invalidates a coordinate to be revalidated again.
/// Use this after changing a tile's gas contents, or when the tile becomes space, etc. /// Use this after changing a tile's gas contents, or when the tile becomes space, etc.
/// </summary> /// </summary>
/// <param name="indices"></param> /// <param name="indices"></param>
void Invalidate(MapIndices indices); void Invalidate(Vector2i indices);
/// <summary> /// <summary>
/// Attempts to fix a sudden vacuum by creating gas. /// Attempts to fix a sudden vacuum by creating gas.
/// </summary> /// </summary>
void FixVacuum(MapIndices indices); void FixVacuum(Vector2i indices);
/// <summary> /// <summary>
/// Revalidates indices immediately. /// Revalidates indices immediately.
/// </summary> /// </summary>
/// <param name="indices"></param> /// <param name="indices"></param>
void UpdateAdjacentBits(MapIndices indices); void UpdateAdjacentBits(Vector2i indices);
/// <summary> /// <summary>
/// Adds an active tile so it becomes processed every update until it becomes inactive. /// 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="indices"></param>
/// <param name="createSpace"></param> /// <param name="createSpace"></param>
/// <returns></returns> /// <returns></returns>
TileAtmosphere GetTile(MapIndices indices, bool createSpace = true); TileAtmosphere GetTile(Vector2i indices, bool createSpace = true);
/// <summary> /// <summary>
/// Returns a tile. /// Returns a tile.
@@ -138,14 +138,14 @@ namespace Content.Server.Atmos
/// <param name="indices"></param> /// <param name="indices"></param>
/// <param name="direction"></param> /// <param name="direction"></param>
/// <returns></returns> /// <returns></returns>
bool IsAirBlocked(MapIndices indices, AtmosDirection direction); bool IsAirBlocked(Vector2i indices, AtmosDirection direction);
/// <summary> /// <summary>
/// Returns if the tile in question is space. /// Returns if the tile in question is space.
/// </summary> /// </summary>
/// <param name="indices"></param> /// <param name="indices"></param>
/// <returns></returns> /// <returns></returns>
bool IsSpace(MapIndices indices); bool IsSpace(Vector2i indices);
/// <summary> /// <summary>
/// Returns the volume in liters for a number of cells/tiles. /// Returns the volume in liters for a number of cells/tiles.
@@ -157,7 +157,7 @@ namespace Content.Server.Atmos
/// <summary> /// <summary>
/// Returns a dictionary of adjacent TileAtmospheres. /// Returns a dictionary of adjacent TileAtmospheres.
/// </summary> /// </summary>
Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(MapIndices indices, bool includeAirBlocked = false); Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(Vector2i indices, bool includeAirBlocked = false);
void Update(float frameTime); void Update(float frameTime);

View File

@@ -106,7 +106,7 @@ namespace Content.Server.Atmos
public TileRef? Tile => GridIndices.GetTileRef(GridIndex); public TileRef? Tile => GridIndices.GetTileRef(GridIndex);
[ViewVariables] [ViewVariables]
public MapIndices GridIndices { get; } public Vector2i GridIndices { get; }
[ViewVariables] [ViewVariables]
public ExcitedGroup ExcitedGroup { get; set; } public ExcitedGroup ExcitedGroup { get; set; }
@@ -122,7 +122,7 @@ namespace Content.Server.Atmos
[ViewVariables] [ViewVariables]
public bool BlocksAllAir => BlockedAirflow == AtmosDirection.All; 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); IoCManager.InjectDependencies(this);
_gridAtmosphereComponent = atmosphereComponent; _gridAtmosphereComponent = atmosphereComponent;
@@ -197,7 +197,7 @@ namespace Content.Server.Atmos
{ {
if(_soundCooldown == 0) if(_soundCooldown == 0)
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Effects/space_wind.ogg", 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)) foreach (var entity in _gridTileLookupSystem.GetEntitiesIntersecting(GridIndex, GridIndices))
@@ -212,7 +212,7 @@ namespace Content.Server.Atmos
var pressureMovements = physics.EnsureController<HighPressureMovementController>(); var pressureMovements = physics.EnsureController<HighPressureMovementController>();
if (pressure.LastHighPressureMovementAirCycle < _gridAtmosphereComponent.UpdateCounter) 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 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); var entities = indices.GetEntitiesInTile(entity.Transform.GridID, true, entity.EntityManager);
foreach (var ent in entities) foreach (var ent in entities)

View File

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

View File

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

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.Atmos; using Content.Server.Atmos;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.GameObjects.Components.Atmos namespace Content.Server.GameObjects.Components.Atmos
{ {
@@ -12,17 +13,17 @@ namespace Content.Server.GameObjects.Components.Atmos
public override void RepopulateTiles() { } public override void RepopulateTiles() { }
public override bool IsSpace(MapIndices indices) public override bool IsSpace(Vector2i indices)
{ {
return true; 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); 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>(); return Enumerable.Empty<AirtightComponent>();
} }

View File

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

View File

@@ -87,7 +87,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
_reactTimer = 0; _reactTimer = 0;
var mapGrid = _mapManager.GetGrid(Owner.Transform.GridID); 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()) foreach (var reagentQuantity in contents.ReagentList.ToArray())
{ {
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue; if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;

View File

@@ -16,6 +16,7 @@ using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Shared.ViewVariables; 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. //Less expensive checks first. Failing those ones, we need to check that the tile isn't obstructed.
if (_ammo <= 0) if (_ammo <= 0)

View File

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

View File

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

View File

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

View File

@@ -603,10 +603,10 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
return Vector2.Zero; return Vector2.Zero;
} }
if (target.TryGetComponent(out ICollidableComponent physicsComponent)) if (target.TryGetComponent(out ICollidableComponent collidable))
{ {
var targetDistance = (targetPos.Position - entityPos.Position); var targetDistance = (targetPos.Position - entityPos.Position);
targetPos = targetPos.Offset(physicsComponent.LinearVelocity * targetDistance); targetPos = targetPos.Offset(collidable.LinearVelocity * targetDistance);
} }
return (targetPos.Position - entityPos.Position).Normalized; 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 // 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 // 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 // i.e. towards the right
if (physicsEntity.TryGetComponent(out ICollidableComponent physicsComponent) && if (physicsEntity.TryGetComponent(out ICollidableComponent collidable) &&
Vector2.Dot(physicsComponent.LinearVelocity, direction) > 0) Vector2.Dot(collidable.LinearVelocity, direction) > 0)
{ {
continue; continue;
} }

View File

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

View File

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

View File

@@ -139,9 +139,9 @@ namespace Content.Server.Throw
var throwDuration = ThrownItemComponent.DefaultThrowTime; var throwDuration = ThrownItemComponent.DefaultThrowTime;
var mass = 1f; 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; var velocityNecessary = distance / throwDuration;

View File

@@ -8,6 +8,7 @@ using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Map;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.Utility namespace Content.Server.Utility
{ {
@@ -28,7 +29,7 @@ namespace Content.Server.Utility
/// Helper that returns all entities in a turf. /// Helper that returns all entities in a turf.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [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>(); gridTileLookup ??= EntitySystem.Get<GridTileLookupSystem>();
return gridTileLookup.GetEntitiesIntersecting(gridId, indices); return gridTileLookup.GetEntitiesIntersecting(gridId, indices);

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -15,16 +16,16 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
/// <summary> /// <summary>
/// Origin of this chunk /// Origin of this chunk
/// </summary> /// </summary>
public MapIndices MapIndices { get; } public Vector2i Vector2i { get; }
public SharedGasTileOverlaySystem.GasOverlayData[,] TileData = new SharedGasTileOverlaySystem.GasOverlayData[SharedGasTileOverlaySystem.ChunkSize, SharedGasTileOverlaySystem.ChunkSize]; public SharedGasTileOverlaySystem.GasOverlayData[,] TileData = new SharedGasTileOverlaySystem.GasOverlayData[SharedGasTileOverlaySystem.ChunkSize, SharedGasTileOverlaySystem.ChunkSize];
public GameTick LastUpdate { get; private set; } public GameTick LastUpdate { get; private set; }
public GasOverlayChunk(GridId gridIndices, MapIndices mapIndices) public GasOverlayChunk(GridId gridIndices, Vector2i Vector2i)
{ {
GridIndices = gridIndices; GridIndices = gridIndices;
MapIndices = mapIndices; Vector2i = Vector2i;
} }
public void Dirty(GameTick currentTick) public void Dirty(GameTick currentTick)
@@ -37,11 +38,11 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="indices"></param> /// <param name="indices"></param>
public void Update(SharedGasTileOverlaySystem.GasOverlayData data, MapIndices indices) public void Update(SharedGasTileOverlaySystem.GasOverlayData data, Vector2i indices)
{ {
DebugTools.Assert(InBounds(indices)); DebugTools.Assert(InBounds(indices));
var (offsetX, offsetY) = (indices.X - MapIndices.X, var (offsetX, offsetY) = (indices.X - Vector2i.X,
indices.Y - MapIndices.Y); indices.Y - Vector2i.Y);
TileData[offsetX, offsetY] = data; TileData[offsetX, offsetY] = data;
} }
@@ -64,7 +65,7 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
} }
} }
public void GetData(List<(MapIndices, SharedGasTileOverlaySystem.GasOverlayData)> existingData, HashSet<MapIndices> indices) public void GetData(List<(Vector2i, SharedGasTileOverlaySystem.GasOverlayData)> existingData, HashSet<Vector2i> indices)
{ {
foreach (var index in indices) foreach (var index in indices)
{ {
@@ -72,27 +73,27 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
} }
} }
public IEnumerable<MapIndices> GetAllIndices() public IEnumerable<Vector2i> GetAllIndices()
{ {
for (var x = 0; x < SharedGasTileOverlaySystem.ChunkSize; x++) for (var x = 0; x < SharedGasTileOverlaySystem.ChunkSize; x++)
{ {
for (var y = 0; y < SharedGasTileOverlaySystem.ChunkSize; y++) for (var y = 0; y < SharedGasTileOverlaySystem.ChunkSize; y++)
{ {
yield return new MapIndices(MapIndices.X + x, MapIndices.Y + y); yield return new Vector2i(Vector2i.X + x, Vector2i.Y + y);
} }
} }
} }
public SharedGasTileOverlaySystem.GasOverlayData GetData(MapIndices indices) public SharedGasTileOverlaySystem.GasOverlayData GetData(Vector2i indices)
{ {
DebugTools.Assert(InBounds(indices)); DebugTools.Assert(InBounds(indices));
return TileData[indices.X - MapIndices.X, indices.Y - MapIndices.Y]; return TileData[indices.X - Vector2i.X, indices.Y - Vector2i.Y];
} }
private bool InBounds(MapIndices indices) private bool InBounds(Vector2i indices)
{ {
if (indices.X < MapIndices.X || indices.Y < MapIndices.Y) return false; if (indices.X < Vector2i.X || indices.Y < Vector2i.Y) return false;
if (indices.X >= MapIndices.X + SharedGasTileOverlaySystem.ChunkSize || indices.Y >= MapIndices.Y + SharedGasTileOverlaySystem.ChunkSize) return false; if (indices.X >= Vector2i.X + SharedGasTileOverlaySystem.ChunkSize || indices.Y >= Vector2i.Y + SharedGasTileOverlaySystem.ChunkSize) return false;
return true; return true;
} }
} }

View File

@@ -6,6 +6,7 @@ using Robust.Shared.Map;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Robust.Shared.Maths;
namespace Content.Shared.GameObjects.EntitySystems.Atmos namespace Content.Shared.GameObjects.EntitySystems.Atmos
{ {
@@ -41,11 +42,11 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
{ {
public GridId GridId { get; } public GridId GridId { get; }
public MapIndices BaseIdx { get; } public Vector2i BaseIdx { get; }
// LocalViewRange*LocalViewRange // LocalViewRange*LocalViewRange
public AtmosDebugOverlayData[] OverlayData { get; } public AtmosDebugOverlayData[] OverlayData { get; }
public AtmosDebugOverlayMessage(GridId gridIndices, MapIndices baseIdx, AtmosDebugOverlayData[] overlayData) public AtmosDebugOverlayMessage(GridId gridIndices, Vector2i baseIdx, AtmosDebugOverlayData[] overlayData)
{ {
GridId = gridIndices; GridId = gridIndices;
BaseIdx = baseIdx; BaseIdx = baseIdx;

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -13,9 +14,9 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
public const byte ChunkSize = 8; public const byte ChunkSize = 8;
protected float AccumulatedFrameTime; protected float AccumulatedFrameTime;
public static MapIndices GetGasChunkIndices(MapIndices indices) public static Vector2i GetGasChunkIndices(Vector2i indices)
{ {
return new MapIndices((int) Math.Floor((float) indices.X / ChunkSize) * ChunkSize, (int) MathF.Floor((float) indices.Y / ChunkSize) * ChunkSize); return new Vector2i((int) Math.Floor((float) indices.X / ChunkSize) * ChunkSize, (int) MathF.Floor((float) indices.Y / ChunkSize) * ChunkSize);
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]
@@ -85,9 +86,9 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
{ {
public GridId GridId { get; } public GridId GridId { get; }
public List<(MapIndices, GasOverlayData)> OverlayData { get; } public List<(Vector2i, GasOverlayData)> OverlayData { get; }
public GasOverlayMessage(GridId gridIndices, List<(MapIndices,GasOverlayData)> overlayData) public GasOverlayMessage(GridId gridIndices, List<(Vector2i,GasOverlayData)> overlayData)
{ {
GridId = gridIndices; GridId = gridIndices;
OverlayData = overlayData; OverlayData = overlayData;

View File

@@ -28,7 +28,7 @@ namespace Content.Shared.Maps
/// <summary> /// <summary>
/// Attempts to get the turf at map indices with grid id or null if no such turf is found. /// Attempts to get the turf at map indices with grid id or null if no such turf is found.
/// </summary> /// </summary>
public static TileRef GetTileRef(this MapIndices mapIndices, GridId gridId, IMapManager? mapManager = null) public static TileRef GetTileRef(this Vector2i Vector2i, GridId gridId, IMapManager? mapManager = null)
{ {
if (!gridId.IsValid()) if (!gridId.IsValid())
return default; return default;
@@ -38,7 +38,7 @@ namespace Content.Shared.Maps
if (!mapManager.TryGetGrid(gridId, out var grid)) if (!mapManager.TryGetGrid(gridId, out var grid))
return default; return default;
if (!grid.TryGetTileRef(mapIndices, out var tile)) if (!grid.TryGetTileRef(Vector2i, out var tile))
return default; return default;
return tile; return tile;
@@ -76,10 +76,10 @@ namespace Content.Shared.Maps
entityManager ??= IoCManager.Resolve<IEntityManager>(); entityManager ??= IoCManager.Resolve<IEntityManager>();
mapManager ??= IoCManager.Resolve<IMapManager>(); mapManager ??= IoCManager.Resolve<IMapManager>();
return coordinates.ToMapIndices(entityManager, mapManager).PryTile(coordinates.GetGridId(entityManager)); return coordinates.ToVector2i(entityManager, mapManager).PryTile(coordinates.GetGridId(entityManager));
} }
public static bool PryTile(this MapIndices indices, GridId gridId, public static bool PryTile(this Vector2i indices, GridId gridId,
IMapManager? mapManager = null, ITileDefinitionManager? tileDefinitionManager = null, IEntityManager? entityManager = null) IMapManager? mapManager = null, ITileDefinitionManager? tileDefinitionManager = null, IEntityManager? entityManager = null)
{ {
mapManager ??= IoCManager.Resolve<IMapManager>(); mapManager ??= IoCManager.Resolve<IMapManager>();
@@ -114,7 +114,7 @@ namespace Content.Shared.Maps
var half = mapGrid.TileSize / 2f; var half = mapGrid.TileSize / 2f;
//Actually spawn the relevant tile item at the right position and give it some random offset. //Actually spawn the relevant tile item at the right position and give it some random offset.
var tileItem = entityManager.SpawnEntity(tileDef.ItemDropPrototypeName, indices.ToEntityCoordinates(mapManager, tileRef.GridIndex).Offset(new Vector2(half, half))); var tileItem = entityManager.SpawnEntity(tileDef.ItemDropPrototypeName, indices.ToEntityCoordinates(tileRef.GridIndex, mapManager).Offset(new Vector2(half, half)));
tileItem.RandomOffset(0.25f); tileItem.RandomOffset(0.25f);
return true; return true;
} }
@@ -146,7 +146,7 @@ namespace Content.Shared.Maps
/// <summary> /// <summary>
/// Helper that returns all entities in a turf. /// Helper that returns all entities in a turf.
/// </summary> /// </summary>
public static IEnumerable<IEntity> GetEntitiesInTile(this MapIndices indices, GridId gridId, bool approximate = false, IEntityManager? entityManager = null) public static IEnumerable<IEntity> GetEntitiesInTile(this Vector2i indices, GridId gridId, bool approximate = false, IEntityManager? entityManager = null)
{ {
return GetEntitiesInTile(indices.GetTileRef(gridId), approximate, entityManager); return GetEntitiesInTile(indices.GetTileRef(gridId), approximate, entityManager);
} }
@@ -178,7 +178,7 @@ namespace Content.Shared.Maps
{ {
mapManager ??= IoCManager.Resolve<IMapManager>(); mapManager ??= IoCManager.Resolve<IMapManager>();
return turf.GridIndices.ToEntityCoordinates(mapManager, turf.GridIndex); return turf.GridIndices.ToEntityCoordinates(turf.GridIndex, mapManager);
} }
/// <summary> /// <summary>