Remove obsolete GridId and all references to it (#3279)

This commit is contained in:
SpaceManiac
2022-10-08 22:23:40 -07:00
committed by GitHub
parent e222f82059
commit ebaa8d9ac3
55 changed files with 225 additions and 638 deletions

View File

@@ -297,12 +297,11 @@ namespace Robust.Client.Console.Commands
return;
}
string gridId = args[0];
string indices = args[1];
if (!int.TryParse(args[0], out var id))
if (!EntityUid.TryParse(args[0], out var gridUid))
{
shell.WriteError($"{args[0]} is not a valid integer.");
shell.WriteError($"{args[0]} is not a valid entity UID.");
return;
}
@@ -313,14 +312,11 @@ namespace Robust.Client.Console.Commands
}
var mapMan = IoCManager.Resolve<IMapManager>();
if (mapMan.GridExists(new GridId(int.Parse(gridId, CultureInfo.InvariantCulture))))
if (mapMan.TryGetGrid(gridUid, out var grid))
{
foreach (var entity in
mapMan.GetGrid(new GridId(int.Parse(gridId, CultureInfo.InvariantCulture))).GetAnchoredEntities(
new Vector2i(
int.Parse(indices.Split(',')[0], CultureInfo.InvariantCulture),
int.Parse(indices.Split(',')[1], CultureInfo.InvariantCulture))))
foreach (var entity in grid.GetAnchoredEntities(new Vector2i(
int.Parse(indices.Split(',')[0], CultureInfo.InvariantCulture),
int.Parse(indices.Split(',')[1], CultureInfo.InvariantCulture))))
{
shell.WriteLine(entity.ToString());
}
@@ -437,22 +433,20 @@ namespace Robust.Client.Console.Commands
return;
}
if (!int.TryParse(args[0], out var id))
if (!EntityUid.TryParse(args[0], out var gridUid))
{
shell.WriteLine($"{args[0]} is not a valid integer.");
shell.WriteLine($"{args[0]} is not a valid entity UID.");
return;
}
var gridId = new GridId(int.Parse(args[0]));
var mapManager = IoCManager.Resolve<IMapManager>();
if (mapManager.TryGetGrid(gridId, out var grid))
if (mapManager.TryGetGrid(gridUid, out var grid))
{
shell.WriteLine(mapManager.GetGrid(gridId).GetAllTiles().Count().ToString());
shell.WriteLine(grid.GetAllTiles().Count().ToString());
}
else
{
shell.WriteError($"No grid exists with id {id}");
shell.WriteError($"No grid exists with id {gridUid}");
}
}
}

View File

@@ -20,7 +20,7 @@ namespace Robust.Client.Debugging
private Label? _label;
private (GridId GridId, TileRef Tile)? _hovered;
private (EntityUid GridId, TileRef Tile)? _hovered;
public bool Enabled
{
@@ -71,9 +71,9 @@ namespace Robust.Client.Debugging
var tile = grid.GetTileRef(spot);
_label.Position = mouseSpot.Position + new Vector2(32, 0);
if (_hovered?.GridId == grid.Index && _hovered?.Tile == tile) return;
if (_hovered?.GridId == grid.GridEntityId && _hovered?.Tile == tile) return;
_hovered = (grid.Index, tile);
_hovered = (grid.GridEntityId, tile);
var text = new StringBuilder();

View File

@@ -13,7 +13,7 @@ namespace Robust.Client.GameObjects
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[ViewVariables] private (GridId, Vector2i) _lastPosition;
[ViewVariables] private (EntityUid, Vector2i) _lastPosition;
[ViewVariables] internal OccluderDir Occluding { get; private set; }
[ViewVariables] internal uint UpdateGeneration { get; set; }
@@ -46,8 +46,9 @@ namespace Robust.Client.GameObjects
if(!xform.Anchored)
return;
var grid = _mapManager.GetGrid(xform.GridID);
_lastPosition = (xform.GridID, grid.TileIndicesFor(xform.Coordinates));
var gridId = xform.GridUid ?? throw new InvalidOperationException("Anchored without a grid");
var grid = _mapManager.GetGrid(gridId);
_lastPosition = (gridId, grid.TileIndicesFor(xform.Coordinates));
}
protected override void Shutdown()
@@ -92,7 +93,7 @@ namespace Robust.Client.GameObjects
if (!xform.Anchored)
return;
var grid = _mapManager.GetGrid(xform.GridID);
var grid = _mapManager.GetGrid(xform.GridUid ?? throw new InvalidOperationException("Anchored without a grid"));
var position = xform.Coordinates;
void CheckDir(Direction dir, OccluderDir oclDir)
{

View File

@@ -1933,7 +1933,7 @@ namespace Robust.Client.GameObjects
_ => textureSize
};
}
return Box2.CenteredAround(Offset, size * _scale);
}

View File

@@ -81,7 +81,7 @@ namespace Robust.Client.GameObjects
occluderQuery.HasComponent(sender))
{
var xform = EntityManager.GetComponent<TransformComponent>(sender);
if (!_mapManager.TryGetGrid(xform.GridID, out grid))
if (!_mapManager.TryGetGrid(xform.GridUid, out grid))
return;
var coords = xform.Coordinates;
@@ -122,13 +122,13 @@ namespace Robust.Client.GameObjects
/// </summary>
internal sealed class OccluderDirtyEvent : EntityEventArgs
{
public OccluderDirtyEvent(EntityUid sender, (GridId grid, Vector2i pos)? lastPosition)
public OccluderDirtyEvent(EntityUid sender, (EntityUid grid, Vector2i pos)? lastPosition)
{
LastPosition = lastPosition;
Sender = sender;
}
public (GridId grid, Vector2i pos)? LastPosition { get; }
public (EntityUid grid, Vector2i pos)? LastPosition { get; }
public EntityUid Sender { get; }
}
}

View File

@@ -251,7 +251,7 @@ namespace Robust.Client.GameObjects
var deltaPosition = new Vector2(0f, 0f);
//If we have an emitter we can do special effects around that emitter position
if (_mapManager.GridExists(EmitterCoordinates.GetGridId(_entityManager)))
if (_mapManager.GridExists(EmitterCoordinates.GetGridUid(_entityManager)))
{
//Calculate delta p due to radial velocity
var positionRelativeToEmitter =

View File

@@ -3,7 +3,7 @@ using Robust.Shared.GameObjects;
namespace Robust.Client.GameObjects;
internal class GridRenderingSystem : EntitySystem
internal sealed class GridRenderingSystem : EntitySystem
{
private readonly IClydeInternal _clyde;

View File

@@ -241,7 +241,7 @@ namespace Robust.Client.GameObjects
private void MapManagerOnGridCreated(GridInitializeEvent ev)
{
EntityManager.EnsureComponent<RenderingTreeComponent>(_mapManager.GetGrid(ev.GridId).GridEntityId);
EntityManager.EnsureComponent<RenderingTreeComponent>(_mapManager.GetGrid(ev.EntityUid).GridEntityId);
}
private RenderingTreeComponent? GetRenderTree(EntityUid entity, TransformComponent xform, EntityQuery<TransformComponent> xforms)

View File

@@ -13,7 +13,7 @@ namespace Robust.Client.Graphics.Clyde
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private readonly Dictionary<GridId, Dictionary<Vector2i, MapChunkData>> _mapChunkData =
private readonly Dictionary<EntityUid, Dictionary<Vector2i, MapChunkData>> _mapChunkData =
new();
private int _verticesPerChunk(MapChunk chunk) => chunk.ChunkSize * chunk.ChunkSize * 4;
@@ -42,7 +42,7 @@ namespace Robust.Client.Graphics.Clyde
{
var grid = (IMapGridInternal) mapGrid;
if (!_mapChunkData.ContainsKey(grid.Index))
if (!_mapChunkData.ContainsKey(grid.GridEntityId))
{
continue;
}
@@ -58,7 +58,7 @@ namespace Robust.Client.Graphics.Clyde
_updateChunkMesh(grid, chunk);
}
var datum = _mapChunkData[grid.Index][chunk.Indices];
var datum = _mapChunkData[grid.GridEntityId][chunk.Indices];
if (datum.TileCount == 0)
{
@@ -77,7 +77,7 @@ namespace Robust.Client.Graphics.Clyde
private void _updateChunkMesh(IMapGrid grid, MapChunk chunk)
{
var data = _mapChunkData[grid.Index];
var data = _mapChunkData[grid.GridEntityId];
if (!data.TryGetValue(chunk.Indices, out var datum))
{
@@ -145,11 +145,11 @@ namespace Robust.Client.Graphics.Clyde
var eboSize = _indicesPerChunk(chunk) * sizeof(ushort);
var vbo = new GLBuffer(this, BufferTarget.ArrayBuffer, BufferUsageHint.DynamicDraw,
vboSize, $"Grid {grid.Index} chunk {chunk.Indices} VBO");
vboSize, $"Grid {grid.GridEntityId} chunk {chunk.Indices} VBO");
var ebo = new GLBuffer(this, BufferTarget.ElementArrayBuffer, BufferUsageHint.DynamicDraw,
eboSize, $"Grid {grid.Index} chunk {chunk.Indices} EBO");
eboSize, $"Grid {grid.GridEntityId} chunk {chunk.Indices} EBO");
ObjectLabelMaybe(ObjectLabelIdentifier.VertexArray, vao, $"Grid {grid.Index} chunk {chunk.Indices} VAO");
ObjectLabelMaybe(ObjectLabelIdentifier.VertexArray, vao, $"Grid {grid.GridEntityId} chunk {chunk.Indices} VAO");
SetupVAOLayout();
CheckGlError();
@@ -163,19 +163,19 @@ namespace Robust.Client.Graphics.Clyde
Dirty = true
};
_mapChunkData[grid.Index].Add(chunk.Indices, datum);
_mapChunkData[grid.GridEntityId].Add(chunk.Indices, datum);
return datum;
}
private bool _isChunkDirty(IMapGrid grid, MapChunk chunk)
{
var data = _mapChunkData[grid.Index];
var data = _mapChunkData[grid.GridEntityId];
return !data.TryGetValue(chunk.Indices, out var datum) || datum.Dirty;
}
public void _setChunkDirty(IMapGrid grid, Vector2i chunk)
{
var data = _mapChunkData[grid.Index];
var data = _mapChunkData[grid.GridEntityId];
if (data.TryGetValue(chunk, out var datum))
{
datum.Dirty = true;
@@ -195,20 +195,20 @@ namespace Robust.Client.Graphics.Clyde
private void _updateTileMapOnUpdate(TileChangedEvent args)
{
var grid = _mapManager.GetGrid(args.NewTile.GridIndex);
var grid = _mapManager.GetGrid(args.NewTile.GridUid);
var chunk = grid.GridTileToChunkIndices(new Vector2i(args.NewTile.X, args.NewTile.Y));
_setChunkDirty(grid, chunk);
}
private void _updateOnGridCreated(GridStartupEvent ev)
{
var gridId = ev.GridId;
var gridId = ev.EntityUid;
_mapChunkData.Add(gridId, new Dictionary<Vector2i, MapChunkData>());
}
private void _updateOnGridRemoved(GridRemovalEvent ev)
{
var gridId = ev.GridId;
var gridId = ev.EntityUid;
var data = _mapChunkData[gridId];
foreach (var chunkDatum in data.Values)

View File

@@ -498,7 +498,9 @@ internal partial class Clyde
public uint WindowId;
public nint GlContext;
public SDL_SysWMinfo SysWMinfo;
#pragma warning disable CS0649
public bool Fullscreen;
#pragma warning restore CS0649
public int SwapInterval;
// Kept around to avoid it being GCd.

View File

@@ -16,7 +16,6 @@ internal partial class Clyde
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ILocalizationManager _loc = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
private readonly Clyde _clyde;

View File

@@ -1,4 +1,5 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -18,9 +19,9 @@ namespace Robust.Client.Placement.Modes
{
MouseCoords = ScreenToCursorGrid(mouseScreen);
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager);
SnapSize = 1f;
if (gridId.IsValid())
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
Grid = pManager.MapManager.GetGrid(gridId);
SnapSize = Grid.TileSize; //Find snap size for the grid.

View File

@@ -51,9 +51,9 @@ namespace Robust.Client.Placement.Modes
{
MouseCoords = ScreenToCursorGrid(mouseScreen);
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager);
SnapSize = 1f;
if (gridId.IsValid())
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
Grid = pManager.MapManager.GetGrid(gridId);
SnapSize = Grid.TileSize; //Find snap size for the grid.

View File

@@ -16,7 +16,7 @@ namespace Robust.Client.Placement.Modes
MouseCoords = ScreenToCursorGrid(mouseScreen).AlignWithClosestGridTile(SearchBoxSize, pManager.EntityManager, pManager.MapManager);
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
var gridId = MouseCoords.GetGridUid(pManager.EntityManager);
if (!pManager.MapManager.TryGetGrid(gridId, out var mapGrid))
return;

View File

@@ -1,4 +1,5 @@
using Robust.Shared.Map;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Robust.Client.Placement.Modes
{
@@ -14,11 +15,11 @@ namespace Robust.Client.Placement.Modes
MouseCoords = ScreenToCursorGrid(mouseScreen);
var tileSize = 1f;
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager);
if (gridId.IsValid())
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
var mapGrid = pManager.MapManager.GetGrid(MouseCoords.GetGridId(pManager.EntityManager));
var mapGrid = pManager.MapManager.GetGrid(gridId);
tileSize = mapGrid.TileSize; //convert from ushort to float
}

View File

@@ -17,11 +17,11 @@ namespace Robust.Client.Placement.Modes
MouseCoords = ScreenToCursorGrid(mouseScreen);
var tileSize = 1f;
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager);
if (gridId.IsValid())
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
var mapGrid = pManager.MapManager.GetGrid(MouseCoords.GetGridId(pManager.EntityManager));
var mapGrid = pManager.MapManager.GetGrid(gridId);
CurrentTile = mapGrid.GetTileRef(MouseCoords);
tileSize = mapGrid.TileSize; //convert from ushort to float
}

View File

@@ -1,4 +1,5 @@
using Robust.Shared.Map;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Robust.Client.Placement.Modes
{
@@ -15,8 +16,8 @@ namespace Robust.Client.Placement.Modes
var tileSize = 1f;
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
if (gridId.IsValid())
var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager);
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
var mapGrid = pManager.MapManager.GetGrid(gridId);
tileSize = mapGrid.TileSize; //convert from ushort to float

View File

@@ -334,7 +334,7 @@ namespace Robust.Client.Placement
private void HandleTileChanged(TileChangedEvent args)
{
var coords = MapManager.GetGrid(args.NewTile.GridIndex).GridTileToLocal(args.NewTile.GridIndices);
var coords = MapManager.GetGrid(args.NewTile.GridUid).GridTileToLocal(args.NewTile.GridIndices);
_pendingTileChanges.RemoveAll(c => c.Item1 == coords);
}
@@ -740,9 +740,9 @@ namespace Robust.Client.Placement
if (CurrentPermission.IsTile)
{
var gridId = coordinates.GetGridId(EntityManager);
var gridIdOpt = coordinates.GetGridUid(EntityManager);
// If we have actually placed something on a valid grid...
if (gridId.IsValid())
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
var grid = MapManager.GetGrid(gridId);

View File

@@ -171,10 +171,9 @@ namespace Robust.Client.Placement
/// </summary>
public TileRef GetTileRef(EntityCoordinates coordinates)
{
var gridId = coordinates.GetGridId(pManager.EntityManager);
var gridUid = coordinates.GetGridUid(pManager.EntityManager);
return gridId.IsValid() ? pManager.MapManager.GetGrid(gridId).GetTileRef(MouseCoords)
: new TileRef(gridId, gridUid.GetValueOrDefault(),
var gridUidOpt = coordinates.GetGridUid(pManager.EntityManager);
return gridUidOpt is EntityUid gridUid && gridUid.IsValid() ? pManager.MapManager.GetGrid(gridUid).GetTileRef(MouseCoords)
: new TileRef(gridUidOpt ?? EntityUid.Invalid,
MouseCoords.ToVector2i(pManager.EntityManager, pManager.MapManager), Tile.Empty);
}

View File

@@ -76,8 +76,7 @@ namespace Robust.Client.UserInterface.CustomControls
{
mouseGridPos = new EntityCoordinates(_mapManager.GetMapEntityId(mouseWorldMap.MapId),
mouseWorldMap.Position);
tile = new TileRef(GridId.Invalid, EntityUid.Invalid,
mouseGridPos.ToVector2i(_entityManager, _mapManager), Tile.Empty);
tile = new TileRef(EntityUid.Invalid, mouseGridPos.ToVector2i(_entityManager, _mapManager), Tile.Empty);
}
var controlHovered = UserInterfaceManager.CurrentlyHovered;
@@ -106,14 +105,14 @@ Mouse Pos:
var playerCoordinates = entityTransform.Coordinates;
var playerRotation = entityTransform.WorldRotation;
Angle gridRotation = _mapManager.TryGetGrid(entityTransform.GridID, out var grid) ? grid.WorldRotation : Angle.Zero;
Angle gridRotation = _mapManager.TryGetGrid(entityTransform.GridUid, out var grid) ? grid.WorldRotation : Angle.Zero;
_textBuilder.Append($@" Screen: {playerScreen}
{playerWorldOffset}
{playerCoordinates}
Rotation: {playerRotation.Degrees:F2}°
EntId: {entityTransform.Owner}
GridID: {entityTransform.GridID}
GridUid: {entityTransform.GridUid}
Grid Rotation: {gridRotation.Degrees:F2}°");
}

View File

@@ -30,7 +30,7 @@ namespace Robust.Client.ViewVariables.Editors
HorizontalExpand = true,
PlaceHolder = "Grid ID",
ToolTip = "Grid ID",
Text = coords.GetGridId(entityManager).ToString()
Text = coords.GetGridUid(entityManager)?.ToString() ?? ""
};
hBoxContainer.AddChild(gridId);
@@ -61,12 +61,12 @@ namespace Robust.Client.ViewVariables.Editors
void OnEntered(LineEdit.LineEditEventArgs e)
{
var gridVal = int.Parse(gridId.Text, CultureInfo.InvariantCulture);
var gridVal = EntityUid.Parse(gridId.Text);
var mapManager = IoCManager.Resolve<IMapManager>();
var xVal = float.Parse(x.Text, CultureInfo.InvariantCulture);
var yVal = float.Parse(y.Text, CultureInfo.InvariantCulture);
if (!mapManager.TryGetGrid(new GridId(gridVal), out var grid))
if (!mapManager.TryGetGrid(gridVal, out var grid))
{
ValueChanged(new EntityCoordinates(EntityUid.Invalid, (xVal, yVal)));
return;

View File

@@ -187,7 +187,7 @@ namespace Robust.Server.Bql
var map = IoCManager.Resolve<IMapManager>();
if (tileTy.TileId == 0)
{
return input.Where(e => entityManager.TryGetComponent<TransformComponent>(e, out var transform) && (transform.GridID == GridId.Invalid) ^ isInverted);
return input.Where(e => entityManager.TryGetComponent<TransformComponent>(e, out var transform) && (transform.GridUid is null) ^ isInverted);
}
else
{
@@ -195,8 +195,7 @@ namespace Robust.Server.Bql
{
if (!entityManager.TryGetComponent<TransformComponent>(e, out var transform)) return isInverted;
var gridId = transform.GridID;
if (!map.TryGetGrid(gridId, out var grid))
if (!map.TryGetGrid(transform.GridUid, out var grid))
return isInverted;
return (grid.GetTileRef(transform.Coordinates).Tile.TypeId == tileTy.TileId) ^ isInverted;
@@ -217,8 +216,8 @@ namespace Robust.Server.Bql
public override IEnumerable<EntityUid> DoSelection(IEnumerable<EntityUid> input, IReadOnlyList<object> arguments, bool isInverted, IEntityManager entityManager)
{
// TODO: Probably easier and significantly faster to just iterate the grid's children.
var grid = new GridId((int) arguments[0]);
return input.Where(e => (entityManager.TryGetComponent<TransformComponent>(e, out var transform) && transform.GridID == grid) ^ isInverted);
var grid = new EntityUid((int) arguments[0]);
return input.Where(e => (entityManager.TryGetComponent<TransformComponent>(e, out var transform) && transform.GridUid == grid) ^ isInverted);
}
}

View File

@@ -408,7 +408,7 @@ namespace Robust.Server.Console.Commands
var pos = pt.Coordinates;
shell.WriteLine(
$"MapID:{pos.GetMapId(entityManager)} GridID:{pos.GetGridId(entityManager)} X:{pos.X:N2} Y:{pos.Y:N2}");
$"MapID:{pos.GetMapId(entityManager)} GridUid:{pos.GetGridUid(entityManager)} X:{pos.X:N2} Y:{pos.Y:N2}");
}
}
@@ -425,7 +425,7 @@ namespace Robust.Server.Console.Commands
shell.WriteError("Wrong number of args.");
}
var gridId = new GridId(int.Parse(args[0]));
var gridId = EntityUid.Parse(args[0]);
var xpos = float.Parse(args[1], CultureInfo.InvariantCulture);
var ypos = float.Parse(args[2], CultureInfo.InvariantCulture);
@@ -457,17 +457,17 @@ namespace Robust.Server.Console.Commands
return;
}
var gridId = new GridId(int.Parse(args[0]));
var gridId = EntityUid.Parse(args[0]);
var mapManager = IoCManager.Resolve<IMapManager>();
if (!mapManager.GridExists(gridId))
{
shell.WriteError($"Grid {gridId.Value} does not exist.");
shell.WriteError($"Grid {gridId} does not exist.");
return;
}
mapManager.DeleteGrid(gridId);
shell.WriteLine($"Grid {gridId.Value} was removed.");
shell.WriteLine($"Grid {gridId} was removed.");
}
}
@@ -524,7 +524,7 @@ namespace Robust.Server.Console.Commands
mapId, mapManager.IsMapInitialized(mapId),
mapManager.IsMapPaused(mapId),
mapManager.GetMapEntityId(mapId),
string.Join(",", mapManager.GetAllMapGrids(mapId).Select(grid => grid.Index)));
string.Join(",", mapManager.GetAllMapGrids(mapId).Select(grid => grid.GridEntityId)));
}
shell.WriteLine(msg.ToString());
@@ -545,13 +545,13 @@ namespace Robust.Server.Console.Commands
var msg = new StringBuilder();
var xformQuery = entManager.GetEntityQuery<TransformComponent>();
foreach (var grid in mapManager.GetAllGrids().OrderBy(grid => grid.Index.Value))
foreach (var grid in mapManager.GetAllGrids().OrderBy(grid => grid.GridEntityId))
{
var xform = xformQuery.GetComponent(grid.GridEntityId);
var worldPos = xform.WorldPosition;
msg.AppendFormat("{0}: map: {1}, ent: {2}, pos: {3:0.0},{4:0.0} \n",
grid.Index, xform.MapID, grid.GridEntityId, worldPos.X, worldPos.Y);
grid.GridEntityId, xform.MapID, grid.GridEntityId, worldPos.X, worldPos.Y);
}
shell.WriteLine(msg.ToString());

