mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Make Grid Uid Nullable (#2942)
* Make Grid Uid Nullable * Fix recursion * fix detach to null * change obsolete text
This commit is contained in:
@@ -64,6 +64,9 @@ namespace Robust.Shared.GameObjects
|
||||
internal bool _mapIdInitialized;
|
||||
|
||||
// TODO: Cache this.
|
||||
/// <summary>
|
||||
/// The EntityUid of the map which this object is on, if any.
|
||||
/// </summary>
|
||||
public EntityUid? MapUid => _mapManager.MapExists(MapID) ? _mapManager.GetMapEntityId(MapID) : null;
|
||||
|
||||
/// <summary>
|
||||
@@ -72,33 +75,22 @@ namespace Robust.Shared.GameObjects
|
||||
public bool DeferUpdates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the index of the grid which this object is on
|
||||
/// The EntityUid of the grid which this object is on, if any.
|
||||
/// </summary>
|
||||
[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<TransformComponent>();
|
||||
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Disables or enables to ability to locally rotate the entity. When set it removes any local rotation.
|
||||
/// </summary>
|
||||
@@ -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<SharedTransformSystem>().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<TransformComponent> xformQuery)
|
||||
internal EntityUid? FindGridEntityId(EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
if (_entMan.HasComponent<IMapComponent>(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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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<MetaDataComponent>(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<SharedTransformSystem>().SetGridId(this, null);
|
||||
|
||||
var entParentChangedMessage = new EntParentChangedMessage(Owner, oldParent, oldMap, this);
|
||||
_entMan.EventBus.RaiseLocalEvent(Owner, ref entParentChangedMessage);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<EntityUid> GetEntitiesIntersecting(GridId gridId, IEnumerable<Vector2i> gridIndices, LookupFlags flags = DefaultFlags)
|
||||
{
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
|
||||
return GetEntitiesIntersecting(grid.GridEntityId, gridIndices, flags);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the entities intersecting any of the supplied tiles. Faster than doing each tile individually.
|
||||
/// </summary>
|
||||
/// <param name="gridId"></param>
|
||||
/// <param name="gridIndices"></param>
|
||||
/// <returns></returns>
|
||||
public HashSet<EntityUid> GetEntitiesIntersecting(GridId gridId, IEnumerable<Vector2i> gridIndices, LookupFlags flags = DefaultFlags)
|
||||
public HashSet<EntityUid> GetEntitiesIntersecting(EntityUid gridId, IEnumerable<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<EntityUid>();
|
||||
@@ -489,7 +497,14 @@ public sealed partial class EntityLookupSystem
|
||||
return intersecting;
|
||||
}
|
||||
|
||||
[Obsolete("Use Grid EntityUid")]
|
||||
public HashSet<EntityUid> GetEntitiesIntersecting(GridId gridId, Vector2i gridIndices, LookupFlags flags = DefaultFlags)
|
||||
{
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
|
||||
return GetEntitiesIntersecting(grid.GridEntityId, gridIndices, flags);
|
||||
}
|
||||
|
||||
public HashSet<EntityUid> GetEntitiesIntersecting(EntityUid gridId, Vector2i gridIndices, LookupFlags flags = DefaultFlags)
|
||||
{
|
||||
// Technically this doesn't consider anything overlapping from outside the grid but is this an issue?
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
|
||||
@@ -519,7 +534,14 @@ public sealed partial class EntityLookupSystem
|
||||
return intersecting;
|
||||
}
|
||||
|
||||
[Obsolete("Use grid EntityUid")]
|
||||
public HashSet<EntityUid> GetEntitiesIntersecting(GridId gridId, Box2 worldAABB, LookupFlags flags = DefaultFlags)
|
||||
{
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
|
||||
return GetEntitiesIntersecting(grid.GridEntityId, worldAABB, flags);
|
||||
}
|
||||
|
||||
public HashSet<EntityUid> GetEntitiesIntersecting(EntityUid gridId, Box2 worldAABB, LookupFlags flags = DefaultFlags)
|
||||
{
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
|
||||
|
||||
@@ -527,7 +549,7 @@ public sealed partial class EntityLookupSystem
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var intersecting = new HashSet<EntityUid>();
|
||||
|
||||
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<EntityUid> GetEntitiesIntersecting(GridId gridId, Box2Rotated worldBounds, LookupFlags flags = DefaultFlags)
|
||||
{
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
|
||||
return GetEntitiesIntersecting(grid.GridEntityId, worldBounds, flags);
|
||||
}
|
||||
|
||||
public HashSet<EntityUid> GetEntitiesIntersecting(EntityUid gridId, Box2Rotated worldBounds, LookupFlags flags = DefaultFlags)
|
||||
{
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid)) return new HashSet<EntityUid>();
|
||||
|
||||
@@ -567,7 +596,7 @@ public sealed partial class EntityLookupSystem
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IEnumerable<EntityUid> GetEntitiesIntersecting(TileRef tileRef, LookupFlags flags = DefaultFlags)
|
||||
{
|
||||
return GetEntitiesIntersecting(tileRef.GridIndex, tileRef.GridIndices, flags);
|
||||
return GetEntitiesIntersecting(tileRef.GridUid, tileRef.GridIndices, flags);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<IMapGridComponent>(_mapManager.GetGridEuid(xform.GridID)));
|
||||
UnanchorEntity(xform, Comp<IMapGridComponent>(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
|
||||
/// <summary>
|
||||
/// Sets the <see cref="GridId"/> for the transformcomponent. Does not Dirty it.
|
||||
/// </summary>
|
||||
public void SetGridId(TransformComponent xform, GridId gridId)
|
||||
public void SetGridId(TransformComponent xform, EntityUid? gridId, EntityQuery<TransformComponent>? xformQuery = null)
|
||||
{
|
||||
SetGridId(xform, gridId, GetEntityQuery<TransformComponent>());
|
||||
if (xform._gridUid == gridId) return;
|
||||
|
||||
|
||||
DebugTools.Assert(gridId == null || HasComp<MapGridComponent>(gridId));
|
||||
|
||||
xformQuery ??= GetEntityQuery<TransformComponent>();
|
||||
SetGridIdRecursive(xform, gridId, xformQuery.Value);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="SetGridId"/> />
|
||||
private void SetGridId(TransformComponent xform, GridId gridId, EntityQuery<TransformComponent> xformQuery)
|
||||
private static void SetGridIdRecursive(TransformComponent xform, EntityUid? gridId, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
if (xform.GridID == gridId) return;
|
||||
|
||||
SetGridIdRecursive(xform, gridId, xformQuery);
|
||||
}
|
||||
|
||||
private static void SetGridIdRecursive(TransformComponent xform, GridId gridId, EntityQuery<TransformComponent> 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<MapGridComponent>(_mapManager.GetGridEuid(component.GridID));
|
||||
DebugTools.Assert(component.GridUid != null);
|
||||
var iGrid = Comp<MapGridComponent>(component.GridUid!.Value);
|
||||
AnchorEntity(component, iGrid);
|
||||
DebugTools.Assert(component.Anchored);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<GridId, GridDatum>[]? GridData;
|
||||
public readonly KeyValuePair<EntityUid, GridDatum>[]? GridData;
|
||||
|
||||
public GameStateMapData(KeyValuePair<GridId, GridDatum>[]? gridData)
|
||||
public GameStateMapData(KeyValuePair<EntityUid, GridDatum>[]? gridData)
|
||||
{
|
||||
GridData = gridData;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
/// <param name="entityManager"></param>
|
||||
/// <returns>Grid Id this entity is on or <see cref="GridId.Invalid"/></returns>
|
||||
[Obsolete("Use GetGridUid")]
|
||||
public GridId GetGridId(IEntityManager entityManager)
|
||||
{
|
||||
return !IsValid(entityManager) ? GridId.Invalid : entityManager.GetComponent<TransformComponent>(EntityId).GridID;
|
||||
if (!IsValid(entityManager))
|
||||
return GridId.Invalid;
|
||||
|
||||
var uid = entityManager.GetComponent<TransformComponent>(EntityId).GridUid;
|
||||
|
||||
if (uid == null)
|
||||
return GridId.Invalid;
|
||||
|
||||
return entityManager.GetComponent<IMapGridComponent>(uid.Value).GridIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -226,17 +235,6 @@ namespace Robust.Shared.Map
|
||||
return !IsValid(entityManager) ? null : entityManager.GetComponent<TransformComponent>(EntityId).GridUid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Grid EntityUid these coordinates are on.
|
||||
/// If none of the ancestors are a grid, returns null instead.
|
||||
/// </summary>
|
||||
/// <param name="entityManager"></param>
|
||||
/// <returns>Grid EntityUid this entity is on or null</returns>
|
||||
public EntityUid GetGridEntityId(IEntityManager entityManager)
|
||||
{
|
||||
return !IsValid(entityManager) ? EntityUid.Invalid : entityManager.GetComponent<TransformComponent>(EntityId).GridEntityId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Map Id these coordinates are on.
|
||||
/// If the relative entity is not valid, returns <see cref="MapId.Nullspace"/> instead.
|
||||
|
||||
@@ -78,19 +78,6 @@ namespace Robust.Shared.Map
|
||||
return IoCManager.Resolve<IMapManager>().GetGridEuid(self);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="GridId"/> is an alias of the <see cref="EntityUid"/> that
|
||||
/// holds the <see cref="IMapGridComponent"/>.
|
||||
/// </summary>
|
||||
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<IMapManager>().GetGridComp(euid).GridIndex;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -45,8 +45,8 @@ namespace Robust.Shared.Map
|
||||
/// <param name="oldTile">The old tile that got replaced.</param>
|
||||
void RaiseOnTileChanged(TileRef tileRef, Tile oldTile);
|
||||
|
||||
bool TryGetGridComp(GridId id, [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);
|
||||
|
||||
@@ -119,6 +119,7 @@ namespace Robust.Shared.Map
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
[Obsolete("Use Transform System + GridEntityId")]
|
||||
public Vector2 WorldPosition
|
||||
{
|
||||
get
|
||||
@@ -140,6 +141,7 @@ namespace Robust.Shared.Map
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
[Obsolete("Use Transform System + GridEntityId")]
|
||||
public Angle WorldRotation
|
||||
{
|
||||
get
|
||||
@@ -161,6 +163,7 @@ namespace Robust.Shared.Map
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
[Obsolete("Use Transform System + GridEntityId")]
|
||||
public Matrix3 WorldMatrix
|
||||
{
|
||||
get
|
||||
@@ -175,6 +178,7 @@ namespace Robust.Shared.Map
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
[Obsolete("Use Transform System + GridEntityId")]
|
||||
public Matrix3 InvWorldMatrix
|
||||
{
|
||||
get
|
||||
|
||||
@@ -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<IMapGridComponent>(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<IMapGridComponent>(euid);
|
||||
return EntityManager.HasComponent<IMapGridComponent>(euid);
|
||||
}
|
||||
|
||||
public IEnumerable<IMapGrid> GetAllMapGrids(MapId mapId)
|
||||
|
||||
@@ -46,7 +46,7 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager
|
||||
|
||||
public GameStateMapData? GetStateData(GameTick fromTick)
|
||||
{
|
||||
var gridDatums = new Dictionary<GridId, GameStateMapData.GridDatum>();
|
||||
var gridDatums = new Dictionary<EntityUid, GameStateMapData.GridDatum>();
|
||||
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<KeyValuePair<GridId, GameStateMapData.GridDatum>>());
|
||||
return new GameStateMapData(gridDatums.ToArray<KeyValuePair<EntityUid, GameStateMapData.GridDatum>>());
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,11 +143,11 @@ namespace Robust.Shared.Player
|
||||
/// <summary>
|
||||
/// Add all players whose entity is on a certain grid.
|
||||
/// </summary>
|
||||
public Filter AddInGrid(GridId gridId, IEntityManager? entMan = null)
|
||||
public Filter AddInGrid(EntityUid uid, IEntityManager? entMan = null)
|
||||
{
|
||||
IoCManager.Resolve(ref entMan);
|
||||
var xformQuery = entMan.GetEntityQuery<TransformComponent>();
|
||||
return AddWhereAttachedEntity(entity => xformQuery.GetComponent(entity).GridID == gridId);
|
||||
return AddWhereAttachedEntity(entity => xformQuery.GetComponent(entity).GridUid == uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -309,7 +309,7 @@ namespace Robust.Shared.Player
|
||||
/// <summary>
|
||||
/// A new filter with all players whose attached entity is on a certain grid.
|
||||
/// </summary>
|
||||
public static Filter BroadcastGrid(GridId grid)
|
||||
public static Filter BroadcastGrid(EntityUid grid)
|
||||
{
|
||||
return Empty().AddInGrid(grid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user