Replace MapIndices to Vector2i (#1318)

This commit is contained in:
DrSmugleaf
2020-10-11 14:33:09 +02:00
committed by GitHub
parent 29086a5b4b
commit da76788751
22 changed files with 194 additions and 177 deletions

View File

@@ -305,7 +305,7 @@ namespace Robust.Client.Console.Commands
internal class SnapGridGetCell : IConsoleCommand
{
public string Command => "sggcell";
public string Help => "sggcell <gridID> <mapIndices> [offset]\nThat mapindices param is in the form x<int>,y<int>.";
public string Help => "sggcell <gridID> <vector2i> [offset]\nThat vector2i param is in the form x<int>,y<int>.";
public string Description => "Lists entities on a snap grid cell.";
public bool Execute(IDebugConsole console, params string[] args)
@@ -349,7 +349,7 @@ namespace Robust.Client.Console.Commands
{
foreach (var entity in
mapMan.GetGrid(new GridId(int.Parse(gridId, CultureInfo.InvariantCulture))).GetSnapGridCell(
new MapIndices(
new Vector2i(
int.Parse(indices.Split(',')[0], CultureInfo.InvariantCulture),
int.Parse(indices.Split(',')[1], CultureInfo.InvariantCulture)),
selectedOffset))

View File

@@ -12,7 +12,7 @@ namespace Robust.Client.GameObjects
{
internal SnapGridComponent? SnapGrid { get; private set; }
[ViewVariables] private (GridId, MapIndices) _lastPosition;
[ViewVariables] private (GridId, Vector2i) _lastPosition;
[ViewVariables] internal OccluderDir Occluding { get; private set; }
[ViewVariables] internal uint UpdateGeneration { get; set; }

View File

@@ -83,10 +83,10 @@ namespace Robust.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));
}
}
@@ -112,14 +112,14 @@ namespace Robust.Client.GameObjects.EntitySystems
/// </summary>
internal sealed class OccluderDirtyEvent : EntitySystemMessage
{
public OccluderDirtyEvent(IEntity sender, (GridId grid, MapIndices pos)? lastPosition, SnapGridOffset offset)
public OccluderDirtyEvent(IEntity sender, (GridId grid, Vector2i pos)? lastPosition, SnapGridOffset offset)
{
LastPosition = lastPosition;
Offset = offset;
Sender = sender;
}
public (GridId grid, MapIndices pos)? LastPosition { get; }
public (GridId grid, Vector2i pos)? LastPosition { get; }
public SnapGridOffset Offset { get; }
public IEntity Sender { get; }
}

View File

@@ -14,8 +14,8 @@ namespace Robust.Client.Graphics.Clyde
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private readonly Dictionary<GridId, Dictionary<MapIndices, MapChunkData>> _mapChunkData =
new Dictionary<GridId, Dictionary<MapIndices, MapChunkData>>();
private readonly Dictionary<GridId, Dictionary<Vector2i, MapChunkData>> _mapChunkData =
new Dictionary<GridId, Dictionary<Vector2i, MapChunkData>>();
private int _verticesPerChunk(IMapChunk chunk) => chunk.ChunkSize * chunk.ChunkSize * 4;
private int _indicesPerChunk(IMapChunk chunk) => chunk.ChunkSize * chunk.ChunkSize * GetQuadBatchIndexCount();
@@ -182,7 +182,7 @@ namespace Robust.Client.Graphics.Clyde
return !data.TryGetValue(chunk.Indices, out var datum) || datum.Dirty;
}
public void _setChunkDirty(IMapGrid grid, MapIndices chunk)
public void _setChunkDirty(IMapGrid grid, Vector2i chunk)
{
var data = _mapChunkData[grid.Index];
if (data.TryGetValue(chunk, out var datum))
@@ -205,13 +205,13 @@ namespace Robust.Client.Graphics.Clyde
private void _updateTileMapOnUpdate(object? sender, TileChangedEventArgs args)
{
var grid = _mapManager.GetGrid(args.NewTile.GridIndex);
var chunk = grid.GridTileToChunkIndices(new MapIndices(args.NewTile.X, args.NewTile.Y));
var chunk = grid.GridTileToChunkIndices(new Vector2i(args.NewTile.X, args.NewTile.Y));
_setChunkDirty(grid, chunk);
}
private void _updateOnGridCreated(GridId gridId)
{
_mapChunkData.Add(gridId, new Dictionary<MapIndices, MapChunkData>());
_mapChunkData.Add(gridId, new Dictionary<Vector2i, MapChunkData>());
}
private void _updateOnGridRemoved(GridId gridId)

View File

@@ -1,11 +1,12 @@
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Robust.Server.GameObjects.EntitySystemMessages
{
/// <summary>
/// Event for when the intersecting MapIndices of an entity changes.
/// Event for when the intersecting Vector2i of an entity changes.
/// Not called for space (given no tiles).
/// </summary>
/// <remarks>
@@ -13,9 +14,9 @@ namespace Robust.Server.GameObjects.EntitySystemMessages
/// </remarks>
public sealed class TileLookupUpdateMessage : EntitySystemMessage
{
public Dictionary<GridId, List<MapIndices>>? NewIndices { get; }
public Dictionary<GridId, List<Vector2i>>? NewIndices { get; }
public TileLookupUpdateMessage(Dictionary<GridId, List<MapIndices>>? indices)
public TileLookupUpdateMessage(Dictionary<GridId, List<Vector2i>>? indices)
{
NewIndices = indices;
}

View File

@@ -1,4 +1,5 @@
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Robust.Server.GameObjects.EntitySystems.TileLookup
{
@@ -7,11 +8,11 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
internal const byte ChunkSize = 16;
internal GridId GridId { get; }
internal MapIndices Indices { get; }
internal Vector2i Indices { get; }
private GridTileLookupNode[,] _nodes = new GridTileLookupNode[ChunkSize,ChunkSize];
internal GridTileLookupChunk(GridId gridId, MapIndices indices)
internal GridTileLookupChunk(GridId gridId, Vector2i indices)
{
GridId = gridId;
Indices = indices;
@@ -20,12 +21,12 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
{
for (var y = 0; y < ChunkSize; y++)
{
_nodes[x, y] = new GridTileLookupNode(this, new MapIndices(Indices.X + x, Indices.Y + y));
_nodes[x, y] = new GridTileLookupNode(this, new Vector2i(Indices.X + x, Indices.Y + y));
}
}
}
internal GridTileLookupNode GetNode(MapIndices nodeIndices)
internal GridTileLookupNode GetNode(Vector2i nodeIndices)
{
return _nodes[nodeIndices.X - Indices.X, nodeIndices.Y - Indices.Y];
}

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Robust.Server.GameObjects.EntitySystems.TileLookup
{
@@ -8,7 +9,7 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
{
internal GridTileLookupChunk ParentChunk { get; }
internal MapIndices Indices { get; }
internal Vector2i Indices { get; }
internal IEnumerable<IEntity> Entities
{
@@ -24,7 +25,7 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
private readonly HashSet<IEntity> _entities = new HashSet<IEntity>();
internal GridTileLookupNode(GridTileLookupChunk parentChunk, MapIndices indices)
internal GridTileLookupNode(GridTileLookupChunk parentChunk, Vector2i indices)
{
ParentChunk = parentChunk;
Indices = indices;

View File

@@ -25,8 +25,8 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
{
[Dependency] private readonly IMapManager _mapManager = default!;
private readonly Dictionary<GridId, Dictionary<MapIndices, GridTileLookupChunk>> _graph =
new Dictionary<GridId, Dictionary<MapIndices, GridTileLookupChunk>>();
private readonly Dictionary<GridId, Dictionary<Vector2i, GridTileLookupChunk>> _graph =
new Dictionary<GridId, Dictionary<Vector2i, GridTileLookupChunk>>();
/// <summary>
/// Need to store the nodes for each entity because if the entity is deleted its transform is no longer valid.
@@ -51,12 +51,12 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
}
/// <summary>
/// Yields all of the entities intersecting a particular MapIndices
/// Yields all of the entities intersecting a particular Vector2i
/// </summary>
/// <param name="gridId"></param>
/// <param name="gridIndices"></param>
/// <returns></returns>
public IEnumerable<IEntity> GetEntitiesIntersecting(GridId gridId, MapIndices gridIndices)
public IEnumerable<IEntity> GetEntitiesIntersecting(GridId gridId, Vector2i gridIndices)
{
if (gridId == GridId.Invalid)
{
@@ -80,9 +80,9 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
}
}
public List<MapIndices> GetIndices(IEntity entity)
public List<Vector2i> GetIndices(IEntity entity)
{
var results = new List<MapIndices>();
var results = new List<Vector2i>();
if (!_lastKnownNodes.TryGetValue(entity, out var nodes))
{
@@ -97,13 +97,13 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
return results;
}
private GridTileLookupChunk GetOrCreateChunk(GridId gridId, MapIndices indices)
private GridTileLookupChunk GetOrCreateChunk(GridId gridId, Vector2i indices)
{
var chunkIndices = GetChunkIndices(indices);
if (!_graph.TryGetValue(gridId, out var gridChunks))
{
gridChunks = new Dictionary<MapIndices, GridTileLookupChunk>();
gridChunks = new Dictionary<Vector2i, GridTileLookupChunk>();
_graph[gridId] = gridChunks;
}
@@ -116,9 +116,9 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
return chunk;
}
private MapIndices GetChunkIndices(MapIndices indices)
private Vector2i GetChunkIndices(Vector2i indices)
{
return new MapIndices(
return new Vector2i(
(int) (Math.Floor((float) indices.X / GridTileLookupChunk.ChunkSize) * GridTileLookupChunk.ChunkSize),
(int) (Math.Floor((float) indices.Y / GridTileLookupChunk.ChunkSize) * GridTileLookupChunk.ChunkSize));
}
@@ -171,7 +171,7 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
/// <param name="gridId"></param>
/// <param name="indices"></param>
/// <returns></returns>
private GridTileLookupNode GetOrCreateNode(GridId gridId, MapIndices indices)
private GridTileLookupNode GetOrCreateNode(GridId gridId, Vector2i indices)
{
var chunk = GetOrCreateChunk(gridId, indices);
@@ -179,18 +179,18 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
}
/// <summary>
/// Get the relevant GridId and MapIndices for this entity for lookup.
/// Get the relevant GridId and Vector2i for this entity for lookup.
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
private Dictionary<GridId, List<MapIndices>> GetEntityIndices(IEntity entity)
private Dictionary<GridId, List<Vector2i>> GetEntityIndices(IEntity entity)
{
var entityBounds = GetEntityBox(entity);
var results = new Dictionary<GridId, List<MapIndices>>();
var results = new Dictionary<GridId, List<Vector2i>>();
foreach (var grid in _mapManager.FindGridsIntersecting(entity.Transform.MapID, GetEntityBox(entity)))
{
var indices = new List<MapIndices>();
var indices = new List<Vector2i>();
foreach (var tile in grid.GetTilesIntersecting(entityBounds))
{
@@ -248,7 +248,7 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
private void HandleGridCreated(GridId gridId)
{
_graph[gridId] = new Dictionary<MapIndices, GridTileLookupChunk>();
_graph[gridId] = new Dictionary<Vector2i, GridTileLookupChunk>();
}
private void HandleGridRemoval(GridId gridId)
@@ -282,14 +282,14 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
}
var entityNodes = GetOrCreateNodes(entity);
var newIndices = new Dictionary<GridId, List<MapIndices>>();
var newIndices = new Dictionary<GridId, List<Vector2i>>();
foreach (var node in entityNodes)
{
node.AddEntity(entity);
if (!newIndices.TryGetValue(node.ParentChunk.GridId, out var existing))
{
existing = new List<MapIndices>();
existing = new List<Vector2i>();
newIndices[node.ParentChunk.GridId] = existing;
}
@@ -364,12 +364,12 @@ namespace Robust.Server.GameObjects.EntitySystems.TileLookup
node.AddEntity(moveEvent.Sender);
}
var newIndices = new Dictionary<GridId, List<MapIndices>>();
var newIndices = new Dictionary<GridId, List<Vector2i>>();
foreach (var node in newNodes)
{
if (!newIndices.TryGetValue(node.ParentChunk.GridId, out var existing))
{
existing = new List<MapIndices>();
existing = new List<Vector2i>();
newIndices[node.ParentChunk.GridId] = existing;
}

View File

@@ -7,6 +7,7 @@ namespace Robust.Shared.Maths
[JsonObject(MemberSerialization.Fields)]
[Serializable]
[StructLayout(LayoutKind.Sequential)]
// ReSharper disable once InconsistentNaming
public readonly struct Vector2i : IEquatable<Vector2i>
{
public static readonly Vector2i Zero = (0, 0);
@@ -61,7 +62,7 @@ namespace Robust.Shared.Maths
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is Vector2i && Equals((Vector2i) obj);
return obj is Vector2i vector && Equals(vector);
}
/// <summary>
@@ -131,6 +132,16 @@ namespace Robust.Shared.Maths
return new Vector2(a.X / scale, a.Y / scale);
}
public static bool operator ==(Vector2i a, Vector2i b)
{
return a.Equals(b);
}
public static bool operator !=(Vector2i a, Vector2i b)
{
return !a.Equals(b);
}
public void Deconstruct(out int x, out int y)
{
x = X;

View File

@@ -26,7 +26,7 @@ namespace Robust.Shared.GameObjects.Components.Transform
public event Action? OnPositionChanged;
private GridId _lastGrid;
public MapIndices Position { get; private set; }
public Vector2i Position { get; private set; }
public SnapGridOffset Offset => _offset;
/// <inheritdoc />
@@ -93,26 +93,26 @@ namespace Robust.Shared.GameObjects.Components.Transform
return grid;
}
MapIndices SnapGridPosAt(Direction dir, int dist = 1)
Vector2i SnapGridPosAt(Direction dir, int dist = 1)
{
switch (dir)
{
case Direction.East:
return Position + new MapIndices(dist, 0);
return Position + new Vector2i(dist, 0);
case Direction.SouthEast:
return Position + new MapIndices(dist, -dist);
return Position + new Vector2i(dist, -dist);
case Direction.South:
return Position + new MapIndices(0, -dist);
return Position + new Vector2i(0, -dist);
case Direction.SouthWest:
return Position + new MapIndices(-dist, -dist);
return Position + new Vector2i(-dist, -dist);
case Direction.West:
return Position + new MapIndices(-dist, 0);
return Position + new Vector2i(-dist, 0);
case Direction.NorthWest:
return Position + new MapIndices(-dist, dist);
return Position + new Vector2i(-dist, dist);
case Direction.North:
return Position + new MapIndices(0, dist);
return Position + new Vector2i(0, dist);
case Direction.NorthEast:
return Position + new MapIndices(dist, dist);
return Position + new Vector2i(dist, dist);
default:
throw new NotImplementedException();
}
@@ -123,13 +123,13 @@ namespace Robust.Shared.GameObjects.Components.Transform
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
foreach (var cell in grid.GetSnapGridCell(Position, Offset))
yield return cell;
foreach (var cell in grid.GetSnapGridCell(Position + new MapIndices(0, 1), Offset))
foreach (var cell in grid.GetSnapGridCell(Position + new Vector2i(0, 1), Offset))
yield return cell;
foreach (var cell in grid.GetSnapGridCell(Position + new MapIndices(0, -1), Offset))
foreach (var cell in grid.GetSnapGridCell(Position + new Vector2i(0, -1), Offset))
yield return cell;
foreach (var cell in grid.GetSnapGridCell(Position + new MapIndices(1, 0), Offset))
foreach (var cell in grid.GetSnapGridCell(Position + new Vector2i(1, 0), Offset))
yield return cell;
foreach (var cell in grid.GetSnapGridCell(Position + new MapIndices(-1, 0), Offset))
foreach (var cell in grid.GetSnapGridCell(Position + new Vector2i(-1, 0), Offset))
yield return cell;
}
@@ -139,7 +139,7 @@ namespace Robust.Shared.GameObjects.Components.Transform
for (var y = -n; y <= n; ++y)
for (var x = -n; x <= n; ++x)
{
foreach (var cell in grid.GetSnapGridCell(Position + new MapIndices(x, y), Offset))
foreach (var cell in grid.GetSnapGridCell(Position + new Vector2i(x, y), Offset))
yield return cell;
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
namespace Robust.Shared.GameStates
@@ -55,14 +56,14 @@ namespace Robust.Shared.GameStates
[Serializable, NetSerializable]
public struct ChunkDatum
{
public readonly MapIndices Index;
public readonly Vector2i Index;
// Definitely wasteful to send EVERY tile.
// Optimize away future coder.
// Also it's stored row-major.
public readonly Tile[] TileData;
public ChunkDatum(MapIndices index, Tile[] tileData)
public ChunkDatum(Vector2i index, Tile[] tileData)
{
Index = index;
TileData = tileData;

View File

@@ -363,15 +363,15 @@ namespace Robust.Shared.Map
}
/// <summary>
/// Converts this set of coordinates to MapIndices.
/// Converts this set of coordinates to Vector2i.
/// </summary>
/// <param name="entityManager"></param>
/// <param name="mapManager"></param>
/// <returns></returns>
public MapIndices ToMapIndices(IEntityManager entityManager, IMapManager mapManager)
public Vector2i ToVector2i(IEntityManager entityManager, IMapManager mapManager)
{
if(!IsValid(entityManager))
return new MapIndices();
return new Vector2i();
var gridId = GetGridId(entityManager);
@@ -382,7 +382,7 @@ namespace Robust.Shared.Map
var (x, y) = ToMapPos(entityManager);
return new MapIndices((int) x, (int) y);
return new Vector2i((int) x, (int) y);
}
/// <summary>

View File

@@ -28,7 +28,7 @@ namespace Robust.Shared.Map
/// <summary>
/// The positional indices of this chunk in the <see cref="IMapGrid"/>.
/// </summary>
MapIndices Indices { get; }
Vector2i Indices { get; }
/// <summary>
/// Returns the tile at the given indices.
@@ -43,7 +43,7 @@ namespace Robust.Shared.Map
/// </summary>
/// <param name="indices">The tile indices relative to the chunk origin.</param>
/// <returns>A reference to a tile.</returns>
TileRef GetTileRef(MapIndices indices);
TileRef GetTileRef(Vector2i indices);
Tile GetTile(ushort xIndex, ushort yIndex);
@@ -68,14 +68,14 @@ namespace Robust.Shared.Map
/// </summary>
/// <param name="gridTile">Tile indices relative to the grid.</param>
/// <returns>Tile indices relative to this chunk.</returns>
MapIndices GridTileToChunkTile(MapIndices gridTile);
Vector2i GridTileToChunkTile(Vector2i gridTile);
/// <summary>
/// Translates chunk tile indices to grid tile indices.
/// </summary>
/// <param name="chunkTile">The indices relative to the chunk origin.</param>
/// <returns>The indices relative to the grid origin.</returns>
MapIndices ChunkTileToGridTile(MapIndices chunkTile);
Vector2i ChunkTileToGridTile(Vector2i chunkTile);
IEnumerable<SnapGridComponent> GetSnapGridCell(ushort xCell, ushort yCell, SnapGridOffset offset);
@@ -90,6 +90,6 @@ namespace Robust.Shared.Map
/// Tests if a point is on top of a non-empty tile.
/// </summary>
/// <param name="localIndices">Local tile indices</param>
bool CollidesWithChunk(MapIndices localIndices);
bool CollidesWithChunk(Vector2i localIndices);
}
}

View File

@@ -85,7 +85,7 @@ namespace Robust.Shared.Map
/// </summary>
/// <param name="tileCoordinates">The location of the tile in coordinates.</param>
/// <returns>The tile at the tile coordinates.</returns>
TileRef GetTileRef(MapIndices tileCoordinates);
TileRef GetTileRef(Vector2i tileCoordinates);
/// <summary>
/// Returns all tiles in the grid, in row-major order [xTileIndex, yTileIndex].
@@ -105,7 +105,7 @@ namespace Robust.Shared.Map
/// </summary>
/// <param name="gridIndices"></param>
/// <param name="tile">The tile to insert at the coordinates.</param>
void SetTile(MapIndices gridIndices, Tile tile);
void SetTile(Vector2i gridIndices, Tile tile);
/// <summary>
/// Returns all tiles inside the area that match the predicate.
@@ -123,15 +123,15 @@ namespace Robust.Shared.Map
#region SnapGridAccess
IEnumerable<SnapGridComponent> GetSnapGridCell(EntityCoordinates coords, SnapGridOffset offset);
IEnumerable<SnapGridComponent> GetSnapGridCell(MapIndices pos, SnapGridOffset offset);
IEnumerable<SnapGridComponent> GetSnapGridCell(Vector2i pos, SnapGridOffset offset);
MapIndices SnapGridCellFor(EntityCoordinates coords, SnapGridOffset offset);
MapIndices SnapGridCellFor(MapCoordinates worldPos, SnapGridOffset offset);
MapIndices SnapGridCellFor(Vector2 localPos, SnapGridOffset offset);
Vector2i SnapGridCellFor(EntityCoordinates coords, SnapGridOffset offset);
Vector2i SnapGridCellFor(MapCoordinates worldPos, SnapGridOffset offset);
Vector2i SnapGridCellFor(Vector2 localPos, SnapGridOffset offset);
void AddToSnapGridCell(MapIndices pos, SnapGridOffset offset, SnapGridComponent snap);
void AddToSnapGridCell(Vector2i pos, SnapGridOffset offset, SnapGridComponent snap);
void AddToSnapGridCell(EntityCoordinates coords, SnapGridOffset offset, SnapGridComponent snap);
void RemoveFromSnapGridCell(MapIndices pos, SnapGridOffset offset, SnapGridComponent snap);
void RemoveFromSnapGridCell(Vector2i pos, SnapGridOffset offset, SnapGridComponent snap);
void RemoveFromSnapGridCell(EntityCoordinates coords, SnapGridOffset offset, SnapGridComponent snap);
#endregion SnapGridAccess
@@ -143,7 +143,7 @@ namespace Robust.Shared.Map
/// </summary>
/// <param name="coords"></param>
/// <returns></returns>
MapIndices CoordinatesToTile(EntityCoordinates coords);
Vector2i CoordinatesToTile(EntityCoordinates coords);
/// <summary>
/// Transforms world-space coordinates from the global origin to the grid local origin.
@@ -169,7 +169,7 @@ namespace Robust.Shared.Map
/// </summary>
/// <param name="posWorld">Position in the world.</param>
/// <returns>Indices of a tile on the grid.</returns>
MapIndices WorldToTile(Vector2 posWorld);
Vector2i WorldToTile(Vector2 posWorld);
/// <summary>
/// Transforms grid-space tile indices to local coordinates.
@@ -177,19 +177,19 @@ namespace Robust.Shared.Map
/// </summary>
/// <param name="gridTile"></param>
/// <returns></returns>
EntityCoordinates GridTileToLocal(MapIndices gridTile);
EntityCoordinates GridTileToLocal(Vector2i gridTile);
/// <summary>
/// Transforms grid-space tile indices to map coordinate position.
/// The resulting coordinates are centered on the tile.
/// </summary>
Vector2 GridTileToWorldPos(MapIndices gridTile);
Vector2 GridTileToWorldPos(Vector2i gridTile);
/// <summary>
/// Transforms grid-space tile indices to map coordinates.
/// The resulting coordinates are centered on the tile.
/// </summary>
MapCoordinates GridTileToWorld(MapIndices gridTile);
MapCoordinates GridTileToWorld(Vector2i gridTile);
/// <summary>
/// Transforms grid indices into a tile reference, returns false if no tile is found.
@@ -197,12 +197,12 @@ namespace Robust.Shared.Map
/// <param name="indices">The Grid Tile indices.</param>
/// <param name="tile"></param>
/// <returns></returns>
bool TryGetTileRef(MapIndices indices, out TileRef tile);
bool TryGetTileRef(Vector2i indices, out TileRef tile);
/// <summary>
/// Transforms grid indices into a tile reference, returns false if no tile is found.
/// Transforms coordinates into a tile reference, returns false if no tile is found.
/// </summary>
/// <param name="indices">The Grid Tile indices.</param>
/// <param name="coords">The coordinates.</param>
/// <param name="tile"></param>
/// <returns></returns>
bool TryGetTileRef(EntityCoordinates coords, out TileRef tile);
@@ -210,18 +210,18 @@ namespace Robust.Shared.Map
/// <summary>
/// Transforms grid tile indices to chunk indices.
/// </summary>
MapIndices GridTileToChunkIndices(MapIndices gridTile);
Vector2i GridTileToChunkIndices(Vector2i gridTile);
/// <summary>
/// Transforms local grid coordinates to chunk indices.
/// </summary>
MapIndices LocalToChunkIndices(EntityCoordinates gridPos);
Vector2i LocalToChunkIndices(EntityCoordinates gridPos);
#endregion Transforms
#region Collision
bool CollidesWithGrid(MapIndices indices);
bool CollidesWithGrid(Vector2i indices);
#endregion
}

View File

@@ -34,12 +34,12 @@ namespace Robust.Shared.Map
/// </summary>
/// <param name="chunkIndices">The indices of the chunk in this grid.</param>
/// <returns>The existing or new chunk.</returns>
IMapChunkInternal GetChunk(MapIndices chunkIndices);
IMapChunkInternal GetChunk(Vector2i chunkIndices);
/// <summary>
/// Returns all chunks in this grid. This will not generate new chunks.
/// </summary>
/// <returns>All chunks in the grid.</returns>
IReadOnlyDictionary<MapIndices, IMapChunkInternal> GetMapChunks();
IReadOnlyDictionary<Vector2i, IMapChunkInternal> GetMapChunks();
}
}

View File

@@ -11,7 +11,7 @@ namespace Robust.Shared.Map
internal class MapChunk : IMapChunkInternal
{
private readonly IMapGridInternal _grid;
private readonly MapIndices _gridIndices;
private readonly Vector2i _gridIndices;
private readonly Tile[,] _tiles;
private readonly SnapGridCell[,] _snapGrid;
@@ -35,7 +35,7 @@ namespace Robust.Shared.Map
{
_grid = grid;
LastModifiedTick = grid.CurTick;
_gridIndices = new MapIndices(x, y);
_gridIndices = new Vector2i(x, y);
ChunkSize = chunkSize;
_tiles = new Tile[ChunkSize, ChunkSize];
@@ -53,7 +53,7 @@ namespace Robust.Shared.Map
public int Y => _gridIndices.Y;
/// <inheritdoc />
public MapIndices Indices => _gridIndices;
public Vector2i Indices => _gridIndices;
/// <inheritdoc />
public TileRef GetTileRef(ushort xIndex, ushort yIndex)
@@ -64,12 +64,12 @@ namespace Robust.Shared.Map
if (yIndex >= ChunkSize)
throw new ArgumentOutOfRangeException(nameof(yIndex), "Tile indices out of bounds.");
var indices = ChunkTileToGridTile(new MapIndices(xIndex, yIndex));
var indices = ChunkTileToGridTile(new Vector2i(xIndex, yIndex));
return new TileRef(_grid.ParentMapId, _grid.Index, indices, _tiles[xIndex, yIndex]);
}
/// <inheritdoc />
public TileRef GetTileRef(MapIndices indices)
public TileRef GetTileRef(Vector2i indices)
{
if (indices.X >= ChunkSize || indices.X < 0 || indices.Y >= ChunkSize || indices.Y < 0)
throw new ArgumentOutOfRangeException(nameof(indices), "Tile indices out of bounds.");
@@ -100,7 +100,7 @@ namespace Robust.Shared.Map
if (ignoreEmpty && _tiles[x, y].IsEmpty)
continue;
var indices = ChunkTileToGridTile(new MapIndices(x, y));
var indices = ChunkTileToGridTile(new Vector2i(x, y));
yield return new TileRef(_grid.ParentMapId, _grid.Index, indices.X, indices.Y, _tiles[x, y]);
}
}
@@ -119,7 +119,7 @@ namespace Robust.Shared.Map
if (_tiles[xIndex, yIndex].TypeId == tile.TypeId)
return;
var gridTile = ChunkTileToGridTile(new MapIndices(xIndex, yIndex));
var gridTile = ChunkTileToGridTile(new Vector2i(xIndex, yIndex));
var newTileRef = new TileRef(_grid.ParentMapId, _grid.Index, gridTile, tile);
var oldTile = _tiles[xIndex, yIndex];
LastModifiedTick = _grid.CurTick;
@@ -147,7 +147,7 @@ namespace Robust.Shared.Map
if (_tiles[x, y].IsEmpty)
continue;
var gridTile = ChunkTileToGridTile(new MapIndices(x, y));
var gridTile = ChunkTileToGridTile(new Vector2i(x, y));
yield return new TileRef(_grid.ParentMapId, _grid.Index, gridTile.X, gridTile.Y, _tiles[x, y]);
}
}
@@ -159,16 +159,16 @@ namespace Robust.Shared.Map
}
/// <inheritdoc />
public MapIndices GridTileToChunkTile(MapIndices gridTile)
public Vector2i GridTileToChunkTile(Vector2i gridTile)
{
var size = ChunkSize;
var x = MathHelper.Mod(gridTile.X, size);
var y = MathHelper.Mod(gridTile.Y, size);
return new MapIndices(x, y);
return new Vector2i(x, y);
}
/// <inheritdoc />
public MapIndices ChunkTileToGridTile(MapIndices chunkTile)
public Vector2i ChunkTileToGridTile(Vector2i chunkTile)
{
return chunkTile + _gridIndices * ChunkSize;
}
@@ -271,7 +271,7 @@ namespace Robust.Shared.Map
}
/// <inheritdoc />
public bool CollidesWithChunk(MapIndices localIndices)
public bool CollidesWithChunk(Vector2i localIndices)
{
return _tiles[localIndices.X, localIndices.Y].TypeId != Tile.Empty.TypeId;
}

View File

@@ -59,7 +59,7 @@ namespace Robust.Shared.Map
/// <summary>
/// Grid chunks than make up this grid.
/// </summary>
private readonly Dictionary<MapIndices, IMapChunkInternal> _chunks = new Dictionary<MapIndices, IMapChunkInternal>();
private readonly Dictionary<Vector2i, IMapChunkInternal> _chunks = new Dictionary<Vector2i, IMapChunkInternal>();
private readonly IMapManagerInternal _mapManager;
private readonly IEntityManager _entityManager;
@@ -202,7 +202,7 @@ namespace Robust.Shared.Map
}
/// <inheritdoc />
public TileRef GetTileRef(MapIndices tileCoordinates)
public TileRef GetTileRef(Vector2i tileCoordinates)
{
var chunkIndices = GridTileToChunkIndices(tileCoordinates);
@@ -233,11 +233,11 @@ namespace Robust.Shared.Map
public void SetTile(EntityCoordinates coords, Tile tile)
{
var localTile = CoordinatesToTile(coords);
SetTile(new MapIndices(localTile.X, localTile.Y), tile);
SetTile(new Vector2i(localTile.X, localTile.Y), tile);
}
/// <inheritdoc />
public void SetTile(MapIndices gridIndices, Tile tile)
public void SetTile(Vector2i gridIndices, Tile tile)
{
var (chunk, chunkTile) = ChunkAndOffsetForTile(gridIndices);
chunk.SetTile((ushort)chunkTile.X, (ushort)chunkTile.Y, tile);
@@ -247,8 +247,8 @@ namespace Robust.Shared.Map
public IEnumerable<TileRef> GetTilesIntersecting(Box2 worldArea, bool ignoreEmpty = true, Predicate<TileRef>? predicate = null)
{
var localArea = new Box2(WorldToLocal(worldArea.BottomLeft), WorldToLocal(worldArea.TopRight));
var gridTileLb = new MapIndices((int)Math.Floor(localArea.Left), (int)Math.Floor(localArea.Bottom));
var gridTileRt = new MapIndices((int)Math.Floor(localArea.Right), (int)Math.Floor(localArea.Top));
var gridTileLb = new Vector2i((int)Math.Floor(localArea.Left), (int)Math.Floor(localArea.Bottom));
var gridTileRt = new Vector2i((int)Math.Floor(localArea.Right), (int)Math.Floor(localArea.Top));
var tiles = new List<TileRef>();
@@ -256,11 +256,11 @@ namespace Robust.Shared.Map
{
for (var y = gridTileLb.Y; y <= gridTileRt.Y; y++)
{
var gridChunk = GridTileToChunkIndices(new MapIndices(x, y));
var gridChunk = GridTileToChunkIndices(new Vector2i(x, y));
if (_chunks.TryGetValue(gridChunk, out var chunk))
{
var chunkTile = chunk.GridTileToChunkTile(new MapIndices(x, y));
var chunkTile = chunk.GridTileToChunkTile(new Vector2i(x, y));
var tile = chunk.GetTileRef((ushort)chunkTile.X, (ushort)chunkTile.Y);
if (ignoreEmpty && tile.Tile.IsEmpty)
@@ -334,11 +334,11 @@ namespace Robust.Shared.Map
/// <inheritdoc />
public IMapChunkInternal GetChunk(int xIndex, int yIndex)
{
return GetChunk(new MapIndices(xIndex, yIndex));
return GetChunk(new Vector2i(xIndex, yIndex));
}
/// <inheritdoc />
public IMapChunkInternal GetChunk(MapIndices chunkIndices)
public IMapChunkInternal GetChunk(Vector2i chunkIndices)
{
if (_chunks.TryGetValue(chunkIndices, out var output))
return output;
@@ -347,7 +347,7 @@ namespace Robust.Shared.Map
}
/// <inheritdoc />
public IReadOnlyDictionary<MapIndices, IMapChunkInternal> GetMapChunks()
public IReadOnlyDictionary<Vector2i, IMapChunkInternal> GetMapChunks()
{
return _chunks;
}
@@ -363,14 +363,14 @@ namespace Robust.Shared.Map
}
/// <inheritdoc />
public IEnumerable<SnapGridComponent> GetSnapGridCell(MapIndices pos, SnapGridOffset offset)
public IEnumerable<SnapGridComponent> GetSnapGridCell(Vector2i pos, SnapGridOffset offset)
{
var (chunk, chunkTile) = ChunkAndOffsetForTile(pos);
return chunk.GetSnapGridCell((ushort)chunkTile.X, (ushort)chunkTile.Y, offset);
}
/// <inheritdoc />
public MapIndices SnapGridCellFor(EntityCoordinates coords, SnapGridOffset offset)
public Vector2i SnapGridCellFor(EntityCoordinates coords, SnapGridOffset offset)
{
DebugTools.Assert(ParentMapId == _mapManager.GetGrid(coords.GetGridId(_entityManager)).ParentMapId);
@@ -379,7 +379,7 @@ namespace Robust.Shared.Map
}
/// <inheritdoc />
public MapIndices SnapGridCellFor(MapCoordinates worldPos, SnapGridOffset offset)
public Vector2i SnapGridCellFor(MapCoordinates worldPos, SnapGridOffset offset)
{
DebugTools.Assert(ParentMapId == worldPos.MapId);
@@ -388,7 +388,7 @@ namespace Robust.Shared.Map
}
/// <inheritdoc />
public MapIndices SnapGridCellFor(Vector2 localPos, SnapGridOffset offset)
public Vector2i SnapGridCellFor(Vector2 localPos, SnapGridOffset offset)
{
if (offset == SnapGridOffset.Edge)
{
@@ -396,11 +396,11 @@ namespace Robust.Shared.Map
}
var x = (int)Math.Floor(localPos.X / TileSize);
var y = (int)Math.Floor(localPos.Y / TileSize);
return new MapIndices(x, y);
return new Vector2i(x, y);
}
/// <inheritdoc />
public void AddToSnapGridCell(MapIndices pos, SnapGridOffset offset, SnapGridComponent snap)
public void AddToSnapGridCell(Vector2i pos, SnapGridOffset offset, SnapGridComponent snap)
{
var (chunk, chunkTile) = ChunkAndOffsetForTile(pos);
chunk.AddToSnapGridCell((ushort)chunkTile.X, (ushort)chunkTile.Y, offset, snap);
@@ -413,7 +413,7 @@ namespace Robust.Shared.Map
}
/// <inheritdoc />
public void RemoveFromSnapGridCell(MapIndices pos, SnapGridOffset offset, SnapGridComponent snap)
public void RemoveFromSnapGridCell(Vector2i pos, SnapGridOffset offset, SnapGridComponent snap)
{
var (chunk, chunkTile) = ChunkAndOffsetForTile(pos);
chunk.RemoveFromSnapGridCell((ushort)chunkTile.X, (ushort)chunkTile.Y, offset, snap);
@@ -425,7 +425,7 @@ namespace Robust.Shared.Map
RemoveFromSnapGridCell(SnapGridCellFor(coords, offset), offset, snap);
}
private (IMapChunk, MapIndices) ChunkAndOffsetForTile(MapIndices pos)
private (IMapChunk, Vector2i) ChunkAndOffsetForTile(Vector2i pos)
{
var gridChunkIndices = GridTileToChunkIndices(pos);
var chunk = GetChunk(gridChunkIndices);
@@ -463,37 +463,37 @@ namespace Robust.Shared.Map
return posLocal + WorldPosition;
}
public MapIndices WorldToTile(Vector2 posWorld)
public Vector2i WorldToTile(Vector2 posWorld)
{
var local = WorldToLocal(posWorld);
var x = (int)Math.Floor(local.X / TileSize);
var y = (int)Math.Floor(local.Y / TileSize);
return new MapIndices(x, y);
return new Vector2i(x, y);
}
/// <summary>
/// Transforms entity coordinates to tile indices relative to grid origin.
/// </summary>
public MapIndices CoordinatesToTile(EntityCoordinates coords)
public Vector2i CoordinatesToTile(EntityCoordinates coords)
{
var local = WorldToLocal(coords.ToMapPos(_entityManager));
var x = (int)Math.Floor(local.X / TileSize);
var y = (int)Math.Floor(local.Y / TileSize);
return new MapIndices(x, y);
return new Vector2i(x, y);
}
/// <summary>
/// Transforms global world coordinates to chunk indices relative to grid origin.
/// </summary>
public MapIndices LocalToChunkIndices(EntityCoordinates gridPos)
public Vector2i LocalToChunkIndices(EntityCoordinates gridPos)
{
var local = WorldToLocal(gridPos.ToMapPos(_entityManager));
var x = (int)Math.Floor(local.X / (TileSize * ChunkSize));
var y = (int)Math.Floor(local.Y / (TileSize * ChunkSize));
return new MapIndices(x, y);
return new Vector2i(x, y);
}
public bool CollidesWithGrid(MapIndices indices)
public bool CollidesWithGrid(Vector2i indices)
{
var chunkIndices = GridTileToChunkIndices(indices);
if (!_chunks.TryGetValue(chunkIndices, out var chunk))
@@ -509,21 +509,21 @@ namespace Robust.Shared.Map
}
/// <inheritdoc />
public MapIndices GridTileToChunkIndices(MapIndices gridTile)
public Vector2i GridTileToChunkIndices(Vector2i gridTile)
{
var x = (int)Math.Floor(gridTile.X / (float)ChunkSize);
var y = (int)Math.Floor(gridTile.Y / (float)ChunkSize);
return new MapIndices(x, y);
return new Vector2i(x, y);
}
/// <inheritdoc />
public EntityCoordinates GridTileToLocal(MapIndices gridTile)
public EntityCoordinates GridTileToLocal(Vector2i gridTile)
{
return new EntityCoordinates(GridEntityId, (gridTile.X * TileSize + (TileSize / 2f), gridTile.Y * TileSize + (TileSize / 2f)));
}
public Vector2 GridTileToWorldPos(MapIndices gridTile)
public Vector2 GridTileToWorldPos(Vector2i gridTile)
{
var locX = gridTile.X * TileSize + (TileSize / 2f);
var locY = gridTile.Y * TileSize + (TileSize / 2f);
@@ -531,13 +531,13 @@ namespace Robust.Shared.Map
return new Vector2(locX, locY) + WorldPosition;
}
public MapCoordinates GridTileToWorld(MapIndices gridTile)
public MapCoordinates GridTileToWorld(Vector2i gridTile)
{
return new MapCoordinates(GridTileToWorldPos(gridTile), ParentMapId);
}
/// <inheritdoc />
public bool TryGetTileRef(MapIndices indices, out TileRef tile)
public bool TryGetTileRef(Vector2i indices, out TileRef tile)
{
var chunkIndices = GridTileToChunkIndices(indices);
if (!_chunks.TryGetValue(chunkIndices, out var chunk))

View File

@@ -7,6 +7,7 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -152,7 +153,7 @@ namespace Robust.Shared.Map
grid.WorldPosition = gridDatum.Coordinates.Position;
var modified = new List<(MapIndices position, Tile tile)>();
var modified = new List<(Vector2i position, Tile tile)>();
foreach (var chunkData in gridDatum.ChunkData)
{
var chunk = grid.GetChunk(chunkData.Index);
@@ -168,7 +169,7 @@ namespace Robust.Shared.Map
if (chunk.GetTileRef(x, y).Tile != tile)
{
chunk.SetTile(x, y, tile);
modified.Add((new MapIndices(chunk.X * grid.ChunkSize + x, chunk.Y * grid.ChunkSize + y), tile));
modified.Add((new Vector2i(chunk.X * grid.ChunkSize + x, chunk.Y * grid.ChunkSize + y), tile));
}
}
}

View File

@@ -645,12 +645,12 @@ namespace Robust.Shared.Map
/// </summary>
public IMapGrid Grid { get; }
public IReadOnlyCollection<(MapIndices position, Tile tile)> Modified { get; }
public IReadOnlyCollection<(Vector2i position, Tile tile)> Modified { get; }
/// <summary>
/// Creates a new instance of this class.
/// </summary>
public GridChangedEventArgs(IMapGrid grid, IReadOnlyCollection<(MapIndices position, Tile tile)> modified)
public GridChangedEventArgs(IMapGrid grid, IReadOnlyCollection<(Vector2i position, Tile tile)> modified)
{
Grid = grid;
Modified = modified;

View File

@@ -1,5 +1,6 @@
using System;
using JetBrains.Annotations;
using Robust.Shared.Maths;
namespace Robust.Shared.Map
{
@@ -22,7 +23,7 @@ namespace Robust.Shared.Map
/// <summary>
/// Positional indices of this tile on the grid.
/// </summary>
public readonly MapIndices GridIndices;
public readonly Vector2i GridIndices;
/// <summary>
/// Actual data of this Tile.
@@ -38,7 +39,7 @@ namespace Robust.Shared.Map
/// <param name="yIndex">Positional Y index of this tile on the grid.</param>
/// <param name="tile">Actual data of this tile.</param>
internal TileRef(MapId mapId, GridId gridId, int xIndex, int yIndex, Tile tile)
: this(mapId, gridId, new MapIndices(xIndex, yIndex), tile) { }
: this(mapId, gridId, new Vector2i(xIndex, yIndex), tile) { }
/// <summary>
/// Constructs a new instance of TileRef.
@@ -47,7 +48,7 @@ namespace Robust.Shared.Map
/// <param name="gridId">Identifier of the grid this tile belongs to.</param>
/// <param name="gridIndices">Positional indices of this tile on the grid.</param>
/// <param name="tile">Actual data of this tile.</param>
internal TileRef(MapId mapId, GridId gridId, MapIndices gridIndices, Tile tile)
internal TileRef(MapId mapId, GridId gridId, Vector2i gridIndices, Tile tile)
{
MapIndex = mapId;
GridIndex = gridId;

View File

@@ -29,7 +29,7 @@ namespace Robust.UnitTesting.Shared.Map
Assert.That(chunk.X, Is.EqualTo(7));
Assert.That(chunk.Y, Is.EqualTo(9));
Assert.That(chunk.Indices, Is.EqualTo(new MapIndices(7,9)));
Assert.That(chunk.Indices, Is.EqualTo(new Vector2i(7,9)));
}
[Test]
@@ -107,7 +107,7 @@ namespace Robust.UnitTesting.Shared.Map
var chunk = MapChunkFactory(7, 9);
chunk.SetTile(3, 5, new Tile(1, 3));
var result = chunk.GetTileRef(new MapIndices(3, 5));
var result = chunk.GetTileRef(new Vector2i(3, 5));
Assert.That(result.X, Is.EqualTo(8 * 7 + 3));
Assert.That(result.Y, Is.EqualTo(8 * 9 + 5));
@@ -124,8 +124,8 @@ namespace Robust.UnitTesting.Shared.Map
Assert.Throws<ArgumentOutOfRangeException>((() => chunk.GetTileRef(8, 0)));
Assert.Throws<ArgumentOutOfRangeException>((() => chunk.GetTileRef(0, 8)));
Assert.Throws<ArgumentOutOfRangeException>((() => chunk.GetTileRef(new MapIndices(8,0))));
Assert.Throws<ArgumentOutOfRangeException>((() => chunk.GetTileRef(new MapIndices(0, 8))));
Assert.Throws<ArgumentOutOfRangeException>((() => chunk.GetTileRef(new Vector2i(8,0))));
Assert.Throws<ArgumentOutOfRangeException>((() => chunk.GetTileRef(new Vector2i(0, 8))));
}
[Test]
@@ -164,13 +164,13 @@ namespace Robust.UnitTesting.Shared.Map
Assert.That(tiles[0],
Is.EqualTo(new TileRef(new MapId(11),
new GridId(13),
new MapIndices(8 * 7 + 3, 8 * 9 + 5),
new Vector2i(8 * 7 + 3, 8 * 9 + 5),
new Tile(1, 3))));
Assert.That(tiles[1],
Is.EqualTo(new TileRef(new MapId(11),
new GridId(13),
new MapIndices(8 * 7 + 5, 8 * 9 + 4),
new Vector2i(8 * 7 + 5, 8 * 9 + 4),
new Tile(5, 7))));
}
@@ -189,13 +189,13 @@ namespace Robust.UnitTesting.Shared.Map
Assert.That(tiles[8*3+5],
Is.EqualTo(new TileRef(new MapId(11),
new GridId(13),
new MapIndices(8 * 7 + 3, 8 * 9 + 5),
new Vector2i(8 * 7 + 3, 8 * 9 + 5),
new Tile(1, 3))));
Assert.That(tiles[8*5+4],
Is.EqualTo(new TileRef(new MapId(11),
new GridId(13),
new MapIndices(8 * 7 + 5, 8 * 9 + 4),
new Vector2i(8 * 7 + 5, 8 * 9 + 4),
new Tile(5, 7))));
}
@@ -249,13 +249,13 @@ namespace Robust.UnitTesting.Shared.Map
Assert.That(tiles[0],
Is.EqualTo(new TileRef(new MapId(11),
new GridId(13),
new MapIndices(8 * 7 + 3, 8 * 9 + 5),
new Vector2i(8 * 7 + 3, 8 * 9 + 5),
new Tile(1, 3))));
Assert.That(tiles[1],
Is.EqualTo(new TileRef(new MapId(11),
new GridId(13),
new MapIndices(8 * 7 + 5, 8 * 9 + 4),
new Vector2i(8 * 7 + 5, 8 * 9 + 4),
new Tile(5, 7))));
}
@@ -267,12 +267,12 @@ namespace Robust.UnitTesting.Shared.Map
// 8x8 chunk (-1,-1) occupies tiles -8 to -1 on each axis
var chunk = MapChunkFactory(-1, -1);
var indices = chunk.GridTileToChunkTile(new MapIndices(-3, -5));
var indices = chunk.GridTileToChunkTile(new Vector2i(-3, -5));
// drawing this out helps a ton
// grid tile -1,-1 is chunk tile 7,7
// grid tile -8,-8 is chunk tile 0,0
Assert.That(indices, Is.EqualTo(new MapIndices(5, 3)));
Assert.That(indices, Is.EqualTo(new Vector2i(5, 3)));
}
[Test]
@@ -449,7 +449,7 @@ namespace Robust.UnitTesting.Shared.Map
var chunk = MapChunkFactory(7, 9);
chunk.SetTile(3, 5, new Tile(1));
var result = chunk.CollidesWithChunk(new MapIndices(3, 5));
var result = chunk.CollidesWithChunk(new Vector2i(3, 5));
Assert.That(result, Is.True);
}
@@ -460,7 +460,7 @@ namespace Robust.UnitTesting.Shared.Map
var chunk = MapChunkFactory(7, 9);
chunk.SetTile(3, 5, new Tile(1));
var result = chunk.CollidesWithChunk(new MapIndices(3, 6));
var result = chunk.CollidesWithChunk(new Vector2i(3, 6));
Assert.That(result, Is.False);
}

View File

@@ -34,13 +34,13 @@ namespace Robust.UnitTesting.Shared.Map
public void GetTileRefCoords()
{
var grid = MapGridFactory(new GridId(1));
grid.SetTile(new MapIndices(-9, -1), new Tile(1, 2));
grid.SetTile(new Vector2i(-9, -1), new Tile(1, 2));
var result = grid.GetTileRef(new MapIndices(-9, -1));
var result = grid.GetTileRef(new Vector2i(-9, -1));
Assert.That(grid.ChunkCount, Is.EqualTo(1));
Assert.That(grid.GetMapChunks().Keys.ToList()[0], Is.EqualTo(new MapIndices(-2, -1)));
Assert.That(result, Is.EqualTo(new TileRef(new MapId(5), new GridId(1), new MapIndices(-9,-1), new Tile(1, 2))));
Assert.That(grid.GetMapChunks().Keys.ToList()[0], Is.EqualTo(new Vector2i(-2, -1)));
Assert.That(result, Is.EqualTo(new TileRef(new MapId(5), new GridId(1), new Vector2i(-9,-1), new Tile(1, 2))));
}
/// <summary>
@@ -51,8 +51,8 @@ namespace Robust.UnitTesting.Shared.Map
{
var grid = MapGridFactory(new GridId(1));
grid.SetTile(new MapIndices(-1, -2), new Tile(1));
grid.SetTile(new MapIndices(1, 2), new Tile(1));
grid.SetTile(new Vector2i(-1, -2), new Tile(1));
grid.SetTile(new Vector2i(1, 2), new Tile(1));
var bounds = grid.WorldBounds;
@@ -71,10 +71,10 @@ namespace Robust.UnitTesting.Shared.Map
{
var grid = MapGridFactory(new GridId(1));
grid.SetTile(new MapIndices(-1, -2), new Tile(1));
grid.SetTile(new MapIndices(1, 2), new Tile(1));
grid.SetTile(new Vector2i(-1, -2), new Tile(1));
grid.SetTile(new Vector2i(1, 2), new Tile(1));
grid.SetTile(new MapIndices(1, 2), Tile.Empty);
grid.SetTile(new Vector2i(1, 2), Tile.Empty);
var bounds = grid.WorldBounds;
@@ -90,9 +90,9 @@ namespace Robust.UnitTesting.Shared.Map
{
var grid = MapGridFactory(new GridId(1));
var result = grid.GridTileToChunkIndices(new MapIndices(-9, -1));
var result = grid.GridTileToChunkIndices(new Vector2i(-9, -1));
Assert.That(result, Is.EqualTo(new MapIndices(-2, -1)));
Assert.That(result, Is.EqualTo(new Vector2i(-2, -1)));
}
/// <summary>
@@ -103,7 +103,7 @@ namespace Robust.UnitTesting.Shared.Map
{
var grid = MapGridFactory(new GridId(1));
var result = grid.GridTileToLocal(new MapIndices(0, 0)).Position;
var result = grid.GridTileToLocal(new Vector2i(0, 0)).Position;
Assert.That(result.X, Is.EqualTo(0.5f));
Assert.That(result.Y, Is.EqualTo(0.5f));
@@ -114,7 +114,7 @@ namespace Robust.UnitTesting.Shared.Map
{
var grid = MapGridFactory(new GridId(1));
var foundTile = grid.TryGetTileRef(new MapIndices(-9, -1), out var tileRef);
var foundTile = grid.TryGetTileRef(new Vector2i(-9, -1), out var tileRef);
Assert.That(foundTile, Is.False);
Assert.That(tileRef, Is.EqualTo(new TileRef()));
@@ -125,23 +125,23 @@ namespace Robust.UnitTesting.Shared.Map
public void TryGetTileRefTileExists()
{
var grid = MapGridFactory(new GridId(1));
grid.SetTile(new MapIndices(-9, -1), new Tile(1, 2));
grid.SetTile(new Vector2i(-9, -1), new Tile(1, 2));
var foundTile = grid.TryGetTileRef(new MapIndices(-9, -1), out var tileRef);
var foundTile = grid.TryGetTileRef(new Vector2i(-9, -1), out var tileRef);
Assert.That(foundTile, Is.True);
Assert.That(grid.ChunkCount, Is.EqualTo(1));
Assert.That(grid.GetMapChunks().Keys.ToList()[0], Is.EqualTo(new MapIndices(-2, -1)));
Assert.That(tileRef, Is.EqualTo(new TileRef(new MapId(5), new GridId(1), new MapIndices(-9, -1), new Tile(1, 2))));
Assert.That(grid.GetMapChunks().Keys.ToList()[0], Is.EqualTo(new Vector2i(-2, -1)));
Assert.That(tileRef, Is.EqualTo(new TileRef(new MapId(5), new GridId(1), new Vector2i(-9, -1), new Tile(1, 2))));
}
[Test]
public void PointCollidesWithGrid()
{
var grid = MapGridFactory(new GridId(1));
grid.SetTile(new MapIndices(19, 23), new Tile(1));
grid.SetTile(new Vector2i(19, 23), new Tile(1));
var result = grid.CollidesWithGrid(new MapIndices(19, 23));
var result = grid.CollidesWithGrid(new Vector2i(19, 23));
Assert.That(result, Is.True);
}
@@ -150,9 +150,9 @@ namespace Robust.UnitTesting.Shared.Map
public void PointNotCollideWithGrid()
{
var grid = MapGridFactory(new GridId(1));
grid.SetTile(new MapIndices(19, 23), new Tile(1));
grid.SetTile(new Vector2i(19, 23), new Tile(1));
var result = grid.CollidesWithGrid(new MapIndices(19, 24));
var result = grid.CollidesWithGrid(new Vector2i(19, 24));
Assert.That(result, Is.False);
}