View File

@@ -38,7 +38,7 @@ namespace Robust.Server.GameObjects
foreach (var grid in toDelete)
{
MapManager.DeleteGrid(grid.Index);
MapManager.DeleteGrid(grid.GridEntityId);
}
}
}

View File

@@ -23,7 +23,7 @@ public interface IPVSCollection
/// Adds a player session to the collection. Returns false if the player was already present.
/// </summary>
public bool AddPlayer(ICommonSession session);
public void AddGrid(GridId gridId);
public void AddGrid(EntityUid gridId);
public void AddMap(MapId mapId);
/// <summary>
@@ -31,7 +31,7 @@ public interface IPVSCollection
/// </summary>
public bool RemovePlayer(ICommonSession session);
public void RemoveGrid(GridId gridId);
public void RemoveGrid(EntityUid gridId);
public void RemoveMap(MapId mapId);
@@ -67,7 +67,7 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
/// <summary>
/// Index of which <see cref="TIndex"/> are contained in which gridchunk, indexed by <see cref="Vector2i"/>.
/// </summary>
private readonly Dictionary<GridId, Dictionary<Vector2i, HashSet<TIndex>>> _gridChunkContents = new();
private readonly Dictionary<EntityUid, Dictionary<Vector2i, HashSet<TIndex>>> _gridChunkContents = new();
/// <summary>
/// List of <see cref="TIndex"/> that should always get sent.
@@ -190,7 +190,7 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
public bool TryGetChunk(MapId mapId, Vector2i chunkIndices, [NotNullWhen(true)] out HashSet<TIndex>? indices) =>
_mapChunkContents[mapId].TryGetValue(chunkIndices, out indices);
public bool TryGetChunk(GridId gridId, Vector2i chunkIndices, [NotNullWhen(true)] out HashSet<TIndex>? indices) =>
public bool TryGetChunk(EntityUid gridId, Vector2i chunkIndices, [NotNullWhen(true)] out HashSet<TIndex>? indices) =>
_gridChunkContents[gridId].TryGetValue(chunkIndices, out indices);
public HashSet<TIndex>.Enumerator GetElementsForSession(ICommonSession session) => _localOverrides[session].GetEnumerator();
@@ -262,7 +262,7 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
}
/// <inheritdoc />
public void AddGrid(GridId gridId) => _gridChunkContents[gridId] = new();
public void AddGrid(EntityUid gridId) => _gridChunkContents[gridId] = new();
/// <inheritdoc />
public void AddMap(MapId mapId) => _mapChunkContents[mapId] = new();
@@ -286,7 +286,7 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
}
/// <inheritdoc />
public void RemoveGrid(GridId gridId)
public void RemoveGrid(EntityUid gridId)
{
foreach (var (_, indices) in _gridChunkContents[gridId])
{
@@ -399,8 +399,8 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
if(!removeFromOverride && IsOverride(index))
return;
var gridId = coordinates.GetGridId(_entityManager);
if (gridId != GridId.Invalid)
var gridIdOpt = coordinates.GetGridUid(_entityManager);
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
var gridIndices = GetChunkIndices(coordinates.Position);
UpdateIndex(index, gridId, gridIndices, true); //skip overridecheck bc we already did it (saves some dict lookups)
@@ -414,8 +414,8 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
public IChunkIndexLocation GetChunkIndex(EntityCoordinates coordinates)
{
var gridId = coordinates.GetGridId(_entityManager);
if (gridId != GridId.Invalid)
var gridIdOpt = coordinates.GetGridUid(_entityManager);
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
var gridIndices = GetChunkIndices(coordinates.Position);
return new GridChunkLocation(gridId, gridIndices);
@@ -433,7 +433,7 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
/// <param name="gridId">The id of the grid.</param>
/// <param name="chunkIndices">The indices of the chunk.</param>
/// <param name="removeFromOverride">An index at an override position will not be updated unless you set this flag.</param>
public void UpdateIndex(TIndex index, GridId gridId, Vector2i chunkIndices, bool removeFromOverride = false)
public void UpdateIndex(TIndex index, EntityUid gridId, Vector2i chunkIndices, bool removeFromOverride = false)
{
if(!removeFromOverride && IsOverride(index))
return;
@@ -509,13 +509,13 @@ public struct MapChunkLocation : IIndexLocation, IChunkIndexLocation, IEquatable
public struct GridChunkLocation : IIndexLocation, IChunkIndexLocation, IEquatable<GridChunkLocation>
{
public GridChunkLocation(GridId gridId, Vector2i chunkIndices)
public GridChunkLocation(EntityUid gridId, Vector2i chunkIndices)
{
GridId = gridId;
ChunkIndices = chunkIndices;
}
public GridId GridId { get; init; }
public EntityUid GridId { get; init; }
public Vector2i ChunkIndices { get; init; }
public bool Equals(GridChunkLocation other)

View File

@@ -407,20 +407,19 @@ internal sealed partial class PVSSystem : EntitySystem
{
foreach (var pvsCollection in _pvsCollections)
{
pvsCollection.RemoveGrid(ev.GridId);
pvsCollection.RemoveGrid(ev.EntityUid);
}
}
private void OnGridCreated(GridInitializeEvent ev)
{
var gridId = ev.GridId;
var gridId = ev.EntityUid;
foreach (var pvsCollection in _pvsCollections)
{
pvsCollection.AddGrid(gridId);
}
var euid = _mapManager.GetGridEuid(gridId);
_entityPvsCollection.UpdateIndex(euid);
_entityPvsCollection.UpdateIndex(gridId);
}
private void OnMapDestroyed(MapChangedEvent e)
@@ -534,7 +533,7 @@ internal sealed partial class PVSSystem : EntitySystem
while (gridChunkEnumerator.MoveNext(out var gridChunkIndices))
{
var chunkLocation = new GridChunkLocation(mapGrid.Index, gridChunkIndices.Value);
var chunkLocation = new GridChunkLocation(mapGrid.GridEntityId, gridChunkIndices.Value);
var entry = (visMask, chunkLocation);
if (gridDict.TryGetValue(chunkLocation, out var indexOf))

View File

@@ -246,7 +246,6 @@ namespace Robust.Server.Maps
/// Handles the primary bulk of state during the map serialization process.
/// </summary>
internal sealed class MapContext : ISerializationContext, IEntityLoadContext,
ITypeSerializer<GridId, ValueDataNode>,
ITypeSerializer<EntityUid, ValueDataNode>,
ITypeReaderWriter<EntityUid, ValueDataNode>
{
@@ -263,9 +262,8 @@ namespace Robust.Server.Maps
/// If we're using savemap and not savebp then save everything on map.
/// </summary>
internal MapId? MapId { get; set; }
private readonly Dictionary<GridId, int> GridIDMap = new();
private readonly Dictionary<EntityUid, int> GridIDMap = new();
public readonly List<MapGrid> Grids = new();
private readonly List<GridId> _readGridIndices = new();
private EntityQuery<TransformComponent>? _xformQuery = null;
private readonly Dictionary<EntityUid, int> EntityUidMap = new();
@@ -315,12 +313,10 @@ namespace Robust.Server.Maps
RootNode = new MappingDataNode();
TypeWriters = new Dictionary<Type, object>()
{
{typeof(GridId), this},
{typeof(EntityUid), this}
};
TypeReaders = new Dictionary<(Type, Type), object>()
{
{(typeof(GridId), typeof(ValueDataNode)), this},
{(typeof(EntityUid), typeof(ValueDataNode)), this}
};
}
@@ -344,12 +340,10 @@ namespace Robust.Server.Maps
_prototypeManager = prototypeManager;
TypeWriters = new Dictionary<Type, object>()
{
{typeof(GridId), this},
{typeof(EntityUid), this}
};
TypeReaders = new Dictionary<(Type, Type), object>()
{
{(typeof(GridId), typeof(ValueDataNode)), this},
{(typeof(EntityUid), typeof(ValueDataNode)), this}
};
}
@@ -366,9 +360,6 @@ namespace Robust.Server.Maps
// Create the new map.
AllocMap();
// Maps grid section indices to GridIds, for deserializing GridIds on entities.
ReadGridSectionIndices();
// Entities are first allocated. This allows us to know the future UID of all entities on the map before
// even ExposeData is loaded. This allows us to resolve serialized EntityUid instances correctly.
AllocEntities();
@@ -539,18 +530,18 @@ namespace Robust.Server.Maps
private void ReadGridSection()
{
// There were no new grids, nothing to do here.
if(_readGridIndices.Count == 0)
return;
// MapGrids already contain their assigned GridId from their ctor, and the MapComponents just got deserialized.
// Now we need to actually bind the MapGrids to their components so that you can resolve GridId -> EntityUid
// After doing this, it should be 100% safe to use the MapManager API like normal.
var yamlGrids = RootNode.Get<SequenceDataNode>("grids");
// There were no new grids, nothing to do here.
if (yamlGrids.Count == 0)
return;
// get ents that the grids will bind to
var gridComps = new Dictionary<GridId, MapGridComponent>(_readGridIndices.Count);
var gridComps = new MapGridComponent[yamlGrids.Count];
var gridQuery = _serverEntityManager.GetEntityQuery<MapGridComponent>();
@@ -563,22 +554,16 @@ namespace Robust.Server.Maps
// These should actually be new, pre-init
DebugTools.Assert(gridComp.LifeStage == ComponentLifeStage.Added);
// yaml deserializer turns "null" into Invalid, this has been encountered by a customer from failed serialization.
DebugTools.Assert(gridComp.GridIndex != GridId.Invalid);
gridComps[gridComp.GridIndex] = gridComp;
}
for (var index = 0; index < _readGridIndices.Count; index++)
for (var index = 0; index < yamlGrids.Count; index++)
{
// Here is where the implicit index pairing magic happens from the yaml.
var gridIndex = _readGridIndices[index];
var yamlGrid = (MappingDataNode)yamlGrids[index];
// designed to throw if something is broken, every grid must map to an ent
var gridComp = gridComps[gridIndex];
DebugTools.Assert(gridComp.GridIndex == gridIndex);
var gridComp = gridComps[index];
MappingDataNode yamlGridInfo = (MappingDataNode)yamlGrid["settings"];
SequenceDataNode yamlGridChunks = (SequenceDataNode)yamlGrid["chunks"];
@@ -693,18 +678,6 @@ namespace Robust.Server.Maps
}
}
private void ReadGridSectionIndices()
{
// sets up the mapping so the serializer can properly deserialize GridIds.
var yamlGrids = RootNode.Get<SequenceDataNode>("grids");
for (var i = 0; i < yamlGrids.Count; i++)
{
_readGridIndices.Add(_mapManager.GenerateGridId(null));
}
}
private void AllocMap()
{
// Both blueprint and map deserialization use this,
@@ -883,13 +856,13 @@ namespace Robust.Server.Maps
// Serialization
public void RegisterGrid(IMapGrid grid)
{
if (GridIDMap.ContainsKey(grid.Index))
if (GridIDMap.ContainsKey(grid.GridEntityId))
{
throw new InvalidOperationException();
}
Grids.Add((MapGrid) grid);
GridIDMap.Add(grid.Index, GridIDMap.Count);
GridIDMap.Add(grid.GridEntityId, GridIDMap.Count);
}
public YamlNode Serialize()
@@ -960,7 +933,8 @@ namespace Robust.Server.Maps
foreach (var entity in _serverEntityManager.GetEntities())
{
var currentTransform = transformCompQuery.GetComponent(entity);
if ((MapId != null && currentTransform.MapID != MapId) || (MapId == null && !GridIDMap.ContainsKey(currentTransform.GridID))) continue;
if (MapId != null && currentTransform.MapID != MapId) continue;
if (MapId == null && (!(currentTransform.GridUid is EntityUid gridId) || !GridIDMap.ContainsKey(gridId))) continue;
var currentEntity = entity;
@@ -1110,28 +1084,6 @@ namespace Robust.Server.Maps
: base(message) { }
}
public GridId Read(ISerializationManager serializationManager, ValueDataNode node,
IDependencyCollection dependencies,
bool skipHook,
ISerializationContext? context = null, GridId _ = default)
{
// This is the code that deserializes the Grids index into the GridId. This has to happen between Grid allocation
// and when grids are bound to their entities.
if (node.Value == "null")
{
throw new MapLoadException($"Error in map file: found local grid ID '{node.Value}' which does not exist.");
}
var val = int.Parse(node.Value);
if (val >= _readGridIndices.Count)
{
throw new MapLoadException($"Error in map file: found local grid ID '{val}' which does not exist.");
}
return _readGridIndices[val];
}
ValidationNode ITypeValidator<EntityUid, ValueDataNode>.Validate(ISerializationManager serializationManager,
ValueDataNode node, IDependencyCollection dependencies, ISerializationContext? context)
{
@@ -1148,19 +1100,6 @@ namespace Robust.Server.Maps
return new ValidatedValueNode(node);
}
ValidationNode ITypeValidator<GridId, ValueDataNode>.Validate(ISerializationManager serializationManager,
ValueDataNode node, IDependencyCollection dependencies, ISerializationContext? context)
{
if (node.Value == "null") return new ValidatedValueNode(node);
if (!int.TryParse(node.Value, out var val) || val >= Grids.Count)
{
return new ErrorNode(node, "Invalid GridId", true);
}
return new ValidatedValueNode(node);
}
public DataNode Write(ISerializationManager serializationManager, EntityUid value,
IDependencyCollection dependencies, bool alwaysWrite = false,
ISerializationContext? context = null)
@@ -1182,21 +1121,6 @@ namespace Robust.Server.Maps
}
}
public DataNode Write(ISerializationManager serializationManager, GridId value,
IDependencyCollection dependencies, bool alwaysWrite = false,
ISerializationContext? context = null)
{
if (!GridIDMap.TryGetValue(value, out var gridMapped))
{
Logger.WarningS("map", "Cannot write grid ID '{0}', falling back to nullspace.", gridMapped);
return new ValueDataNode("");
}
else
{
return new ValueDataNode(gridMapped.ToString(CultureInfo.InvariantCulture));
}
}
EntityUid ITypeReader<EntityUid, ValueDataNode>.Read(ISerializationManager serializationManager,
ValueDataNode node,
IDependencyCollection dependencies,
@@ -1221,14 +1145,6 @@ namespace Robust.Server.Maps
}
}
[MustUseReturnValue]
public GridId Copy(ISerializationManager serializationManager, GridId source, GridId target,
bool skipHook,
ISerializationContext? context = null)
{
return new(source.Value);
}
[MustUseReturnValue]
public EntityUid Copy(ISerializationManager serializationManager, EntityUid source, EntityUid target,
bool skipHook,

View File

@@ -246,13 +246,13 @@ namespace Robust.Server.Physics
var (gridPos, gridRot) = oldGridXform.GetWorldPositionRotation(xformQuery);
var mapBody = bodyQuery.GetComponent(mapGrid.GridEntityId);
var oldGridComp = gridQuery.GetComponent(mapGrid.GridEntityId);
var newGrids = new GridId[grids.Count - 1];
var newGrids = new EntityUid[grids.Count - 1];
for (var i = 0; i < grids.Count - 1; i++)
{
var group = grids[i];
var splitGrid = _mapManager.CreateGrid(mapGrid.ParentMapId);
newGrids[i] = splitGrid.Index;
newGrids[i] = splitGrid.GridEntityId;
// Keep same origin / velocity etc; this makes updating a lot faster and easier.
splitGrid.WorldPosition = gridPos;
@@ -310,7 +310,7 @@ namespace Robust.Server.Physics
var tilePos = offset + tile;
var bounds = _lookup.GetLocalBounds(tilePos, mapGrid.TileSize);
foreach (var ent in _lookup.GetEntitiesIntersecting(mapGrid.Index, tilePos, LookupFlags.None))
foreach (var ent in _lookup.GetEntitiesIntersecting(mapGrid.GridEntityId, tilePos, LookupFlags.None))
{
// Consider centre of entity position maybe?
var entXform = xformQuery.GetComponent(ent);
@@ -355,7 +355,7 @@ namespace Robust.Server.Physics
}
// Allow content to react to the grid being split...
var ev = new GridSplitEvent(newGrids, mapGrid.Index);
var ev = new GridSplitEvent(newGrids, mapGrid.GridEntityId);
RaiseLocalEvent(uid, ref ev, true);
_logger.Debug($"Split {grids.Count} grids in {sw.Elapsed}");
@@ -745,14 +745,14 @@ public readonly struct GridSplitEvent
/// <summary>
/// Contains the IDs of the newly created grids.
/// </summary>
public readonly GridId[] NewGrids;
public readonly EntityUid[] NewGrids;
/// <summary>
/// The grid that has been split.
/// </summary>
public readonly GridId Grid;
public readonly EntityUid Grid;
public GridSplitEvent(GridId[] newGrids, GridId grid)
public GridSplitEvent(EntityUid[] newGrids, EntityUid grid)
{
NewGrids = newGrids;
Grid = grid;

View File

@@ -17,8 +17,6 @@ namespace Robust.Shared.GameObjects
/// </summary>
public interface IMapGridComponent : IComponent
{
[Obsolete("Use EntityUids instead")]
GridId GridIndex { get; }
IMapGrid Grid { get; }
}
@@ -34,20 +32,16 @@ namespace Robust.Shared.GameObjects
// If you want to remove this, you would have to restructure the map save file.
[ViewVariables(VVAccess.ReadOnly)]
[DataField("index")]
#pragma warning disable CS0618
private GridId _gridIndex = GridId.Invalid;
#pragma warning restore CS0618
private int _gridIndex = 0;
private IMapGrid? _mapGrid;
/// <inheritdoc />
[Obsolete("Use EntityUid instead")]
public GridId GridIndex
internal int GridIndex
{
get => _gridIndex;
internal set => _gridIndex = value;
set => _gridIndex = value;
}
private IMapGrid? _mapGrid;
[DataField("chunkSize")]
private ushort _chunkSize = 16;
@@ -82,7 +76,7 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
public override ComponentState GetComponentState()
{
return new MapGridComponentState(_gridIndex, _chunkSize);
return new MapGridComponentState(Owner, _chunkSize);
}
/// <inheritdoc />
@@ -93,7 +87,6 @@ namespace Robust.Shared.GameObjects
if (curState is not MapGridComponentState state)
return;
_gridIndex = state.GridIndex;
_chunkSize = state.ChunkSize;
}
@@ -101,13 +94,10 @@ namespace Robust.Shared.GameObjects
{
DebugTools.Assert(LifeStage == ComponentLifeStage.Added);
#pragma warning disable CS0618
var grid = new MapGrid(_mapManager, _entMan, GridIndex, chunkSize);
#pragma warning restore CS0618
var grid = new MapGrid(_mapManager, _entMan, Owner, chunkSize);
grid.TileSize = tileSize;
Grid = grid;
grid.GridEntityId = Owner;
_mapManager.OnGridAllocated(this, grid);
return grid;
@@ -174,7 +164,7 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// Index of the grid this component is linked to.
/// </summary>
public GridId GridIndex { get; }
public EntityUid GridIndex { get; }
/// <summary>
/// The size of the chunks in the map grid.
@@ -186,7 +176,7 @@ namespace Robust.Shared.GameObjects
/// </summary>
/// <param name="gridIndex">Index of the grid this component is linked to.</param>
/// <param name="chunkSize">The size of the chunks in the map grid.</param>
public MapGridComponentState(GridId gridIndex, ushort chunkSize)
public MapGridComponentState(EntityUid gridIndex, ushort chunkSize)
{
GridIndex = gridIndex;
ChunkSize = chunkSize;

View File

@@ -85,14 +85,6 @@ namespace Robust.Shared.GameObjects
[Access(typeof(SharedTransformSystem))]
internal EntityUid? _gridUid = null;
[Obsolete("Use GridUid")]
public GridId GridID
{
get => _entMan.TryGetComponent(GridUid, out MapGridComponent? grid)
? grid.GridIndex
: GridId.Invalid;
}
/// <summary>
/// Disables or enables to ability to locally rotate the entity. When set it removes any local rotation.
/// </summary>
@@ -406,7 +398,7 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// Local offset of this entity relative to its parent
/// (<see cref="Parent"/> if it's not null, to <see cref="GridID"/> otherwise).
/// (<see cref="Parent"/> if it's not null, to <see cref="GridUid"/> otherwise).
/// </summary>
[Animatable]
[ViewVariables(VVAccess.ReadWrite)]

View File

@@ -457,13 +457,6 @@ public sealed partial class EntityLookupSystem
#region Grid Methods
[Obsolete("Use Grid EntityUid")]
public HashSet<EntityUid> GetEntitiesIntersecting(GridId gridId, IEnumerable<Vector2i> gridIndices, LookupFlags flags = DefaultFlags)
{
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
return GetEntitiesIntersecting(grid.GridEntityId, gridIndices, flags);
}
/// <summary>
/// Returns the entities intersecting any of the supplied tiles. Faster than doing each tile individually.
/// </summary>
@@ -504,13 +497,6 @@ public sealed partial class EntityLookupSystem
return intersecting;
}
[Obsolete("Use Grid EntityUid")]
public HashSet<EntityUid> GetEntitiesIntersecting(GridId gridId, Vector2i gridIndices, LookupFlags flags = DefaultFlags)
{
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
return GetEntitiesIntersecting(grid.GridEntityId, gridIndices, flags);
}
public HashSet<EntityUid> GetEntitiesIntersecting(EntityUid gridId, Vector2i gridIndices, LookupFlags flags = DefaultFlags)
{
// Technically this doesn't consider anything overlapping from outside the grid but is this an issue?
@@ -541,13 +527,6 @@ public sealed partial class EntityLookupSystem
return intersecting;
}
[Obsolete("Use grid EntityUid")]
public HashSet<EntityUid> GetEntitiesIntersecting(GridId gridId, Box2 worldAABB, LookupFlags flags = DefaultFlags)
{
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
return GetEntitiesIntersecting(grid.GridEntityId, worldAABB, flags);
}
public HashSet<EntityUid> GetEntitiesIntersecting(EntityUid gridId, Box2 worldAABB, LookupFlags flags = DefaultFlags)
{
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
@@ -570,13 +549,6 @@ public sealed partial class EntityLookupSystem
return intersecting;
}
[Obsolete("Use grid EntityUid")]
public HashSet<EntityUid> GetEntitiesIntersecting(GridId gridId, Box2Rotated worldBounds, LookupFlags flags = DefaultFlags)
{
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
return GetEntitiesIntersecting(grid.GridEntityId, worldBounds, flags);
}
public HashSet<EntityUid> GetEntitiesIntersecting(EntityUid gridId, Box2Rotated worldBounds, LookupFlags flags = DefaultFlags)
{
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();

View File

@@ -46,21 +46,19 @@ namespace Robust.Shared.GameObjects
private void OnGridInit(EntityUid uid, MapGridComponent component, ComponentInit args)
{
#pragma warning disable CS0618
var msg = new GridInitializeEvent(uid, component.GridIndex);
var msg = new GridInitializeEvent(uid);
RaiseLocalEvent(uid, msg, true);
}
private void OnGridStartup(EntityUid uid, MapGridComponent component, ComponentStartup args)
{
#pragma warning disable CS0618
var msg = new GridStartupEvent(uid, component.GridIndex);
var msg = new GridStartupEvent(uid);
RaiseLocalEvent(uid, msg, true);
}
private void OnGridRemove(EntityUid uid, MapGridComponent component, ComponentShutdown args)
{
RaiseLocalEvent(uid, new GridRemovalEvent(uid, component.GridIndex), true);
RaiseLocalEvent(uid, new GridRemovalEvent(uid), true);
MapManager.OnComponentRemoved(component);
}
}
@@ -99,26 +97,20 @@ namespace Robust.Shared.GameObjects
public sealed class GridStartupEvent : EntityEventArgs
{
public EntityUid EntityUid { get; }
[Obsolete("Use EntityUids")]
public GridId GridId { get; }
public GridStartupEvent(EntityUid uid, GridId gridId)
public GridStartupEvent(EntityUid uid)
{
EntityUid = uid;
GridId = gridId;
}
}
public sealed class GridRemovalEvent : EntityEventArgs
{
public EntityUid EntityUid { get; }
[Obsolete("Use EntityUids")]
public GridId GridId { get; }
public GridRemovalEvent(EntityUid uid, GridId gridId)
public GridRemovalEvent(EntityUid uid)
{
EntityUid = uid;
GridId = gridId;
}
}
@@ -128,13 +120,10 @@ namespace Robust.Shared.GameObjects
public sealed class GridInitializeEvent : EntityEventArgs
{
public EntityUid EntityUid { get; }
[Obsolete("Use EntityUids")]
public GridId GridId { get; }
public GridInitializeEvent(EntityUid uid, GridId gridId)
public GridInitializeEvent(EntityUid uid)
{
EntityUid = uid;
GridId = gridId;
}
}
#pragma warning restore CS0618

View File

@@ -7,17 +7,6 @@ namespace Robust.Shared.Map
{
public static class CoordinatesExtensions
{
[Obsolete("Use EntityUid overload instead.")]
public static EntityCoordinates ToEntityCoordinates(this Vector2i vector, GridId gridId, IMapManager? mapManager = null)
{
IoCManager.Resolve(ref mapManager);
var grid = mapManager.GetGrid(gridId);
var tile = grid.TileSize;
return new EntityCoordinates(grid.GridEntityId, (vector.X * tile, vector.Y * tile));
}
public static EntityCoordinates ToEntityCoordinates(this Vector2i vector, EntityUid gridId, IMapManager? mapManager = null)
{
IoCManager.Resolve(ref mapManager);

View File

@@ -150,11 +150,10 @@ namespace Robust.Shared.Map
if(!IsValid(entityManager))
return new Vector2i();
var gridId = GetGridUid(entityManager);
if (gridId != null)
var gridIdOpt = GetGridUid(entityManager);
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
return mapManager.GetGrid(gridId.Value).GetTileRef(this).GridIndices;
return mapManager.GetGrid(gridId).GetTileRef(this).GridIndices;
}
var (x, y) = ToMapPos(entityManager);
@@ -204,26 +203,6 @@ namespace Robust.Shared.Map
return new EntityCoordinates(entity, localPos);
}
/// <summary>
/// Returns the Grid Id these coordinates are on.
/// If none of the ancestors are a grid, returns <see cref="GridId.Invalid"/> grid instead.
/// </summary>
/// <param name="entityManager"></param>
/// <returns>Grid Id this entity is on or <see cref="GridId.Invalid"/></returns>
[Obsolete("Use GetGridUid")]
public GridId GetGridId(IEntityManager entityManager)
{
if (!IsValid(entityManager))
return GridId.Invalid;
var uid = entityManager.GetComponent<TransformComponent>(EntityId).GridUid;
if (uid == null)
return GridId.Invalid;
return entityManager.GetComponent<IMapGridComponent>(uid.Value).GridIndex;
}
/// <summary>
/// Returns the Grid EntityUid these coordinates are on.
/// If none of the ancestors are a grid, returns null instead.

View File

@@ -8,10 +8,10 @@ namespace Robust.Shared.Map;
[Obsolete("EntityQuery for MapGridComponent instead")]
public struct GridEnumerator
{
private Dictionary<GridId, EntityUid>.Enumerator _enumerator;
private IEnumerator<EntityUid> _enumerator;
private EntityQuery<MapGridComponent> _query;
internal GridEnumerator(Dictionary<GridId, EntityUid>.Enumerator enumerator, EntityQuery<MapGridComponent> query)
internal GridEnumerator(IEnumerator<EntityUid> enumerator, EntityQuery<MapGridComponent> query)
{
_enumerator = enumerator;
_query = query;
@@ -25,9 +25,7 @@ public struct GridEnumerator
return false;
}
var (_, uid) = _enumerator.Current;
grid = _query.GetComponent(uid).Grid;
grid = _query.GetComponent(_enumerator.Current).Grid;
return true;
}
}

View File

@@ -7,5 +7,5 @@ namespace Robust.Shared.Map
/// </summary>
/// <param name="mapId">Passed to the delegate given it may no longer be retrievable.</param>
/// <param name="gridId">The index of the grid being changed.</param>
public delegate void GridEventHandler(MapId mapId, GridId gridId);
public delegate void GridEventHandler(MapId mapId, EntityUid gridId);
}

View File

@@ -1,76 +0,0 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
namespace Robust.Shared.Map
{
[Serializable, NetSerializable]
[Obsolete("Use EntityUids instead.")]
public struct GridId : IEquatable<GridId>
{
/// <summary>
/// An invalid grid ID.
/// </summary>
public static readonly GridId Invalid = new(0);
internal readonly int Value;
/// <summary>
/// Constructs a new instance of <see cref="GridId"/>.
/// </summary>
/// <remarks>
/// This should NOT be used in regular code, and is only public for special/legacy
/// cases. Generally you should only use this for parsing a GridId in console commands
/// and immediately check if the grid actually exists in the <see cref="IMapManager"/>.
/// </remarks>
public GridId(int value)
{
Value = value;
}
public bool IsValid()
{
return Value > 0;
}
/// <inheritdoc />
public bool Equals(GridId other)
{
return Value == other.Value;
}
/// <inheritdoc />
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is GridId id && Equals(id);
}
/// <inheritdoc />
public override int GetHashCode()
{
return Value;
}
public static bool operator ==(GridId a, GridId b)
{
return a.Value == b.Value;
}
public static bool operator !=(GridId a, GridId b)
{
return !(a == b);
}
public static explicit operator int(GridId self)
{
return self.Value;
}
public override string ToString()
{
return Value.ToString();
}
}
}

View File

@@ -22,12 +22,6 @@ namespace Robust.Shared.Map
/// </summary>
EntityUid GridEntityId { get; }
/// <summary>
/// The identifier of this grid.
/// </summary>
[Obsolete("Use EntityUids instead")]
GridId Index { get; }
/// <summary>
/// The length of the side of a square tile in world units.
/// </summary>

View File

@@ -92,19 +92,12 @@ namespace Robust.Shared.Map
void DeleteMap(MapId mapId);
[Obsolete("Use overload without GridId parameter instead")]
// ReSharper disable once MethodOverloadWithOptionalParameter
IMapGrid CreateGrid(MapId currentMapId, GridId? gridId = null, ushort chunkSize = 16);
IMapGrid CreateGrid(MapId currentMapId, ushort chunkSize = 16);
IMapGrid CreateGrid(MapId currentMapId, in GridCreateOptions options);
IMapGrid CreateGrid(MapId currentMapId);
[Obsolete("Use EntityUids instead")]
IMapGrid GetGrid(GridId gridId);
IMapGrid GetGrid(EntityUid gridId);
[Obsolete("Use EntityUids instead")]
bool TryGetGrid(GridId gridId, [NotNullWhen(true)] out IMapGrid? grid);
bool TryGetGrid([NotNullWhen(true)] EntityUid? euid, [NotNullWhen(true)] out IMapGrid? grid);
[Obsolete("Use EntityUids instead")]
bool GridExists(GridId gridId);
bool GridExists([NotNullWhen(true)] EntityUid? euid);
IEnumerable<IMapGrid> GetAllMapGrids(MapId mapId);
@@ -150,8 +143,7 @@ namespace Robust.Shared.Map
/// <param name="approx">Set to false if you wish to accurately get the grid bounds per-tile.</param>
IEnumerable<IMapGrid> FindGridsIntersecting(MapId mapId, Box2Rotated worldArea, bool approx = false);
[Obsolete("Delete the grid's entity instead")]
void DeleteGrid(GridId gridId);
void DeleteGrid(EntityUid euid);
/// <summary>
/// A tile is being modified.
@@ -190,10 +182,6 @@ namespace Robust.Shared.Map
[Obsolete("Whatever this is used for, it is a terrible idea. Create a new map and get it's MapId.")]
MapId NextMapId();
[Obsolete("Use EntityUids instead")]
EntityUid GetGridEuid(GridId id);
[Obsolete("Use EntityUids instead")]
IMapGridComponent GetGridComp(GridId id);
IMapGridComponent GetGridComp(EntityUid euid);
//
@@ -212,10 +200,6 @@ namespace Robust.Shared.Map
[Pure]
bool IsGridPaused(IMapGrid grid);
[Pure]
[Obsolete("Use EntityUids instead")]
bool IsGridPaused(GridId gridId);
[Pure]
bool IsGridPaused(EntityUid gridId);

View File

@@ -15,7 +15,7 @@ namespace Robust.Shared.Map
void OnComponentRemoved(MapGridComponent comp);
void ChunkRemoved(GridId gridId, MapChunk chunk);
void ChunkRemoved(EntityUid gridId, MapChunk chunk);
/// <summary>
/// Specific version of TryFindGridAt that allows re-usable data structures to be passed in for optimisation reasons.
@@ -46,11 +46,8 @@ namespace Robust.Shared.Map
/// <param name="oldTile">The old tile that got replaced.</param>
void RaiseOnTileChanged(TileRef tileRef, Tile oldTile);
bool TryGetGridComp(GridId id, [NotNullWhen(true)] out IMapGridComponent? comp);
bool TryGetGridEuid(GridId id, [NotNullWhen(true)] out EntityUid? euid);
void TrueGridDelete(MapGrid grid);
void TrueDeleteMap(MapId mapId);
GridId GenerateGridId(GridId? forcedGridId);
void OnGridAllocated(MapGridComponent gridComponent, MapGrid mapGrid);
void OnGridBoundsChange(EntityUid uid, MapGrid grid);
}

View File

@@ -76,11 +76,11 @@ namespace Robust.Shared.Map
/// <param name="entityManager"></param>
/// <param name="gridIndex">Index identifier of this grid.</param>
/// <param name="chunkSize">The dimension of this square chunk.</param>
internal MapGrid(IMapManagerInternal mapManager, IEntityManager entityManager, GridId gridIndex, ushort chunkSize)
internal MapGrid(IMapManagerInternal mapManager, IEntityManager entityManager, EntityUid gridEntityId, ushort chunkSize)
{
_mapManager = mapManager;
_entityManager = entityManager;
Index = gridIndex;
GridEntityId = gridEntityId;
ChunkSize = chunkSize;
LastTileModifiedTick = _mapManager.GameTiming.CurTick;
}
@@ -111,11 +111,6 @@ namespace Robust.Shared.Map
[ViewVariables]
public ushort ChunkSize { get; }
/// <inheritdoc />
[ViewVariables]
[Obsolete("Use EntityUids instead")]
public GridId Index { get; }
/// <summary>
/// The length of the side of a square tile in world units.
/// </summary>
@@ -218,7 +213,7 @@ namespace Robust.Shared.Map
if (!_chunks.TryGetValue(chunkIndices, out var output))
{
// Chunk doesn't exist, return a tileRef to an empty (space) tile.
return new TileRef(Index, GridEntityId, tileCoordinates.X, tileCoordinates.Y, default);
return new TileRef(GridEntityId, tileCoordinates.X, tileCoordinates.Y, default);
}
var chunkTileIndices = output.GridTileToChunkTile(tileCoordinates);
@@ -241,7 +236,7 @@ namespace Robust.Shared.Map
throw new ArgumentOutOfRangeException(nameof(yIndex), "Tile indices out of bounds.");
var indices = mapChunk.ChunkTileToGridTile(new Vector2i(xIndex, yIndex));
return new TileRef(Index, GridEntityId, indices, mapChunk.GetTile(xIndex, yIndex));
return new TileRef(GridEntityId, indices, mapChunk.GetTile(xIndex, yIndex));
}
/// <inheritdoc />
@@ -260,7 +255,7 @@ namespace Robust.Shared.Map
continue;
var (gridX, gridY) = new Vector2i(x, y) + chunk.Indices * ChunkSize;
yield return new TileRef(Index, GridEntityId, gridX, gridY, tile);
yield return new TileRef(GridEntityId, gridX, gridY, tile);
}
}
}
@@ -269,7 +264,7 @@ namespace Robust.Shared.Map
/// <inheritdoc />
public GridTileEnumerator GetAllTilesEnumerator(bool ignoreEmpty = true)
{
return new GridTileEnumerator(Index, GridEntityId, _chunks.GetEnumerator(), ChunkSize, ignoreEmpty);
return new GridTileEnumerator(GridEntityId, _chunks.GetEnumerator(), ChunkSize, ignoreEmpty);
}
/// <inheritdoc />
@@ -370,7 +365,7 @@ namespace Robust.Shared.Map
}
else if (!ignoreEmpty)
{
var tile = new TileRef(Index, GridEntityId, x, y, new Tile());
var tile = new TileRef(GridEntityId, x, y, new Tile());
if (predicate == null || predicate(tile))
yield return tile;
@@ -426,11 +421,11 @@ namespace Robust.Shared.Map
chunk.Fixtures.Clear();
_chunks.Remove(origin);
_mapManager.ChunkRemoved(Index, chunk);
_mapManager.ChunkRemoved(GridEntityId, chunk);
if (_chunks.Count == 0)
{
_entityManager.EventBus.RaiseLocalEvent(GridEntityId, new EmptyGridEvent {GridId = Index}, true);
_entityManager.EventBus.RaiseLocalEvent(GridEntityId, new EmptyGridEvent {GridId = GridEntityId}, true);
}
}
@@ -788,9 +783,9 @@ namespace Robust.Shared.Map
public EntityCoordinates MapToGrid(MapCoordinates posWorld)
{
if(posWorld.MapId != ParentMapId)
throw new ArgumentException($"Grid {Index} is on map {ParentMapId}, but coords are on map {posWorld.MapId}.", nameof(posWorld));
throw new ArgumentException($"Grid {GridEntityId} is on map {ParentMapId}, but coords are on map {posWorld.MapId}.", nameof(posWorld));
if (!_mapManager.TryGetGrid(Index, out var grid))
if (!_mapManager.TryGetGrid(GridEntityId, out var grid))
{
return new EntityCoordinates(_mapManager.GetMapEntityId(posWorld.MapId), (posWorld.X, posWorld.Y));
}
@@ -1019,7 +1014,7 @@ namespace Robust.Shared.Map
// ParentMapId is not able to be accessed on unbound grids, so we can't even call this function for unbound grids.
if(!_mapManager.SuppressOnTileChanged)
{
var newTileRef = new TileRef(Index, GridEntityId, gridTile, newTile);
var newTileRef = new TileRef(GridEntityId, gridTile, newTile);
_mapManager.RaiseOnTileChanged(newTileRef, oldTile);
}
@@ -1035,7 +1030,7 @@ namespace Robust.Shared.Map
/// </summary>
public sealed class EmptyGridEvent : EntityEventArgs
{
public GridId GridId { get; init; }
public EntityUid GridId { get; init; }
}
/// <summary>
@@ -1043,16 +1038,14 @@ namespace Robust.Shared.Map
/// </summary>
public struct GridTileEnumerator
{
private GridId _gridId;
private EntityUid _gridUid;
private Dictionary<Vector2i, MapChunk>.Enumerator _chunkEnumerator;
private readonly ushort _chunkSize;
private int _index;
private bool _ignoreEmpty;
internal GridTileEnumerator(GridId gridId, EntityUid gridUid, Dictionary<Vector2i, MapChunk>.Enumerator chunkEnumerator, ushort chunkSize, bool ignoreEmpty)
internal GridTileEnumerator(EntityUid gridUid, Dictionary<Vector2i, MapChunk>.Enumerator chunkEnumerator, ushort chunkSize, bool ignoreEmpty)
{
_gridId = gridId;
_gridUid = gridUid;
_chunkEnumerator = chunkEnumerator;
_chunkSize = chunkSize;
@@ -1087,7 +1080,7 @@ namespace Robust.Shared.Map
var gridX = x + chunkOrigin.X * _chunkSize;
var gridY = y + chunkOrigin.Y * _chunkSize;
tileRef = new TileRef(_gridId, _gridUid, gridX, gridY, tile);
tileRef = new TileRef(_gridUid, gridX, gridY, tile);
return true;
}
}

View File

@@ -61,65 +61,21 @@ public sealed class TileChangedEventArgs : EventArgs
internal partial class MapManager
{
private readonly Dictionary<GridId, EntityUid> _grids = new();
private readonly HashSet<EntityUid> _grids = new();
private GridId _highestGridId = GridId.Invalid;
public virtual void ChunkRemoved(GridId gridId, MapChunk chunk) { }
public EntityUid GetGridEuid(GridId id)
{
DebugTools.Assert(id != GridId.Invalid);
//This turns into a linear search with EntityQuery without the _grids mapping
return _grids[id];
}
public bool TryGetGridEuid(GridId id, [NotNullWhen(true)] out EntityUid? euid)
{
DebugTools.Assert(id != GridId.Invalid);
if (_grids.TryGetValue(id, out var result))
{
euid = result;
return true;
}
euid = null;
return false;
}
public IMapGridComponent GetGridComp(GridId id)
{
DebugTools.Assert(id != GridId.Invalid);
var euid = GetGridEuid(id);
return GetGridComp(euid);
}
public virtual void ChunkRemoved(EntityUid gridId, MapChunk chunk) { }
public IMapGridComponent GetGridComp(EntityUid euid)
{
return EntityManager.GetComponent<IMapGridComponent>(euid);
}
public bool TryGetGridComp(GridId id, [MaybeNullWhen(false)] out IMapGridComponent comp)
{
DebugTools.Assert(id != GridId.Invalid);
var euid = GetGridEuid(id);
if (EntityManager.TryGetComponent(euid, out comp))
return true;
comp = default;
return false;
}
/// <inheritdoc />
public void OnGridAllocated(MapGridComponent gridComponent, MapGrid mapGrid)
{
_grids.Add(mapGrid.Index, mapGrid.GridEntityId);
Logger.InfoS("map", $"Binding grid {mapGrid.Index} to entity {gridComponent.Owner}");
OnGridCreated?.Invoke(mapGrid.ParentMapId, mapGrid.Index);
_grids.Add(mapGrid.GridEntityId);
Logger.InfoS("map", $"Binding grid {mapGrid.GridEntityId} to entity {gridComponent.Owner}");
OnGridCreated?.Invoke(mapGrid.ParentMapId, mapGrid.GridEntityId);
}
public GridEnumerator GetAllGridsEnumerator()
@@ -132,21 +88,21 @@ internal partial class MapManager
{
var compQuery = EntityManager.GetEntityQuery<MapGridComponent>();
foreach (var (_, uid) in _grids)
foreach (var uid in _grids)
{
yield return compQuery.GetComponent(uid).Grid;
}
}
// ReSharper disable once MethodOverloadWithOptionalParameter
public IMapGrid CreateGrid(MapId currentMapId, GridId? forcedGridId = null, ushort chunkSize = 16)
public IMapGrid CreateGrid(MapId currentMapId, ushort chunkSize = 16)
{
return CreateGrid(currentMapId, forcedGridId, chunkSize, default);
return CreateGrid(currentMapId, chunkSize, default);
}
public IMapGrid CreateGrid(MapId currentMapId, in GridCreateOptions options)
{
return CreateGrid(currentMapId, null, options.ChunkSize, default);
return CreateGrid(currentMapId, options.ChunkSize, default);
}
public IMapGrid CreateGrid(MapId currentMapId)
@@ -154,14 +110,6 @@ internal partial class MapManager
return CreateGrid(currentMapId, GridCreateOptions.Default);
}
public IMapGrid GetGrid(GridId gridId)
{
DebugTools.Assert(gridId != GridId.Invalid);
var euid = GetGridEuid(gridId);
return GetGridComp(euid).Grid;
}
public IMapGrid GetGrid(EntityUid gridId)
{
DebugTools.Assert(gridId.IsValid());
@@ -186,32 +134,6 @@ internal partial class MapManager
return false;
}
[Obsolete("Use EntityUids")]
public bool TryGetGrid(GridId gridId, [MaybeNullWhen(false)] out IMapGrid grid)
{
// grid 0 compatibility
if (gridId == GridId.Invalid)
{
grid = default;
return false;
}
if (!TryGetGridEuid(gridId, out var euid))
{
grid = default;
return false;
}
return TryGetGrid(euid, out grid);
}
[Obsolete("Use EntityUids")]
public bool GridExists(GridId gridId)
{
// grid 0 compatibility
return gridId != GridId.Invalid && TryGetGridEuid(gridId, out var euid) && GridExists(euid);
}
public bool GridExists([NotNullWhen(true)] EntityUid? euid)
{
return EntityManager.HasComponent<IMapGridComponent>(euid);
@@ -231,31 +153,30 @@ internal partial class MapManager
enumerator = new FindGridsEnumerator(EntityManager, GetAllGrids().Cast<MapGrid>().GetEnumerator(), mapId, worldAabb, approx);
}
[Obsolete("Delete the grid's entity instead")]
public virtual void DeleteGrid(GridId gridId)
public virtual void DeleteGrid(EntityUid euid)
{
#if DEBUG
DebugTools.Assert(_dbgGuardRunning);
#endif
// Possible the grid was already deleted / is invalid
if (!TryGetGrid(gridId, out var iGrid))
if (!TryGetGrid(euid, out var iGrid))
{
DebugTools.Assert($"Calling {nameof(DeleteGrid)} with unknown id {gridId}.");
DebugTools.Assert($"Calling {nameof(DeleteGrid)} with unknown uid {euid}.");
return; // Silently fail on release
}
var grid = (MapGrid)iGrid;
if (grid.Deleting)
{
DebugTools.Assert($"Calling {nameof(DeleteGrid)} multiple times for grid {gridId}.");
DebugTools.Assert($"Calling {nameof(DeleteGrid)} multiple times for grid {euid}.");
return; // Silently fail on release
}
var entityId = grid.GridEntityId;
if (!EntityManager.TryGetComponent(entityId, out MetaDataComponent? metaComp))
{
DebugTools.Assert($"Calling {nameof(DeleteGrid)} with {gridId}, but there was no allocated entity.");
DebugTools.Assert($"Calling {nameof(DeleteGrid)} with {euid}, but there was no allocated entity.");
return; // Silently fail on release
}
@@ -270,14 +191,13 @@ internal partial class MapManager
grid.Deleting = true;
var mapId = grid.ParentMapId;
var gridId = grid.Index;
_grids.Remove(grid.Index);
_grids.Remove(grid.GridEntityId);
Logger.DebugS("map", $"Deleted grid {gridId}");
Logger.DebugS("map", $"Deleted grid {grid.GridEntityId}");
// TODO: Remove this trash
OnGridRemoved?.Invoke(mapId, gridId);
OnGridRemoved?.Invoke(mapId, grid.GridEntityId);
}
/// <inheritdoc />
@@ -298,8 +218,8 @@ internal partial class MapManager
public void OnComponentRemoved(MapGridComponent comp)
{
var gridIndex = comp.GridIndex;
if (gridIndex == GridId.Invalid)
var gridIndex = comp.Owner;
if (gridIndex == EntityUid.Invalid)
return;
if (!GridExists(gridIndex))
@@ -323,11 +243,11 @@ internal partial class MapManager
return;
TileChanged?.Invoke(this, new TileChangedEventArgs(tileRef, oldTile));
var euid = GetGridEuid(tileRef.GridIndex);
var euid = tileRef.GridUid;
EntityManager.EventBus.RaiseLocalEvent(euid, new TileChangedEvent(euid, tileRef, oldTile), true);
}
protected MapGrid CreateGrid(MapId currentMapId, GridId? forcedGridId, ushort chunkSize, EntityUid forcedGridEuid)
protected MapGrid CreateGrid(MapId currentMapId, ushort chunkSize, EntityUid forcedGridEuid)
{
var gridEnt = EntityManager.CreateEntityUninitialized(null, forcedGridEuid);
@@ -335,13 +255,11 @@ internal partial class MapManager
MapGrid grid;
using (var preInit = EntityManager.AddComponentUninitialized<MapGridComponent>(gridEnt))
{
var actualId = GenerateGridId(forcedGridId);
preInit.Comp.GridIndex = actualId; // Required because of MapGrid needing it in ctor
preInit.Comp.AllocMapGrid(chunkSize, 1);
grid = (MapGrid) preInit.Comp.Grid;
}
Logger.DebugS("map", $"Binding new grid {grid.Index} to entity {grid.GridEntityId}");
Logger.DebugS("map", $"Binding new grid {grid.GridEntityId}");
//TODO: This is a hack to get TransformComponent.MapId working before entity states
//are applied. After they are applied the parent may be different, but the MapId will
@@ -360,23 +278,4 @@ internal partial class MapManager
mapManager.GridChanged?.Invoke(mapManager, new GridChangedEventArgs(mapGrid, changedTiles));
mapManager.EntityManager.EventBus.RaiseLocalEvent(mapGrid.GridEntityId, new GridModifiedEvent(mapGrid, changedTiles), true);
}
public GridId GenerateGridId(GridId? forcedGridId)
{
var actualId = forcedGridId ?? new GridId(_highestGridId.Value + 1);
if(actualId == GridId.Invalid)
throw new InvalidOperationException($"Cannot allocate a grid with an Invalid ID.");
if (GridExists(actualId))
throw new InvalidOperationException($"A grid with ID {actualId} already exists");
if (_highestGridId.Value < actualId.Value)
_highestGridId = actualId;
if(forcedGridId is not null) // this function basically just passes forced gridIds through.
Logger.DebugS("map", $"Allocating new GridId {actualId}.");
return actualId;
}
}

