Update content for new lookup API (#7363)

This commit is contained in:
metalgearsloth
2022-04-06 19:35:18 +10:00
committed by GitHub
parent 8ac330649b
commit de6651ac01
17 changed files with 83 additions and 86 deletions

View File

@@ -18,6 +18,7 @@ using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Server.Chat.Commands
@@ -101,7 +102,7 @@ namespace Content.Server.Chat.Commands
}
// Get all entities in range of the suicider
var entities = EntitySystem.Get<EntityLookupSystem>().GetEntitiesInRange(owner, 1, LookupFlags.Approximate | LookupFlags.IncludeAnchored).ToArray();
var entities = EntitySystem.Get<EntityLookupSystem>().GetEntitiesInRange(owner, 1, LookupFlags.Approximate | LookupFlags.Anchored).ToArray();
if (entities.Length > 0)
{

View File

@@ -52,7 +52,7 @@ namespace Content.Server.Construction.Conditions
var transform = entityManager.GetComponent<TransformComponent>(uid);
var indices = transform.Coordinates.ToVector2i(entityManager, IoCManager.Resolve<IMapManager>());
var entities = indices.GetEntitiesInTile(transform.GridID, LookupFlags.Approximate | LookupFlags.IncludeAnchored, EntitySystem.Get<EntityLookupSystem>());
var entities = indices.GetEntitiesInTile(transform.GridID, LookupFlags.Approximate | LookupFlags.Anchored, EntitySystem.Get<EntityLookupSystem>());
foreach (var ent in entities)
{

View File

@@ -16,6 +16,7 @@ using Content.Shared.Inventory;
using Content.Shared.Popups;
using Content.Shared.Stacks;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Players;
using Robust.Shared.Timing;
@@ -79,9 +80,9 @@ namespace Content.Server.Construction
var pos = Transform(user).MapPosition;
foreach (var near in _lookupSystem.GetEntitiesInRange(user!, 2f, LookupFlags.Approximate))
foreach (var near in _lookupSystem.GetEntitiesInRange(user, 2f, LookupFlags.Approximate))
{
if (_interactionSystem.InRangeUnobstructed(pos, near, 2f) && _containerSystem.IsInSameOrParentContainer(user, near))
if (_interactionSystem.InRangeUnobstructed(pos, near, 2f) && _containerSystem.IsInSameOrParentContainer(user, near))
yield return near;
}
}

View File

@@ -16,6 +16,7 @@ using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager;
using Content.Shared.Inventory.Events;
using Content.Server.Nutrition.EntitySystems;
using Robust.Shared.Map;
using Robust.Shared.Utility;
namespace Content.Server.Disease
@@ -369,7 +370,7 @@ namespace Content.Server.Disease
var carrierQuery = GetEntityQuery<DiseaseCarrierComponent>();
foreach (var entity in _lookup.GetEntitiesInRange(xform.MapID, xform.WorldPosition, 2f))
foreach (var entity in _lookup.GetEntitiesInRange(xform.MapPosition, 2f))
{
if (!carrierQuery.TryGetComponent(entity, out var carrier) ||
!_interactionSystem.InRangeUnobstructed(uid, entity)) continue;

View File

@@ -21,6 +21,7 @@ using Content.Server.UserInterface;
using Robust.Shared.Player;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Storage;
using Robust.Shared.Map;
using Robust.Shared.Random;
using Robust.Shared.Timing;
@@ -175,7 +176,7 @@ namespace Content.Server.Drone
private bool NonDronesInRange(EntityUid uid, DroneComponent component)
{
var xform = Comp<TransformComponent>(uid);
foreach (var entity in _lookup.GetEntitiesInRange(xform.MapID, xform.WorldPosition, component.InteractionBlockRange))
foreach (var entity in _lookup.GetEntitiesInRange(xform.MapPosition, component.InteractionBlockRange))
{
if (HasComp<MindComponent>(entity) && !HasComp<DroneComponent>(entity) && !HasComp<GhostComponent>(entity))
{

View File

@@ -170,7 +170,7 @@ namespace Content.Server.Electrocution
if (electrified.NoWindowInTile)
{
foreach (var entity in transform.Coordinates.GetEntitiesInTile(
LookupFlags.Approximate | LookupFlags.IncludeAnchored, _entityLookup))
LookupFlags.Approximate | LookupFlags.Anchored, _entityLookup))
{
if (_tagSystem.HasTag(entity, "Window"))
return false;

View File

@@ -191,27 +191,21 @@ public sealed partial class ExplosionSystem : EntitySystem
// enumerator-changed-while-enumerating errors.
List<(EntityUid, TransformComponent?) > list = new();
EntityUidQueryCallback callback = uid =>
void AddIntersecting(List<(EntityUid, TransformComponent?)> listy)
{
if (processed.Contains(uid))
return;
if (!xformQuery.TryGetComponent(uid, out var xform))
return;
if (xform.ParentUid != grid.GridEntityId)
foreach (var uid in _entityLookup.GetLocalEntitiesIntersecting(lookup, ref gridBox, LookupFlags.None))
{
if (!metaQuery.TryGetComponent(uid, out var meta))
return;
// Not parented to grid. Likely in a container.
if (_containerSystem.IsEntityInContainer(uid, meta))
return;
if (processed.Contains(uid))
continue;
if (!xformQuery.TryGetComponent(uid, out var xform))
continue;
listy.Add((uid, xform));
}
}
list.Add((uid, xform));
};
_entityLookup.FastEntitiesIntersecting(lookup, ref gridBox, callback);
AddIntersecting(list);
// process those entities
foreach (var (entity, xform) in list)
@@ -241,7 +235,7 @@ public sealed partial class ExplosionSystem : EntitySystem
return !tileBlocked;
list.Clear();
_entityLookup.FastEntitiesIntersecting(lookup, ref gridBox, callback);
AddIntersecting(list);
foreach (var (entity, xform) in list)
{
@@ -274,38 +268,34 @@ public sealed partial class ExplosionSystem : EntitySystem
var worldBox = spaceMatrix.TransformBox(gridBox);
List<(EntityUid, TransformComponent)> list = new();
EntityUidQueryCallback callback = uid =>
void AddIntersecting(List<(EntityUid, TransformComponent)> listy)
{
if (processed.Contains(uid))
return;
var xform = xformQuery.GetComponent(uid);
if (xform.ParentUid == lookup.Owner)
foreach (var uid in _entityLookup.GetEntitiesIntersecting(lookup, ref worldBox, LookupFlags.None))
{
// parented directly to the map, use local position
if (gridBox.Contains(invSpaceMatrix.Transform(xform.LocalPosition)))
list.Add((uid, xform));
if (processed.Contains(uid))
return;
return;
var xform = xformQuery.GetComponent(uid);
if (xform.ParentUid == lookup.Owner)
{
// parented directly to the map, use local position
if (gridBox.Contains(invSpaceMatrix.Transform(xform.LocalPosition)))
listy.Add((uid, xform));
return;
}
// "worldPos" should be the space/map local position.
var worldPos = _transformSystem.GetWorldPosition(xform, xformQuery);
// finally check if it intersects our tile
if (gridBox.Contains(invSpaceMatrix.Transform(worldPos)))
listy.Add((uid, xform));
}
}
if (!metaQuery.TryGetComponent(uid, out var meta))
return;
// Not parented to map. Likely in a container.
if (_containerSystem.IsEntityInContainer(uid, meta))
return;
// "worldPos" should be the space/map local position.
var worldPos = _transformSystem.GetWorldPosition(xform, xformQuery);
// finally check if it intersects our tile
if (gridBox.Contains(invSpaceMatrix.Transform(worldPos)))
list.Add((uid, xform));
};
_entityLookup.FastEntitiesIntersecting(lookup, ref worldBox, callback);
AddIntersecting(list);
foreach (var (entity, xform) in list)
{
@@ -319,7 +309,7 @@ public sealed partial class ExplosionSystem : EntitySystem
// Also, throw any entities that were spawned as shrapnel. Compared to entity spawning & destruction, this extra
// lookup is relatively minor computational cost, and throwing is disabled for nukes anyways.
list.Clear();
_entityLookup.FastEntitiesIntersecting(lookup, ref worldBox, callback);
AddIntersecting(list);
foreach (var (entity, xform) in list)
{
ProcessEntity(entity, epicenter, null, throwForce, id, damageQuery, physicsQuery, xform);
@@ -455,7 +445,7 @@ sealed class Explosion
public readonly HashSet<EntityUid> ProcessedEntities = new();
/// <summary>
/// This integer tracks how much of this explosion has been processed.
/// This integer tracks how much of this explosion has been processed.
/// </summary>
public int CurrentIteration { get; private set; } = 0;
@@ -652,7 +642,7 @@ sealed class Explosion
}
/// <summary>
/// Attempt to process (i.e., damage entities) some number of grid tiles.
/// Attempt to process (i.e., damage entities) some number of grid tiles.
/// </summary>
public int Process(int processingTarget)
{

View File

@@ -191,12 +191,12 @@ namespace Content.Server.Singularity.EntitySystems
{
// I tried having it so level 6 can de-anchor. BAD IDEA, MASSIVE LAG.
if (entity == component.Owner ||
!EntityManager.TryGetComponent<PhysicsComponent?>(entity, out var collidableComponent) ||
!TryComp<PhysicsComponent?>(entity, out var collidableComponent) ||
collidableComponent.BodyType == BodyType.Static) continue;
if (!CanPull(entity)) continue;
var vec = worldPos - EntityManager.GetComponent<TransformComponent>(entity).WorldPosition;
var vec = worldPos - Transform(entity).WorldPosition;
if (vec.Length < destroyRange - 0.01f) continue;

View File

@@ -476,7 +476,7 @@ namespace Content.Server.Storage.Components
protected virtual IEnumerable<EntityUid> DetermineCollidingEntities()
{
var entityLookup = EntitySystem.Get<EntityLookupSystem>();
return entityLookup.GetEntitiesIntersecting(Owner, _enteringRange, LookupFlags.Approximate);
return entityLookup.GetEntitiesInRange(Owner, _enteringRange, LookupFlags.Approximate);
}
}