From 4171b3ec4e872df2a20f81993a508acf7390f481 Mon Sep 17 00:00:00 2001
From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Date: Mon, 20 Jun 2022 12:08:23 +1200
Subject: [PATCH] Make Grid Uid Nullable (#2942)
* Make Grid Uid Nullable
* Fix recursion
* fix detach to null
* change obsolete text
---
.../Transform/TransformComponent.cs | 56 ++++++++-----------
.../Systems/CollisionWakeSystem.cs | 2 +-
.../Systems/EntityLookup.Queries.cs | 35 +++++++++++-
.../Systems/SharedGridTraversalSystem.cs | 18 +++---
.../SharedTransformSystem.Component.cs | 37 ++++++------
.../Systems/SharedTransformSystem.cs | 6 +-
Robust.Shared/GameStates/GameStateMapData.cs | 5 +-
Robust.Shared/Map/CoordinatesExtensions.cs | 10 ++++
Robust.Shared/Map/EntityCoordinates.cs | 24 ++++----
Robust.Shared/Map/GridId.cs | 13 -----
Robust.Shared/Map/IMapManager.cs | 4 +-
Robust.Shared/Map/IMapManagerInternal.cs | 4 +-
Robust.Shared/Map/MapGrid.cs | 4 ++
.../Map/MapManager.GridCollection.cs | 15 +++--
Robust.Shared/Map/NetworkedMapManager.cs | 17 +++---
Robust.Shared/Player/Filter.cs | 6 +-
16 files changed, 138 insertions(+), 118 deletions(-)
diff --git a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs
index a548f7816..615c258b0 100644
--- a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs
+++ b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs
@@ -64,6 +64,9 @@ namespace Robust.Shared.GameObjects
internal bool _mapIdInitialized;
// TODO: Cache this.
+ ///
+ /// The EntityUid of the map which this object is on, if any.
+ ///
public EntityUid? MapUid => _mapManager.MapExists(MapID) ? _mapManager.GetMapEntityId(MapID) : null;
///
@@ -72,33 +75,22 @@ namespace Robust.Shared.GameObjects
public bool DeferUpdates { get; set; }
///
- /// Returns the index of the grid which this object is on
+ /// The EntityUid of the grid which this object is on, if any.
///
[ViewVariables]
+ public EntityUid? GridUid => _gridUid;
+
+ [Access(typeof(SharedTransformSystem))]
+ internal EntityUid? _gridUid = null;
+
+ [Obsolete("Use GridUid")]
public GridId GridID
{
- get => _gridId;
- internal set
- {
- if (_gridId.Equals(value)) return;
-
- _gridId = value;
- var childEnumerator = ChildEnumerator;
- var xformQuery = _entMan.GetEntityQuery();
-
- while (childEnumerator.MoveNext(out var child))
- {
- xformQuery.GetComponent(child.Value).GridID = value;
- }
- }
+ get => _entMan.TryGetComponent(GridUid, out MapGridComponent? grid)
+ ? grid.GridIndex
+ : GridId.Invalid;
}
- internal GridId _gridId = GridId.Invalid;
-
- // TODO: Cache this.
- public EntityUid? GridUid => _mapManager.TryGetGrid(_gridId, out var mapGrid) ? mapGrid.GridEntityId : null;
- public EntityUid GridEntityId => _mapManager.TryGetGrid(_gridId, out var mapGrid) ? mapGrid.GridEntityId : EntityUid.Invalid;
-
///
/// Disables or enables to ability to locally rotate the entity. When set it removes any local rotation.
///
@@ -357,7 +349,7 @@ namespace Robust.Shared.GameObjects
ChangeMapId(newParent.MapID, xformQuery);
// Cache new GridID before raising the event.
- GridID = GetGridIndex(xformQuery);
+ _entMan.EntitySysManager.GetEntitySystem().SetGridId(this, FindGridEntityId(xformQuery), xformQuery);
// preserve world rotation
if (LifeStage == ComponentLifeStage.Running)
@@ -516,24 +508,24 @@ namespace Robust.Shared.GameObjects
[ViewVariables] internal EntityUid LerpParent { get; set; }
- internal GridId GetGridIndex(EntityQuery xformQuery)
+ internal EntityUid? FindGridEntityId(EntityQuery xformQuery)
{
if (_entMan.HasComponent(Owner))
{
- return GridId.Invalid;
+ return null;
}
if (_entMan.TryGetComponent(Owner, out IMapGridComponent? gridComponent))
{
- return gridComponent.GridIndex;
+ return Owner;
}
if (_parent.IsValid())
{
- return xformQuery.GetComponent(_parent).GridID;
+ return xformQuery.GetComponent(_parent).GridUid;
}
- return _mapManager.TryFindGridAt(MapID, WorldPosition, out var mapgrid) ? mapgrid.Index : GridId.Invalid;
+ return _mapManager.TryFindGridAt(MapID, WorldPosition, out var mapgrid) ? mapgrid.GridEntityId : null;
}
///
@@ -632,13 +624,10 @@ namespace Robust.Shared.GameObjects
LerpParent = EntityUid.Invalid;
// TODO: When ECSing this can just pass it into the anchor setter
- if (Anchored && _mapManager.TryGetGrid(GridID, out var grid))
+ if (Anchored && _entMan.TryGetComponent(GridUid, out MetaDataComponent? meta))
{
- if (_entMan.GetComponent(grid.GridEntityId).EntityLifeStage <=
- EntityLifeStage.MapInitialized)
- {
+ if (meta.EntityLifeStage <= EntityLifeStage.MapInitialized)
Anchored = false;
- }
}
else
{
@@ -652,7 +641,8 @@ namespace Robust.Shared.GameObjects
_parent = EntityUid.Invalid;
var oldMap = MapID;
MapID = MapId.Nullspace;
- GridID = GridId.Invalid;
+ if (GridUid != null)
+ _entMan.EntitySysManager.GetEntitySystem().SetGridId(this, null);
var entParentChangedMessage = new EntParentChangedMessage(Owner, oldParent, oldMap, this);
_entMan.EventBus.RaiseLocalEvent(Owner, ref entParentChangedMessage);
diff --git a/Robust.Shared/GameObjects/Systems/CollisionWakeSystem.cs b/Robust.Shared/GameObjects/Systems/CollisionWakeSystem.cs
index 3c0028db4..1aea4ed6e 100644
--- a/Robust.Shared/GameObjects/Systems/CollisionWakeSystem.cs
+++ b/Robust.Shared/GameObjects/Systems/CollisionWakeSystem.cs
@@ -117,7 +117,7 @@ namespace Robust.Shared.GameObjects
// If we're attached to the map we'll also just never disable collision due to how grid movement works.
body.CanCollide = body.Awake ||
(TryComp(uid, out JointComponent? jointComponent) && jointComponent.JointCount > 0) ||
- xform.GridID == GridId.Invalid;
+ xform.GridUid == null;
}
}
}
diff --git a/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs b/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs
index b67601b09..53de550ba 100644
--- a/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs
+++ b/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
@@ -449,13 +450,20 @@ 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.
///
///
///
///
- public HashSet GetEntitiesIntersecting(GridId gridId, IEnumerable gridIndices, LookupFlags flags = DefaultFlags)
+ public HashSet GetEntitiesIntersecting(EntityUid gridId, IEnumerable gridIndices, LookupFlags flags = DefaultFlags)
{
// Technically this doesn't consider anything overlapping from outside the grid but is this an issue?
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet();
@@ -489,7 +497,14 @@ 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?
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet();
@@ -519,7 +534,14 @@ 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();
@@ -527,7 +549,7 @@ public sealed partial class EntityLookupSystem
var xformQuery = GetEntityQuery();
var intersecting = new HashSet();
- AddEntitiesIntersecting(grid.GridEntityId, intersecting, worldAABB, flags, lookupQuery, xformQuery);
+ AddEntitiesIntersecting(gridId, intersecting, worldAABB, flags, lookupQuery, xformQuery);
if ((flags & LookupFlags.Anchored) != 0x0)
{
@@ -541,7 +563,14 @@ 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();
@@ -567,7 +596,7 @@ public sealed partial class EntityLookupSystem
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable GetEntitiesIntersecting(TileRef tileRef, LookupFlags flags = DefaultFlags)
{
- return GetEntitiesIntersecting(tileRef.GridIndex, tileRef.GridIndices, flags);
+ return GetEntitiesIntersecting(tileRef.GridUid, tileRef.GridIndices, flags);
}
#endregion
diff --git a/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs b/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs
index b3c2df0c4..868b47d56 100644
--- a/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs
+++ b/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs
@@ -77,7 +77,7 @@ namespace Robust.Shared.GameObjects
// DebugTools.Assert(!float.IsNaN(moveEvent.NewPosition.X) && !float.IsNaN(moveEvent.NewPosition.Y));
// We only do grid-traversal parent changes if the entity is currently parented to a map or a grid.
- var parentIsMap = xform.GridID == GridId.Invalid && maps.HasComponent(xform.ParentUid);
+ var parentIsMap = xform.GridUid == null && maps.HasComponent(xform.ParentUid);
if (!parentIsMap && !grids.HasComponent(xform.ParentUid))
return;
var mapPos = moveEvent.NewPosition.ToMapPos(EntityManager);
@@ -87,22 +87,22 @@ namespace Robust.Shared.GameObjects
if (_mapManager.TryFindGridAt(xform.MapID, mapPos, _gridBuffer, xforms, bodies, out var grid))
{
// Some minor duplication here with AttachParent but only happens when going on/off grid so not a big deal ATM.
- if (grid.Index != xform.GridID)
+ if (grid.GridEntityId != xform.GridUid)
{
xform.AttachParent(grid.GridEntityId);
- var ev = new ChangedGridEvent(entity, xform.GridID, grid.Index);
+ var ev = new ChangedGridEvent(entity, xform.GridUid, grid.GridEntityId);
RaiseLocalEvent(entity, ref ev);
}
}
else
{
- var oldGridId = xform.GridID;
+ var oldGridId = xform.GridUid;
// Attach them to map / they are on an invalid grid
- if (oldGridId != GridId.Invalid)
+ if (oldGridId != null)
{
xform.AttachParent(_mapManager.GetMapEntityIdOrThrow(xform.MapID));
- var ev = new ChangedGridEvent(entity, oldGridId, GridId.Invalid);
+ var ev = new ChangedGridEvent(entity, oldGridId, null);
RaiseLocalEvent(entity, ref ev);
}
}
@@ -113,10 +113,10 @@ namespace Robust.Shared.GameObjects
public readonly struct ChangedGridEvent
{
public readonly EntityUid Entity;
- public readonly GridId OldGrid;
- public readonly GridId NewGrid;
+ public readonly EntityUid? OldGrid;
+ public readonly EntityUid? NewGrid;
- public ChangedGridEvent(EntityUid entity, GridId oldGrid, GridId newGrid)
+ public ChangedGridEvent(EntityUid entity, EntityUid? oldGrid, EntityUid? newGrid)
{
Entity = entity;
OldGrid = oldGrid;
diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs
index e40111311..64a780c40 100644
--- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs
+++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs
@@ -36,7 +36,7 @@ public abstract partial class SharedTransformSystem
xform._parent = newGrid.Owner;
xform._anchored = true;
- SetGridId(xform, newGrid.GridIndex, xformQuery);
+ SetGridId(xform, newGrid.Owner, xformQuery);
var reParent = new EntParentChangedMessage(xform.Owner, oldGrid.Owner, xform.MapID, xform);
RaiseLocalEvent(xform.Owner, ref reParent);
// TODO: Ideally shouldn't need to call the moveevent
@@ -55,7 +55,6 @@ public abstract partial class SharedTransformSystem
RaiseLocalEvent(xform.Owner, ref ev);
}
-
public bool AnchorEntity(TransformComponent xform, IMapGrid grid, Vector2i tileIndices)
{
var result = grid.AddToSnapGridCell(tileIndices, xform.Owner);
@@ -88,7 +87,7 @@ public abstract partial class SharedTransformSystem
public bool AnchorEntity(TransformComponent xform)
{
- if (!_mapManager.TryGetGrid(xform.GridID, out var grid))
+ if (!_mapManager.TryGetGrid(xform.GridUid, out var grid))
{
return false;
}
@@ -101,10 +100,10 @@ public abstract partial class SharedTransformSystem
{
//HACK: Client grid pivot causes this.
//TODO: make grid components the actual grid
- if(xform.GridID == GridId.Invalid)
+ if(xform.GridUid == null)
return;
- UnanchorEntity(xform, Comp(_mapManager.GetGridEuid(xform.GridID)));
+ UnanchorEntity(xform, Comp(xform.GridUid.Value));
}
public void UnanchorEntity(TransformComponent xform, IMapGridComponent grid)
@@ -213,7 +212,8 @@ public abstract partial class SharedTransformSystem
xformQuery.GetComponent(component.ParentUid)._children.Add(uid);
}
- component.GridID = component.GetGridIndex(xformQuery);
+
+ SetGridId(component, component.FindGridEntityId(xformQuery));
component.RebuildMatrices();
}
@@ -244,22 +244,20 @@ public abstract partial class SharedTransformSystem
///
/// Sets the for the transformcomponent. Does not Dirty it.
///
- public void SetGridId(TransformComponent xform, GridId gridId)
+ public void SetGridId(TransformComponent xform, EntityUid? gridId, EntityQuery? xformQuery = null)
{
- SetGridId(xform, gridId, GetEntityQuery());
+ if (xform._gridUid == gridId) return;
+
+
+ DebugTools.Assert(gridId == null || HasComp(gridId));
+
+ xformQuery ??= GetEntityQuery();
+ SetGridIdRecursive(xform, gridId, xformQuery.Value);
}
- /// />
- private void SetGridId(TransformComponent xform, GridId gridId, EntityQuery xformQuery)
+ private static void SetGridIdRecursive(TransformComponent xform, EntityUid? gridId, EntityQuery xformQuery)
{
- if (xform.GridID == gridId) return;
-
- SetGridIdRecursive(xform, gridId, xformQuery);
- }
-
- private static void SetGridIdRecursive(TransformComponent xform, GridId gridId, EntityQuery xformQuery)
- {
- xform._gridId = gridId;
+ xform._gridUid = gridId;
var childEnumerator = xform.ChildEnumerator;
while (childEnumerator.MoveNext(out var child))
@@ -401,7 +399,8 @@ public abstract partial class SharedTransformSystem
// Anchored currently does a TryFindGridAt internally which may fail in particularly... violent situations.
if (newState.Anchored && !component.Anchored)
{
- var iGrid = Comp(_mapManager.GetGridEuid(component.GridID));
+ DebugTools.Assert(component.GridUid != null);
+ var iGrid = Comp(component.GridUid!.Value);
AnchorEntity(component, iGrid);
DebugTools.Assert(component.Anchored);
}
diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs
index 8e504c9ac..e90fd038a 100644
--- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs
+++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs
@@ -110,7 +110,7 @@ namespace Robust.Shared.GameObjects
public EntityCoordinates GetMoverCoordinates(TransformComponent xform)
{
// If they're parented directly to the map or grid then just return the coordinates.
- if (!_mapManager.TryGetGrid(xform.GridID, out var grid))
+ if (!_mapManager.TryGetGrid(xform.GridUid, out var grid))
{
var mapUid = _mapManager.GetMapEntityId(xform.MapID);
var coordinates = xform.Coordinates;
@@ -176,11 +176,11 @@ namespace Robust.Shared.GameObjects
return Vector2i.Zero;
// Fast path, we're not on a grid.
- if (xform.GridID == GridId.Invalid)
+ if (xform.GridUid == null)
return (Vector2i) xform.WorldPosition;
// We're on a grid, need to convert the coordinates to grid tiles.
- return _mapManager.GetGrid(xform.GridID).CoordinatesToTile(xform.Coordinates);
+ return _mapManager.GetGrid(xform.GridUid.Value).CoordinatesToTile(xform.Coordinates);
}
}
diff --git a/Robust.Shared/GameStates/GameStateMapData.cs b/Robust.Shared/GameStates/GameStateMapData.cs
index 22ef5d154..9e8f1a5ef 100644
--- a/Robust.Shared/GameStates/GameStateMapData.cs
+++ b/Robust.Shared/GameStates/GameStateMapData.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
@@ -9,9 +10,9 @@ namespace Robust.Shared.GameStates
[Serializable, NetSerializable]
public sealed class GameStateMapData
{
- public readonly KeyValuePair[]? GridData;
+ public readonly KeyValuePair[]? GridData;
- public GameStateMapData(KeyValuePair[]? gridData)
+ public GameStateMapData(KeyValuePair[]? gridData)
{
GridData = gridData;
}
diff --git a/Robust.Shared/Map/CoordinatesExtensions.cs b/Robust.Shared/Map/CoordinatesExtensions.cs
index f7c9e5672..5cd3cd48d 100644
--- a/Robust.Shared/Map/CoordinatesExtensions.cs
+++ b/Robust.Shared/Map/CoordinatesExtensions.cs
@@ -16,6 +16,16 @@ namespace Robust.Shared.Map
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);
+
+ var grid = mapManager.GetGrid(gridId);
+ var tile = grid.TileSize;
+
+ return new EntityCoordinates(grid.GridEntityId, (vector.X * tile, vector.Y * tile));
+ }
+
public static EntityCoordinates AlignWithClosestGridTile(this EntityCoordinates coordinates, float searchBoxSize = 1.5f, IEntityManager? entityManager = null, IMapManager? mapManager = null)
{
var coords = coordinates;
diff --git a/Robust.Shared/Map/EntityCoordinates.cs b/Robust.Shared/Map/EntityCoordinates.cs
index 0abdb57a8..d9de62a2b 100644
--- a/Robust.Shared/Map/EntityCoordinates.cs
+++ b/Robust.Shared/Map/EntityCoordinates.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -210,9 +210,18 @@ namespace Robust.Shared.Map
///
///
/// Grid Id this entity is on or
+ [Obsolete("Use GetGridUid")]
public GridId GetGridId(IEntityManager entityManager)
{
- return !IsValid(entityManager) ? GridId.Invalid : entityManager.GetComponent(EntityId).GridID;
+ if (!IsValid(entityManager))
+ return GridId.Invalid;
+
+ var uid = entityManager.GetComponent(EntityId).GridUid;
+
+ if (uid == null)
+ return GridId.Invalid;
+
+ return entityManager.GetComponent(uid.Value).GridIndex;
}
///
@@ -226,17 +235,6 @@ namespace Robust.Shared.Map
return !IsValid(entityManager) ? null : entityManager.GetComponent(EntityId).GridUid;
}
- ///
- /// Returns the Grid EntityUid these coordinates are on.
- /// If none of the ancestors are a grid, returns null instead.
- ///
- ///
- /// Grid EntityUid this entity is on or null
- public EntityUid GetGridEntityId(IEntityManager entityManager)
- {
- return !IsValid(entityManager) ? EntityUid.Invalid : entityManager.GetComponent(EntityId).GridEntityId;
- }
-
///
/// Returns the Map Id these coordinates are on.
/// If the relative entity is not valid, returns instead.
diff --git a/Robust.Shared/Map/GridId.cs b/Robust.Shared/Map/GridId.cs
index b9efb2952..6720de6c8 100644
--- a/Robust.Shared/Map/GridId.cs
+++ b/Robust.Shared/Map/GridId.cs
@@ -78,19 +78,6 @@ namespace Robust.Shared.Map
return IoCManager.Resolve().GetGridEuid(self);
}
- ///
- /// is an alias of the that
- /// holds the .
- ///
- public static implicit operator GridId(EntityUid euid)
- {
- // If this throws, you are using an EntityUid that isn't a grid.
- // This would raise the question, "Why does your code think this entity is a grid?".
- // Grid-ness is defined by the entity having an IMapGridComponent,
- // was the component removed without you knowing?
- return IoCManager.Resolve().GetGridComp(euid).GridIndex;
- }
-
public override string ToString()
{
return Value.ToString();
diff --git a/Robust.Shared/Map/IMapManager.cs b/Robust.Shared/Map/IMapManager.cs
index ffb84b5c2..af6d7d8ea 100644
--- a/Robust.Shared/Map/IMapManager.cs
+++ b/Robust.Shared/Map/IMapManager.cs
@@ -182,8 +182,8 @@ namespace Robust.Shared.Map
EntityUid GetGridEuid(GridId id);
IMapGridComponent GetGridComp(GridId id);
IMapGridComponent GetGridComp(EntityUid euid);
- bool TryGetGrid(EntityUid euid, [NotNullWhen(true)] out IMapGrid? grid);
- bool GridExists(EntityUid euid);
+ bool TryGetGrid([NotNullWhen(true)] EntityUid? euid, [NotNullWhen(true)] out IMapGrid? grid);
+ bool GridExists([NotNullWhen(true)] EntityUid? euid);
//
// Pausing functions
diff --git a/Robust.Shared/Map/IMapManagerInternal.cs b/Robust.Shared/Map/IMapManagerInternal.cs
index 70888ad67..cfff185c2 100644
--- a/Robust.Shared/Map/IMapManagerInternal.cs
+++ b/Robust.Shared/Map/IMapManagerInternal.cs
@@ -45,8 +45,8 @@ namespace Robust.Shared.Map
/// The old tile that got replaced.
void RaiseOnTileChanged(TileRef tileRef, Tile oldTile);
- bool TryGetGridComp(GridId id, [MaybeNullWhen(false)]out IMapGridComponent comp);
- bool TryGetGridEuid(GridId id, [MaybeNullWhen(false)]out EntityUid euid);
+ 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);
diff --git a/Robust.Shared/Map/MapGrid.cs b/Robust.Shared/Map/MapGrid.cs
index 06e478ad7..59374840c 100644
--- a/Robust.Shared/Map/MapGrid.cs
+++ b/Robust.Shared/Map/MapGrid.cs
@@ -119,6 +119,7 @@ namespace Robust.Shared.Map
///
[ViewVariables]
+ [Obsolete("Use Transform System + GridEntityId")]
public Vector2 WorldPosition
{
get
@@ -140,6 +141,7 @@ namespace Robust.Shared.Map
///
[ViewVariables]
+ [Obsolete("Use Transform System + GridEntityId")]
public Angle WorldRotation
{
get
@@ -161,6 +163,7 @@ namespace Robust.Shared.Map
///
[ViewVariables]
+ [Obsolete("Use Transform System + GridEntityId")]
public Matrix3 WorldMatrix
{
get
@@ -175,6 +178,7 @@ namespace Robust.Shared.Map
///
[ViewVariables]
+ [Obsolete("Use Transform System + GridEntityId")]
public Matrix3 InvWorldMatrix
{
get
diff --git a/Robust.Shared/Map/MapManager.GridCollection.cs b/Robust.Shared/Map/MapManager.GridCollection.cs
index f9c3ed5a3..cddda00cb 100644
--- a/Robust.Shared/Map/MapManager.GridCollection.cs
+++ b/Robust.Shared/Map/MapManager.GridCollection.cs
@@ -72,14 +72,17 @@ internal partial class MapManager
return _grids[id];
}
- public bool TryGetGridEuid(GridId id, [MaybeNullWhen(false)] out EntityUid euid)
+ public bool TryGetGridEuid(GridId id, [NotNullWhen(true)] out EntityUid? euid)
{
DebugTools.Assert(id != GridId.Invalid);
- if (_grids.TryGetValue(id, out euid))
+ if (_grids.TryGetValue(id, out var result))
+ {
+ euid = result;
return true;
+ }
- euid = default;
+ euid = null;
return false;
}
@@ -157,7 +160,7 @@ internal partial class MapManager
return EntityManager.HasComponent(uid);
}
- public bool TryGetGrid(EntityUid euid, [MaybeNullWhen(false)] out IMapGrid grid)
+ public bool TryGetGrid([NotNullWhen(true)] EntityUid? euid, [MaybeNullWhen(false)] out IMapGrid grid)
{
if (EntityManager.TryGetComponent(euid, out IMapGridComponent? comp))
{
@@ -193,9 +196,9 @@ internal partial class MapManager
return gridId != GridId.Invalid && TryGetGridEuid(gridId, out var euid) && GridExists(euid);
}
- public bool GridExists(EntityUid euid)
+ public bool GridExists([NotNullWhen(true)] EntityUid? euid)
{
- return EntityManager.EntityExists(euid) && EntityManager.HasComponent(euid);
+ return EntityManager.HasComponent(euid);
}
public IEnumerable GetAllMapGrids(MapId mapId)
diff --git a/Robust.Shared/Map/NetworkedMapManager.cs b/Robust.Shared/Map/NetworkedMapManager.cs
index 07776ede7..7e56462be 100644
--- a/Robust.Shared/Map/NetworkedMapManager.cs
+++ b/Robust.Shared/Map/NetworkedMapManager.cs
@@ -46,7 +46,7 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager
public GameStateMapData? GetStateData(GameTick fromTick)
{
- var gridDatums = new Dictionary();
+ var gridDatums = new Dictionary();
var enumerator = GetAllGridsEnumerator();
while (enumerator.MoveNext(out var iGrid))
@@ -94,14 +94,14 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager
new MapCoordinates(grid.WorldPosition, grid.ParentMapId),
grid.WorldRotation);
- gridDatums.Add(grid.Index, gridDatum);
+ gridDatums.Add(grid.GridEntityId, gridDatum);
}
// no point sending empty collections
if (gridDatums.Count == 0)
return default;
- return new GameStateMapData(gridDatums.ToArray>());
+ return new GameStateMapData(gridDatums.ToArray>());
}
public void CullDeletionHistory(GameTick upToTick)
@@ -143,28 +143,27 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager
else if (data != null && data.GridData != null && compChange.State is MapGridComponentState gridCompState)
{
var gridEuid = entityState.Uid;
- var gridId = gridCompState.GridIndex;
var chunkSize = gridCompState.ChunkSize;
// grid already exists from a previous state
- if(GridExists(gridId))
+ if(GridExists(gridEuid))
continue;
- DebugTools.Assert(chunkSize > 0, $"Invalid chunk size in entity state for new grid {gridId}.");
+ DebugTools.Assert(chunkSize > 0, $"Invalid chunk size in entity state for new grid {gridEuid}.");
MapId gridMapId = default;
foreach (var kvData in data.GridData)
{
- if (kvData.Key != gridId)
+ if (kvData.Key != gridEuid)
continue;
gridMapId = kvData.Value.Coordinates.MapId;
break;
}
- DebugTools.Assert(gridMapId != default, $"Could not find corresponding gridData for new grid {gridId}.");
+ DebugTools.Assert(gridMapId != default, $"Could not find corresponding gridData for new grid {gridEuid}.");
- _newGrids.Add((gridMapId, gridEuid, gridId, chunkSize));
+ _newGrids.Add((gridMapId, gridEuid, gridCompState.GridIndex, chunkSize));
}
}
}
diff --git a/Robust.Shared/Player/Filter.cs b/Robust.Shared/Player/Filter.cs
index 82be163c8..5cbdcda7a 100644
--- a/Robust.Shared/Player/Filter.cs
+++ b/Robust.Shared/Player/Filter.cs
@@ -143,11 +143,11 @@ namespace Robust.Shared.Player
///
/// Add all players whose entity is on a certain grid.
///
- public Filter AddInGrid(GridId gridId, IEntityManager? entMan = null)
+ public Filter AddInGrid(EntityUid uid, IEntityManager? entMan = null)
{
IoCManager.Resolve(ref entMan);
var xformQuery = entMan.GetEntityQuery();
- return AddWhereAttachedEntity(entity => xformQuery.GetComponent(entity).GridID == gridId);
+ return AddWhereAttachedEntity(entity => xformQuery.GetComponent(entity).GridUid == uid);
}
///
@@ -309,7 +309,7 @@ namespace Robust.Shared.Player
///
/// A new filter with all players whose attached entity is on a certain grid.
///
- public static Filter BroadcastGrid(GridId grid)
+ public static Filter BroadcastGrid(EntityUid grid)
{
return Empty().AddInGrid(grid);
}