View File

@@ -60,7 +60,7 @@ internal partial class MapManager
foreach (var grid in grids)
{
DeleteGrid(grid.Index);
DeleteGrid(grid.GridEntityId);
}
if (mapId != MapId.Nullspace)

View File

@@ -164,19 +164,6 @@ namespace Robust.Shared.Map
return IsMapPaused(grid.ParentMapId);
}
/// <inheritdoc />
[Obsolete("Use EntityUids instead")]
public bool IsGridPaused(GridId gridId)
{
if (TryGetGrid(gridId, out var grid))
{
return IsGridPaused(grid);
}
Logger.ErrorS("map", $"Tried to check if unknown grid {gridId} was paused.");
return true;
}
public bool IsGridPaused(EntityUid gridId)
{
if (TryGetGrid(gridId, out var grid))

View File

@@ -41,10 +41,7 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber
EnsureNullspaceExistsAndClear();
DebugTools.Assert(_grids.Count == 0);
#pragma warning disable CS0618
// Not really sure what to do with this. Can't hurt to leave it in.
DebugTools.Assert(!GridExists(GridId.Invalid));
#pragma warning restore CS0618
DebugTools.Assert(!GridExists(EntityUid.Invalid));
}
/// <inheritdoc />
@@ -63,9 +60,7 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber
#if DEBUG
DebugTools.Assert(_grids.Count == 0);
#pragma warning disable CS0618
DebugTools.Assert(!GridExists(GridId.Invalid));
#pragma warning restore CS0618
DebugTools.Assert(!GridExists(EntityUid.Invalid));
_dbgGuardRunning = false;
#endif
}

