diff --git a/Robust.Client/Console/Commands/Debug.cs b/Robust.Client/Console/Commands/Debug.cs index 9f5caa603..269455d93 100644 --- a/Robust.Client/Console/Commands/Debug.cs +++ b/Robust.Client/Console/Commands/Debug.cs @@ -297,11 +297,12 @@ namespace Robust.Client.Console.Commands return; } + string gridId = args[0]; string indices = args[1]; - if (!EntityUid.TryParse(args[0], out var gridUid)) + if (!int.TryParse(args[0], out var id)) { - shell.WriteError($"{args[0]} is not a valid entity UID."); + shell.WriteError($"{args[0]} is not a valid integer."); return; } @@ -312,11 +313,14 @@ namespace Robust.Client.Console.Commands } var mapMan = IoCManager.Resolve(); - if (mapMan.TryGetGrid(gridUid, out var grid)) + + if (mapMan.GridExists(new GridId(int.Parse(gridId, CultureInfo.InvariantCulture)))) { - foreach (var entity in grid.GetAnchoredEntities(new Vector2i( - int.Parse(indices.Split(',')[0], CultureInfo.InvariantCulture), - int.Parse(indices.Split(',')[1], CultureInfo.InvariantCulture)))) + 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)))) { shell.WriteLine(entity.ToString()); } @@ -433,20 +437,22 @@ namespace Robust.Client.Console.Commands return; } - if (!EntityUid.TryParse(args[0], out var gridUid)) + if (!int.TryParse(args[0], out var id)) { - shell.WriteLine($"{args[0]} is not a valid entity UID."); + shell.WriteLine($"{args[0]} is not a valid integer."); return; } + var gridId = new GridId(int.Parse(args[0])); var mapManager = IoCManager.Resolve(); - if (mapManager.TryGetGrid(gridUid, out var grid)) + + if (mapManager.TryGetGrid(gridId, out var grid)) { - shell.WriteLine(grid.GetAllTiles().Count().ToString()); + shell.WriteLine(mapManager.GetGrid(gridId).GetAllTiles().Count().ToString()); } else { - shell.WriteError($"No grid exists with id {gridUid}"); + shell.WriteError($"No grid exists with id {id}"); } } } diff --git a/Robust.Client/Debugging/DebugAnchoringSystem.cs b/Robust.Client/Debugging/DebugAnchoringSystem.cs index 833219cc3..446acfad7 100644 --- a/Robust.Client/Debugging/DebugAnchoringSystem.cs +++ b/Robust.Client/Debugging/DebugAnchoringSystem.cs @@ -20,7 +20,7 @@ namespace Robust.Client.Debugging private Label? _label; - private (EntityUid GridId, TileRef Tile)? _hovered; + private (GridId 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.GridEntityId && _hovered?.Tile == tile) return; + if (_hovered?.GridId == grid.Index && _hovered?.Tile == tile) return; - _hovered = (grid.GridEntityId, tile); + _hovered = (grid.Index, tile); var text = new StringBuilder(); diff --git a/Robust.Client/GameObjects/Components/Light/ClientOccluderComponent.cs b/Robust.Client/GameObjects/Components/Light/ClientOccluderComponent.cs index 332087fef..2458682ba 100644 --- a/Robust.Client/GameObjects/Components/Light/ClientOccluderComponent.cs +++ b/Robust.Client/GameObjects/Components/Light/ClientOccluderComponent.cs @@ -13,7 +13,7 @@ namespace Robust.Client.GameObjects [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!; - [ViewVariables] private (EntityUid, Vector2i) _lastPosition; + [ViewVariables] private (GridId, Vector2i) _lastPosition; [ViewVariables] internal OccluderDir Occluding { get; private set; } [ViewVariables] internal uint UpdateGeneration { get; set; } @@ -46,9 +46,8 @@ namespace Robust.Client.GameObjects if(!xform.Anchored) return; - var gridId = xform.GridUid ?? throw new InvalidOperationException("Anchored without a grid"); - var grid = _mapManager.GetGrid(gridId); - _lastPosition = (gridId, grid.TileIndicesFor(xform.Coordinates)); + var grid = _mapManager.GetGrid(xform.GridID); + _lastPosition = (xform.GridID, grid.TileIndicesFor(xform.Coordinates)); } protected override void Shutdown() @@ -93,7 +92,7 @@ namespace Robust.Client.GameObjects if (!xform.Anchored) return; - var grid = _mapManager.GetGrid(xform.GridUid ?? throw new InvalidOperationException("Anchored without a grid")); + var grid = _mapManager.GetGrid(xform.GridID); var position = xform.Coordinates; void CheckDir(Direction dir, OccluderDir oclDir) { diff --git a/Robust.Client/GameObjects/Components/Renderable/SpriteComponent.cs b/Robust.Client/GameObjects/Components/Renderable/SpriteComponent.cs index 918a8ed19..74ecdae4c 100644 --- a/Robust.Client/GameObjects/Components/Renderable/SpriteComponent.cs +++ b/Robust.Client/GameObjects/Components/Renderable/SpriteComponent.cs @@ -1933,7 +1933,7 @@ namespace Robust.Client.GameObjects _ => textureSize }; } - + return Box2.CenteredAround(Offset, size * _scale); } diff --git a/Robust.Client/GameObjects/EntitySystems/ClientOccluderSystem.cs b/Robust.Client/GameObjects/EntitySystems/ClientOccluderSystem.cs index b3b4bc4f4..a7ed0ae43 100644 --- a/Robust.Client/GameObjects/EntitySystems/ClientOccluderSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/ClientOccluderSystem.cs @@ -81,7 +81,7 @@ namespace Robust.Client.GameObjects occluderQuery.HasComponent(sender)) { var xform = EntityManager.GetComponent(sender); - if (!_mapManager.TryGetGrid(xform.GridUid, out grid)) + if (!_mapManager.TryGetGrid(xform.GridID, out grid)) return; var coords = xform.Coordinates; @@ -122,13 +122,13 @@ namespace Robust.Client.GameObjects /// internal sealed class OccluderDirtyEvent : EntityEventArgs { - public OccluderDirtyEvent(EntityUid sender, (EntityUid grid, Vector2i pos)? lastPosition) + public OccluderDirtyEvent(EntityUid sender, (GridId grid, Vector2i pos)? lastPosition) { LastPosition = lastPosition; Sender = sender; } - public (EntityUid grid, Vector2i pos)? LastPosition { get; } + public (GridId grid, Vector2i pos)? LastPosition { get; } public EntityUid Sender { get; } } } diff --git a/Robust.Client/GameObjects/EntitySystems/EffectSystem.cs b/Robust.Client/GameObjects/EntitySystems/EffectSystem.cs index a80fb9243..703d1f4e0 100644 --- a/Robust.Client/GameObjects/EntitySystems/EffectSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/EffectSystem.cs @@ -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.GetGridUid(_entityManager))) + if (_mapManager.GridExists(EmitterCoordinates.GetGridId(_entityManager))) { //Calculate delta p due to radial velocity var positionRelativeToEmitter = diff --git a/Robust.Client/GameObjects/EntitySystems/GridRenderingSystem.cs b/Robust.Client/GameObjects/EntitySystems/GridRenderingSystem.cs index 631ecf60c..7489b4a13 100644 --- a/Robust.Client/GameObjects/EntitySystems/GridRenderingSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/GridRenderingSystem.cs @@ -3,7 +3,7 @@ using Robust.Shared.GameObjects; namespace Robust.Client.GameObjects; -internal sealed class GridRenderingSystem : EntitySystem +internal class GridRenderingSystem : EntitySystem { private readonly IClydeInternal _clyde; diff --git a/Robust.Client/GameObjects/EntitySystems/RenderingTreeSystem.cs b/Robust.Client/GameObjects/EntitySystems/RenderingTreeSystem.cs index b3f1951c7..1e69548f6 100644 --- a/Robust.Client/GameObjects/EntitySystems/RenderingTreeSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/RenderingTreeSystem.cs @@ -241,7 +241,7 @@ namespace Robust.Client.GameObjects private void MapManagerOnGridCreated(GridInitializeEvent ev) { - EntityManager.EnsureComponent(_mapManager.GetGrid(ev.EntityUid).GridEntityId); + EntityManager.EnsureComponent(_mapManager.GetGrid(ev.GridId).GridEntityId); } private RenderingTreeComponent? GetRenderTree(EntityUid entity, TransformComponent xform, EntityQuery xforms) diff --git a/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs b/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs index 6d107fc04..7c9778623 100644 --- a/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs +++ b/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs @@ -13,7 +13,7 @@ namespace Robust.Client.Graphics.Clyde { [Dependency] private readonly IEntityManager _entityManager = default!; - private readonly Dictionary> _mapChunkData = + private readonly Dictionary> _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.GridEntityId)) + if (!_mapChunkData.ContainsKey(grid.Index)) { continue; } @@ -58,7 +58,7 @@ namespace Robust.Client.Graphics.Clyde _updateChunkMesh(grid, chunk); } - var datum = _mapChunkData[grid.GridEntityId][chunk.Indices]; + var datum = _mapChunkData[grid.Index][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.GridEntityId]; + var data = _mapChunkData[grid.Index]; 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.GridEntityId} chunk {chunk.Indices} VBO"); + vboSize, $"Grid {grid.Index} chunk {chunk.Indices} VBO"); var ebo = new GLBuffer(this, BufferTarget.ElementArrayBuffer, BufferUsageHint.DynamicDraw, - eboSize, $"Grid {grid.GridEntityId} chunk {chunk.Indices} EBO"); + eboSize, $"Grid {grid.Index} chunk {chunk.Indices} EBO"); - ObjectLabelMaybe(ObjectLabelIdentifier.VertexArray, vao, $"Grid {grid.GridEntityId} chunk {chunk.Indices} VAO"); + ObjectLabelMaybe(ObjectLabelIdentifier.VertexArray, vao, $"Grid {grid.Index} chunk {chunk.Indices} VAO"); SetupVAOLayout(); CheckGlError(); @@ -163,19 +163,19 @@ namespace Robust.Client.Graphics.Clyde Dirty = true }; - _mapChunkData[grid.GridEntityId].Add(chunk.Indices, datum); + _mapChunkData[grid.Index].Add(chunk.Indices, datum); return datum; } private bool _isChunkDirty(IMapGrid grid, MapChunk chunk) { - var data = _mapChunkData[grid.GridEntityId]; + var data = _mapChunkData[grid.Index]; return !data.TryGetValue(chunk.Indices, out var datum) || datum.Dirty; } public void _setChunkDirty(IMapGrid grid, Vector2i chunk) { - var data = _mapChunkData[grid.GridEntityId]; + var data = _mapChunkData[grid.Index]; 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.GridUid); + var grid = _mapManager.GetGrid(args.NewTile.GridIndex); var chunk = grid.GridTileToChunkIndices(new Vector2i(args.NewTile.X, args.NewTile.Y)); _setChunkDirty(grid, chunk); } private void _updateOnGridCreated(GridStartupEvent ev) { - var gridId = ev.EntityUid; + var gridId = ev.GridId; _mapChunkData.Add(gridId, new Dictionary()); } private void _updateOnGridRemoved(GridRemovalEvent ev) { - var gridId = ev.EntityUid; + var gridId = ev.GridId; var data = _mapChunkData[gridId]; foreach (var chunkDatum in data.Values) diff --git a/Robust.Client/Graphics/Clyde/Windowing/Sdl2.Windows.cs b/Robust.Client/Graphics/Clyde/Windowing/Sdl2.Windows.cs index ecdc0f207..b4d11e070 100644 --- a/Robust.Client/Graphics/Clyde/Windowing/Sdl2.Windows.cs +++ b/Robust.Client/Graphics/Clyde/Windowing/Sdl2.Windows.cs @@ -498,9 +498,7 @@ 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. diff --git a/Robust.Client/Graphics/Clyde/Windowing/Sdl2.cs b/Robust.Client/Graphics/Clyde/Windowing/Sdl2.cs index b631f6e8e..35e4af295 100644 --- a/Robust.Client/Graphics/Clyde/Windowing/Sdl2.cs +++ b/Robust.Client/Graphics/Clyde/Windowing/Sdl2.cs @@ -16,6 +16,7 @@ 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; diff --git a/Robust.Client/Placement/Modes/AlignSnapgridBorder.cs b/Robust.Client/Placement/Modes/AlignSnapgridBorder.cs index 21c0ce0f0..ed2fd446c 100644 --- a/Robust.Client/Placement/Modes/AlignSnapgridBorder.cs +++ b/Robust.Client/Placement/Modes/AlignSnapgridBorder.cs @@ -1,5 +1,4 @@ using System; -using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -19,9 +18,9 @@ namespace Robust.Client.Placement.Modes { MouseCoords = ScreenToCursorGrid(mouseScreen); - var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager); + var gridId = MouseCoords.GetGridId(pManager.EntityManager); SnapSize = 1f; - if (gridIdOpt is EntityUid gridId && gridId.IsValid()) + if (gridId.IsValid()) { Grid = pManager.MapManager.GetGrid(gridId); SnapSize = Grid.TileSize; //Find snap size for the grid. diff --git a/Robust.Client/Placement/Modes/AlignSnapgridCenter.cs b/Robust.Client/Placement/Modes/AlignSnapgridCenter.cs index 00edb67b1..83c8f465b 100644 --- a/Robust.Client/Placement/Modes/AlignSnapgridCenter.cs +++ b/Robust.Client/Placement/Modes/AlignSnapgridCenter.cs @@ -51,9 +51,9 @@ namespace Robust.Client.Placement.Modes { MouseCoords = ScreenToCursorGrid(mouseScreen); - var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager); + var gridId = MouseCoords.GetGridId(pManager.EntityManager); SnapSize = 1f; - if (gridIdOpt is EntityUid gridId && gridId.IsValid()) + if (gridId.IsValid()) { Grid = pManager.MapManager.GetGrid(gridId); SnapSize = Grid.TileSize; //Find snap size for the grid. diff --git a/Robust.Client/Placement/Modes/AlignTileAny.cs b/Robust.Client/Placement/Modes/AlignTileAny.cs index dc92ad0f9..3568b2b41 100644 --- a/Robust.Client/Placement/Modes/AlignTileAny.cs +++ b/Robust.Client/Placement/Modes/AlignTileAny.cs @@ -16,7 +16,7 @@ namespace Robust.Client.Placement.Modes MouseCoords = ScreenToCursorGrid(mouseScreen).AlignWithClosestGridTile(SearchBoxSize, pManager.EntityManager, pManager.MapManager); - var gridId = MouseCoords.GetGridUid(pManager.EntityManager); + var gridId = MouseCoords.GetGridId(pManager.EntityManager); if (!pManager.MapManager.TryGetGrid(gridId, out var mapGrid)) return; diff --git a/Robust.Client/Placement/Modes/AlignTileDense.cs b/Robust.Client/Placement/Modes/AlignTileDense.cs index 30c0f1c73..afa35e144 100644 --- a/Robust.Client/Placement/Modes/AlignTileDense.cs +++ b/Robust.Client/Placement/Modes/AlignTileDense.cs @@ -1,5 +1,4 @@ -using Robust.Shared.GameObjects; -using Robust.Shared.Map; +using Robust.Shared.Map; namespace Robust.Client.Placement.Modes { @@ -15,11 +14,11 @@ namespace Robust.Client.Placement.Modes MouseCoords = ScreenToCursorGrid(mouseScreen); var tileSize = 1f; - var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager); + var gridId = MouseCoords.GetGridId(pManager.EntityManager); - if (gridIdOpt is EntityUid gridId && gridId.IsValid()) + if (gridId.IsValid()) { - var mapGrid = pManager.MapManager.GetGrid(gridId); + var mapGrid = pManager.MapManager.GetGrid(MouseCoords.GetGridId(pManager.EntityManager)); tileSize = mapGrid.TileSize; //convert from ushort to float } diff --git a/Robust.Client/Placement/Modes/AlignTileEmpty.cs b/Robust.Client/Placement/Modes/AlignTileEmpty.cs index f5dc8dabf..dda0e846b 100644 --- a/Robust.Client/Placement/Modes/AlignTileEmpty.cs +++ b/Robust.Client/Placement/Modes/AlignTileEmpty.cs @@ -17,11 +17,11 @@ namespace Robust.Client.Placement.Modes MouseCoords = ScreenToCursorGrid(mouseScreen); var tileSize = 1f; - var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager); + var gridId = MouseCoords.GetGridId(pManager.EntityManager); - if (gridIdOpt is EntityUid gridId && gridId.IsValid()) + if (gridId.IsValid()) { - var mapGrid = pManager.MapManager.GetGrid(gridId); + var mapGrid = pManager.MapManager.GetGrid(MouseCoords.GetGridId(pManager.EntityManager)); CurrentTile = mapGrid.GetTileRef(MouseCoords); tileSize = mapGrid.TileSize; //convert from ushort to float } diff --git a/Robust.Client/Placement/Modes/AlignTileNonDense.cs b/Robust.Client/Placement/Modes/AlignTileNonDense.cs index 1cde193d8..598480dfd 100644 --- a/Robust.Client/Placement/Modes/AlignTileNonDense.cs +++ b/Robust.Client/Placement/Modes/AlignTileNonDense.cs @@ -1,5 +1,4 @@ -using Robust.Shared.GameObjects; -using Robust.Shared.Map; +using Robust.Shared.Map; namespace Robust.Client.Placement.Modes { @@ -16,8 +15,8 @@ namespace Robust.Client.Placement.Modes var tileSize = 1f; - var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager); - if (gridIdOpt is EntityUid gridId && gridId.IsValid()) + var gridId = MouseCoords.GetGridId(pManager.EntityManager); + if (gridId.IsValid()) { var mapGrid = pManager.MapManager.GetGrid(gridId); tileSize = mapGrid.TileSize; //convert from ushort to float diff --git a/Robust.Client/Placement/PlacementManager.cs b/Robust.Client/Placement/PlacementManager.cs index 28d9aca7a..5f9a90b80 100644 --- a/Robust.Client/Placement/PlacementManager.cs +++ b/Robust.Client/Placement/PlacementManager.cs @@ -334,7 +334,7 @@ namespace Robust.Client.Placement private void HandleTileChanged(TileChangedEvent args) { - var coords = MapManager.GetGrid(args.NewTile.GridUid).GridTileToLocal(args.NewTile.GridIndices); + var coords = MapManager.GetGrid(args.NewTile.GridIndex).GridTileToLocal(args.NewTile.GridIndices); _pendingTileChanges.RemoveAll(c => c.Item1 == coords); } @@ -740,9 +740,9 @@ namespace Robust.Client.Placement if (CurrentPermission.IsTile) { - var gridIdOpt = coordinates.GetGridUid(EntityManager); + var gridId = coordinates.GetGridId(EntityManager); // If we have actually placed something on a valid grid... - if (gridIdOpt is EntityUid gridId && gridId.IsValid()) + if (gridId.IsValid()) { var grid = MapManager.GetGrid(gridId); diff --git a/Robust.Client/Placement/PlacementMode.cs b/Robust.Client/Placement/PlacementMode.cs index a64ddc39c..e59e34b0f 100644 --- a/Robust.Client/Placement/PlacementMode.cs +++ b/Robust.Client/Placement/PlacementMode.cs @@ -171,9 +171,10 @@ namespace Robust.Client.Placement /// public TileRef GetTileRef(EntityCoordinates coordinates) { - var gridUidOpt = coordinates.GetGridUid(pManager.EntityManager); - return gridUidOpt is EntityUid gridUid && gridUid.IsValid() ? pManager.MapManager.GetGrid(gridUid).GetTileRef(MouseCoords) - : new TileRef(gridUidOpt ?? EntityUid.Invalid, + 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(), MouseCoords.ToVector2i(pManager.EntityManager, pManager.MapManager), Tile.Empty); } diff --git a/Robust.Client/UserInterface/CustomControls/DebugCoordsPanel.cs b/Robust.Client/UserInterface/CustomControls/DebugCoordsPanel.cs index ed7d3f4e9..01ddf8b62 100644 --- a/Robust.Client/UserInterface/CustomControls/DebugCoordsPanel.cs +++ b/Robust.Client/UserInterface/CustomControls/DebugCoordsPanel.cs @@ -76,7 +76,8 @@ namespace Robust.Client.UserInterface.CustomControls { mouseGridPos = new EntityCoordinates(_mapManager.GetMapEntityId(mouseWorldMap.MapId), mouseWorldMap.Position); - tile = new TileRef(EntityUid.Invalid, mouseGridPos.ToVector2i(_entityManager, _mapManager), Tile.Empty); + tile = new TileRef(GridId.Invalid, EntityUid.Invalid, + mouseGridPos.ToVector2i(_entityManager, _mapManager), Tile.Empty); } var controlHovered = UserInterfaceManager.CurrentlyHovered; @@ -105,14 +106,14 @@ Mouse Pos: var playerCoordinates = entityTransform.Coordinates; var playerRotation = entityTransform.WorldRotation; - Angle gridRotation = _mapManager.TryGetGrid(entityTransform.GridUid, out var grid) ? grid.WorldRotation : Angle.Zero; + Angle gridRotation = _mapManager.TryGetGrid(entityTransform.GridID, out var grid) ? grid.WorldRotation : Angle.Zero; _textBuilder.Append($@" Screen: {playerScreen} {playerWorldOffset} {playerCoordinates} Rotation: {playerRotation.Degrees:F2}° EntId: {entityTransform.Owner} - GridUid: {entityTransform.GridUid} + GridID: {entityTransform.GridID} Grid Rotation: {gridRotation.Degrees:F2}°"); } diff --git a/Robust.Client/ViewVariables/Editors/VVPropEditorEntityCoordinates.cs b/Robust.Client/ViewVariables/Editors/VVPropEditorEntityCoordinates.cs index 17657e66c..319e406f0 100644 --- a/Robust.Client/ViewVariables/Editors/VVPropEditorEntityCoordinates.cs +++ b/Robust.Client/ViewVariables/Editors/VVPropEditorEntityCoordinates.cs @@ -30,7 +30,7 @@ namespace Robust.Client.ViewVariables.Editors HorizontalExpand = true, PlaceHolder = "Grid ID", ToolTip = "Grid ID", - Text = coords.GetGridUid(entityManager)?.ToString() ?? "" + Text = coords.GetGridId(entityManager).ToString() }; hBoxContainer.AddChild(gridId); @@ -61,12 +61,12 @@ namespace Robust.Client.ViewVariables.Editors void OnEntered(LineEdit.LineEditEventArgs e) { - var gridVal = EntityUid.Parse(gridId.Text); + var gridVal = int.Parse(gridId.Text, CultureInfo.InvariantCulture); var mapManager = IoCManager.Resolve(); var xVal = float.Parse(x.Text, CultureInfo.InvariantCulture); var yVal = float.Parse(y.Text, CultureInfo.InvariantCulture); - if (!mapManager.TryGetGrid(gridVal, out var grid)) + if (!mapManager.TryGetGrid(new GridId(gridVal), out var grid)) { ValueChanged(new EntityCoordinates(EntityUid.Invalid, (xVal, yVal))); return; diff --git a/Robust.Server/Bql/BqlQuerySelector.Builtin.cs b/Robust.Server/Bql/BqlQuerySelector.Builtin.cs index 2830962a7..1936c1328 100644 --- a/Robust.Server/Bql/BqlQuerySelector.Builtin.cs +++ b/Robust.Server/Bql/BqlQuerySelector.Builtin.cs @@ -187,7 +187,7 @@ namespace Robust.Server.Bql var map = IoCManager.Resolve(); if (tileTy.TileId == 0) { - return input.Where(e => entityManager.TryGetComponent(e, out var transform) && (transform.GridUid is null) ^ isInverted); + return input.Where(e => entityManager.TryGetComponent(e, out var transform) && (transform.GridID == GridId.Invalid) ^ isInverted); } else { @@ -195,7 +195,8 @@ namespace Robust.Server.Bql { if (!entityManager.TryGetComponent(e, out var transform)) return isInverted; - if (!map.TryGetGrid(transform.GridUid, out var grid)) + var gridId = transform.GridID; + if (!map.TryGetGrid(gridId, out var grid)) return isInverted; return (grid.GetTileRef(transform.Coordinates).Tile.TypeId == tileTy.TileId) ^ isInverted; @@ -216,8 +217,8 @@ namespace Robust.Server.Bql public override IEnumerable DoSelection(IEnumerable input, IReadOnlyList arguments, bool isInverted, IEntityManager entityManager) { // TODO: Probably easier and significantly faster to just iterate the grid's children. - var grid = new EntityUid((int) arguments[0]); - return input.Where(e => (entityManager.TryGetComponent(e, out var transform) && transform.GridUid == grid) ^ isInverted); + var grid = new GridId((int) arguments[0]); + return input.Where(e => (entityManager.TryGetComponent(e, out var transform) && transform.GridID == grid) ^ isInverted); } } diff --git a/Robust.Server/Console/Commands/MapCommands.cs b/Robust.Server/Console/Commands/MapCommands.cs index 04d8ce6d3..014c997cb 100644 --- a/Robust.Server/Console/Commands/MapCommands.cs +++ b/Robust.Server/Console/Commands/MapCommands.cs @@ -408,7 +408,7 @@ namespace Robust.Server.Console.Commands var pos = pt.Coordinates; shell.WriteLine( - $"MapID:{pos.GetMapId(entityManager)} GridUid:{pos.GetGridUid(entityManager)} X:{pos.X:N2} Y:{pos.Y:N2}"); + $"MapID:{pos.GetMapId(entityManager)} GridID:{pos.GetGridId(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 = EntityUid.Parse(args[0]); + var gridId = new GridId(int.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 = EntityUid.Parse(args[0]); + var gridId = new GridId(int.Parse(args[0])); var mapManager = IoCManager.Resolve(); if (!mapManager.GridExists(gridId)) { - shell.WriteError($"Grid {gridId} does not exist."); + shell.WriteError($"Grid {gridId.Value} does not exist."); return; } mapManager.DeleteGrid(gridId); - shell.WriteLine($"Grid {gridId} was removed."); + shell.WriteLine($"Grid {gridId.Value} 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.GridEntityId))); + string.Join(",", mapManager.GetAllMapGrids(mapId).Select(grid => grid.Index))); } shell.WriteLine(msg.ToString()); @@ -545,13 +545,13 @@ namespace Robust.Server.Console.Commands var msg = new StringBuilder(); var xformQuery = entManager.GetEntityQuery(); - foreach (var grid in mapManager.GetAllGrids().OrderBy(grid => grid.GridEntityId)) + foreach (var grid in mapManager.GetAllGrids().OrderBy(grid => grid.Index.Value)) { 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.GridEntityId, xform.MapID, grid.GridEntityId, worldPos.X, worldPos.Y); + grid.Index, xform.MapID, grid.GridEntityId, worldPos.X, worldPos.Y); } shell.WriteLine(msg.ToString()); diff --git a/Robust.Server/GameObjects/EntitySystems/MapSystem.cs b/Robust.Server/GameObjects/EntitySystems/MapSystem.cs index 3496dba5f..9db20ccfb 100644 --- a/Robust.Server/GameObjects/EntitySystems/MapSystem.cs +++ b/Robust.Server/GameObjects/EntitySystems/MapSystem.cs @@ -38,7 +38,7 @@ namespace Robust.Server.GameObjects foreach (var grid in toDelete) { - MapManager.DeleteGrid(grid.GridEntityId); + MapManager.DeleteGrid(grid.Index); } } } diff --git a/Robust.Server/GameStates/PVSCollection.cs b/Robust.Server/GameStates/PVSCollection.cs index fc81e48f8..2e31951da 100644 --- a/Robust.Server/GameStates/PVSCollection.cs +++ b/Robust.Server/GameStates/PVSCollection.cs @@ -23,7 +23,7 @@ public interface IPVSCollection /// Adds a player session to the collection. Returns false if the player was already present. /// public bool AddPlayer(ICommonSession session); - public void AddGrid(EntityUid gridId); + public void AddGrid(GridId gridId); public void AddMap(MapId mapId); /// @@ -31,7 +31,7 @@ public interface IPVSCollection /// public bool RemovePlayer(ICommonSession session); - public void RemoveGrid(EntityUid gridId); + public void RemoveGrid(GridId gridId); public void RemoveMap(MapId mapId); @@ -67,7 +67,7 @@ public sealed class PVSCollection : IPVSCollection where TIndex : ICompa /// /// Index of which are contained in which gridchunk, indexed by . /// - private readonly Dictionary>> _gridChunkContents = new(); + private readonly Dictionary>> _gridChunkContents = new(); /// /// List of that should always get sent. @@ -190,7 +190,7 @@ public sealed class PVSCollection : IPVSCollection where TIndex : ICompa public bool TryGetChunk(MapId mapId, Vector2i chunkIndices, [NotNullWhen(true)] out HashSet? indices) => _mapChunkContents[mapId].TryGetValue(chunkIndices, out indices); - public bool TryGetChunk(EntityUid gridId, Vector2i chunkIndices, [NotNullWhen(true)] out HashSet? indices) => + public bool TryGetChunk(GridId gridId, Vector2i chunkIndices, [NotNullWhen(true)] out HashSet? indices) => _gridChunkContents[gridId].TryGetValue(chunkIndices, out indices); public HashSet.Enumerator GetElementsForSession(ICommonSession session) => _localOverrides[session].GetEnumerator(); @@ -262,7 +262,7 @@ public sealed class PVSCollection : IPVSCollection where TIndex : ICompa } /// - public void AddGrid(EntityUid gridId) => _gridChunkContents[gridId] = new(); + public void AddGrid(GridId gridId) => _gridChunkContents[gridId] = new(); /// public void AddMap(MapId mapId) => _mapChunkContents[mapId] = new(); @@ -286,7 +286,7 @@ public sealed class PVSCollection : IPVSCollection where TIndex : ICompa } /// - public void RemoveGrid(EntityUid gridId) + public void RemoveGrid(GridId gridId) { foreach (var (_, indices) in _gridChunkContents[gridId]) { @@ -399,8 +399,8 @@ public sealed class PVSCollection : IPVSCollection where TIndex : ICompa if(!removeFromOverride && IsOverride(index)) return; - var gridIdOpt = coordinates.GetGridUid(_entityManager); - if (gridIdOpt is EntityUid gridId && gridId.IsValid()) + var gridId = coordinates.GetGridId(_entityManager); + if (gridId != GridId.Invalid) { 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 : IPVSCollection where TIndex : ICompa public IChunkIndexLocation GetChunkIndex(EntityCoordinates coordinates) { - var gridIdOpt = coordinates.GetGridUid(_entityManager); - if (gridIdOpt is EntityUid gridId && gridId.IsValid()) + var gridId = coordinates.GetGridId(_entityManager); + if (gridId != GridId.Invalid) { var gridIndices = GetChunkIndices(coordinates.Position); return new GridChunkLocation(gridId, gridIndices); @@ -433,7 +433,7 @@ public sealed class PVSCollection : IPVSCollection where TIndex : ICompa /// The id of the grid. /// The indices of the chunk. /// An index at an override position will not be updated unless you set this flag. - public void UpdateIndex(TIndex index, EntityUid gridId, Vector2i chunkIndices, bool removeFromOverride = false) + public void UpdateIndex(TIndex index, GridId 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 { - public GridChunkLocation(EntityUid gridId, Vector2i chunkIndices) + public GridChunkLocation(GridId gridId, Vector2i chunkIndices) { GridId = gridId; ChunkIndices = chunkIndices; } - public EntityUid GridId { get; init; } + public GridId GridId { get; init; } public Vector2i ChunkIndices { get; init; } public bool Equals(GridChunkLocation other) diff --git a/Robust.Server/GameStates/PVSSystem.cs b/Robust.Server/GameStates/PVSSystem.cs index e6738f0fa..6d47ae4e8 100644 --- a/Robust.Server/GameStates/PVSSystem.cs +++ b/Robust.Server/GameStates/PVSSystem.cs @@ -407,19 +407,20 @@ internal sealed partial class PVSSystem : EntitySystem { foreach (var pvsCollection in _pvsCollections) { - pvsCollection.RemoveGrid(ev.EntityUid); + pvsCollection.RemoveGrid(ev.GridId); } } private void OnGridCreated(GridInitializeEvent ev) { - var gridId = ev.EntityUid; + var gridId = ev.GridId; foreach (var pvsCollection in _pvsCollections) { pvsCollection.AddGrid(gridId); } - _entityPvsCollection.UpdateIndex(gridId); + var euid = _mapManager.GetGridEuid(gridId); + _entityPvsCollection.UpdateIndex(euid); } private void OnMapDestroyed(MapChangedEvent e) @@ -533,7 +534,7 @@ internal sealed partial class PVSSystem : EntitySystem while (gridChunkEnumerator.MoveNext(out var gridChunkIndices)) { - var chunkLocation = new GridChunkLocation(mapGrid.GridEntityId, gridChunkIndices.Value); + var chunkLocation = new GridChunkLocation(mapGrid.Index, gridChunkIndices.Value); var entry = (visMask, chunkLocation); if (gridDict.TryGetValue(chunkLocation, out var indexOf)) diff --git a/Robust.Server/Maps/MapLoader.cs b/Robust.Server/Maps/MapLoader.cs index c1402b8fd..80d213c14 100644 --- a/Robust.Server/Maps/MapLoader.cs +++ b/Robust.Server/Maps/MapLoader.cs @@ -246,6 +246,7 @@ namespace Robust.Server.Maps /// Handles the primary bulk of state during the map serialization process. /// internal sealed class MapContext : ISerializationContext, IEntityLoadContext, + ITypeSerializer, ITypeSerializer, ITypeReaderWriter { @@ -262,8 +263,9 @@ namespace Robust.Server.Maps /// If we're using savemap and not savebp then save everything on map. /// internal MapId? MapId { get; set; } - private readonly Dictionary GridIDMap = new(); + private readonly Dictionary GridIDMap = new(); public readonly List Grids = new(); + private readonly List _readGridIndices = new(); private EntityQuery? _xformQuery = null; private readonly Dictionary EntityUidMap = new(); @@ -313,10 +315,12 @@ namespace Robust.Server.Maps RootNode = new MappingDataNode(); TypeWriters = new Dictionary() { + {typeof(GridId), this}, {typeof(EntityUid), this} }; TypeReaders = new Dictionary<(Type, Type), object>() { + {(typeof(GridId), typeof(ValueDataNode)), this}, {(typeof(EntityUid), typeof(ValueDataNode)), this} }; } @@ -340,10 +344,12 @@ namespace Robust.Server.Maps _prototypeManager = prototypeManager; TypeWriters = new Dictionary() { + {typeof(GridId), this}, {typeof(EntityUid), this} }; TypeReaders = new Dictionary<(Type, Type), object>() { + {(typeof(GridId), typeof(ValueDataNode)), this}, {(typeof(EntityUid), typeof(ValueDataNode)), this} }; } @@ -360,6 +366,9 @@ 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(); @@ -530,18 +539,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("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 MapGridComponent[yamlGrids.Count]; + var gridComps = new Dictionary(_readGridIndices.Count); var gridQuery = _serverEntityManager.GetEntityQuery(); @@ -554,16 +563,22 @@ 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 < yamlGrids.Count; index++) + for (var index = 0; index < _readGridIndices.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[index]; + var gridComp = gridComps[gridIndex]; + + DebugTools.Assert(gridComp.GridIndex == gridIndex); MappingDataNode yamlGridInfo = (MappingDataNode)yamlGrid["settings"]; SequenceDataNode yamlGridChunks = (SequenceDataNode)yamlGrid["chunks"]; @@ -678,6 +693,18 @@ namespace Robust.Server.Maps } } + private void ReadGridSectionIndices() + { + // sets up the mapping so the serializer can properly deserialize GridIds. + + var yamlGrids = RootNode.Get("grids"); + + for (var i = 0; i < yamlGrids.Count; i++) + { + _readGridIndices.Add(_mapManager.GenerateGridId(null)); + } + } + private void AllocMap() { // Both blueprint and map deserialization use this, @@ -856,13 +883,13 @@ namespace Robust.Server.Maps // Serialization public void RegisterGrid(IMapGrid grid) { - if (GridIDMap.ContainsKey(grid.GridEntityId)) + if (GridIDMap.ContainsKey(grid.Index)) { throw new InvalidOperationException(); } Grids.Add((MapGrid) grid); - GridIDMap.Add(grid.GridEntityId, GridIDMap.Count); + GridIDMap.Add(grid.Index, GridIDMap.Count); } public YamlNode Serialize() @@ -933,8 +960,7 @@ namespace Robust.Server.Maps foreach (var entity in _serverEntityManager.GetEntities()) { var currentTransform = transformCompQuery.GetComponent(entity); - if (MapId != null && currentTransform.MapID != MapId) continue; - if (MapId == null && (!(currentTransform.GridUid is EntityUid gridId) || !GridIDMap.ContainsKey(gridId))) continue; + if ((MapId != null && currentTransform.MapID != MapId) || (MapId == null && !GridIDMap.ContainsKey(currentTransform.GridID))) continue; var currentEntity = entity; @@ -1084,6 +1110,28 @@ 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.Validate(ISerializationManager serializationManager, ValueDataNode node, IDependencyCollection dependencies, ISerializationContext? context) { @@ -1100,6 +1148,19 @@ namespace Robust.Server.Maps return new ValidatedValueNode(node); } + ValidationNode ITypeValidator.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) @@ -1121,6 +1182,21 @@ 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.Read(ISerializationManager serializationManager, ValueDataNode node, IDependencyCollection dependencies, @@ -1145,6 +1221,14 @@ 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, diff --git a/Robust.Server/Physics/GridFixtureSystem.cs b/Robust.Server/Physics/GridFixtureSystem.cs index 44b023347..2f352addc 100644 --- a/Robust.Server/Physics/GridFixtureSystem.cs +++ b/Robust.Server/Physics/GridFixtureSystem.cs @@ -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 EntityUid[grids.Count - 1]; + var newGrids = new GridId[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.GridEntityId; + newGrids[i] = splitGrid.Index; // 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.GridEntityId, tilePos, LookupFlags.None)) + foreach (var ent in _lookup.GetEntitiesIntersecting(mapGrid.Index, 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.GridEntityId); + var ev = new GridSplitEvent(newGrids, mapGrid.Index); RaiseLocalEvent(uid, ref ev, true); _logger.Debug($"Split {grids.Count} grids in {sw.Elapsed}"); @@ -745,14 +745,14 @@ public readonly struct GridSplitEvent /// /// Contains the IDs of the newly created grids. /// - public readonly EntityUid[] NewGrids; + public readonly GridId[] NewGrids; /// /// The grid that has been split. /// - public readonly EntityUid Grid; + public readonly GridId Grid; - public GridSplitEvent(EntityUid[] newGrids, EntityUid grid) + public GridSplitEvent(GridId[] newGrids, GridId grid) { NewGrids = newGrids; Grid = grid; diff --git a/Robust.Shared/GameObjects/Components/Map/MapGridComponent.cs b/Robust.Shared/GameObjects/Components/Map/MapGridComponent.cs index 9b9f3e9b0..57824e925 100644 --- a/Robust.Shared/GameObjects/Components/Map/MapGridComponent.cs +++ b/Robust.Shared/GameObjects/Components/Map/MapGridComponent.cs @@ -17,6 +17,8 @@ namespace Robust.Shared.GameObjects /// public interface IMapGridComponent : IComponent { + [Obsolete("Use EntityUids instead")] + GridId GridIndex { get; } IMapGrid Grid { get; } } @@ -32,16 +34,20 @@ namespace Robust.Shared.GameObjects // If you want to remove this, you would have to restructure the map save file. [ViewVariables(VVAccess.ReadOnly)] [DataField("index")] - private int _gridIndex = 0; - - internal int GridIndex - { - get => _gridIndex; - set => _gridIndex = value; - } +#pragma warning disable CS0618 + private GridId _gridIndex = GridId.Invalid; +#pragma warning restore CS0618 private IMapGrid? _mapGrid; + /// + [Obsolete("Use EntityUid instead")] + public GridId GridIndex + { + get => _gridIndex; + internal set => _gridIndex = value; + } + [DataField("chunkSize")] private ushort _chunkSize = 16; @@ -76,7 +82,7 @@ namespace Robust.Shared.GameObjects /// public override ComponentState GetComponentState() { - return new MapGridComponentState(Owner, _chunkSize); + return new MapGridComponentState(_gridIndex, _chunkSize); } /// @@ -87,6 +93,7 @@ namespace Robust.Shared.GameObjects if (curState is not MapGridComponentState state) return; + _gridIndex = state.GridIndex; _chunkSize = state.ChunkSize; } @@ -94,10 +101,13 @@ namespace Robust.Shared.GameObjects { DebugTools.Assert(LifeStage == ComponentLifeStage.Added); - var grid = new MapGrid(_mapManager, _entMan, Owner, chunkSize); +#pragma warning disable CS0618 + var grid = new MapGrid(_mapManager, _entMan, GridIndex, chunkSize); +#pragma warning restore CS0618 grid.TileSize = tileSize; Grid = grid; + grid.GridEntityId = Owner; _mapManager.OnGridAllocated(this, grid); return grid; @@ -164,7 +174,7 @@ namespace Robust.Shared.GameObjects /// /// Index of the grid this component is linked to. /// - public EntityUid GridIndex { get; } + public GridId GridIndex { get; } /// /// The size of the chunks in the map grid. @@ -176,7 +186,7 @@ namespace Robust.Shared.GameObjects /// /// Index of the grid this component is linked to. /// The size of the chunks in the map grid. - public MapGridComponentState(EntityUid gridIndex, ushort chunkSize) + public MapGridComponentState(GridId gridIndex, ushort chunkSize) { GridIndex = gridIndex; ChunkSize = chunkSize; diff --git a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs index fab1d1ae7..3016402bc 100644 --- a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs +++ b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs @@ -85,6 +85,14 @@ 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; + } + /// /// Disables or enables to ability to locally rotate the entity. When set it removes any local rotation. /// @@ -398,7 +406,7 @@ namespace Robust.Shared.GameObjects /// /// Local offset of this entity relative to its parent - /// ( if it's not null, to otherwise). + /// ( if it's not null, to otherwise). /// [Animatable] [ViewVariables(VVAccess.ReadWrite)] diff --git a/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs b/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs index bedd1ea96..6127a87ff 100644 --- a/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs +++ b/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs @@ -457,6 +457,13 @@ public sealed partial class EntityLookupSystem #region Grid Methods + [Obsolete("Use Grid EntityUid")] + public HashSet GetEntitiesIntersecting(GridId gridId, IEnumerable gridIndices, LookupFlags flags = DefaultFlags) + { + if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet(); + return GetEntitiesIntersecting(grid.GridEntityId, gridIndices, flags); + } + /// /// Returns the entities intersecting any of the supplied tiles. Faster than doing each tile individually. /// @@ -497,6 +504,13 @@ public sealed partial class EntityLookupSystem return intersecting; } + [Obsolete("Use Grid EntityUid")] + public HashSet GetEntitiesIntersecting(GridId gridId, Vector2i gridIndices, LookupFlags flags = DefaultFlags) + { + if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet(); + return GetEntitiesIntersecting(grid.GridEntityId, gridIndices, flags); + } + public HashSet GetEntitiesIntersecting(EntityUid gridId, Vector2i gridIndices, LookupFlags flags = DefaultFlags) { // Technically this doesn't consider anything overlapping from outside the grid but is this an issue? @@ -527,6 +541,13 @@ public sealed partial class EntityLookupSystem return intersecting; } + [Obsolete("Use grid EntityUid")] + public HashSet GetEntitiesIntersecting(GridId gridId, Box2 worldAABB, LookupFlags flags = DefaultFlags) + { + if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet(); + return GetEntitiesIntersecting(grid.GridEntityId, worldAABB, flags); + } + public HashSet GetEntitiesIntersecting(EntityUid gridId, Box2 worldAABB, LookupFlags flags = DefaultFlags) { if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet(); @@ -549,6 +570,13 @@ public sealed partial class EntityLookupSystem return intersecting; } + [Obsolete("Use grid EntityUid")] + public HashSet GetEntitiesIntersecting(GridId gridId, Box2Rotated worldBounds, LookupFlags flags = DefaultFlags) + { + if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet(); + return GetEntitiesIntersecting(grid.GridEntityId, worldBounds, flags); + } + public HashSet GetEntitiesIntersecting(EntityUid gridId, Box2Rotated worldBounds, LookupFlags flags = DefaultFlags) { if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet(); diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs index 71754be4c..29695f015 100644 --- a/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs @@ -46,19 +46,21 @@ namespace Robust.Shared.GameObjects private void OnGridInit(EntityUid uid, MapGridComponent component, ComponentInit args) { - var msg = new GridInitializeEvent(uid); +#pragma warning disable CS0618 + var msg = new GridInitializeEvent(uid, component.GridIndex); RaiseLocalEvent(uid, msg, true); } private void OnGridStartup(EntityUid uid, MapGridComponent component, ComponentStartup args) { - var msg = new GridStartupEvent(uid); +#pragma warning disable CS0618 + var msg = new GridStartupEvent(uid, component.GridIndex); RaiseLocalEvent(uid, msg, true); } private void OnGridRemove(EntityUid uid, MapGridComponent component, ComponentShutdown args) { - RaiseLocalEvent(uid, new GridRemovalEvent(uid), true); + RaiseLocalEvent(uid, new GridRemovalEvent(uid, component.GridIndex), true); MapManager.OnComponentRemoved(component); } } @@ -97,20 +99,26 @@ namespace Robust.Shared.GameObjects public sealed class GridStartupEvent : EntityEventArgs { public EntityUid EntityUid { get; } + [Obsolete("Use EntityUids")] + public GridId GridId { get; } - public GridStartupEvent(EntityUid uid) + public GridStartupEvent(EntityUid uid, GridId gridId) { EntityUid = uid; + GridId = gridId; } } public sealed class GridRemovalEvent : EntityEventArgs { public EntityUid EntityUid { get; } + [Obsolete("Use EntityUids")] + public GridId GridId { get; } - public GridRemovalEvent(EntityUid uid) + public GridRemovalEvent(EntityUid uid, GridId gridId) { EntityUid = uid; + GridId = gridId; } } @@ -120,10 +128,13 @@ namespace Robust.Shared.GameObjects public sealed class GridInitializeEvent : EntityEventArgs { public EntityUid EntityUid { get; } + [Obsolete("Use EntityUids")] + public GridId GridId { get; } - public GridInitializeEvent(EntityUid uid) + public GridInitializeEvent(EntityUid uid, GridId gridId) { EntityUid = uid; + GridId = gridId; } } #pragma warning restore CS0618 diff --git a/Robust.Shared/Map/CoordinatesExtensions.cs b/Robust.Shared/Map/CoordinatesExtensions.cs index e3a17b655..5e8a6fafd 100644 --- a/Robust.Shared/Map/CoordinatesExtensions.cs +++ b/Robust.Shared/Map/CoordinatesExtensions.cs @@ -7,6 +7,17 @@ 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); diff --git a/Robust.Shared/Map/EntityCoordinates.cs b/Robust.Shared/Map/EntityCoordinates.cs index 7bc0d17f3..fcb530313 100644 --- a/Robust.Shared/Map/EntityCoordinates.cs +++ b/Robust.Shared/Map/EntityCoordinates.cs @@ -150,10 +150,11 @@ namespace Robust.Shared.Map if(!IsValid(entityManager)) return new Vector2i(); - var gridIdOpt = GetGridUid(entityManager); - if (gridIdOpt is EntityUid gridId && gridId.IsValid()) + var gridId = GetGridUid(entityManager); + + if (gridId != null) { - return mapManager.GetGrid(gridId).GetTileRef(this).GridIndices; + return mapManager.GetGrid(gridId.Value).GetTileRef(this).GridIndices; } var (x, y) = ToMapPos(entityManager); @@ -203,6 +204,26 @@ namespace Robust.Shared.Map return new EntityCoordinates(entity, localPos); } + /// + /// Returns the Grid Id these coordinates are on. + /// If none of the ancestors are a grid, returns grid instead. + /// + /// + /// Grid Id this entity is on or + [Obsolete("Use GetGridUid")] + public GridId GetGridId(IEntityManager entityManager) + { + if (!IsValid(entityManager)) + return GridId.Invalid; + + var uid = entityManager.GetComponent(EntityId).GridUid; + + if (uid == null) + return GridId.Invalid; + + return entityManager.GetComponent(uid.Value).GridIndex; + } + /// /// Returns the Grid EntityUid these coordinates are on. /// If none of the ancestors are a grid, returns null instead. diff --git a/Robust.Shared/Map/GridEnumerator.cs b/Robust.Shared/Map/GridEnumerator.cs index 621e38d40..87bc6c27c 100644 --- a/Robust.Shared/Map/GridEnumerator.cs +++ b/Robust.Shared/Map/GridEnumerator.cs @@ -8,10 +8,10 @@ namespace Robust.Shared.Map; [Obsolete("EntityQuery for MapGridComponent instead")] public struct GridEnumerator { - private IEnumerator _enumerator; + private Dictionary.Enumerator _enumerator; private EntityQuery _query; - internal GridEnumerator(IEnumerator enumerator, EntityQuery query) + internal GridEnumerator(Dictionary.Enumerator enumerator, EntityQuery query) { _enumerator = enumerator; _query = query; @@ -25,7 +25,9 @@ public struct GridEnumerator return false; } - grid = _query.GetComponent(_enumerator.Current).Grid; + var (_, uid) = _enumerator.Current; + + grid = _query.GetComponent(uid).Grid; return true; } } diff --git a/Robust.Shared/Map/GridEventHandler.cs b/Robust.Shared/Map/GridEventHandler.cs index d0f6f3747..40830c119 100644 --- a/Robust.Shared/Map/GridEventHandler.cs +++ b/Robust.Shared/Map/GridEventHandler.cs @@ -7,5 +7,5 @@ namespace Robust.Shared.Map /// /// Passed to the delegate given it may no longer be retrievable. /// The index of the grid being changed. - public delegate void GridEventHandler(MapId mapId, EntityUid gridId); + public delegate void GridEventHandler(MapId mapId, GridId gridId); } diff --git a/Robust.Shared/Map/GridId.cs b/Robust.Shared/Map/GridId.cs new file mode 100644 index 000000000..1a64fb2a7 --- /dev/null +++ b/Robust.Shared/Map/GridId.cs @@ -0,0 +1,76 @@ +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 + { + /// + /// An invalid grid ID. + /// + public static readonly GridId Invalid = new(0); + + internal readonly int Value; + + /// + /// Constructs a new instance of . + /// + /// + /// 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 . + /// + public GridId(int value) + { + Value = value; + } + + public bool IsValid() + { + return Value > 0; + } + + /// + public bool Equals(GridId other) + { + return Value == other.Value; + } + + /// + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is GridId id && Equals(id); + } + + /// + 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(); + } + } +} diff --git a/Robust.Shared/Map/IMapGrid.cs b/Robust.Shared/Map/IMapGrid.cs index b6cdc70af..1aef8fc9c 100644 --- a/Robust.Shared/Map/IMapGrid.cs +++ b/Robust.Shared/Map/IMapGrid.cs @@ -22,6 +22,12 @@ namespace Robust.Shared.Map /// EntityUid GridEntityId { get; } + /// + /// The identifier of this grid. + /// + [Obsolete("Use EntityUids instead")] + GridId Index { get; } + /// /// The length of the side of a square tile in world units. /// diff --git a/Robust.Shared/Map/IMapManager.cs b/Robust.Shared/Map/IMapManager.cs index 14caf7350..ce1ea3294 100644 --- a/Robust.Shared/Map/IMapManager.cs +++ b/Robust.Shared/Map/IMapManager.cs @@ -92,12 +92,19 @@ namespace Robust.Shared.Map void DeleteMap(MapId mapId); + [Obsolete("Use overload without GridId parameter instead")] // ReSharper disable once MethodOverloadWithOptionalParameter - IMapGrid CreateGrid(MapId currentMapId, ushort chunkSize = 16); + IMapGrid CreateGrid(MapId currentMapId, GridId? gridId = null, 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 GetAllMapGrids(MapId mapId); @@ -143,7 +150,8 @@ namespace Robust.Shared.Map /// Set to false if you wish to accurately get the grid bounds per-tile. IEnumerable FindGridsIntersecting(MapId mapId, Box2Rotated worldArea, bool approx = false); - void DeleteGrid(EntityUid euid); + [Obsolete("Delete the grid's entity instead")] + void DeleteGrid(GridId gridId); /// /// A tile is being modified. @@ -182,6 +190,10 @@ 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); // @@ -200,6 +212,10 @@ namespace Robust.Shared.Map [Pure] bool IsGridPaused(IMapGrid grid); + [Pure] + [Obsolete("Use EntityUids instead")] + bool IsGridPaused(GridId gridId); + [Pure] bool IsGridPaused(EntityUid gridId); diff --git a/Robust.Shared/Map/IMapManagerInternal.cs b/Robust.Shared/Map/IMapManagerInternal.cs index 8697c88ff..a31f7d3cd 100644 --- a/Robust.Shared/Map/IMapManagerInternal.cs +++ b/Robust.Shared/Map/IMapManagerInternal.cs @@ -15,7 +15,7 @@ namespace Robust.Shared.Map void OnComponentRemoved(MapGridComponent comp); - void ChunkRemoved(EntityUid gridId, MapChunk chunk); + void ChunkRemoved(GridId gridId, MapChunk chunk); /// /// Specific version of TryFindGridAt that allows re-usable data structures to be passed in for optimisation reasons. @@ -46,8 +46,11 @@ namespace Robust.Shared.Map /// The old tile that got replaced. 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); } diff --git a/Robust.Shared/Map/MapGrid.cs b/Robust.Shared/Map/MapGrid.cs index ff33f55bf..691e2ceaa 100644 --- a/Robust.Shared/Map/MapGrid.cs +++ b/Robust.Shared/Map/MapGrid.cs @@ -76,11 +76,11 @@ namespace Robust.Shared.Map /// /// Index identifier of this grid. /// The dimension of this square chunk. - internal MapGrid(IMapManagerInternal mapManager, IEntityManager entityManager, EntityUid gridEntityId, ushort chunkSize) + internal MapGrid(IMapManagerInternal mapManager, IEntityManager entityManager, GridId gridIndex, ushort chunkSize) { _mapManager = mapManager; _entityManager = entityManager; - GridEntityId = gridEntityId; + Index = gridIndex; ChunkSize = chunkSize; LastTileModifiedTick = _mapManager.GameTiming.CurTick; } @@ -111,6 +111,11 @@ namespace Robust.Shared.Map [ViewVariables] public ushort ChunkSize { get; } + /// + [ViewVariables] + [Obsolete("Use EntityUids instead")] + public GridId Index { get; } + /// /// The length of the side of a square tile in world units. /// @@ -213,7 +218,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(GridEntityId, tileCoordinates.X, tileCoordinates.Y, default); + return new TileRef(Index, GridEntityId, tileCoordinates.X, tileCoordinates.Y, default); } var chunkTileIndices = output.GridTileToChunkTile(tileCoordinates); @@ -236,7 +241,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(GridEntityId, indices, mapChunk.GetTile(xIndex, yIndex)); + return new TileRef(Index, GridEntityId, indices, mapChunk.GetTile(xIndex, yIndex)); } /// @@ -255,7 +260,7 @@ namespace Robust.Shared.Map continue; var (gridX, gridY) = new Vector2i(x, y) + chunk.Indices * ChunkSize; - yield return new TileRef(GridEntityId, gridX, gridY, tile); + yield return new TileRef(Index, GridEntityId, gridX, gridY, tile); } } } @@ -264,7 +269,7 @@ namespace Robust.Shared.Map /// public GridTileEnumerator GetAllTilesEnumerator(bool ignoreEmpty = true) { - return new GridTileEnumerator(GridEntityId, _chunks.GetEnumerator(), ChunkSize, ignoreEmpty); + return new GridTileEnumerator(Index, GridEntityId, _chunks.GetEnumerator(), ChunkSize, ignoreEmpty); } /// @@ -365,7 +370,7 @@ namespace Robust.Shared.Map } else if (!ignoreEmpty) { - var tile = new TileRef(GridEntityId, x, y, new Tile()); + var tile = new TileRef(Index, GridEntityId, x, y, new Tile()); if (predicate == null || predicate(tile)) yield return tile; @@ -421,11 +426,11 @@ namespace Robust.Shared.Map chunk.Fixtures.Clear(); _chunks.Remove(origin); - _mapManager.ChunkRemoved(GridEntityId, chunk); + _mapManager.ChunkRemoved(Index, chunk); if (_chunks.Count == 0) { - _entityManager.EventBus.RaiseLocalEvent(GridEntityId, new EmptyGridEvent {GridId = GridEntityId}, true); + _entityManager.EventBus.RaiseLocalEvent(GridEntityId, new EmptyGridEvent {GridId = Index}, true); } } @@ -783,9 +788,9 @@ namespace Robust.Shared.Map public EntityCoordinates MapToGrid(MapCoordinates posWorld) { if(posWorld.MapId != ParentMapId) - throw new ArgumentException($"Grid {GridEntityId} is on map {ParentMapId}, but coords are on map {posWorld.MapId}.", nameof(posWorld)); + throw new ArgumentException($"Grid {Index} is on map {ParentMapId}, but coords are on map {posWorld.MapId}.", nameof(posWorld)); - if (!_mapManager.TryGetGrid(GridEntityId, out var grid)) + if (!_mapManager.TryGetGrid(Index, out var grid)) { return new EntityCoordinates(_mapManager.GetMapEntityId(posWorld.MapId), (posWorld.X, posWorld.Y)); } @@ -1014,7 +1019,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(GridEntityId, gridTile, newTile); + var newTileRef = new TileRef(Index, GridEntityId, gridTile, newTile); _mapManager.RaiseOnTileChanged(newTileRef, oldTile); } @@ -1030,7 +1035,7 @@ namespace Robust.Shared.Map /// public sealed class EmptyGridEvent : EntityEventArgs { - public EntityUid GridId { get; init; } + public GridId GridId { get; init; } } /// @@ -1038,14 +1043,16 @@ namespace Robust.Shared.Map /// public struct GridTileEnumerator { + private GridId _gridId; private EntityUid _gridUid; private Dictionary.Enumerator _chunkEnumerator; private readonly ushort _chunkSize; private int _index; private bool _ignoreEmpty; - internal GridTileEnumerator(EntityUid gridUid, Dictionary.Enumerator chunkEnumerator, ushort chunkSize, bool ignoreEmpty) + internal GridTileEnumerator(GridId gridId, EntityUid gridUid, Dictionary.Enumerator chunkEnumerator, ushort chunkSize, bool ignoreEmpty) { + _gridId = gridId; _gridUid = gridUid; _chunkEnumerator = chunkEnumerator; _chunkSize = chunkSize; @@ -1080,7 +1087,7 @@ namespace Robust.Shared.Map var gridX = x + chunkOrigin.X * _chunkSize; var gridY = y + chunkOrigin.Y * _chunkSize; - tileRef = new TileRef(_gridUid, gridX, gridY, tile); + tileRef = new TileRef(_gridId, _gridUid, gridX, gridY, tile); return true; } } diff --git a/Robust.Shared/Map/MapManager.GridCollection.cs b/Robust.Shared/Map/MapManager.GridCollection.cs index c193cbaa0..fdaa2d23f 100644 --- a/Robust.Shared/Map/MapManager.GridCollection.cs +++ b/Robust.Shared/Map/MapManager.GridCollection.cs @@ -61,21 +61,65 @@ public sealed class TileChangedEventArgs : EventArgs internal partial class MapManager { - private readonly HashSet _grids = new(); + private readonly Dictionary _grids = new(); - public virtual void ChunkRemoved(EntityUid gridId, MapChunk chunk) { } + 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 IMapGridComponent GetGridComp(EntityUid euid) { return EntityManager.GetComponent(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; + } + /// public void OnGridAllocated(MapGridComponent gridComponent, MapGrid mapGrid) { - _grids.Add(mapGrid.GridEntityId); - Logger.InfoS("map", $"Binding grid {mapGrid.GridEntityId} to entity {gridComponent.Owner}"); - OnGridCreated?.Invoke(mapGrid.ParentMapId, mapGrid.GridEntityId); + _grids.Add(mapGrid.Index, mapGrid.GridEntityId); + Logger.InfoS("map", $"Binding grid {mapGrid.Index} to entity {gridComponent.Owner}"); + OnGridCreated?.Invoke(mapGrid.ParentMapId, mapGrid.Index); } public GridEnumerator GetAllGridsEnumerator() @@ -88,21 +132,21 @@ internal partial class MapManager { var compQuery = EntityManager.GetEntityQuery(); - 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, ushort chunkSize = 16) + public IMapGrid CreateGrid(MapId currentMapId, GridId? forcedGridId = null, ushort chunkSize = 16) { - return CreateGrid(currentMapId, chunkSize, default); + return CreateGrid(currentMapId, forcedGridId, chunkSize, default); } public IMapGrid CreateGrid(MapId currentMapId, in GridCreateOptions options) { - return CreateGrid(currentMapId, options.ChunkSize, default); + return CreateGrid(currentMapId, null, options.ChunkSize, default); } public IMapGrid CreateGrid(MapId currentMapId) @@ -110,6 +154,14 @@ 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()); @@ -134,6 +186,32 @@ 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(euid); @@ -153,30 +231,31 @@ internal partial class MapManager enumerator = new FindGridsEnumerator(EntityManager, GetAllGrids().Cast().GetEnumerator(), mapId, worldAabb, approx); } - public virtual void DeleteGrid(EntityUid euid) + [Obsolete("Delete the grid's entity instead")] + public virtual void DeleteGrid(GridId gridId) { #if DEBUG DebugTools.Assert(_dbgGuardRunning); #endif // Possible the grid was already deleted / is invalid - if (!TryGetGrid(euid, out var iGrid)) + if (!TryGetGrid(gridId, out var iGrid)) { - DebugTools.Assert($"Calling {nameof(DeleteGrid)} with unknown uid {euid}."); + DebugTools.Assert($"Calling {nameof(DeleteGrid)} with unknown id {gridId}."); return; // Silently fail on release } var grid = (MapGrid)iGrid; if (grid.Deleting) { - DebugTools.Assert($"Calling {nameof(DeleteGrid)} multiple times for grid {euid}."); + DebugTools.Assert($"Calling {nameof(DeleteGrid)} multiple times for grid {gridId}."); return; // Silently fail on release } var entityId = grid.GridEntityId; if (!EntityManager.TryGetComponent(entityId, out MetaDataComponent? metaComp)) { - DebugTools.Assert($"Calling {nameof(DeleteGrid)} with {euid}, but there was no allocated entity."); + DebugTools.Assert($"Calling {nameof(DeleteGrid)} with {gridId}, but there was no allocated entity."); return; // Silently fail on release } @@ -191,13 +270,14 @@ internal partial class MapManager grid.Deleting = true; var mapId = grid.ParentMapId; + var gridId = grid.Index; - _grids.Remove(grid.GridEntityId); + _grids.Remove(grid.Index); - Logger.DebugS("map", $"Deleted grid {grid.GridEntityId}"); + Logger.DebugS("map", $"Deleted grid {gridId}"); // TODO: Remove this trash - OnGridRemoved?.Invoke(mapId, grid.GridEntityId); + OnGridRemoved?.Invoke(mapId, gridId); } /// @@ -218,8 +298,8 @@ internal partial class MapManager public void OnComponentRemoved(MapGridComponent comp) { - var gridIndex = comp.Owner; - if (gridIndex == EntityUid.Invalid) + var gridIndex = comp.GridIndex; + if (gridIndex == GridId.Invalid) return; if (!GridExists(gridIndex)) @@ -243,11 +323,11 @@ internal partial class MapManager return; TileChanged?.Invoke(this, new TileChangedEventArgs(tileRef, oldTile)); - var euid = tileRef.GridUid; + var euid = GetGridEuid(tileRef.GridIndex); EntityManager.EventBus.RaiseLocalEvent(euid, new TileChangedEvent(euid, tileRef, oldTile), true); } - protected MapGrid CreateGrid(MapId currentMapId, ushort chunkSize, EntityUid forcedGridEuid) + protected MapGrid CreateGrid(MapId currentMapId, GridId? forcedGridId, ushort chunkSize, EntityUid forcedGridEuid) { var gridEnt = EntityManager.CreateEntityUninitialized(null, forcedGridEuid); @@ -255,11 +335,13 @@ internal partial class MapManager MapGrid grid; using (var preInit = EntityManager.AddComponentUninitialized(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.GridEntityId}"); + Logger.DebugS("map", $"Binding new grid {grid.Index} to entity {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 @@ -278,4 +360,23 @@ 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; + } } diff --git a/Robust.Shared/Map/MapManager.MapCollection.cs b/Robust.Shared/Map/MapManager.MapCollection.cs index 79da7ef0c..a4a24cbe9 100644 --- a/Robust.Shared/Map/MapManager.MapCollection.cs +++ b/Robust.Shared/Map/MapManager.MapCollection.cs @@ -60,7 +60,7 @@ internal partial class MapManager foreach (var grid in grids) { - DeleteGrid(grid.GridEntityId); + DeleteGrid(grid.Index); } if (mapId != MapId.Nullspace) diff --git a/Robust.Shared/Map/MapManager.Pause.cs b/Robust.Shared/Map/MapManager.Pause.cs index 8f32a0524..cae9a6804 100644 --- a/Robust.Shared/Map/MapManager.Pause.cs +++ b/Robust.Shared/Map/MapManager.Pause.cs @@ -164,6 +164,19 @@ namespace Robust.Shared.Map return IsMapPaused(grid.ParentMapId); } + /// + [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)) diff --git a/Robust.Shared/Map/MapManager.cs b/Robust.Shared/Map/MapManager.cs index a568e2b23..91fa157ac 100644 --- a/Robust.Shared/Map/MapManager.cs +++ b/Robust.Shared/Map/MapManager.cs @@ -41,7 +41,10 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber EnsureNullspaceExistsAndClear(); DebugTools.Assert(_grids.Count == 0); - DebugTools.Assert(!GridExists(EntityUid.Invalid)); +#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 } /// @@ -60,7 +63,9 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber #if DEBUG DebugTools.Assert(_grids.Count == 0); - DebugTools.Assert(!GridExists(EntityUid.Invalid)); +#pragma warning disable CS0618 + DebugTools.Assert(!GridExists(GridId.Invalid)); +#pragma warning restore CS0618 _dbgGuardRunning = false; #endif } diff --git a/Robust.Shared/Map/NetworkedMapManager.cs b/Robust.Shared/Map/NetworkedMapManager.cs index 9ded5be3b..e6f8bffc0 100644 --- a/Robust.Shared/Map/NetworkedMapManager.cs +++ b/Robust.Shared/Map/NetworkedMapManager.cs @@ -23,16 +23,16 @@ internal interface INetworkedMapManager : IMapManagerInternal internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager { - private readonly Dictionary> _chunkDeletionHistory = new(); + private readonly Dictionary> _chunkDeletionHistory = new(); - public override void DeleteGrid(EntityUid gridId) + public override void DeleteGrid(GridId gridId) { base.DeleteGrid(gridId); // No point syncing chunk removals anymore! _chunkDeletionHistory.Remove(gridId); } - public override void ChunkRemoved(EntityUid gridId, MapChunk chunk) + public override void ChunkRemoved(GridId 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(); - if (_chunkDeletionHistory.TryGetValue(grid.GridEntityId, out var chunks)) + if (_chunkDeletionHistory.TryGetValue(grid.Index, 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, ushort chunkSize)> _newGrids = new(); + private List<(MapId mapId, EntityUid euid, GridId gridId, ushort chunkSize)> _newGrids = new(); public void ApplyGameStatePre(GameStateMapData? data, ReadOnlySpan 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, chunkSize)); + _newGrids.Add((gridMapId, gridEuid, gridCompState.GridIndex, chunkSize)); } } } @@ -173,9 +173,9 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager _newMaps.Clear(); // create all the new grids - foreach (var (mapId, euid, chunkSize) in _newGrids) + foreach (var (mapId, euid, gridId, chunkSize) in _newGrids) { - CreateGrid(mapId, chunkSize, euid); + CreateGrid(mapId, gridId, chunkSize, euid); } _newGrids.Clear(); } diff --git a/Robust.Shared/Map/TileRef.cs b/Robust.Shared/Map/TileRef.cs index dcd858a6a..5be2a00b6 100644 --- a/Robust.Shared/Map/TileRef.cs +++ b/Robust.Shared/Map/TileRef.cs @@ -13,7 +13,13 @@ namespace Robust.Shared.Map [PublicAPI] public readonly struct TileRef : IEquatable, ISpanFormattable { - public static TileRef Zero => new(EntityUid.Invalid, Vector2i.Zero, Tile.Empty); + public static TileRef Zero => new(GridId.Invalid, EntityUid.Invalid, Vector2i.Zero, Tile.Empty); + + /// + /// Identifier of the this Tile belongs to. + /// + [Obsolete("Use EntityUids instead")] + public readonly GridId GridIndex; /// /// Grid Entity this Tile belongs to. @@ -38,8 +44,8 @@ namespace Robust.Shared.Map /// Positional X index of this tile on the grid. /// Positional Y index of this tile on the grid. /// Actual data of this tile. - internal TileRef(EntityUid gridUid, int xIndex, int yIndex, Tile tile) - : this(gridUid, new Vector2i(xIndex, yIndex), tile) { } + internal TileRef(GridId gridId, EntityUid gridUid, int xIndex, int yIndex, Tile tile) + : this(gridId, gridUid, new Vector2i(xIndex, yIndex), tile) { } /// /// Constructs a new instance of TileRef. @@ -48,8 +54,9 @@ namespace Robust.Shared.Map /// Identifier of the grid entity this tile belongs to. /// Positional indices of this tile on the grid. /// Actual data of this tile. - internal TileRef(EntityUid gridUid, Vector2i gridIndices, Tile tile) + internal TileRef(GridId gridId, EntityUid gridUid, Vector2i gridIndices, Tile tile) { + GridIndex = gridId; GridUid = gridUid; GridIndices = gridIndices; Tile = tile; @@ -91,7 +98,7 @@ namespace Robust.Shared.Map /// public bool Equals(TileRef other) { - return GridUid.Equals(other.GridUid) && + return GridIndex.Equals(other.GridIndex) && GridIndices.Equals(other.GridIndices) && Tile.Equals(other.Tile); } @@ -125,7 +132,7 @@ namespace Robust.Shared.Map { unchecked { - var hashCode = GridUid.GetHashCode(); + var hashCode = GridIndex.GetHashCode(); hashCode = (hashCode * 397) ^ GridIndices.GetHashCode(); hashCode = (hashCode * 397) ^ Tile.GetHashCode(); return hashCode; diff --git a/Robust.Shared/Prototypes/PrototypeManager.cs b/Robust.Shared/Prototypes/PrototypeManager.cs index 7306a9f32..7b18ae2e9 100644 --- a/Robust.Shared/Prototypes/PrototypeManager.cs +++ b/Robust.Shared/Prototypes/PrototypeManager.cs @@ -201,7 +201,6 @@ namespace Robust.Shared.Prototypes [BaseTypeRequired(typeof(IPrototype))] [MeansImplicitUse] [MeansDataDefinition] - [Virtual] public class PrototypeAttribute : Attribute { private readonly string type; diff --git a/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs b/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs index 105072c50..af7d7c993 100644 --- a/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs +++ b/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs @@ -103,7 +103,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components Assert.Multiple(() => { Assert.That(childTrans.MapID, Is.EqualTo(parentTrans.MapID)); - Assert.That(childTrans.GridUid, Is.EqualTo(parentTrans.GridUid)); + Assert.That(childTrans.GridID, Is.EqualTo(parentTrans.GridID)); Assert.That(childTrans.Coordinates, Is.EqualTo(new EntityCoordinates(parentTrans.Owner, (-1, -1)))); Assert.That(childTrans.WorldPosition, Is.EqualTo(new Vector2(4, 4))); }); diff --git a/Robust.UnitTesting/Shared/EntityLookup_Test.cs b/Robust.UnitTesting/Shared/EntityLookup_Test.cs index 65a00d324..370af289e 100644 --- a/Robust.UnitTesting/Shared/EntityLookup_Test.cs +++ b/Robust.UnitTesting/Shared/EntityLookup_Test.cs @@ -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.GridEntityId); + mapManager.DeleteGrid(grid.Index); 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.GridEntityId); + mapManager.DeleteGrid(grid.Index); mapManager.DeleteMap(mapId); } } diff --git a/Robust.UnitTesting/Shared/GameObjects/EntityState_Tests.cs b/Robust.UnitTesting/Shared/GameObjects/EntityState_Tests.cs index de1de065a..6dd4c803b 100644 --- a/Robust.UnitTesting/Shared/GameObjects/EntityState_Tests.cs +++ b/Robust.UnitTesting/Shared/GameObjects/EntityState_Tests.cs @@ -62,7 +62,7 @@ namespace Robust.UnitTesting.Shared.GameObjects new EntityUid(512), new [] { - new ComponentChange(0, new MapGridComponentState(new EntityUid(0), 16), default) + new ComponentChange(0, new MapGridComponentState(new GridId(0), 16), default) }, default); serializer.Serialize(stream, payload); diff --git a/Robust.UnitTesting/Shared/Map/EntityCoordinates_Tests.cs b/Robust.UnitTesting/Shared/Map/EntityCoordinates_Tests.cs index 531efce93..7eceb94d1 100644 --- a/Robust.UnitTesting/Shared/Map/EntityCoordinates_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/EntityCoordinates_Tests.cs @@ -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().GetComponent(mapEnt).Coordinates.GetGridUid(entityManager), Is.Null); - Assert.That(IoCManager.Resolve().GetComponent(newEnt).Coordinates.GetGridUid(entityManager), Is.Null); + Assert.That(IoCManager.Resolve().GetComponent(mapEnt).Coordinates.GetGridId(entityManager), Is.EqualTo(GridId.Invalid)); + Assert.That(IoCManager.Resolve().GetComponent(newEnt).Coordinates.GetGridId(entityManager), Is.EqualTo(GridId.Invalid)); Assert.That(IoCManager.Resolve().GetComponent(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().GetComponent(gridEnt).Coordinates.GetGridUid(entityManager), Is.Null); - Assert.That(IoCManager.Resolve().GetComponent(newEnt).Coordinates.GetGridUid(entityManager), Is.EqualTo(grid.GridEntityId)); + Assert.That(IoCManager.Resolve().GetComponent(gridEnt).Coordinates.GetGridId(entityManager), Is.EqualTo(GridId.Invalid)); + Assert.That(IoCManager.Resolve().GetComponent(newEnt).Coordinates.GetGridId(entityManager), Is.EqualTo(grid.Index)); Assert.That(IoCManager.Resolve().GetComponent(newEnt).Coordinates.EntityId, Is.EqualTo(gridEnt)); } diff --git a/Robust.UnitTesting/Shared/Map/GridSplit_Tests.cs b/Robust.UnitTesting/Shared/Map/GridSplit_Tests.cs index 4827cde6a..cda2f64a9 100644 --- a/Robust.UnitTesting/Shared/Map/GridSplit_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/GridSplit_Tests.cs @@ -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.GridUid, Is.EqualTo(newGrid.GridEntityId)); + Assert.That(anchoredXform.GridID, Is.EqualTo(newGrid.Index)); Assert.That(newGridXform._children, Does.Contain(anchored)); Assert.That(dummyXform.ParentUid, Is.EqualTo(newGrid.GridEntityId)); - Assert.That(dummyXform.GridUid, Is.EqualTo(newGrid.GridEntityId)); + Assert.That(dummyXform.GridID, Is.EqualTo(newGrid.Index)); Assert.That(newGridXform._children, Does.Contain(dummy)); }); mapManager.DeleteMap(mapId); diff --git a/Robust.UnitTesting/Shared/Map/MapGrid_Tests.cs b/Robust.UnitTesting/Shared/Map/MapGrid_Tests.cs index 1831bdfcd..2ade64b85 100644 --- a/Robust.UnitTesting/Shared/Map/MapGrid_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/MapGrid_Tests.cs @@ -30,7 +30,7 @@ namespace Robust.UnitTesting.Shared.Map var sim = SimulationFactory(); var mapMan = sim.Resolve(); var mapId = mapMan.CreateMap(); - var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8); + var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 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.GridEntityId, new Vector2i(-9,-1), new Tile(1, (TileRenderFlag)1, 1)))); + Assert.That(result, Is.EqualTo(new TileRef(grid.Index, grid.GridEntityId, new Vector2i(-9,-1), new Tile(1, (TileRenderFlag)1, 1)))); } /// @@ -50,7 +50,7 @@ namespace Robust.UnitTesting.Shared.Map var sim = SimulationFactory(); var mapMan = sim.Resolve(); var mapId = mapMan.CreateMap(); - var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8); + var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 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(); var mapId = mapMan.CreateMap(); - var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8); + var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 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(); var mapId = mapMan.CreateMap(); - var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8); + var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 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(); var mapId = mapMan.CreateMap(); - var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8); + var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 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(); var mapId = mapMan.CreateMap(); - var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8); + var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 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(); var mapId = mapMan.CreateMap(); - var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8); + var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 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.GridEntityId, new Vector2i(-9, -1), new Tile(1, (TileRenderFlag)1, 1)))); + Assert.That(tileRef, Is.EqualTo(new TileRef(grid.Index, 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(); var mapId = mapMan.CreateMap(); - var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8); + var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 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(); var mapId = mapMan.CreateMap(); - var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, 8); + var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8); grid.SetTile(new Vector2i(19, 23), new Tile(1)); diff --git a/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs b/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs index 72efc40b1..614d14136 100644 --- a/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs @@ -46,11 +46,11 @@ namespace Robust.UnitTesting.Shared.Map var mapID = new MapId(11); mapMan.CreateMap(mapID); - var grid = mapMan.CreateGrid(mapID); + var gridId = mapMan.CreateGrid(mapID).GridEntityId; mapMan.Restart(); - Assert.That(mapMan.GridExists(grid.GridEntityId), Is.False); + Assert.That(mapMan.GridExists(gridId), Is.False); } /// @@ -71,7 +71,7 @@ namespace Robust.UnitTesting.Shared.Map mapMan.Restart(); Assert.That(mapMan.MapExists(MapId.Nullspace), Is.True); - Assert.That(mapMan.GridExists(EntityUid.Invalid), Is.False); + Assert.That(mapMan.GridExists(GridId.Invalid), Is.False); Assert.That(entMan.Deleted(oldEntity), Is.True); }