From 404743f073eb1c3dbe585bec76b76a6b8c6cda2a Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:43:59 +1000 Subject: [PATCH] Fix examine threading issues (#30160) --- Content.Shared/Examine/ExamineSystemShared.cs | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Content.Shared/Examine/ExamineSystemShared.cs b/Content.Shared/Examine/ExamineSystemShared.cs index 4100b07483..682018949a 100644 --- a/Content.Shared/Examine/ExamineSystemShared.cs +++ b/Content.Shared/Examine/ExamineSystemShared.cs @@ -18,6 +18,7 @@ namespace Content.Shared.Examine { public abstract partial class ExamineSystemShared : EntitySystem { + [Dependency] private readonly OccluderSystem _occluder = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly SharedContainerSystem _containerSystem = default!; [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!; @@ -182,12 +183,9 @@ namespace Content.Shared.Examine length = MaxRaycastRange; } - var occluderSystem = Get(); - IoCManager.Resolve(ref entMan); - var ray = new Ray(origin.Position, dir.Normalized()); - var rayResults = occluderSystem - .IntersectRayWithPredicate(origin.MapId, ray, length, state, predicate, false).ToList(); + var rayResults = _occluder + .IntersectRayWithPredicate(origin.MapId, ray, length, state, predicate, false); if (rayResults.Count == 0) return true; @@ -195,13 +193,13 @@ namespace Content.Shared.Examine foreach (var result in rayResults) { - if (!entMan.TryGetComponent(result.HitEntity, out OccluderComponent? o)) + if (!TryComp(result.HitEntity, out OccluderComponent? o)) { continue; } var bBox = o.BoundingBox; - bBox = bBox.Translated(entMan.GetComponent(result.HitEntity).WorldPosition); + bBox = bBox.Translated(_transform.GetWorldPosition(result.HitEntity)); if (bBox.Contains(origin.Position) || bBox.Contains(other.Position)) { @@ -216,7 +214,6 @@ namespace Content.Shared.Examine public bool InRangeUnOccluded(EntityUid origin, EntityUid other, float range = ExamineRange, Ignored? predicate = null, bool ignoreInsideBlocker = true) { - var entMan = IoCManager.Resolve(); var originPos = _transform.GetMapCoordinates(origin); var otherPos = _transform.GetMapCoordinates(other); @@ -225,16 +222,14 @@ namespace Content.Shared.Examine public bool InRangeUnOccluded(EntityUid origin, EntityCoordinates other, float range = ExamineRange, Ignored? predicate = null, bool ignoreInsideBlocker = true) { - var entMan = IoCManager.Resolve(); var originPos = _transform.GetMapCoordinates(origin); - var otherPos = other.ToMap(entMan, _transform); + var otherPos = _transform.ToMapCoordinates(other); return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker); } public bool InRangeUnOccluded(EntityUid origin, MapCoordinates other, float range = ExamineRange, Ignored? predicate = null, bool ignoreInsideBlocker = true) { - var entMan = IoCManager.Resolve(); var originPos = _transform.GetMapCoordinates(origin); return InRangeUnOccluded(originPos, other, range, predicate, ignoreInsideBlocker); @@ -250,11 +245,12 @@ namespace Content.Shared.Examine } var hasDescription = false; + var metadata = MetaData(entity); //Add an entity description if one is declared - if (!string.IsNullOrEmpty(EntityManager.GetComponent(entity).EntityDescription)) + if (!string.IsNullOrEmpty(metadata.EntityDescription)) { - message.AddText(EntityManager.GetComponent(entity).EntityDescription); + message.AddText(metadata.EntityDescription); hasDescription = true; } -- 2.52.0