Split entity lookups from entity manager (#3747)

* Split entity lookups from entity manager

* IoC instead

* IoC refactor

* Fix bad resolve

* Remove EntityManager EntityLookup

* Update submodule

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-04-06 13:31:07 +10:00
committed by GitHub
parent 677706b117
commit 67f9e9cb5e
24 changed files with 50 additions and 44 deletions

View File

@@ -116,7 +116,7 @@ namespace Content.Server.GameObjects.Components.Fluids
PuddleComponent? puddle = null;
var spilt = false;
var spillEntities = entityManager.GetEntitiesIntersecting(mapGrid.ParentMapId, spillGridCoords.Position).ToArray();
var spillEntities = IoCManager.Resolve<IEntityLookup>().GetEntitiesIntersecting(mapGrid.ParentMapId, spillGridCoords.Position).ToArray();
foreach (var spillEntity in spillEntities)
{
if (spillEntity.TryGetComponent(out ISolutionInteractionsComponent? solutionContainerComponent) &&

View File

@@ -19,6 +19,7 @@ using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Network;
@@ -498,7 +499,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
if(_areaInsert && (eventArgs.Target == null || !eventArgs.Target.HasComponent<SharedItemComponent>()))
{
var validStorables = new List<IEntity>();
foreach (var entity in Owner.EntityManager.GetEntitiesInRange(eventArgs.ClickLocation, 1))
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(eventArgs.ClickLocation, 1))
{
if (!entity.Transform.IsMapTransform
|| entity == eventArgs.User

View File

@@ -94,7 +94,7 @@ namespace Content.Server.GameObjects.Components.Portal
}
if (_avoidCollidable)
{
foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(mapCoords))
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesIntersecting(mapCoords))
{
// Added this component to avoid stacking portals and causing shenanigans
// TODO: Doesn't do a great job of stopping stacking portals for directed
@@ -139,7 +139,7 @@ namespace Content.Server.GameObjects.Components.Portal
private bool EmptySpace(IEntity user, Vector2 target)
{
// TODO: Check the user's spot? Upside is no stacking TPs but downside is they can't unstuck themselves from walls.
foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(user.Transform.MapID, target))
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesIntersecting(user.Transform.MapID, target))
{
if (entity.HasComponent<IPhysBody>() || entity.HasComponent<PortalComponent>())
{

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -101,7 +102,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
private List<PowerReceiverComponent> FindAvailableReceivers()
{
var nearbyEntities = Owner.EntityManager
var nearbyEntities = IoCManager.Resolve<IEntityLookup>()
.GetEntitiesInRange(Owner, PowerTransferRange);
var receivers = new List<PowerReceiverComponent>();

View File

@@ -7,9 +7,7 @@ using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -22,8 +20,6 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
[RegisterComponent]
public class PowerReceiverComponent : Component, IExamine
{
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
[ViewVariables] [ComponentDependency] private readonly IPhysBody? _physicsComponent = null;
public override string Name => "PowerReceiver";
@@ -131,7 +127,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
private bool TryFindAvailableProvider(out IPowerProvider foundProvider)
{
var nearbyEntities = _serverEntityManager
var nearbyEntities = IoCManager.Resolve<IEntityLookup>()
.GetEntitiesInRange(Owner, PowerReceptionRange);
foreach (var entity in nearbyEntities)
@@ -140,7 +136,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
{
if (provider.Connectable)
{
if (provider.Owner.Transform.Coordinates.TryDistance(_serverEntityManager, Owner.Transform.Coordinates, out var distance))
if (provider.Owner.Transform.Coordinates.TryDistance(Owner.EntityManager, Owner.Transform.Coordinates, out var distance))
{
if (distance < Math.Min(PowerReceptionRange, provider.PowerTransferRange))
{

View File

@@ -34,7 +34,7 @@ namespace Content.Server.GameObjects.Components.Weapon
public static void FlashAreaHelper(IEntity source, float range, float duration, string? sound = null)
{
foreach (var entity in source.EntityManager.GetEntitiesInRange(source.Transform.Coordinates, range))
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(source.Transform.Coordinates, range))
{
if (!entity.TryGetComponent(out FlashableComponent? flashable) ||
!source.InRangeUnobstructed(entity, range, CollisionGroup.Opaque)) continue;

View File

@@ -7,6 +7,7 @@ using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -69,7 +70,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
return false;
}
foreach (var entity in Owner.EntityManager.GetEntitiesInRange(Owner.Transform.Coordinates, _range))
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(Owner.Transform.Coordinates, _range))
{
Flash(entity, eventArgs.User, _aoeFlashDuration);
}