mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 14:52:35 +02:00
Cache MapUid (#3687)
This commit is contained in:
@@ -99,14 +99,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// <summary>
|
||||
/// The EntityUid of the map which this object is on, if any.
|
||||
/// </summary>
|
||||
public EntityUid? MapUid
|
||||
{
|
||||
get
|
||||
{
|
||||
var id = _mapManager.GetMapEntityId(MapID);
|
||||
return id.IsValid() ? id : null;
|
||||
}
|
||||
}
|
||||
public EntityUid? MapUid { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The EntityUid of the grid which this object is on, if any.
|
||||
@@ -485,6 +478,8 @@ namespace Robust.Shared.GameObjects
|
||||
if (newMapId == MapID)
|
||||
return;
|
||||
|
||||
EntityUid? newUid = newMapId == MapId.Nullspace ? null : _mapManager.GetMapEntityId(newMapId);
|
||||
|
||||
//Set Paused state
|
||||
var mapPaused = _mapManager.IsMapPaused(newMapId);
|
||||
var metaEnts = _entMan.GetEntityQuery<MetaDataComponent>();
|
||||
@@ -492,12 +487,14 @@ namespace Robust.Shared.GameObjects
|
||||
var metaSystem = _entMan.EntitySysManager.GetEntitySystem<MetaDataSystem>();
|
||||
metaSystem.SetEntityPaused(Owner, mapPaused, metaData);
|
||||
|
||||
MapUid = newUid;
|
||||
MapID = newMapId;
|
||||
UpdateChildMapIdsRecursive(MapID, mapPaused, xformQuery, metaEnts, metaSystem);
|
||||
UpdateChildMapIdsRecursive(MapID, newUid, mapPaused, xformQuery, metaEnts, metaSystem);
|
||||
}
|
||||
|
||||
internal void UpdateChildMapIdsRecursive(
|
||||
MapId newMapId,
|
||||
EntityUid? newUid,
|
||||
bool mapPaused,
|
||||
EntityQuery<TransformComponent> xformQuery,
|
||||
EntityQuery<MetaDataComponent> metaQuery,
|
||||
@@ -513,11 +510,12 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
var concrete = xformQuery.GetComponent(child.Value);
|
||||
|
||||
concrete.MapUid = newUid;
|
||||
concrete.MapID = newMapId;
|
||||
|
||||
if (concrete.ChildCount != 0)
|
||||
{
|
||||
concrete.UpdateChildMapIdsRecursive(newMapId, mapPaused, xformQuery, metaQuery, system);
|
||||
concrete.UpdateChildMapIdsRecursive(newMapId, newUid, mapPaused, xformQuery, metaQuery, system);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public abstract partial class SharedTransformSystem
|
||||
// Children MAY be initialized here before their parents are.
|
||||
// We do this whole dance to handle this recursively,
|
||||
// setting _mapIdInitialized along the way to avoid going to the MapComponent every iteration.
|
||||
static MapId FindMapIdAndSet(TransformComponent xform, IEntityManager entMan, EntityQuery<TransformComponent> xformQuery)
|
||||
static MapId FindMapIdAndSet(TransformComponent xform, IEntityManager entMan, EntityQuery<TransformComponent> xformQuery, IMapManager mapManager)
|
||||
{
|
||||
if (xform._mapIdInitialized)
|
||||
return xform.MapID;
|
||||
@@ -191,7 +191,7 @@ public abstract partial class SharedTransformSystem
|
||||
|
||||
if (xform.ParentUid.IsValid())
|
||||
{
|
||||
value = FindMapIdAndSet(xformQuery.GetComponent(xform.ParentUid), entMan, xformQuery);
|
||||
value = FindMapIdAndSet(xformQuery.GetComponent(xform.ParentUid), entMan, xformQuery, mapManager);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -207,6 +207,7 @@ public abstract partial class SharedTransformSystem
|
||||
}
|
||||
}
|
||||
|
||||
xform.MapUid = value == MapId.Nullspace ? null : mapManager.GetMapEntityId(value);
|
||||
xform.MapID = value;
|
||||
xform._mapIdInitialized = true;
|
||||
return value;
|
||||
@@ -216,7 +217,7 @@ public abstract partial class SharedTransformSystem
|
||||
|
||||
if (!component._mapIdInitialized)
|
||||
{
|
||||
FindMapIdAndSet(component, EntityManager, xformQuery);
|
||||
FindMapIdAndSet(component, EntityManager, xformQuery, _mapManager);
|
||||
component._mapIdInitialized = true;
|
||||
}
|
||||
|
||||
@@ -1124,23 +1125,6 @@ public abstract partial class SharedTransformSystem
|
||||
#endregion
|
||||
|
||||
#region State Handling
|
||||
private void ChangeMapId(TransformComponent xform, MapId newMapId, EntityQuery<TransformComponent> xformQuery, EntityQuery<MetaDataComponent> metaQuery)
|
||||
{
|
||||
if (newMapId == xform.MapID)
|
||||
return;
|
||||
|
||||
//Set Paused state
|
||||
var mapPaused = _mapManager.IsMapPaused(newMapId);
|
||||
var meta = metaQuery.GetComponent(xform.Owner);
|
||||
_metaSys.SetEntityPaused(xform.Owner, mapPaused, meta);
|
||||
|
||||
// Map entities retain their map Uids
|
||||
if (xform.Owner != xform.MapUid)
|
||||
xform.MapID = newMapId;
|
||||
|
||||
xform.UpdateChildMapIdsRecursive(newMapId, mapPaused, xformQuery, metaQuery, _metaSys);
|
||||
}
|
||||
|
||||
public void DetachParentToNull(TransformComponent xform)
|
||||
{
|
||||
if (xform._parent.IsValid())
|
||||
|
||||
Reference in New Issue
Block a user