Deprecate entitylookupcomponent (#12159)

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2022-10-27 23:37:55 +11:00
committed by GitHub
parent 03f45ceb56
commit 6b6d52850a
13 changed files with 58 additions and 34 deletions

View File

@@ -32,7 +32,7 @@ public sealed class AccessOverlay : Overlay
var xformQuery = _entityManager.GetEntityQuery<TransformComponent>(); var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
foreach (var ent in _lookup.GetEntitiesIntersecting(args.MapId, args.WorldAABB, foreach (var ent in _lookup.GetEntitiesIntersecting(args.MapId, args.WorldAABB,
LookupFlags.Anchored | LookupFlags.Approximate)) LookupFlags.Static | LookupFlags.Approximate))
{ {
if (!readerQuery.TryGetComponent(ent, out var reader) || if (!readerQuery.TryGetComponent(ent, out var reader) ||
!xformQuery.TryGetComponent(ent, out var xform)) !xformQuery.TryGetComponent(ent, out var xform))

View File

@@ -34,28 +34,30 @@ namespace Content.IntegrationTests.Tests.Chemistry
var prototypeManager = server.ResolveDependency<IPrototypeManager>(); var prototypeManager = server.ResolveDependency<IPrototypeManager>();
var testMap = await PoolManager.CreateTestMap(pairTracker); var testMap = await PoolManager.CreateTestMap(pairTracker);
var coordinates = testMap.GridCoords; var coordinates = testMap.GridCoords;
var solutionSystem = server.ResolveDependency<IEntitySystemManager>()
.GetEntitySystem<SolutionContainerSystem>();
foreach (var reactionPrototype in prototypeManager.EnumeratePrototypes<ReactionPrototype>()) foreach (var reactionPrototype in prototypeManager.EnumeratePrototypes<ReactionPrototype>())
{ {
//since i have no clue how to isolate each loop assert-wise im just gonna throw this one in for good measure //since i have no clue how to isolate each loop assert-wise im just gonna throw this one in for good measure
Console.WriteLine($"Testing {reactionPrototype.ID}"); Console.WriteLine($"Testing {reactionPrototype.ID}");
EntityUid beaker; EntityUid beaker = default;
Solution component = null; Solution component = null;
await server.WaitAssertion(() => await server.WaitAssertion(() =>
{ {
beaker = entityManager.SpawnEntity("TestSolutionContainer", coordinates); beaker = entityManager.SpawnEntity("TestSolutionContainer", coordinates);
Assert.That(EntitySystem.Get<SolutionContainerSystem>() Assert.That(solutionSystem
.TryGetSolution(beaker, "beaker", out component)); .TryGetSolution(beaker, "beaker", out component));
foreach (var (id, reactant) in reactionPrototype.Reactants) foreach (var (id, reactant) in reactionPrototype.Reactants)
{ {
Assert.That(EntitySystem.Get<SolutionContainerSystem>() Assert.That(solutionSystem
.TryAddReagent(beaker, component, id, reactant.Amount, out var quantity)); .TryAddReagent(beaker, component, id, reactant.Amount, out var quantity));
Assert.That(reactant.Amount, Is.EqualTo(quantity)); Assert.That(reactant.Amount, Is.EqualTo(quantity));
} }
EntitySystem.Get<SolutionContainerSystem>().SetTemperature(beaker, component, reactionPrototype.MinimumTemperature); solutionSystem.SetTemperature(beaker, component, reactionPrototype.MinimumTemperature);
}); });
await server.WaitIdleAsync(); await server.WaitIdleAsync();

View File

@@ -145,9 +145,12 @@ namespace Content.Server.Chemistry.Components
/// with the other area effects from the inception.</param> /// with the other area effects from the inception.</param>
public void React(float averageExposures) public void React(float averageExposures)
{ {
if (!_entities.EntitySysManager.GetEntitySystem<SolutionContainerSystem>()
if (!_entities.EntitySysManager.GetEntitySystem<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)) .TryGetSolution(Owner, SolutionName, out var solution) ||
solution.Contents.Count == 0)
{
return; return;
}
var xform = _entities.GetComponent<TransformComponent>(Owner); var xform = _entities.GetComponent<TransformComponent>(Owner);
if (!MapManager.TryGetGrid(xform.GridUid, out var mapGrid)) if (!MapManager.TryGetGrid(xform.GridUid, out var mapGrid))
@@ -158,6 +161,7 @@ namespace Content.Server.Chemistry.Components
var lookup = _entities.EntitySysManager.GetEntitySystem<EntityLookupSystem>(); var lookup = _entities.EntitySysManager.GetEntitySystem<EntityLookupSystem>();
var solutionFraction = 1 / Math.Floor(averageExposures); var solutionFraction = 1 / Math.Floor(averageExposures);
var ents = lookup.GetEntitiesIntersecting(tile, LookupFlags.Uncontained).ToArray();
foreach (var reagentQuantity in solution.Contents.ToArray()) foreach (var reagentQuantity in solution.Contents.ToArray())
{ {
@@ -173,14 +177,14 @@ namespace Content.Server.Chemistry.Components
} }
// Touch every entity on the tile // Touch every entity on the tile
foreach (var entity in lookup.GetEntitiesIntersecting(tile).ToArray()) foreach (var entity in ents)
{ {
chemistry.ReactionEntity(entity, ReactionMethod.Touch, reagent, chemistry.ReactionEntity(entity, ReactionMethod.Touch, reagent,
reagentQuantity.Quantity * solutionFraction, solution); reagentQuantity.Quantity * solutionFraction, solution);
} }
} }
foreach (var entity in lookup.GetEntitiesIntersecting(tile).ToArray()) foreach (var entity in ents)
{ {
ReactWithEntity(entity, solutionFraction); ReactWithEntity(entity, solutionFraction);
} }

View File

@@ -6,6 +6,7 @@ using Content.Shared.Physics;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -188,7 +189,7 @@ public sealed partial class ExplosionSystem : EntitySystem
/// Find entities on a grid tile using the EntityLookupComponent and apply explosion effects. /// Find entities on a grid tile using the EntityLookupComponent and apply explosion effects.
/// </summary> /// </summary>
/// <returns>True if the underlying tile can be uprooted, false if the tile is blocked by a dense entity</returns> /// <returns>True if the underlying tile can be uprooted, false if the tile is blocked by a dense entity</returns>
internal bool ExplodeTile(EntityLookupComponent lookup, internal bool ExplodeTile(BroadphaseComponent lookup,
IMapGrid grid, IMapGrid grid,
Vector2i tile, Vector2i tile,
float throwForce, float throwForce,
@@ -209,7 +210,9 @@ public sealed partial class ExplosionSystem : EntitySystem
var state = (list, processed, xformQuery); var state = (list, processed, xformQuery);
// get entities: // get entities:
lookup.Tree.QueryAabb(ref state, GridQueryCallback, gridBox, true); lookup.DynamicTree.QueryAabb(ref state, GridQueryCallback, gridBox, true);
lookup.StaticTree.QueryAabb(ref state, GridQueryCallback, gridBox, true);
lookup.SundriesTree.QueryAabb(ref state, GridQueryCallback, gridBox, true);
// process those entities // process those entities
foreach (var xform in list) foreach (var xform in list)
@@ -250,7 +253,9 @@ public sealed partial class ExplosionSystem : EntitySystem
return !tileBlocked; return !tileBlocked;
list.Clear(); list.Clear();
lookup.Tree.QueryAabb(ref state, GridQueryCallback, gridBox, true); lookup.DynamicTree.QueryAabb(ref state, GridQueryCallback, gridBox, true);
lookup.StaticTree.QueryAabb(ref state, GridQueryCallback, gridBox, true);
lookup.SundriesTree.QueryAabb(ref state, GridQueryCallback, gridBox, true);
foreach (var xform in list) foreach (var xform in list)
{ {
@@ -272,10 +277,18 @@ public sealed partial class ExplosionSystem : EntitySystem
return true; return true;
} }
private bool GridQueryCallback(
ref (List<TransformComponent> List, HashSet<EntityUid> Processed, EntityQuery<TransformComponent> XformQuery) state,
in FixtureProxy proxy)
{
var owner = proxy.Fixture.Body.Owner;
return GridQueryCallback(ref state, in owner);
}
/// <summary> /// <summary>
/// Same as <see cref="ExplodeTile"/>, but for SPAAAAAAACE. /// Same as <see cref="ExplodeTile"/>, but for SPAAAAAAACE.
/// </summary> /// </summary>
internal void ExplodeSpace(EntityLookupComponent lookup, internal void ExplodeSpace(BroadphaseComponent lookup,
Matrix3 spaceMatrix, Matrix3 spaceMatrix,
Matrix3 invSpaceMatrix, Matrix3 invSpaceMatrix,
Vector2i tile, Vector2i tile,
@@ -295,7 +308,9 @@ public sealed partial class ExplosionSystem : EntitySystem
var state = (list, processed, invSpaceMatrix, lookup.Owner, xformQuery, gridBox); var state = (list, processed, invSpaceMatrix, lookup.Owner, xformQuery, gridBox);
// get entities: // get entities:
lookup.Tree.QueryAabb(ref state, SpaceQueryCallback, worldBox, true); lookup.DynamicTree.QueryAabb(ref state, SpaceQueryCallback, worldBox, true);
lookup.StaticTree.QueryAabb(ref state, SpaceQueryCallback, worldBox, true);
lookup.SundriesTree.QueryAabb(ref state, SpaceQueryCallback, worldBox, true);
foreach (var xform in state.Item1) foreach (var xform in state.Item1)
{ {
@@ -309,7 +324,9 @@ public sealed partial class ExplosionSystem : EntitySystem
// Also, throw any entities that were spawned as shrapnel. Compared to entity spawning & destruction, this extra // 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. // lookup is relatively minor computational cost, and throwing is disabled for nukes anyways.
list.Clear(); list.Clear();
lookup.Tree.QueryAabb(ref state, SpaceQueryCallback, worldBox, true); lookup.DynamicTree.QueryAabb(ref state, SpaceQueryCallback, worldBox, true);
lookup.StaticTree.QueryAabb(ref state, SpaceQueryCallback, worldBox, true);
lookup.SundriesTree.QueryAabb(ref state, SpaceQueryCallback, worldBox, true);
foreach (var xform in list) foreach (var xform in list)
{ {
@@ -342,6 +359,14 @@ public sealed partial class ExplosionSystem : EntitySystem
return true; return true;
} }
private bool SpaceQueryCallback(
ref (List<TransformComponent> List, HashSet<EntityUid> Processed, Matrix3 InvSpaceMatrix, EntityUid LookupOwner, EntityQuery<TransformComponent> XformQuery, Box2 GridBox) state,
in FixtureProxy proxy)
{
var owner = proxy.Fixture.Body.Owner;
return SpaceQueryCallback(ref state, in owner);
}
/// <summary> /// <summary>
/// This function actually applies the explosion affects to an entity. /// This function actually applies the explosion affects to an entity.
/// </summary> /// </summary>
@@ -460,7 +485,7 @@ sealed class Explosion
/// <summary> /// <summary>
/// Lookup component for this grid (or space/map). /// Lookup component for this grid (or space/map).
/// </summary> /// </summary>
public EntityLookupComponent Lookup; public BroadphaseComponent Lookup;
/// <summary> /// <summary>
/// The actual grid that this corresponds to. If null, this implies space. /// The actual grid that this corresponds to. If null, this implies space.
@@ -513,7 +538,7 @@ sealed class Explosion
// Variables used for enumerating over tiles, grids, etc // Variables used for enumerating over tiles, grids, etc
private DamageSpecifier _currentDamage = default!; private DamageSpecifier _currentDamage = default!;
private EntityLookupComponent _currentLookup = default!; private BroadphaseComponent _currentLookup = default!;
private IMapGrid? _currentGrid; private IMapGrid? _currentGrid;
private float _currentIntensity; private float _currentIntensity;
private float _currentThrowForce; private float _currentThrowForce;
@@ -600,7 +625,7 @@ sealed class Explosion
_explosionData.Add(new() _explosionData.Add(new()
{ {
TileLists = spaceData.TileLists, TileLists = spaceData.TileLists,
Lookup = entMan.GetComponent<EntityLookupComponent>(mapUid), Lookup = entMan.GetComponent<BroadphaseComponent>(mapUid),
MapGrid = null MapGrid = null
}); });
@@ -613,7 +638,7 @@ sealed class Explosion
_explosionData.Add(new() _explosionData.Add(new()
{ {
TileLists = grid.TileLists, TileLists = grid.TileLists,
Lookup = entMan.GetComponent<EntityLookupComponent>(grid.Grid.GridEntityId), Lookup = entMan.GetComponent<BroadphaseComponent>(grid.Grid.GridEntityId),
MapGrid = grid.Grid MapGrid = grid.Grid
}); });
} }

View File

@@ -168,6 +168,9 @@ namespace Content.Server.Physics.Controllers
private void OnConveyorShutdown(EntityUid uid, ConveyorComponent component, ComponentShutdown args) private void OnConveyorShutdown(EntityUid uid, ConveyorComponent component, ComponentShutdown args)
{ {
if (MetaData(uid).EntityLifeStage >= EntityLifeStage.Terminating)
return;
RemComp<ActiveConveyorComponent>(uid); RemComp<ActiveConveyorComponent>(uid);
if (!TryComp<PhysicsComponent>(uid, out var body)) if (!TryComp<PhysicsComponent>(uid, out var body))

View File

@@ -47,7 +47,11 @@ public abstract class SharedFlyBySoundSystem : EntitySystem
private void OnShutdown(EntityUid uid, FlyBySoundComponent component, ComponentShutdown args) private void OnShutdown(EntityUid uid, FlyBySoundComponent component, ComponentShutdown args)
{ {
if (!TryComp<PhysicsComponent>(uid, out var body)) return; if (!TryComp<PhysicsComponent>(uid, out var body) ||
MetaData(uid).EntityLifeStage >= EntityLifeStage.Terminating)
{
return;
}
_fixtures.DestroyFixture(body, FlyByFixture); _fixtures.DestroyFixture(body, FlyByFixture);
} }

View File

@@ -663,7 +663,6 @@ entities:
parent: 943 parent: 943
type: Transform type: Transform
- type: MapGrid - type: MapGrid
- type: EntityLookup
- type: Broadphase - type: Broadphase
- id: Bagel - id: Bagel
type: BecomesStation type: BecomesStation
@@ -31751,7 +31750,6 @@ entities:
- type: Transform - type: Transform
- index: 4 - index: 4
type: Map type: Map
- type: EntityLookup
- type: Broadphase - type: Broadphase
- type: PhysicsMap - type: PhysicsMap
- type: OccluderTree - type: OccluderTree

View File

@@ -5535,7 +5535,6 @@ entities:
- type: Transform - type: Transform
- index: 5 - index: 5
type: Map type: Map
- type: EntityLookup
- type: Broadphase - type: Broadphase
- type: PhysicsMap - type: PhysicsMap
- type: OccluderTree - type: OccluderTree
@@ -56709,7 +56708,6 @@ entities:
parent: 780 parent: 780
type: Transform type: Transform
- type: MapGrid - type: MapGrid
- type: EntityLookup
- type: Broadphase - type: Broadphase
- id: Boxstation - id: Boxstation
type: BecomesStation type: BecomesStation
@@ -113447,7 +113445,6 @@ entities:
type: Transform type: Transform
- index: 1 - index: 1
type: MapGrid type: MapGrid
- type: EntityLookup
- type: Broadphase - type: Broadphase
- angularDamping: 0.05 - angularDamping: 0.05
linearDamping: 0.05 linearDamping: 0.05

View File

@@ -134,7 +134,6 @@ entities:
- parent: null - parent: null
type: Transform type: Transform
- type: MapGrid - type: MapGrid
- type: EntityLookup
- type: Broadphase - type: Broadphase
- id: centcomm - id: centcomm
type: BecomesStation type: BecomesStation

View File

@@ -918,7 +918,6 @@ entities:
- type: Transform - type: Transform
- index: 7 - index: 7
type: Map type: Map
- type: EntityLookup
- type: Broadphase - type: Broadphase
- type: PhysicsMap - type: PhysicsMap
- type: OccluderTree - type: OccluderTree
@@ -953,7 +952,6 @@ entities:
parent: 122 parent: 122
type: Transform type: Transform
- type: MapGrid - type: MapGrid
- type: EntityLookup
- type: Broadphase - type: Broadphase
- angularDamping: 0.05 - angularDamping: 0.05
linearDamping: 0.05 linearDamping: 0.05

View File

@@ -118,7 +118,6 @@ entities:
- type: Transform - type: Transform
- index: 15 - index: 15
type: Map type: Map
- type: EntityLookup
- type: Broadphase - type: Broadphase
- type: PhysicsMap - type: PhysicsMap
- type: OccluderTree - type: OccluderTree
@@ -129,7 +128,6 @@ entities:
parent: 0 parent: 0
type: Transform type: Transform
- type: MapGrid - type: MapGrid
- type: EntityLookup
- type: Broadphase - type: Broadphase
- angularDamping: 0.05 - angularDamping: 0.05
linearDamping: 0.05 linearDamping: 0.05

View File

@@ -896,7 +896,6 @@ entities:
parent: 84 parent: 84
type: Transform type: Transform
- type: MapGrid - type: MapGrid
- type: EntityLookup
- type: Broadphase - type: Broadphase
- id: Kettle - id: Kettle
type: BecomesStation type: BecomesStation
@@ -40407,7 +40406,6 @@ entities:
- type: Transform - type: Transform
- index: 4 - index: 4
type: Map type: Map
- type: EntityLookup
- type: Broadphase - type: Broadphase
- type: PhysicsMap - type: PhysicsMap
- type: OccluderTree - type: OccluderTree

View File

@@ -466,7 +466,6 @@ entities:
parent: 5350 parent: 5350
type: Transform type: Transform
- type: MapGrid - type: MapGrid
- type: EntityLookup
- type: Broadphase - type: Broadphase
- angularDamping: 0.05 - angularDamping: 0.05
linearDamping: 0.05 linearDamping: 0.05
@@ -61444,7 +61443,6 @@ entities:
- type: Transform - type: Transform
- index: 4 - index: 4
type: Map type: Map
- type: EntityLookup
- type: Broadphase - type: Broadphase
- type: PhysicsMap - type: PhysicsMap
- type: OccluderTree - type: OccluderTree