Remove 700 usages of Component.Owner (#21100)
This commit is contained in:
@@ -1,24 +1,20 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Destructible;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Climbing;
|
||||
using Content.Shared.Climbing.Components;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Content.Shared.NPC;
|
||||
using Content.Shared.Physics;
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using ClimbableComponent = Content.Shared.Climbing.Components.ClimbableComponent;
|
||||
|
||||
namespace Content.Server.NPC.Pathfinding;
|
||||
|
||||
@@ -102,6 +98,7 @@ public sealed partial class PathfindingSystem
|
||||
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
var pathfinding = new Entity<GridPathfindingComponent>(uid, comp);
|
||||
// TODO: Dump all this shit and just do it live it's probably fast enough.
|
||||
if (comp.DirtyChunks.Count == 0 ||
|
||||
curTime < comp.NextUpdate ||
|
||||
@@ -120,7 +117,7 @@ public sealed partial class PathfindingSystem
|
||||
|
||||
foreach (var origin in comp.DirtyChunks)
|
||||
{
|
||||
var chunk = GetChunk(origin, uid, comp);
|
||||
var chunk = GetChunk(origin, uid, pathfinding);
|
||||
dirt[idx] = chunk;
|
||||
idx++;
|
||||
}
|
||||
@@ -155,7 +152,7 @@ public sealed partial class PathfindingSystem
|
||||
var climbableQuery = GetEntityQuery<ClimbableComponent>();
|
||||
var fixturesQuery = GetEntityQuery<FixturesComponent>();
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
BuildBreadcrumbs(dirt[i], mapGridComp, accessQuery, destructibleQuery, doorQuery, climbableQuery,
|
||||
BuildBreadcrumbs(dirt[i], (uid, mapGridComp), accessQuery, destructibleQuery, doorQuery, climbableQuery,
|
||||
fixturesQuery, xformQuery);
|
||||
});
|
||||
|
||||
@@ -204,7 +201,7 @@ public sealed partial class PathfindingSystem
|
||||
if (index != it1)
|
||||
return;
|
||||
|
||||
BuildNavmesh(chunk, comp);
|
||||
BuildNavmesh(chunk, pathfinding);
|
||||
#if DEBUG
|
||||
Interlocked.Increment(ref updateCount);
|
||||
#endif
|
||||
@@ -254,24 +251,24 @@ public sealed partial class PathfindingSystem
|
||||
|
||||
private void OnCollisionChange(ref CollisionChangeEvent ev)
|
||||
{
|
||||
var xform = Transform(ev.Body.Owner);
|
||||
var xform = Transform(ev.BodyUid);
|
||||
|
||||
if (xform.GridUid == null)
|
||||
return;
|
||||
|
||||
// This will also rebuild on door open / closes which I think is good?
|
||||
var aabb = _lookup.GetAABBNoContainer(ev.Body.Owner, xform.Coordinates.Position, xform.LocalRotation);
|
||||
var aabb = _lookup.GetAABBNoContainer(ev.BodyUid, xform.Coordinates.Position, xform.LocalRotation);
|
||||
DirtyChunkArea(xform.GridUid.Value, aabb);
|
||||
}
|
||||
|
||||
private void OnCollisionLayerChange(ref CollisionLayerChangeEvent ev)
|
||||
{
|
||||
var xform = Transform(ev.Body.Owner);
|
||||
var xform = Transform(ev.Body);
|
||||
|
||||
if (xform.GridUid == null)
|
||||
return;
|
||||
|
||||
var aabb = _lookup.GetAABBNoContainer(ev.Body.Owner, xform.Coordinates.Position, xform.LocalRotation);
|
||||
var aabb = _lookup.GetAABBNoContainer(ev.Body, xform.Coordinates.Position, xform.LocalRotation);
|
||||
DirtyChunkArea(xform.GridUid.Value, aabb);
|
||||
}
|
||||
|
||||
@@ -417,7 +414,7 @@ public sealed partial class PathfindingSystem
|
||||
}
|
||||
|
||||
private void BuildBreadcrumbs(GridPathfindingChunk chunk,
|
||||
MapGridComponent grid,
|
||||
Entity<MapGridComponent> grid,
|
||||
EntityQuery<AccessReaderComponent> accessQuery,
|
||||
EntityQuery<DestructibleComponent> destructibleQuery,
|
||||
EntityQuery<DoorComponent> doorQuery,
|
||||
@@ -450,7 +447,7 @@ public sealed partial class PathfindingSystem
|
||||
var tilePos = new Vector2i(x, y) + gridOrigin;
|
||||
tilePolys.Clear();
|
||||
|
||||
var tile = grid.GetTileRef(tilePos);
|
||||
var tile = grid.Comp.GetTileRef(tilePos);
|
||||
var flags = tile.Tile.IsEmpty ? PathfindingBreadcrumbFlag.Space : PathfindingBreadcrumbFlag.None;
|
||||
// var isBorder = x < 0 || y < 0 || x == ChunkSize - 1 || y == ChunkSize - 1;
|
||||
|
||||
@@ -469,7 +466,7 @@ public sealed partial class PathfindingSystem
|
||||
var xform = xformQuery.GetComponent(ent);
|
||||
|
||||
if (xform.ParentUid != grid.Owner ||
|
||||
grid.LocalToTile(xform.Coordinates) != tilePos)
|
||||
grid.Comp.LocalToTile(xform.Coordinates) != tilePos)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -648,13 +645,13 @@ public sealed partial class PathfindingSystem
|
||||
var polyData = points[x * SubStep + poly.Left, y * SubStep + poly.Bottom].Data;
|
||||
|
||||
var neighbors = new HashSet<PathPoly>();
|
||||
tilePoly.Add(new PathPoly(grid.Owner, chunk.Origin, GetIndex(x, y), box, polyData, neighbors));
|
||||
tilePoly.Add(new PathPoly(grid, chunk.Origin, GetIndex(x, y), box, polyData, neighbors));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log.Debug($"Built breadcrumbs in {sw.Elapsed.TotalMilliseconds}ms");
|
||||
SendBreadcrumbs(chunk, grid.Owner);
|
||||
SendBreadcrumbs(chunk, grid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -729,12 +726,13 @@ public sealed partial class PathfindingSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildNavmesh(GridPathfindingChunk chunk, GridPathfindingComponent component)
|
||||
private void BuildNavmesh(GridPathfindingChunk chunk, Entity<GridPathfindingComponent> pathfinding)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
var chunkPolys = chunk.Polygons;
|
||||
var component = pathfinding.Comp;
|
||||
component.Chunks.TryGetValue(chunk.Origin + new Vector2i(-1, 0), out var leftChunk);
|
||||
component.Chunks.TryGetValue(chunk.Origin + new Vector2i(0, -1), out var bottomChunk);
|
||||
component.Chunks.TryGetValue(chunk.Origin + new Vector2i(1, 0), out var rightChunk);
|
||||
@@ -840,7 +838,7 @@ public sealed partial class PathfindingSystem
|
||||
}
|
||||
|
||||
// Log.Debug($"Built navmesh in {sw.Elapsed.TotalMilliseconds}ms");
|
||||
SendPolys(chunk, component.Owner, chunkPolys);
|
||||
SendPolys(chunk, pathfinding, chunkPolys);
|
||||
}
|
||||
|
||||
private void AddNeighbors(PathPoly polyA, PathPoly polyB)
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Destructible;
|
||||
using Content.Server.NPC.HTN;
|
||||
using Content.Server.NPC.Systems;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.NPC;
|
||||
@@ -577,9 +576,10 @@ namespace Content.Server.NPC.Pathfinding
|
||||
{
|
||||
var msg = new PathBreadcrumbsMessage();
|
||||
|
||||
foreach (var comp in EntityQuery<GridPathfindingComponent>(true))
|
||||
var query = AllEntityQuery<GridPathfindingComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
var netGrid = GetNetEntity(comp.Owner);
|
||||
var netGrid = GetNetEntity(uid);
|
||||
|
||||
msg.Breadcrumbs.Add(netGrid, new Dictionary<Vector2i, List<PathfindingBreadcrumb>>(comp.Chunks.Count));
|
||||
|
||||
@@ -626,9 +626,10 @@ namespace Content.Server.NPC.Pathfinding
|
||||
{
|
||||
var msg = new PathPolysMessage();
|
||||
|
||||
foreach (var comp in EntityQuery<GridPathfindingComponent>(true))
|
||||
var query = AllEntityQuery<GridPathfindingComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
var netGrid = GetNetEntity(comp.Owner);
|
||||
var netGrid = GetNetEntity(uid);
|
||||
|
||||
msg.Polys.Add(netGrid, new Dictionary<Vector2i, Dictionary<Vector2i, List<DebugPathPoly>>>(comp.Chunks.Count));
|
||||
|
||||
|
||||
@@ -10,14 +10,15 @@ public sealed partial class NPCPerceptionSystem
|
||||
/// <param name="frameTime"></param>
|
||||
private void UpdateRecentlyInjected(float frameTime)
|
||||
{
|
||||
foreach (var entity in EntityQuery<NPCRecentlyInjectedComponent>())
|
||||
var query = EntityQueryEnumerator<NPCRecentlyInjectedComponent>();
|
||||
while (query.MoveNext(out var uid, out var entity))
|
||||
{
|
||||
entity.Accumulator += frameTime;
|
||||
if (entity.Accumulator < entity.RemoveTime.TotalSeconds)
|
||||
continue;
|
||||
entity.Accumulator = 0;
|
||||
|
||||
RemComp<NPCRecentlyInjectedComponent>(entity.Owner);
|
||||
RemComp<NPCRecentlyInjectedComponent>(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ public sealed class NPCUtilitySystem : EntitySystem
|
||||
var compZero = comps[0];
|
||||
comps.RemoveAt(0);
|
||||
|
||||
foreach (var comp in _lookup.GetComponentsInRange(compZero.Component.GetType(), mapPos, vision))
|
||||
foreach (var comp in _lookup.GetEntitiesInRange(compZero.Component.GetType(), mapPos, vision))
|
||||
{
|
||||
var ent = comp.Owner;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.NPC.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using System.Linq;
|
||||
using Content.Server.NPC.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.NPC.Systems;
|
||||
|
||||
@@ -160,15 +160,15 @@ public sealed partial class NpcFactionSystem : EntitySystem
|
||||
if (!xformQuery.TryGetComponent(entity, out var entityXform))
|
||||
yield break;
|
||||
|
||||
foreach (var comp in _lookup.GetComponentsInRange<NpcFactionMemberComponent>(entityXform.MapPosition, range))
|
||||
foreach (var ent in _lookup.GetEntitiesInRange<NpcFactionMemberComponent>(entityXform.MapPosition, range))
|
||||
{
|
||||
if (comp.Owner == entity)
|
||||
if (ent.Owner == entity)
|
||||
continue;
|
||||
|
||||
if (!factions.Overlaps(comp.Factions))
|
||||
if (!factions.Overlaps(ent.Comp.Factions))
|
||||
continue;
|
||||
|
||||
yield return comp.Owner;
|
||||
yield return ent.Owner;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user