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

@@ -136,7 +136,7 @@ namespace Content.Client.Audio
//TODO: Make this produce a hashset of nearby entities again. //TODO: Make this produce a hashset of nearby entities again.
var sourceDict = new Dictionary<string, List<AmbientSoundComponent>>(16); var sourceDict = new Dictionary<string, List<AmbientSoundComponent>>(16);
foreach (var entity in _lookup.GetEntitiesInRange(coordinates, _maxAmbientRange + RangeBuffer, LookupFlags.IncludeAnchored | LookupFlags.Approximate)) foreach (var entity in _lookup.GetEntitiesInRange(coordinates, _maxAmbientRange + RangeBuffer, LookupFlags.Anchored | LookupFlags.Approximate))
{ {
if (!EntityManager.TryGetComponent(entity, out AmbientSoundComponent? ambientComp) || if (!EntityManager.TryGetComponent(entity, out AmbientSoundComponent? ambientComp) ||
!ambientComp.Enabled || !ambientComp.Enabled ||

View File

@@ -363,7 +363,7 @@ namespace Content.Client.DragDrop
// TODO: Duplicated in SpriteSystem and TargetOutlineSystem. Should probably be cached somewhere for a frame? // TODO: Duplicated in SpriteSystem and TargetOutlineSystem. Should probably be cached somewhere for a frame?
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition).Position; var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition).Position;
var bounds = new Box2(mousePos - 1.5f, mousePos + 1.5f); var bounds = new Box2(mousePos - 1.5f, mousePos + 1.5f);
var pvsEntities = EntitySystem.Get<EntityLookupSystem>().GetEntitiesIntersecting(_eyeManager.CurrentMap, bounds, LookupFlags.Approximate | LookupFlags.IncludeAnchored); var pvsEntities = EntitySystem.Get<EntityLookupSystem>().GetEntitiesIntersecting(_eyeManager.CurrentMap, bounds, LookupFlags.Approximate | LookupFlags.Anchored);
foreach (var pvsEntity in pvsEntities) foreach (var pvsEntity in pvsEntities)
{ {
if (!EntityManager.TryGetComponent(pvsEntity, out ISpriteComponent? inRangeSprite) || if (!EntityManager.TryGetComponent(pvsEntity, out ISpriteComponent? inRangeSprite) ||

View File

@@ -108,30 +108,33 @@ namespace Content.Client.NodeContainer
// Group visible nodes by grid tiles. // Group visible nodes by grid tiles.
var worldAABB = overlayDrawArgs.WorldAABB; var worldAABB = overlayDrawArgs.WorldAABB;
_lookup.FastEntitiesIntersecting(map, ref worldAABB, entity => var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
foreach (var grid in _mapManager.FindGridsIntersecting(map, worldAABB))
{ {
if (!_system.Entities.TryGetValue(entity, out var nodeData)) foreach (var entity in _lookup.GetEntitiesIntersecting(grid.Index, worldAABB))
return;
var gridId = _entityManager.GetComponent<TransformComponent>(entity).GridID;
var grid = _mapManager.GetGrid(gridId);
var gridDict = _gridIndex.GetOrNew(gridId);
var coords = _entityManager.GetComponent<TransformComponent>(entity).Coordinates;
// TODO: This probably shouldn't be capable of returning NaN...
if (float.IsNaN(coords.Position.X) || float.IsNaN(coords.Position.Y))
return;
var tile = gridDict.GetOrNew(grid.TileIndicesFor(coords));
foreach (var (group, nodeDatum) in nodeData)
{ {
if (!_system.Filtered.Contains(group.GroupId)) if (!_system.Entities.TryGetValue(entity, out var nodeData))
return;
var gridDict = _gridIndex.GetOrNew(grid.Index);
var coords = xformQuery.GetComponent(entity).Coordinates;
// TODO: This probably shouldn't be capable of returning NaN...
if (float.IsNaN(coords.Position.X) || float.IsNaN(coords.Position.Y))
return;
var tile = gridDict.GetOrNew(grid.TileIndicesFor(coords));
foreach (var (group, nodeDatum) in nodeData)
{ {
tile.Add((group, nodeDatum)); if (!_system.Filtered.Contains(group.GroupId))
{
tile.Add((group, nodeDatum));
}
} }
} }
}); }
foreach (var (gridId, gridDict) in _gridIndex) foreach (var (gridId, gridDict) in _gridIndex)
{ {

View File

@@ -115,7 +115,7 @@ public sealed class TargetOutlineSystem : EntitySystem
// TODO: Duplicated in SpriteSystem and DragDropSystem. Should probably be cached somewhere for a frame? // TODO: Duplicated in SpriteSystem and DragDropSystem. Should probably be cached somewhere for a frame?
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition).Position; var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition).Position;
var bounds = new Box2(mousePos - LookupSize, mousePos + LookupSize); var bounds = new Box2(mousePos - LookupSize, mousePos + LookupSize);
var pvsEntities = _lookup.GetEntitiesIntersecting(_eyeManager.CurrentMap, bounds, LookupFlags.Approximate | LookupFlags.IncludeAnchored); var pvsEntities = _lookup.GetEntitiesIntersecting(_eyeManager.CurrentMap, bounds, LookupFlags.Approximate | LookupFlags.Anchored);
foreach (var entity in pvsEntities) foreach (var entity in pvsEntities)
{ {

View File

@@ -114,7 +114,7 @@ namespace Content.Client.Verbs
} }
// Get entities // Get entities
var entities = _entityLookup.GetEntitiesInRange(targetPos.MapId, targetPos.Position, EntityMenuLookupSize) var entities = _entityLookup.GetEntitiesInRange(targetPos, EntityMenuLookupSize)
.ToList(); .ToList();
if (entities.Count == 0) if (entities.Count == 0)

View File

@@ -18,6 +18,7 @@ using Robust.Shared.Enums;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Server.Chat.Commands namespace Content.Server.Chat.Commands
@@ -101,7 +102,7 @@ namespace Content.Server.Chat.Commands
} }
// Get all entities in range of the suicider // 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) if (entities.Length > 0)
{ {

View File

@@ -52,7 +52,7 @@ namespace Content.Server.Construction.Conditions
var transform = entityManager.GetComponent<TransformComponent>(uid); var transform = entityManager.GetComponent<TransformComponent>(uid);
var indices = transform.Coordinates.ToVector2i(entityManager, IoCManager.Resolve<IMapManager>()); 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) foreach (var ent in entities)
{ {

View File

@@ -16,6 +16,7 @@ using Content.Shared.Inventory;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Stacks; using Content.Shared.Stacks;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Players; using Robust.Shared.Players;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -79,7 +80,7 @@ namespace Content.Server.Construction
var pos = Transform(user).MapPosition; 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; yield return near;

View File

@@ -16,6 +16,7 @@ using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager; using Robust.Shared.Serialization.Manager;
using Content.Shared.Inventory.Events; using Content.Shared.Inventory.Events;
using Content.Server.Nutrition.EntitySystems; using Content.Server.Nutrition.EntitySystems;
using Robust.Shared.Map;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Server.Disease namespace Content.Server.Disease
@@ -369,7 +370,7 @@ namespace Content.Server.Disease
var carrierQuery = GetEntityQuery<DiseaseCarrierComponent>(); 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) || if (!carrierQuery.TryGetComponent(entity, out var carrier) ||
!_interactionSystem.InRangeUnobstructed(uid, entity)) continue; !_interactionSystem.InRangeUnobstructed(uid, entity)) continue;

View File

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

View File

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

View File

@@ -191,27 +191,21 @@ public sealed partial class ExplosionSystem : EntitySystem
// enumerator-changed-while-enumerating errors. // enumerator-changed-while-enumerating errors.
List<(EntityUid, TransformComponent?) > list = new(); List<(EntityUid, TransformComponent?) > list = new();
EntityUidQueryCallback callback = uid => void AddIntersecting(List<(EntityUid, TransformComponent?)> listy)
{ {
if (processed.Contains(uid)) foreach (var uid in _entityLookup.GetLocalEntitiesIntersecting(lookup, ref gridBox, LookupFlags.None))
return;
if (!xformQuery.TryGetComponent(uid, out var xform))
return;
if (xform.ParentUid != grid.GridEntityId)
{ {
if (!metaQuery.TryGetComponent(uid, out var meta)) if (processed.Contains(uid))
return; continue;
// Not parented to grid. Likely in a container.
if (_containerSystem.IsEntityInContainer(uid, meta)) if (!xformQuery.TryGetComponent(uid, out var xform))
return; continue;
listy.Add((uid, xform));
} }
}
list.Add((uid, xform)); AddIntersecting(list);
};
_entityLookup.FastEntitiesIntersecting(lookup, ref gridBox, callback);
// process those entities // process those entities
foreach (var (entity, xform) in list) foreach (var (entity, xform) in list)
@@ -241,7 +235,7 @@ public sealed partial class ExplosionSystem : EntitySystem
return !tileBlocked; return !tileBlocked;
list.Clear(); list.Clear();
_entityLookup.FastEntitiesIntersecting(lookup, ref gridBox, callback); AddIntersecting(list);
foreach (var (entity, xform) in list) foreach (var (entity, xform) in list)
{ {
@@ -274,38 +268,34 @@ public sealed partial class ExplosionSystem : EntitySystem
var worldBox = spaceMatrix.TransformBox(gridBox); var worldBox = spaceMatrix.TransformBox(gridBox);
List<(EntityUid, TransformComponent)> list = new(); List<(EntityUid, TransformComponent)> list = new();
EntityUidQueryCallback callback = uid => void AddIntersecting(List<(EntityUid, TransformComponent)> listy)
{ {
if (processed.Contains(uid)) foreach (var uid in _entityLookup.GetEntitiesIntersecting(lookup, ref worldBox, LookupFlags.None))
return;
var xform = xformQuery.GetComponent(uid);
if (xform.ParentUid == lookup.Owner)
{ {
// parented directly to the map, use local position if (processed.Contains(uid))
if (gridBox.Contains(invSpaceMatrix.Transform(xform.LocalPosition))) return;
list.Add((uid, xform));
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)) AddIntersecting(list);
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);
foreach (var (entity, xform) in 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 // 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. // lookup is relatively minor computational cost, and throwing is disabled for nukes anyways.
list.Clear(); list.Clear();
_entityLookup.FastEntitiesIntersecting(lookup, ref worldBox, callback); AddIntersecting(list);
foreach (var (entity, xform) in list) foreach (var (entity, xform) in list)
{ {
ProcessEntity(entity, epicenter, null, throwForce, id, damageQuery, physicsQuery, xform); ProcessEntity(entity, epicenter, null, throwForce, id, damageQuery, physicsQuery, xform);

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. // I tried having it so level 6 can de-anchor. BAD IDEA, MASSIVE LAG.
if (entity == component.Owner || if (entity == component.Owner ||
!EntityManager.TryGetComponent<PhysicsComponent?>(entity, out var collidableComponent) || !TryComp<PhysicsComponent?>(entity, out var collidableComponent) ||
collidableComponent.BodyType == BodyType.Static) continue; collidableComponent.BodyType == BodyType.Static) continue;
if (!CanPull(entity)) 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; if (vec.Length < destroyRange - 0.01f) continue;

View File

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

View File

@@ -20,7 +20,7 @@ namespace Content.Shared.Construction.Conditions
{ {
var result = false; var result = false;
foreach (var entity in location.GetEntitiesInTile(LookupFlags.Approximate | LookupFlags.IncludeAnchored)) foreach (var entity in location.GetEntitiesInTile(LookupFlags.Approximate | LookupFlags.Anchored))
{ {
if (IoCManager.Resolve<IEntityManager>().HasComponent<SharedCanBuildWindowOnTopComponent>(entity)) if (IoCManager.Resolve<IEntityManager>().HasComponent<SharedCanBuildWindowOnTopComponent>(entity))
result = true; result = true;

View File

@@ -16,7 +16,7 @@ namespace Content.Shared.Construction.Conditions
public bool Condition(EntityUid user, EntityCoordinates location, Direction direction) public bool Condition(EntityUid user, EntityCoordinates location, Direction direction)
{ {
var tagSystem = EntitySystem.Get<TagSystem>(); var tagSystem = EntitySystem.Get<TagSystem>();
foreach (var entity in location.GetEntitiesInTile(LookupFlags.Approximate | LookupFlags.IncludeAnchored)) foreach (var entity in location.GetEntitiesInTile(LookupFlags.Approximate | LookupFlags.Anchored))
{ {
if (tagSystem.HasTag(entity, "Window")) if (tagSystem.HasTag(entity, "Window"))
return false; return false;

View File

@@ -157,7 +157,7 @@ namespace Content.Shared.Maps
/// Helper that returns all entities in a turf. /// Helper that returns all entities in a turf.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<EntityUid> GetEntitiesInTile(this TileRef turf, LookupFlags flags = LookupFlags.IncludeAnchored, EntityLookupSystem? lookupSystem = null) public static IEnumerable<EntityUid> GetEntitiesInTile(this TileRef turf, LookupFlags flags = LookupFlags.Anchored, EntityLookupSystem? lookupSystem = null)
{ {
lookupSystem ??= EntitySystem.Get<EntityLookupSystem>(); lookupSystem ??= EntitySystem.Get<EntityLookupSystem>();
@@ -170,7 +170,7 @@ namespace Content.Shared.Maps
/// <summary> /// <summary>
/// Helper that returns all entities in a turf. /// Helper that returns all entities in a turf.
/// </summary> /// </summary>
public static IEnumerable<EntityUid> GetEntitiesInTile(this EntityCoordinates coordinates, LookupFlags flags = LookupFlags.IncludeAnchored, EntityLookupSystem? lookupSystem = null) public static IEnumerable<EntityUid> GetEntitiesInTile(this EntityCoordinates coordinates, LookupFlags flags = LookupFlags.Anchored, EntityLookupSystem? lookupSystem = null)
{ {
var turf = coordinates.GetTileRef(); var turf = coordinates.GetTileRef();
@@ -183,7 +183,7 @@ namespace Content.Shared.Maps
/// <summary> /// <summary>
/// Helper that returns all entities in a turf. /// Helper that returns all entities in a turf.
/// </summary> /// </summary>
public static IEnumerable<EntityUid> GetEntitiesInTile(this Vector2i indices, GridId gridId, LookupFlags flags = LookupFlags.IncludeAnchored, EntityLookupSystem? lookupSystem = null) public static IEnumerable<EntityUid> GetEntitiesInTile(this Vector2i indices, GridId gridId, LookupFlags flags = LookupFlags.Anchored, EntityLookupSystem? lookupSystem = null)
{ {
return GetEntitiesInTile(indices.GetTileRef(gridId), flags, lookupSystem); return GetEntitiesInTile(indices.GetTileRef(gridId), flags, lookupSystem);
} }