mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 15:22:27 +02:00
* All IPhysShapes now expose a property to get the local AABB. * Removed IMapChunk. It's internal, we only have 1 implementation in the engine, no need for abstraction, and removing it helps perf. * Cleaned up issues in MapChunk file. * Encapsulate _tiles access inside MapChunk. * Remove IEnumerable<TileRef> from MapChunk. * Remove CollidesWithChunk * Move CalcWorldAABB and RegenerateCollision from MapChunk to MapGrid. Remove MapChunk.GridId. * Removed MapChunk.GetAllTiles * Removed the terrible mocked unit tests. * Moved the GetTileRef functions from MapChunk to MapGrid. * Add an event raised on MapChunk when a tile is modified. Completely remove the IMapGrid dependency from MapChunk. * Fix bug where you cannot change the tile damage of a tile.
75 lines
1.9 KiB
C#
75 lines
1.9 KiB
C#
using NUnit.Framework;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.UnitTesting.Shared.Map
|
|
{
|
|
[TestFixture, Parallelizable, TestOf(typeof(GridChunkPartition))]
|
|
internal sealed class GridChunkPartition_Tests : RobustUnitTest
|
|
{
|
|
// origin is top left
|
|
private static readonly int[] _testMiscTiles = {
|
|
1, 1, 0, 0,
|
|
0, 1, 1, 0,
|
|
0, 1, 1, 1,
|
|
1, 1, 0, 0,
|
|
};
|
|
|
|
[Test]
|
|
public void PartitionChunk_MiscTiles()
|
|
{
|
|
// Arrange
|
|
var chunk = ChunkFactory(4, _testMiscTiles);
|
|
|
|
// Act
|
|
GridChunkPartition.PartitionChunk(chunk, out var bounds, out _);
|
|
|
|
// box origin is top left
|
|
// algorithm goes down columns of array, starting on left side, then moves right, expanding rectangles to the right
|
|
/*
|
|
0 2 . .
|
|
. 2 3 .
|
|
. 2 3 4
|
|
1 2 . .
|
|
*/
|
|
|
|
Assert.That(bounds, Is.EqualTo(new Box2i(0,0,4,4)));
|
|
}
|
|
|
|
// origin is top left
|
|
private static readonly int[] _testJoinTiles = {
|
|
0, 1, 1, 0,
|
|
0, 1, 1, 0,
|
|
0, 1, 1, 0,
|
|
0, 0, 0, 0,
|
|
};
|
|
|
|
[Test]
|
|
public void PartitionChunk_JoinTiles()
|
|
{
|
|
// Arrange
|
|
var chunk = ChunkFactory(4, _testJoinTiles);
|
|
|
|
// Act
|
|
GridChunkPartition.PartitionChunk(chunk, out var bounds, out _);
|
|
|
|
Assert.That(bounds, Is.EqualTo(new Box2i(1, 0, 3, 3)));
|
|
}
|
|
|
|
private static MapChunk ChunkFactory(ushort size, int[] tiles)
|
|
{
|
|
var chunk = new MapChunk(0, 0, size);
|
|
|
|
for (var i = 0; i < tiles.Length; i++)
|
|
{
|
|
var x = i % size;
|
|
var y = i / size;
|
|
|
|
chunk.SetTile((ushort)x, (ushort)y, new Tile((ushort)tiles[i]));
|
|
}
|
|
|
|
return chunk;
|
|
}
|
|
}
|
|
}
|