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:
@@ -5,6 +5,8 @@ using Content.Shared.Actions;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Content.Shared.Utility;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
@@ -26,8 +28,7 @@ namespace Content.Server.Actions
|
||||
if (!args.Performer.TryGetComponent<SharedActionsComponent>(out var actions)) return;
|
||||
|
||||
// find all IGhostBooAffected nearby and do boo on them
|
||||
var entityMan = args.Performer.EntityManager;
|
||||
var ents = entityMan.GetEntitiesInRange(args.Performer, _radius, false);
|
||||
var ents = IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(args.Performer, _radius, false);
|
||||
|
||||
var booCounter = 0;
|
||||
foreach (var ent in ents)
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace Content.Server.Commands.Chat
|
||||
}
|
||||
}
|
||||
// Get all entities in range of the suicider
|
||||
var entities = owner.EntityManager.GetEntitiesInRange(owner, 1, true).ToArray();
|
||||
var entities = IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(owner, 1, true).ToArray();
|
||||
|
||||
if (entities.Length > 0)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Administration;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Commands.Interactable
|
||||
@@ -43,8 +44,7 @@ namespace Content.Server.Commands.Interactable
|
||||
return;
|
||||
}
|
||||
|
||||
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
|
||||
var entities = serverEntityManager.GetEntitiesInRange(player.AttachedEntity, radius).ToList();
|
||||
var entities = IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(player.AttachedEntity, radius).ToList();
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Administration;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Commands.Interactable
|
||||
@@ -43,8 +44,7 @@ namespace Content.Server.Commands.Interactable
|
||||
return;
|
||||
}
|
||||
|
||||
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
|
||||
var entities = serverEntityManager.GetEntitiesInRange(player.AttachedEntity, radius).ToList();
|
||||
var entities = IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(player.AttachedEntity, radius).ToList();
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Content.Server.Construction.Conditions
|
||||
var type = _componentFactory.GetRegistration(Component).Type;
|
||||
|
||||
var indices = entity.Transform.Coordinates.ToVector2i(entity.EntityManager, _mapManager);
|
||||
var entities = indices.GetEntitiesInTile(entity.Transform.GridID, true, entity.EntityManager);
|
||||
var entities = indices.GetEntitiesInTile(entity.Transform.GridID, true, IoCManager.Resolve<IEntityLookup>());
|
||||
|
||||
foreach (var ent in entities)
|
||||
{
|
||||
|
||||
@@ -70,12 +70,10 @@ namespace Content.Server.Explosions
|
||||
MapId mapId)
|
||||
{
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
|
||||
var entitySystemManager = IoCManager.Resolve<IEntitySystemManager>();
|
||||
|
||||
var exAct = entitySystemManager.GetEntitySystem<ActSystem>();
|
||||
var exAct = EntitySystem.Get<ActSystem>();
|
||||
|
||||
var entitiesInRange = serverEntityManager.GetEntitiesInRange(mapId, boundingBox, 0).ToList();
|
||||
var entitiesInRange = IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(mapId, boundingBox, 0).ToList();
|
||||
|
||||
var impassableEntities = new List<Tuple<IEntity, float>>();
|
||||
var nonImpassableEntities = new List<Tuple<IEntity, float>>();
|
||||
|
||||
@@ -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) &&
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>())
|
||||
{
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var near in EntityManager.GetEntitiesInRange(user!, 2f, true))
|
||||
foreach (var near in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(user!, 2f, true))
|
||||
{
|
||||
yield return near;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using Content.Server.GameObjects.Components.StationEvents;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems.StationEvents
|
||||
@@ -40,6 +41,8 @@ namespace Content.Server.GameObjects.EntitySystems.StationEvents
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var lookupSystem = IoCManager.Resolve<IEntityLookup>();
|
||||
|
||||
foreach (var comp in ComponentManager.EntityQuery<RadiationPulseComponent>(true))
|
||||
{
|
||||
comp.Update(frameTime);
|
||||
@@ -47,7 +50,7 @@ namespace Content.Server.GameObjects.EntitySystems.StationEvents
|
||||
|
||||
if (ent.Deleted) continue;
|
||||
|
||||
foreach (var entity in EntityManager.GetEntitiesInRange(ent.Transform.Coordinates, comp.Range, true))
|
||||
foreach (var entity in lookupSystem.GetEntitiesInRange(ent.Transform.Coordinates, comp.Range, true))
|
||||
{
|
||||
if (entity.Deleted) continue;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.GameObjects.Components.Conveyor;
|
||||
using Content.Server.GameObjects.Components.Recycling;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Controllers;
|
||||
@@ -39,7 +40,7 @@ namespace Content.Server.Physics.Controllers
|
||||
return;
|
||||
}
|
||||
|
||||
var intersecting = EntityManager.GetEntitiesIntersecting(comp.Owner, true);
|
||||
var intersecting = IoCManager.Resolve<IEntityLookup>().GetEntitiesIntersecting(comp.Owner, true);
|
||||
var direction = comp.GetAngle().ToVec();
|
||||
Vector2? ownerPos = null;
|
||||
|
||||
@@ -99,11 +100,12 @@ namespace Content.Server.Physics.Controllers
|
||||
var direction = Vector2.UnitX;
|
||||
Vector2? ownerPos = null;
|
||||
|
||||
// TODO: I know it sucks but conveyors need a refactor
|
||||
for (var i = comp.Intersecting.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var entity = comp.Intersecting[i];
|
||||
|
||||
if (entity.Deleted || !comp.CanMove(entity) || !EntityManager.IsIntersecting(comp.Owner, entity))
|
||||
if (entity.Deleted || !comp.CanMove(entity) || !IoCManager.Resolve<IEntityLookup>().IsIntersecting(comp.Owner, entity))
|
||||
{
|
||||
comp.Intersecting.RemoveAt(i);
|
||||
continue;
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Content.Server.Physics.Controllers
|
||||
{
|
||||
var singularityCoords = component.Owner.Transform.Coordinates;
|
||||
// TODO: Maybe if we have named fixtures needs to pull out the outer circle collider (inner will be for deleting).
|
||||
var entitiesToPull = EntityManager.GetEntitiesInRange(singularityCoords, component.Level * 10);
|
||||
var entitiesToPull = IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(singularityCoords, component.Level * 10);
|
||||
foreach (var entity in entitiesToPull)
|
||||
{
|
||||
if (!entity.TryGetComponent<PhysicsComponent>(out var collidableComponent) || collidableComponent.BodyType == BodyType.Static) continue;
|
||||
|
||||
Reference in New Issue
Block a user