From d58b7f0ebe966f67aa8d6e0a239d6f5d8bc2f79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Aguilera=20Puerto?= Date: Sun, 6 Sep 2020 17:15:16 +0200 Subject: [PATCH] whoops --- Content.Server/Atmos/TileAtmosphere.cs | 3 +- .../Utility/GridTileLookupHelpers.cs | 39 +++++++++++++++++++ Content.Shared/Maps/TurfHelpers.cs | 5 +-- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 Content.Server/Utility/GridTileLookupHelpers.cs diff --git a/Content.Server/Atmos/TileAtmosphere.cs b/Content.Server/Atmos/TileAtmosphere.cs index 2d2db819fd..1a9d5b7e51 100644 --- a/Content.Server/Atmos/TileAtmosphere.cs +++ b/Content.Server/Atmos/TileAtmosphere.cs @@ -6,6 +6,7 @@ using Content.Server.Atmos.Reactions; using Content.Server.GameObjects.Components.Atmos; using Content.Server.GameObjects.EntitySystems.Atmos; using Content.Server.Interfaces; +using Content.Server.Utility; using Content.Shared.Atmos; using Content.Shared.Audio; using Content.Shared.Maps; @@ -1090,7 +1091,7 @@ namespace Content.Server.Atmos // TODO ATMOS firelocks! var reconsiderAdjacent = false; - foreach (var entity in GridIndices.GetEntitiesInTile(GridIndex)) + foreach (var entity in GridIndices.GetEntitiesInTileFast(GridIndex)) { if (!entity.TryGetComponent(out FirelockComponent firelock)) continue; reconsiderAdjacent |= firelock.EmergencyPressureStop(); diff --git a/Content.Server/Utility/GridTileLookupHelpers.cs b/Content.Server/Utility/GridTileLookupHelpers.cs new file mode 100644 index 0000000000..7d5223fe6e --- /dev/null +++ b/Content.Server/Utility/GridTileLookupHelpers.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using Content.Shared.Maps; +using Robust.Server.GameObjects.EntitySystems.TileLookup; +using Robust.Shared.GameObjects.Systems; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Map; + +namespace Content.Server.Utility +{ + public static class GridTileLookupHelpers + { + /// + /// Helper that returns all entities in a turf very fast. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static IEnumerable GetEntitiesInTileFast(this TileRef turf) + { + var gridTileLookup = EntitySystem.Get(); + + return gridTileLookup.GetEntitiesIntersecting(turf.GridIndex, turf.GridIndices); + } + + /// + /// Helper that returns all entities in a turf. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static IEnumerable GetEntitiesInTileFast(this MapIndices indices, GridId gridId) + { + var turf = indices.GetTileRef(gridId); + + if (turf == null) + return Enumerable.Empty(); + + return GetEntitiesInTileFast(turf.Value); + } + } +} diff --git a/Content.Shared/Maps/TurfHelpers.cs b/Content.Shared/Maps/TurfHelpers.cs index dc1d322c65..d059235264 100644 --- a/Content.Shared/Maps/TurfHelpers.cs +++ b/Content.Shared/Maps/TurfHelpers.cs @@ -5,7 +5,6 @@ using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; using Content.Shared.Physics; using Content.Shared.Utility; -using Robust.Server.GameObjects.EntitySystems.TileLookup; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; @@ -127,9 +126,9 @@ namespace Content.Shared.Maps [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable GetEntitiesInTile(this TileRef turf, bool approximate = false) { - var gridTileLookup = EntitySystem.Get(); + var entityManager = IoCManager.Resolve(); - return gridTileLookup.GetEntitiesIntersecting(turf.GridIndex, turf.GridIndices); + return entityManager.GetEntitiesIntersecting(turf.MapIndex, GetWorldTileBox(turf), approximate); } ///