View File

@@ -23,16 +23,16 @@ internal interface INetworkedMapManager : IMapManagerInternal
internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager
{
private readonly Dictionary<GridId, List<(GameTick tick, Vector2i indices)>> _chunkDeletionHistory = new();
private readonly Dictionary<EntityUid, List<(GameTick tick, Vector2i indices)>> _chunkDeletionHistory = new();
public override void DeleteGrid(GridId gridId)
public override void DeleteGrid(EntityUid gridId)
{
base.DeleteGrid(gridId);
// No point syncing chunk removals anymore!
_chunkDeletionHistory.Remove(gridId);
}
public override void ChunkRemoved(GridId gridId, MapChunk chunk)
public override void ChunkRemoved(EntityUid gridId, MapChunk chunk)
{
base.ChunkRemoved(gridId, chunk);
if (!_chunkDeletionHistory.TryGetValue(gridId, out var chunks))
@@ -58,7 +58,7 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager
var chunkData = new List<GameStateMapData.ChunkDatum>();
if (_chunkDeletionHistory.TryGetValue(grid.Index, out var chunks))
if (_chunkDeletionHistory.TryGetValue(grid.GridEntityId, out var chunks))
{
foreach (var (tick, indices) in chunks)
{
@@ -115,7 +115,7 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager
}
private readonly List<(MapId mapId, EntityUid euid)> _newMaps = new();
private List<(MapId mapId, EntityUid euid, GridId gridId, ushort chunkSize)> _newGrids = new();
private List<(MapId mapId, EntityUid euid, ushort chunkSize)> _newGrids = new();
public void ApplyGameStatePre(GameStateMapData? data, ReadOnlySpan<EntityState> entityStates)
{
@@ -160,7 +160,7 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager
DebugTools.Assert(gridMapId != default, $"Could not find corresponding gridData for new grid {gridEuid}.");
_newGrids.Add((gridMapId, gridEuid, gridCompState.GridIndex, chunkSize));
_newGrids.Add((gridMapId, gridEuid, chunkSize));
}
}
}
@@ -173,9 +173,9 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager
_newMaps.Clear();
// create all the new grids
foreach (var (mapId, euid, gridId, chunkSize) in _newGrids)
foreach (var (mapId, euid, chunkSize) in _newGrids)
{
CreateGrid(mapId, gridId, chunkSize, euid);
CreateGrid(mapId, chunkSize, euid);
}
_newGrids.Clear();
}

