mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-06 17:58:05 +02:00
Remove some unnecessary EntityQuery<T> and warns (#4167)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
@@ -21,6 +20,8 @@ namespace Robust.Shared.GameObjects
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
|
||||
private EntityQuery<MapGridComponent> _gridQuery;
|
||||
private EntityQuery<MetaDataComponent> _metaQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
private readonly Queue<MoveEvent> _gridMoves = new();
|
||||
@@ -32,7 +33,10 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
UpdatesOutsidePrediction = true;
|
||||
|
||||
_gridQuery = GetEntityQuery<MapGridComponent>();
|
||||
_metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
SubscribeLocalEvent<TileChangedEvent>(MapManagerOnTileChanged);
|
||||
SubscribeLocalEvent<TransformComponent, ComponentInit>(OnCompInit);
|
||||
SubscribeLocalEvent<TransformComponent, ComponentStartup>(OnCompStartup);
|
||||
@@ -77,20 +81,17 @@ namespace Robust.Shared.GameObjects
|
||||
if (!TryComp(gridId, out BroadphaseComponent? lookup) || !_mapManager.TryGetGrid(gridId, out var grid))
|
||||
return;
|
||||
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||
|
||||
if (!xformQuery.TryGetComponent(gridId, out var gridXform))
|
||||
if (!_xformQuery.TryGetComponent(gridId, out var gridXform))
|
||||
return;
|
||||
|
||||
if (!xformQuery.TryGetComponent(gridXform.MapUid, out var mapTransform))
|
||||
if (!_xformQuery.TryGetComponent(gridXform.MapUid, out var mapTransform))
|
||||
return;
|
||||
|
||||
var aabb = _lookup.GetLocalBounds(tileIndices, grid.TileSize);
|
||||
|
||||
foreach (var entity in _lookup.GetEntitiesIntersecting(lookup, aabb, LookupFlags.Uncontained | LookupFlags.Approximate))
|
||||
{
|
||||
if (!xformQuery.TryGetComponent(entity, out var xform) || xform.ParentUid != gridId)
|
||||
if (!_xformQuery.TryGetComponent(entity, out var xform) || xform.ParentUid != gridId)
|
||||
continue;
|
||||
|
||||
if (!aabb.Contains(xform.LocalPosition))
|
||||
@@ -99,9 +100,9 @@ namespace Robust.Shared.GameObjects
|
||||
// If a tile is being removed due to an explosion or somesuch, some entities are likely being deleted.
|
||||
// Avoid unnecessary entity updates.
|
||||
if (EntityManager.IsQueuedForDeletion(entity))
|
||||
DetachParentToNull(entity, xform, xformQuery, metaQuery, gridXform);
|
||||
DetachParentToNull(entity, xform, gridXform);
|
||||
else
|
||||
SetParent(entity, xform, gridXform.MapUid.Value, xformQuery, mapTransform);
|
||||
SetParent(entity, xform, gridXform.MapUid.Value, mapTransform);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +142,12 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
public EntityCoordinates GetMoverCoordinates(TransformComponent xform, EntityQuery<TransformComponent> xformQuery)
|
||||
public EntityCoordinates GetMoverCoordinates(EntityUid uid)
|
||||
{
|
||||
return GetMoverCoordinates(uid, _xformQuery.GetComponent(uid));
|
||||
}
|
||||
|
||||
public EntityCoordinates GetMoverCoordinates(EntityUid uid, TransformComponent xform)
|
||||
{
|
||||
// Nullspace (or map)
|
||||
if (!xform.ParentUid.IsValid())
|
||||
@@ -149,26 +155,31 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
// GriddUid is only set after init.
|
||||
if (!xform._gridInitialized)
|
||||
InitializeGridUid(xform.Owner, xform, xformQuery, GetEntityQuery<MapGridComponent>());
|
||||
InitializeGridUid(uid, xform);
|
||||
|
||||
// Is the entity directly parented to the grid?
|
||||
if (xform.GridUid == xform.ParentUid)
|
||||
return xform.Coordinates;
|
||||
|
||||
DebugTools.Assert(!_mapManager.IsGrid(xform.Owner) && !_mapManager.IsMap(xform.Owner));
|
||||
DebugTools.Assert(!_mapManager.IsGrid(uid) && !_mapManager.IsMap(uid));
|
||||
|
||||
// Not parented to grid so convert their pos back to the grid.
|
||||
var worldPos = GetWorldPosition(xform, xformQuery);
|
||||
var worldPos = GetWorldPosition(xform, _xformQuery);
|
||||
|
||||
return xform.GridUid == null
|
||||
? new EntityCoordinates(xform.MapUid ?? xform.ParentUid, worldPos)
|
||||
: new EntityCoordinates(xform.GridUid.Value, xformQuery.GetComponent(xform.GridUid.Value).InvLocalMatrix.Transform(worldPos));
|
||||
: new EntityCoordinates(xform.GridUid.Value, _xformQuery.GetComponent(xform.GridUid.Value).InvLocalMatrix.Transform(worldPos));
|
||||
}
|
||||
|
||||
public EntityCoordinates GetMoverCoordinates(EntityCoordinates coordinates, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
return GetMoverCoordinates(coordinates);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Variant of <see cref="GetMoverCoordinates"/> that uses a entity coordinates, rather than an entity's transform.
|
||||
/// </summary>
|
||||
public EntityCoordinates GetMoverCoordinates(EntityCoordinates coordinates, EntityQuery<TransformComponent> xformQuery)
|
||||
public EntityCoordinates GetMoverCoordinates(EntityCoordinates coordinates)
|
||||
{
|
||||
var parentUid = coordinates.EntityId;
|
||||
|
||||
@@ -176,11 +187,11 @@ namespace Robust.Shared.GameObjects
|
||||
if (!parentUid.IsValid())
|
||||
return coordinates;
|
||||
|
||||
var parentXform = xformQuery.GetComponent(parentUid);
|
||||
var parentXform = _xformQuery.GetComponent(parentUid);
|
||||
|
||||
// GriddUid is only set after init.
|
||||
if (!parentXform._gridInitialized)
|
||||
InitializeGridUid(parentUid, parentXform, xformQuery, GetEntityQuery<MapGridComponent>());
|
||||
InitializeGridUid(parentUid, parentXform);
|
||||
|
||||
// Is the entity directly parented to the grid?
|
||||
if (parentXform.GridUid == parentUid)
|
||||
@@ -194,17 +205,17 @@ namespace Robust.Shared.GameObjects
|
||||
DebugTools.Assert(!_mapManager.IsGrid(parentUid) && !_mapManager.IsMap(parentUid));
|
||||
|
||||
// Not parented to grid so convert their pos back to the grid.
|
||||
var worldPos = GetWorldMatrix(parentXform, xformQuery).Transform(coordinates.Position);
|
||||
var worldPos = GetWorldMatrix(parentXform, _xformQuery).Transform(coordinates.Position);
|
||||
|
||||
return parentXform.GridUid == null
|
||||
? new EntityCoordinates(mapId ?? parentUid, worldPos)
|
||||
: new EntityCoordinates(parentXform.GridUid.Value, xformQuery.GetComponent(parentXform.GridUid.Value).InvLocalMatrix.Transform(worldPos));
|
||||
: new EntityCoordinates(parentXform.GridUid.Value, _xformQuery.GetComponent(parentXform.GridUid.Value).InvLocalMatrix.Transform(worldPos));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Variant of <see cref="GetMoverCoordinates()"/> that also returns the entity's world rotation
|
||||
/// </summary>
|
||||
public (EntityCoordinates Coords, Angle worldRot) GetMoverCoordinateRotation(EntityUid uid, TransformComponent xform, EntityQuery<TransformComponent> xformQuery)
|
||||
public (EntityCoordinates Coords, Angle worldRot) GetMoverCoordinateRotation(EntityUid uid, TransformComponent xform)
|
||||
{
|
||||
// Nullspace (or map)
|
||||
if (!xform.ParentUid.IsValid())
|
||||
@@ -212,19 +223,19 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
// GriddUid is only set after init.
|
||||
if (!xform._gridInitialized)
|
||||
InitializeGridUid(uid, xform, xformQuery, GetEntityQuery<MapGridComponent>());
|
||||
InitializeGridUid(uid, xform);
|
||||
|
||||
// Is the entity directly parented to the grid?
|
||||
if (xform.GridUid == xform.ParentUid)
|
||||
return (xform.Coordinates, GetWorldRotation(xform, xformQuery));
|
||||
return (xform.Coordinates, GetWorldRotation(xform, _xformQuery));
|
||||
|
||||
DebugTools.Assert(!_mapManager.IsGrid(uid) && !_mapManager.IsMap(uid));
|
||||
|
||||
var (pos, worldRot) = GetWorldPositionRotation(xform, xformQuery);
|
||||
var (pos, worldRot) = GetWorldPositionRotation(xform, _xformQuery);
|
||||
|
||||
var coords = xform.GridUid == null
|
||||
? new EntityCoordinates(xform.MapUid ?? xform.ParentUid, pos)
|
||||
: new EntityCoordinates(xform.GridUid.Value, xformQuery.GetComponent(xform.GridUid.Value).InvLocalMatrix.Transform(pos));
|
||||
: new EntityCoordinates(xform.GridUid.Value, _xformQuery.GetComponent(xform.GridUid.Value).InvLocalMatrix.Transform(pos));
|
||||
|
||||
return (coords, worldRot);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user