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:
@@ -35,7 +35,7 @@ namespace Content.Client.GameObjects.Components.IconSmoothing
|
||||
|
||||
internal ISpriteComponent Sprite { get; private set; }
|
||||
internal SnapGridComponent SnapGrid { get; private set; }
|
||||
private (GridId, MapIndices) _lastPosition;
|
||||
private (GridId, Vector2i) _lastPosition;
|
||||
|
||||
/// <summary>
|
||||
/// We will smooth with other objects with the same key.
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
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))
|
||||
return null;
|
||||
|
||||
@@ -41,8 +41,8 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
private readonly int[] _fireFrameCounter = new int[FireStates];
|
||||
private readonly Texture[][] _fireFrames = new Texture[FireStates][];
|
||||
|
||||
private Dictionary<GridId, Dictionary<MapIndices, GasOverlayChunk>> _tileData =
|
||||
new Dictionary<GridId, Dictionary<MapIndices, GasOverlayChunk>>();
|
||||
private Dictionary<GridId, Dictionary<Vector2i, GasOverlayChunk>> _tileData =
|
||||
new Dictionary<GridId, Dictionary<Vector2i, GasOverlayChunk>>();
|
||||
|
||||
private AtmosphereSystem _atmosphereSystem = default!;
|
||||
|
||||
@@ -107,11 +107,11 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
}
|
||||
|
||||
// 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))
|
||||
{
|
||||
chunks = new Dictionary<MapIndices, GasOverlayChunk>();
|
||||
chunks = new Dictionary<Vector2i, GasOverlayChunk>();
|
||||
_tileData[gridId] = chunks;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
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))
|
||||
return Array.Empty<(Texture, Color)>();
|
||||
|
||||
@@ -82,16 +82,16 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
{
|
||||
var pos = ev.LastPosition.Value.pos;
|
||||
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(1, 0), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-1, 0), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(0, 1), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(0, -1), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(1, 0), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(-1, 0), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(0, 1), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(0, -1), ev.Offset));
|
||||
if (ev.Mode == IconSmoothingMode.Corners)
|
||||
{
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(1, 1), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-1, -1), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-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 Vector2i(-1, -1), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(-1, 1), ev.Offset));
|
||||
AddValidEntities(grid.GetSnapGridCell(pos + new Vector2i(1, -1), ev.Offset));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
/// </summary>
|
||||
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;
|
||||
Offset = offset;
|
||||
@@ -143,7 +143,7 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
Sender = sender;
|
||||
}
|
||||
|
||||
public (GridId grid, MapIndices pos)? LastPosition { get; }
|
||||
public (GridId grid, Vector2i pos)? LastPosition { get; }
|
||||
public SnapGridOffset Offset { get; }
|
||||
public IconSmoothingMode Mode { get; }
|
||||
public IEntity Sender { get; }
|
||||
|
||||
@@ -6,6 +6,7 @@ using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
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 tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId];
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.Atmos;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Atmos
|
||||
{
|
||||
@@ -91,7 +92,7 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTileAtmosphereMapIndicesNotNullTest()
|
||||
public async Task GetTileAtmosphereVector2iNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
@@ -99,7 +100,7 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var atmosphere = default(MapIndices).GetTileAtmosphere(default);
|
||||
var atmosphere = default(Vector2i).GetTileAtmosphere(default);
|
||||
|
||||
Assert.NotNull(atmosphere);
|
||||
});
|
||||
@@ -109,7 +110,7 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTileAirMapIndicesNotNullTest()
|
||||
public async Task GetTileAirVector2iNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
@@ -117,7 +118,7 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var air = default(MapIndices).GetTileAir(default);
|
||||
var air = default(Vector2i).GetTileAir(default);
|
||||
|
||||
Assert.NotNull(air);
|
||||
});
|
||||
@@ -127,7 +128,7 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryGetTileAtmosphereMapIndicesNotNullTest()
|
||||
public async Task TryGetTileAtmosphereVector2iNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
@@ -135,7 +136,7 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var hasAtmosphere = default(MapIndices).TryGetTileAtmosphere(default, out var atmosphere);
|
||||
var hasAtmosphere = default(Vector2i).TryGetTileAtmosphere(default, out var atmosphere);
|
||||
|
||||
Assert.True(hasAtmosphere);
|
||||
Assert.NotNull(atmosphere);
|
||||
@@ -146,7 +147,7 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryGetTileAirMapIndicesNotNullTest()
|
||||
public async Task TryGetTileAirVector2iNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
@@ -154,7 +155,7 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var hasAir = default(MapIndices).TryGetTileAir(default, out var air);
|
||||
var hasAir = default(Vector2i).TryGetTileAir(default, out var air);
|
||||
|
||||
Assert.True(hasAir);
|
||||
Assert.NotNull(air);
|
||||
|
||||
@@ -32,15 +32,15 @@ namespace Content.IntegrationTests.Tests
|
||||
|
||||
var tileDefinition = tileDefinitionManager["underplating"];
|
||||
var underplating = new Tile(tileDefinition.TileId);
|
||||
gridOne.SetTile(new MapIndices(0, 0), underplating);
|
||||
gridOne.SetTile(new MapIndices(-1, -1), underplating);
|
||||
gridOne.SetTile(new Vector2i(0, 0), 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));
|
||||
|
||||
// Space entity, check that nothing intersects it and that also it doesn't throw.
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
// 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));
|
||||
|
||||
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));
|
||||
});
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Content.IntegrationTests.Tests.Pathfinding
|
||||
public async Task Test()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
var pathfindingSystem = EntitySystem.Get<PathfindingSystem>();
|
||||
@@ -28,32 +28,32 @@ namespace Content.IntegrationTests.Tests.Pathfinding
|
||||
var mapId = mapMan.CreateMap(new MapId(1));
|
||||
var gridId = new GridId(2);
|
||||
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);
|
||||
Assert.That(chunk.Nodes.Length == PathfindingChunk.ChunkSize * PathfindingChunk.ChunkSize);
|
||||
|
||||
|
||||
// Neighbors
|
||||
var chunkNeighbors = chunk.GetNeighbors().ToList();
|
||||
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);
|
||||
chunkNeighbors = chunk.GetNeighbors().ToList();
|
||||
Assert.That(chunkNeighbors.Count == 1);
|
||||
|
||||
|
||||
// Directions
|
||||
Assert.That(PathfindingHelpers.RelativeDirection(neighborChunk, chunk) == Direction.NorthEast);
|
||||
Assert.That(PathfindingHelpers.RelativeDirection(chunk.Nodes[0, 1], chunk.Nodes[0, 0]) == Direction.North);
|
||||
|
||||
|
||||
// Nodes
|
||||
var node = chunk.Nodes[1, 1];
|
||||
var nodeNeighbors = node.GetNeighbors().ToList();
|
||||
Assert.That(nodeNeighbors.Count == 8);
|
||||
|
||||
|
||||
// Bottom-left corner with no chunk neighbor
|
||||
node = chunk.Nodes[0, 0];
|
||||
nodeNeighbors = node.GetNeighbors().ToList();
|
||||
Assert.That(nodeNeighbors.Count == 3);
|
||||
|
||||
|
||||
// Given we have 1 NE neighbor then NE corner should have 4 neighbors due to the 1 extra from the neighbor chunk
|
||||
node = chunk.Nodes[PathfindingChunk.ChunkSize - 1, PathfindingChunk.ChunkSize - 1];
|
||||
nodeNeighbors = node.GetNeighbors().ToList();
|
||||
@@ -62,4 +62,4 @@ namespace Content.IntegrationTests.Tests.Pathfinding
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ namespace Content.IntegrationTests.Tests
|
||||
var mapGrid = mapManager.CreateGrid(mapId);
|
||||
var mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId);
|
||||
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 mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId);
|
||||
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);
|
||||
@@ -63,14 +63,14 @@ namespace Content.IntegrationTests.Tests
|
||||
Assert.Fail();
|
||||
|
||||
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))
|
||||
Assert.Fail();
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
|
||||
@@ -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) { }
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -11,20 +12,20 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
||||
/// Grid for this chunk
|
||||
/// </summary>
|
||||
public GridId GridIndices { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Origin of this chunk
|
||||
/// </summary>
|
||||
public MapIndices MapIndices { get; }
|
||||
|
||||
public Vector2i Vector2i { get; }
|
||||
|
||||
public SharedGasTileOverlaySystem.GasOverlayData[,] TileData = new SharedGasTileOverlaySystem.GasOverlayData[SharedGasTileOverlaySystem.ChunkSize, SharedGasTileOverlaySystem.ChunkSize];
|
||||
|
||||
public GameTick LastUpdate { get; private set; }
|
||||
|
||||
public GasOverlayChunk(GridId gridIndices, MapIndices mapIndices)
|
||||
public GasOverlayChunk(GridId gridIndices, Vector2i Vector2i)
|
||||
{
|
||||
GridIndices = gridIndices;
|
||||
MapIndices = mapIndices;
|
||||
Vector2i = Vector2i;
|
||||
}
|
||||
|
||||
public void Dirty(GameTick currentTick)
|
||||
@@ -37,12 +38,12 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
||||
/// </summary>
|
||||
/// <param name="data"></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));
|
||||
var (offsetX, offsetY) = (indices.X - MapIndices.X,
|
||||
indices.Y - MapIndices.Y);
|
||||
|
||||
var (offsetX, offsetY) = (indices.X - Vector2i.X,
|
||||
indices.Y - Vector2i.Y);
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -72,28 +73,28 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<MapIndices> GetAllIndices()
|
||||
public IEnumerable<Vector2i> GetAllIndices()
|
||||
{
|
||||
for (var x = 0; x < SharedGasTileOverlaySystem.ChunkSize; x++)
|
||||
{
|
||||
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));
|
||||
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 >= MapIndices.X + SharedGasTileOverlaySystem.ChunkSize || indices.Y >= MapIndices.Y + SharedGasTileOverlaySystem.ChunkSize) return false;
|
||||
if (indices.X < Vector2i.X || indices.Y < Vector2i.Y) return false;
|
||||
if (indices.X >= Vector2i.X + SharedGasTileOverlaySystem.ChunkSize || indices.Y >= Vector2i.Y + SharedGasTileOverlaySystem.ChunkSize) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Shared.Atmos;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
||||
{
|
||||
@@ -41,11 +42,11 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
||||
{
|
||||
public GridId GridId { get; }
|
||||
|
||||
public MapIndices BaseIdx { get; }
|
||||
public Vector2i BaseIdx { get; }
|
||||
// LocalViewRange*LocalViewRange
|
||||
public AtmosDebugOverlayData[] OverlayData { get; }
|
||||
|
||||
public AtmosDebugOverlayMessage(GridId gridIndices, MapIndices baseIdx, AtmosDebugOverlayData[] overlayData)
|
||||
public AtmosDebugOverlayMessage(GridId gridIndices, Vector2i baseIdx, AtmosDebugOverlayData[] overlayData)
|
||||
{
|
||||
GridId = gridIndices;
|
||||
BaseIdx = baseIdx;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -13,9 +14,9 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
||||
public const byte ChunkSize = 8;
|
||||
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]
|
||||
@@ -85,9 +86,9 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
||||
{
|
||||
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;
|
||||
OverlayData = overlayData;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Content.Shared.Maps
|
||||
/// <summary>
|
||||
/// Attempts to get the turf at map indices with grid id or null if no such turf is found.
|
||||
/// </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())
|
||||
return default;
|
||||
@@ -38,7 +38,7 @@ namespace Content.Shared.Maps
|
||||
if (!mapManager.TryGetGrid(gridId, out var grid))
|
||||
return default;
|
||||
|
||||
if (!grid.TryGetTileRef(mapIndices, out var tile))
|
||||
if (!grid.TryGetTileRef(Vector2i, out var tile))
|
||||
return default;
|
||||
|
||||
return tile;
|
||||
@@ -76,10 +76,10 @@ namespace Content.Shared.Maps
|
||||
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||
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)
|
||||
{
|
||||
mapManager ??= IoCManager.Resolve<IMapManager>();
|
||||
@@ -114,7 +114,7 @@ namespace Content.Shared.Maps
|
||||
var half = mapGrid.TileSize / 2f;
|
||||
|
||||
//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);
|
||||
return true;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace Content.Shared.Maps
|
||||
/// <summary>
|
||||
/// Helper that returns all entities in a turf.
|
||||
/// </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);
|
||||
}
|
||||
@@ -178,7 +178,7 @@ namespace Content.Shared.Maps
|
||||
{
|
||||
mapManager ??= IoCManager.Resolve<IMapManager>();
|
||||
|
||||
return turf.GridIndices.ToEntityCoordinates(mapManager, turf.GridIndex);
|
||||
return turf.GridIndices.ToEntityCoordinates(turf.GridIndex, mapManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Submodule RobustToolbox updated: cabb9859ec...5bbcdbd3ef
Reference in New Issue
Block a user