diff --git a/Content.Client/Audio/AmbientSoundSystem.cs b/Content.Client/Audio/AmbientSoundSystem.cs index ac684f8822..1738dbe098 100644 --- a/Content.Client/Audio/AmbientSoundSystem.cs +++ b/Content.Client/Audio/AmbientSoundSystem.cs @@ -136,7 +136,7 @@ namespace Content.Client.Audio //TODO: Make this produce a hashset of nearby entities again. var sourceDict = new Dictionary>(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 || diff --git a/Content.Client/DragDrop/DragDropSystem.cs b/Content.Client/DragDrop/DragDropSystem.cs index 5bacb08bff..6cb6ef5f58 100644 --- a/Content.Client/DragDrop/DragDropSystem.cs +++ b/Content.Client/DragDrop/DragDropSystem.cs @@ -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().GetEntitiesIntersecting(_eyeManager.CurrentMap, bounds, LookupFlags.Approximate | LookupFlags.IncludeAnchored); + var pvsEntities = EntitySystem.Get().GetEntitiesIntersecting(_eyeManager.CurrentMap, bounds, LookupFlags.Approximate | LookupFlags.Anchored); foreach (var pvsEntity in pvsEntities) { if (!EntityManager.TryGetComponent(pvsEntity, out ISpriteComponent? inRangeSprite) || diff --git a/Content.Client/NodeContainer/NodeVisualizationOverlay.cs b/Content.Client/NodeContainer/NodeVisualizationOverlay.cs index 13c00fc6be..7946130a2e 100644 --- a/Content.Client/NodeContainer/NodeVisualizationOverlay.cs +++ b/Content.Client/NodeContainer/NodeVisualizationOverlay.cs @@ -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(); + + foreach (var grid in _mapManager.FindGridsIntersecting(map, worldAABB)) { - if (!_system.Entities.TryGetValue(entity, out var nodeData)) - return; - - var gridId = _entityManager.GetComponent(entity).GridID; - var grid = _mapManager.GetGrid(gridId); - var gridDict = _gridIndex.GetOrNew(gridId); - var coords = _entityManager.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) + 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) { diff --git a/Content.Client/Outline/TargetOutlineSystem.cs b/Content.Client/Outline/TargetOutlineSystem.cs index b004d34289..cc2581ac41 100644 --- a/Content.Client/Outline/TargetOutlineSystem.cs +++ b/Content.Client/Outline/TargetOutlineSystem.cs @@ -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) { diff --git a/Content.Client/Verbs/VerbSystem.cs b/Content.Client/Verbs/VerbSystem.cs index b1277d5c97..5a3385a604 100644 --- a/Content.Client/Verbs/VerbSystem.cs +++ b/Content.Client/Verbs/VerbSystem.cs @@ -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) diff --git a/Content.Server/Chat/Commands/SuicideCommand.cs b/Content.Server/Chat/Commands/SuicideCommand.cs index 8c686128aa..89b54f9a50 100644 --- a/Content.Server/Chat/Commands/SuicideCommand.cs +++ b/Content.Server/Chat/Commands/SuicideCommand.cs @@ -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().GetEntitiesInRange(owner, 1, LookupFlags.Approximate | LookupFlags.IncludeAnchored).ToArray(); + var entities = EntitySystem.Get().GetEntitiesInRange(owner, 1, LookupFlags.Approximate | LookupFlags.Anchored).ToArray(); if (entities.Length > 0) { diff --git a/Content.Server/Construction/Conditions/ComponentInTile.cs b/Content.Server/Construction/Conditions/ComponentInTile.cs index 9c9b2c0876..eb8c863b7d 100644 --- a/Content.Server/Construction/Conditions/ComponentInTile.cs +++ b/Content.Server/Construction/Conditions/ComponentInTile.cs @@ -52,7 +52,7 @@ namespace Content.Server.Construction.Conditions var transform = entityManager.GetComponent(uid); var indices = transform.Coordinates.ToVector2i(entityManager, IoCManager.Resolve()); - var entities = indices.GetEntitiesInTile(transform.GridID, LookupFlags.Approximate | LookupFlags.IncludeAnchored, EntitySystem.Get()); + var entities = indices.GetEntitiesInTile(transform.GridID, LookupFlags.Approximate | LookupFlags.Anchored, EntitySystem.Get()); foreach (var ent in entities) { diff --git a/Content.Server/Construction/ConstructionSystem.Initial.cs b/Content.Server/Construction/ConstructionSystem.Initial.cs index 72c9d14967..b40ed21b9d 100644 --- a/Content.Server/Construction/ConstructionSystem.Initial.cs +++ b/Content.Server/Construction/ConstructionSystem.Initial.cs @@ -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; } } diff --git a/Content.Server/Disease/DiseaseSystem.cs b/Content.Server/Disease/DiseaseSystem.cs index b4f553683b..00ce1eb761 100644 --- a/Content.Server/Disease/DiseaseSystem.cs +++ b/Content.Server/Disease/DiseaseSystem.cs @@ -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(); - 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; diff --git a/Content.Server/Drone/DroneSystem.cs b/Content.Server/Drone/DroneSystem.cs index 69b8fb7ac8..c5d46f63b5 100644 --- a/Content.Server/Drone/DroneSystem.cs +++ b/Content.Server/Drone/DroneSystem.cs @@ -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(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(entity) && !HasComp(entity) && !HasComp(entity)) { diff --git a/Content.Server/Electrocution/ElectrocutionSystem.cs b/Content.Server/Electrocution/ElectrocutionSystem.cs index b80cc73d9e..1722732fe6 100644 --- a/Content.Server/Electrocution/ElectrocutionSystem.cs +++ b/Content.Server/Electrocution/ElectrocutionSystem.cs @@ -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; diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs index 352e579d4d..973ffc5ec8 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs @@ -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 ProcessedEntities = new(); /// - /// This integer tracks how much of this explosion has been processed. + /// This integer tracks how much of this explosion has been processed. /// public int CurrentIteration { get; private set; } = 0; @@ -652,7 +642,7 @@ sealed class Explosion } /// - /// Attempt to process (i.e., damage entities) some number of grid tiles. + /// Attempt to process (i.e., damage entities) some number of grid tiles. /// public int Process(int processingTarget) { diff --git a/Content.Server/Singularity/EntitySystems/SingularitySystem.cs b/Content.Server/Singularity/EntitySystems/SingularitySystem.cs index 0d10616e2d..777be02a8c 100644 --- a/Content.Server/Singularity/EntitySystems/SingularitySystem.cs +++ b/Content.Server/Singularity/EntitySystems/SingularitySystem.cs @@ -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(entity, out var collidableComponent) || + !TryComp(entity, out var collidableComponent) || collidableComponent.BodyType == BodyType.Static) continue; if (!CanPull(entity)) continue; - var vec = worldPos - EntityManager.GetComponent(entity).WorldPosition; + var vec = worldPos - Transform(entity).WorldPosition; if (vec.Length < destroyRange - 0.01f) continue; diff --git a/Content.Server/Storage/Components/EntityStorageComponent.cs b/Content.Server/Storage/Components/EntityStorageComponent.cs index 2019803ef1..6d223e97e5 100644 --- a/Content.Server/Storage/Components/EntityStorageComponent.cs +++ b/Content.Server/Storage/Components/EntityStorageComponent.cs @@ -476,7 +476,7 @@ namespace Content.Server.Storage.Components protected virtual IEnumerable DetermineCollidingEntities() { var entityLookup = EntitySystem.Get(); - return entityLookup.GetEntitiesIntersecting(Owner, _enteringRange, LookupFlags.Approximate); + return entityLookup.GetEntitiesInRange(Owner, _enteringRange, LookupFlags.Approximate); } } diff --git a/Content.Shared/Construction/Conditions/EmptyOrWindowValidInTile.cs b/Content.Shared/Construction/Conditions/EmptyOrWindowValidInTile.cs index de9f97e5e0..ca2c6e05e0 100644 --- a/Content.Shared/Construction/Conditions/EmptyOrWindowValidInTile.cs +++ b/Content.Shared/Construction/Conditions/EmptyOrWindowValidInTile.cs @@ -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().HasComponent(entity)) result = true; diff --git a/Content.Shared/Construction/Conditions/NoWindowsInTile.cs b/Content.Shared/Construction/Conditions/NoWindowsInTile.cs index 460ac86088..508a5d6101 100644 --- a/Content.Shared/Construction/Conditions/NoWindowsInTile.cs +++ b/Content.Shared/Construction/Conditions/NoWindowsInTile.cs @@ -16,7 +16,7 @@ namespace Content.Shared.Construction.Conditions public bool Condition(EntityUid user, EntityCoordinates location, Direction direction) { var tagSystem = EntitySystem.Get(); - 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; diff --git a/Content.Shared/Maps/TurfHelpers.cs b/Content.Shared/Maps/TurfHelpers.cs index ffbe77133d..56d3324b59 100644 --- a/Content.Shared/Maps/TurfHelpers.cs +++ b/Content.Shared/Maps/TurfHelpers.cs @@ -157,7 +157,7 @@ namespace Content.Shared.Maps /// Helper that returns all entities in a turf. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IEnumerable GetEntitiesInTile(this TileRef turf, LookupFlags flags = LookupFlags.IncludeAnchored, EntityLookupSystem? lookupSystem = null) + public static IEnumerable GetEntitiesInTile(this TileRef turf, LookupFlags flags = LookupFlags.Anchored, EntityLookupSystem? lookupSystem = null) { lookupSystem ??= EntitySystem.Get(); @@ -170,7 +170,7 @@ namespace Content.Shared.Maps /// /// Helper that returns all entities in a turf. /// - public static IEnumerable GetEntitiesInTile(this EntityCoordinates coordinates, LookupFlags flags = LookupFlags.IncludeAnchored, EntityLookupSystem? lookupSystem = null) + public static IEnumerable GetEntitiesInTile(this EntityCoordinates coordinates, LookupFlags flags = LookupFlags.Anchored, EntityLookupSystem? lookupSystem = null) { var turf = coordinates.GetTileRef(); @@ -183,7 +183,7 @@ namespace Content.Shared.Maps /// /// Helper that returns all entities in a turf. /// - public static IEnumerable GetEntitiesInTile(this Vector2i indices, GridId gridId, LookupFlags flags = LookupFlags.IncludeAnchored, EntityLookupSystem? lookupSystem = null) + public static IEnumerable GetEntitiesInTile(this Vector2i indices, GridId gridId, LookupFlags flags = LookupFlags.Anchored, EntityLookupSystem? lookupSystem = null) { return GetEntitiesInTile(indices.GetTileRef(gridId), flags, lookupSystem); }