View File

@@ -13,13 +13,7 @@ namespace Robust.Shared.Map
[PublicAPI]
public readonly struct TileRef : IEquatable<TileRef>, ISpanFormattable
{
public static TileRef Zero => new(GridId.Invalid, EntityUid.Invalid, Vector2i.Zero, Tile.Empty);
/// <summary>
/// Identifier of the <see cref="MapGrid"/> this Tile belongs to.
/// </summary>
[Obsolete("Use EntityUids instead")]
public readonly GridId GridIndex;
public static TileRef Zero => new(EntityUid.Invalid, Vector2i.Zero, Tile.Empty);
/// <summary>
/// Grid Entity this Tile belongs to.
@@ -44,8 +38,8 @@ namespace Robust.Shared.Map
/// <param name="xIndex">Positional X index of this tile on the grid.</param>
/// <param name="yIndex">Positional Y index of this tile on the grid.</param>
/// <param name="tile">Actual data of this tile.</param>
internal TileRef(GridId gridId, EntityUid gridUid, int xIndex, int yIndex, Tile tile)
: this(gridId, gridUid, new Vector2i(xIndex, yIndex), tile) { }
internal TileRef(EntityUid gridUid, int xIndex, int yIndex, Tile tile)
: this(gridUid, new Vector2i(xIndex, yIndex), tile) { }
/// <summary>
/// Constructs a new instance of TileRef.
@@ -54,9 +48,8 @@ namespace Robust.Shared.Map
/// <param name="gridUid">Identifier of the grid entity 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(GridId gridId, EntityUid gridUid, Vector2i gridIndices, Tile tile)
internal TileRef(EntityUid gridUid, Vector2i gridIndices, Tile tile)
{
GridIndex = gridId;
GridUid = gridUid;
GridIndices = gridIndices;
Tile = tile;
@@ -98,7 +91,7 @@ namespace Robust.Shared.Map
/// <inheritdoc />
public bool Equals(TileRef other)
{
return GridIndex.Equals(other.GridIndex) &&
return GridUid.Equals(other.GridUid) &&
GridIndices.Equals(other.GridIndices) &&
Tile.Equals(other.Tile);
}
@@ -132,7 +125,7 @@ namespace Robust.Shared.Map
{
unchecked
{
var hashCode = GridIndex.GetHashCode();
var hashCode = GridUid.GetHashCode();
hashCode = (hashCode * 397) ^ GridIndices.GetHashCode();
hashCode = (hashCode * 397) ^ Tile.GetHashCode();
return hashCode;

View File

@@ -201,6 +201,7 @@ namespace Robust.Shared.Prototypes
[BaseTypeRequired(typeof(IPrototype))]
[MeansImplicitUse]
[MeansDataDefinition]
[Virtual]
public class PrototypeAttribute : Attribute
{
private readonly string type;

View File

@@ -103,7 +103,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
Assert.Multiple(() =>
{
Assert.That(childTrans.MapID, Is.EqualTo(parentTrans.MapID));
Assert.That(childTrans.GridID, Is.EqualTo(parentTrans.GridID));
Assert.That(childTrans.GridUid, Is.EqualTo(parentTrans.GridUid));
Assert.That(childTrans.Coordinates, Is.EqualTo(new EntityCoordinates(parentTrans.Owner, (-1, -1))));
Assert.That(childTrans.WorldPosition, Is.EqualTo(new Vector2(4, 4)));
});

View File

@@ -43,7 +43,7 @@ namespace Robust.UnitTesting.Shared
Assert.That(lookup.GetEntitiesIntersecting(mapId, theMapSpotBeingUsed, LookupFlags.None).ToList(), Is.Empty);
entManager.DeleteEntity(dummy);
mapManager.DeleteGrid(grid.Index);
mapManager.DeleteGrid(grid.GridEntityId);
mapManager.DeleteMap(mapId);
}
@@ -84,7 +84,7 @@ namespace Robust.UnitTesting.Shared
Assert.That(lookup.GetEntitiesIntersecting(mapId, theMapSpotBeingUsed).ToList().Count, Is.EqualTo(1));
entManager.DeleteEntity(dummy);
mapManager.DeleteGrid(grid.Index);
mapManager.DeleteGrid(grid.GridEntityId);
mapManager.DeleteMap(mapId);
}
}

View File

@@ -62,7 +62,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
new EntityUid(512),
new []
{
new ComponentChange(0, new MapGridComponentState(new GridId(0), 16), default)
new ComponentChange(0, new MapGridComponentState(new EntityUid(0), 16), default)
}, default);
serializer.Serialize(stream, payload);

View File

@@ -137,8 +137,8 @@ namespace Robust.UnitTesting.Shared.Map
var mapEnt = mapManager.CreateNewMapEntity(mapId);
var newEnt = entityManager.CreateEntityUninitialized("dummy", new MapCoordinates(Vector2.Zero, mapId));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mapEnt).Coordinates.GetGridId(entityManager), Is.EqualTo(GridId.Invalid));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.GetGridId(entityManager), Is.EqualTo(GridId.Invalid));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mapEnt).Coordinates.GetGridUid(entityManager), Is.Null);
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.GetGridUid(entityManager), Is.Null);
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.EntityId, Is.EqualTo(mapEnt));
}
@@ -154,8 +154,8 @@ namespace Robust.UnitTesting.Shared.Map
var newEnt = entityManager.CreateEntityUninitialized("dummy", new EntityCoordinates(gridEnt, Vector2.Zero));
// Grids aren't parented to other grids.
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(gridEnt).Coordinates.GetGridId(entityManager), Is.EqualTo(GridId.Invalid));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.GetGridId(entityManager), Is.EqualTo(grid.Index));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(gridEnt).Coordinates.GetGridUid(entityManager), Is.Null);
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.GetGridUid(entityManager), Is.EqualTo(grid.GridEntityId));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.EntityId, Is.EqualTo(gridEnt));
}

View File

@@ -133,11 +133,11 @@ public sealed class GridSplit_Tests
// Assertions baby
Assert.That(anchoredXform.Anchored);
Assert.That(anchoredXform.ParentUid, Is.EqualTo(newGrid.GridEntityId));
Assert.That(anchoredXform.GridID, Is.EqualTo(newGrid.Index));
Assert.That(anchoredXform.GridUid, Is.EqualTo(newGrid.GridEntityId));
Assert.That(newGridXform._children, Does.Contain(anchored));
Assert.That(dummyXform.ParentUid, Is.EqualTo(newGrid.GridEntityId));
Assert.That(dummyXform.GridID, Is.EqualTo(newGrid.Index));
Assert.That(dummyXform.GridUid, Is.EqualTo(newGrid.GridEntityId));
Assert.That(newGridXform._children, Does.Contain(dummy));
});
mapManager.DeleteMap(mapId);

View File

@@ -30,7 +30,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var mapId = mapMan.CreateMap();
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8);
grid.SetTile(new Vector2i(-9, -1), new Tile(1, (TileRenderFlag)1, 1));
@@ -38,7 +38,7 @@ namespace Robust.UnitTesting.Shared.Map
Assert.That(grid.ChunkCount, Is.EqualTo(1));
Assert.That(grid.GetMapChunks().Keys.ToList()[0], Is.EqualTo(new Vector2i(-2, -1)));
Assert.That(result, Is.EqualTo(new TileRef(grid.Index, grid.GridEntityId, new Vector2i(-9,-1), new Tile(1, (TileRenderFlag)1, 1))));
Assert.That(result, Is.EqualTo(new TileRef(grid.GridEntityId, new Vector2i(-9,-1), new Tile(1, (TileRenderFlag)1, 1))));
}
/// <summary>
@@ -50,7 +50,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var mapId = mapMan.CreateMap();
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8);
grid.WorldPosition = new Vector2(3, 5);
grid.SetTile(new Vector2i(-1, -2), new Tile(1));
@@ -74,7 +74,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var mapId = mapMan.CreateMap();
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8);
grid.WorldPosition = new Vector2(3, 5);
grid.SetTile(new Vector2i(-1, -2), new Tile(1));
@@ -97,7 +97,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var mapId = mapMan.CreateMap();
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8);
var result = grid.GridTileToChunkIndices(new Vector2i(-9, -1));
@@ -113,7 +113,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var mapId = mapMan.CreateMap();
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8);
var result = grid.GridTileToLocal(new Vector2i(0, 0)).Position;
@@ -127,7 +127,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var mapId = mapMan.CreateMap();
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8);
var foundTile = grid.TryGetTileRef(new Vector2i(-9, -1), out var tileRef);
@@ -142,7 +142,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var mapId = mapMan.CreateMap();
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8);
grid.SetTile(new Vector2i(-9, -1), new Tile(1, (TileRenderFlag)1, 1));
@@ -151,7 +151,7 @@ namespace Robust.UnitTesting.Shared.Map
Assert.That(foundTile, Is.True);
Assert.That(grid.ChunkCount, Is.EqualTo(1));
Assert.That(grid.GetMapChunks().Keys.ToList()[0], Is.EqualTo(new Vector2i(-2, -1)));
Assert.That(tileRef, Is.EqualTo(new TileRef(grid.Index, grid.GridEntityId, new Vector2i(-9, -1), new Tile(1, (TileRenderFlag)1, 1))));
Assert.That(tileRef, Is.EqualTo(new TileRef(grid.GridEntityId, new Vector2i(-9, -1), new Tile(1, (TileRenderFlag)1, 1))));
}
[Test]
@@ -160,7 +160,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var mapId = mapMan.CreateMap();
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8);
grid.SetTile(new Vector2i(19, 23), new Tile(1));
@@ -175,7 +175,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var mapId = mapMan.CreateMap();
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8);
grid.SetTile(new Vector2i(19, 23), new Tile(1));

View File

@@ -46,11 +46,11 @@ namespace Robust.UnitTesting.Shared.Map
var mapID = new MapId(11);
mapMan.CreateMap(mapID);
var gridId = mapMan.CreateGrid(mapID).GridEntityId;
var grid = mapMan.CreateGrid(mapID);
mapMan.Restart();
Assert.That(mapMan.GridExists(gridId), Is.False);
Assert.That(mapMan.GridExists(grid.GridEntityId), Is.False);
}
/// <summary>
@@ -71,7 +71,7 @@ namespace Robust.UnitTesting.Shared.Map
mapMan.Restart();
Assert.That(mapMan.MapExists(MapId.Nullspace), Is.True);
Assert.That(mapMan.GridExists(GridId.Invalid), Is.False);
Assert.That(mapMan.GridExists(EntityUid.Invalid), Is.False);
Assert.That(entMan.Deleted(oldEntity), Is.True);
}