Update content for new lookup API (#7363)
This commit is contained in:
parent
8ac330649b
commit
de6651ac01
|
|
@ -136,7 +136,7 @@ namespace Content.Client.Audio
|
|||
//TODO: Make this produce a hashset of nearby entities again.
|
||||
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) ||
|
||||
!ambientComp.Enabled ||
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ namespace Content.Client.DragDrop
|
|||
// TODO: Duplicated in SpriteSystem and TargetOutlineSystem. Should probably be cached somewhere for a frame?
|
||||
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition).Position;
|
||||
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)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(pvsEntity, out ISpriteComponent? inRangeSprite) ||
|
||||
|
|
|
|||
|
|
@ -108,30 +108,33 @@ namespace Content.Client.NodeContainer
|
|||
|
||||
// Group visible nodes by grid tiles.
|
||||
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))
|
||||
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)
|
||||
foreach (var entity in _lookup.GetEntitiesIntersecting(grid.Index, worldAABB))
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public sealed class TargetOutlineSystem : EntitySystem
|
|||
// TODO: Duplicated in SpriteSystem and DragDropSystem. Should probably be cached somewhere for a frame?
|
||||
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition).Position;
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ namespace Content.Client.Verbs
|
|||
}
|
||||
|
||||
// Get entities
|
||||
var entities = _entityLookup.GetEntitiesInRange(targetPos.MapId, targetPos.Position, EntityMenuLookupSize)
|
||||
var entities = _entityLookup.GetEntitiesInRange(targetPos, EntityMenuLookupSize)
|
||||
.ToList();
|
||||
|
||||
if (entities.Count == 0)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Content.Shared.Construction.Conditions
|
|||
{
|
||||
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))
|
||||
result = true;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace Content.Shared.Construction.Conditions
|
|||
public bool Condition(EntityUid user, EntityCoordinates location, Direction direction)
|
||||
{
|
||||
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"))
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ namespace Content.Shared.Maps
|
|||
/// Helper that returns all entities in a turf.
|
||||
/// </summary>
|
||||
[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>();
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ namespace Content.Shared.Maps
|
|||
/// <summary>
|
||||
/// Helper that returns all entities in a turf.
|
||||
/// </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();
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ namespace Content.Shared.Maps
|
|||
/// <summary>
|
||||
/// Helper that returns all entities in a turf.
|
||||
/// </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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue