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

@@ -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);

View File

@@ -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));
});

View File

@@ -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();
}
}
}
}

View File

@@ -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)));
}
}