From e05ab3dc5f0872de5009eab173717e339806e869 Mon Sep 17 00:00:00 2001 From: wrexbe Date: Fri, 27 May 2022 04:18:47 -0700 Subject: [PATCH 1/6] Fix StepTrigger error --- Content.Shared/StepTrigger/StepTriggerSystem.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Content.Shared/StepTrigger/StepTriggerSystem.cs b/Content.Shared/StepTrigger/StepTriggerSystem.cs index 5031bdd7a1d4..ed6109343138 100644 --- a/Content.Shared/StepTrigger/StepTriggerSystem.cs +++ b/Content.Shared/StepTrigger/StepTriggerSystem.cs @@ -29,12 +29,16 @@ public override void Update(float frameTime) private bool Update(StepTriggerComponent component) { - if (component.Deleted || !component.Active || component.Colliding.Count == 0) + if (component.Deleted || + !component.Active || + component.Colliding.Count == 0 || + !TryComp(component.Owner, out var ownerTransform)) return true; + foreach (var otherUid in component.Colliding.ToArray()) { - if (!otherUid.IsValid()) + if (!otherUid.IsValid() || !TryComp(otherUid, out var otherTransform)) { component.Colliding.Remove(otherUid); component.CurrentlySteppedOn.Remove(otherUid); @@ -43,8 +47,8 @@ private bool Update(StepTriggerComponent component) } // TODO: This shouldn't be calculating based on world AABBs. - var ourAabb = _entityLookup.GetWorldAABB(component.Owner); - var otherAabb = _entityLookup.GetWorldAABB(otherUid); + var ourAabb = _entityLookup.GetWorldAABB(component.Owner, ownerTransform); + var otherAabb = _entityLookup.GetWorldAABB(otherUid, otherTransform); if (!TryComp(otherUid, out PhysicsComponent? otherPhysics) || !ourAabb.Intersects(otherAabb)) { From 6e8af9bb8cb4ddaa9371f90ab2cf8994f1382a1c Mon Sep 17 00:00:00 2001 From: wrexbe Date: Fri, 27 May 2022 15:39:05 -0700 Subject: [PATCH 2/6] Changed it --- .../StepTrigger/StepTriggerSystem.cs | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/Content.Shared/StepTrigger/StepTriggerSystem.cs b/Content.Shared/StepTrigger/StepTriggerSystem.cs index ed6109343138..ae451d6cd120 100644 --- a/Content.Shared/StepTrigger/StepTriggerSystem.cs +++ b/Content.Shared/StepTrigger/StepTriggerSystem.cs @@ -18,66 +18,62 @@ public override void Initialize() public override void Update(float frameTime) { - foreach (var (_, trigger) in EntityQuery()) + foreach (var (_, trigger, transform) in EntityQuery()) { - if (!Update(trigger)) + if (!Update(trigger, transform)) continue; RemComp(trigger.Owner); } } - private bool Update(StepTriggerComponent component) + private bool Update(StepTriggerComponent component, TransformComponent transform) { if (component.Deleted || !component.Active || - component.Colliding.Count == 0 || - !TryComp(component.Owner, out var ownerTransform)) + component.Colliding.Count == 0) return true; foreach (var otherUid in component.Colliding.ToArray()) { - if (!otherUid.IsValid() || !TryComp(otherUid, out var otherTransform)) - { - component.Colliding.Remove(otherUid); - component.CurrentlySteppedOn.Remove(otherUid); - component.Dirty(); - continue; - } - - // TODO: This shouldn't be calculating based on world AABBs. - var ourAabb = _entityLookup.GetWorldAABB(component.Owner, ownerTransform); - var otherAabb = _entityLookup.GetWorldAABB(otherUid, otherTransform); + var shouldRemoveFromColliding = UpdateColliding(component, transform, otherUid); + if (!shouldRemoveFromColliding) continue; - if (!TryComp(otherUid, out PhysicsComponent? otherPhysics) || !ourAabb.Intersects(otherAabb)) - { - component.Colliding.Remove(otherUid); - component.CurrentlySteppedOn.Remove(otherUid); - component.Dirty(); - continue; - } + component.Colliding.Remove(otherUid); + component.CurrentlySteppedOn.Remove(otherUid); + component.Dirty(); + } + return false; + } - if (component.CurrentlySteppedOn.Contains(otherUid)) - continue; + private bool UpdateColliding(StepTriggerComponent component, TransformComponent ownerTransform, EntityUid otherUid) + { + if (!otherUid.IsValid() || + !TryComp(otherUid, out PhysicsComponent? otherPhysics)) + return true; - if (!CanTrigger(component.Owner, otherUid, component)) - continue; + if (component.CurrentlySteppedOn.Contains(otherUid) || + !CanTrigger(component.Owner, otherUid, component) || + otherPhysics.LinearVelocity.Length < component.RequiredTriggerSpeed) + return false; - if (otherPhysics.LinearVelocity.Length < component.RequiredTriggerSpeed) - continue; + // TODO: This shouldn't be calculating based on world AABBs. + var ourAabb = _entityLookup.GetWorldAABB(component.Owner, ownerTransform); + var otherAabb = _entityLookup.GetWorldAABB(otherUid); - var percentage = otherAabb.IntersectPercentage(ourAabb); - if (percentage < component.IntersectRatio) - continue; + if (!ourAabb.Intersects(otherAabb)) + return true; - var ev = new StepTriggeredEvent { Source = component.Owner, Tripper = otherUid }; - RaiseLocalEvent(component.Owner, ref ev); + var percentage = otherAabb.IntersectPercentage(ourAabb); + if (percentage < component.IntersectRatio) + return false; - component.CurrentlySteppedOn.Add(otherUid); - component.Dirty(); - } + var ev = new StepTriggeredEvent { Source = component.Owner, Tripper = otherUid }; + RaiseLocalEvent(component.Owner, ref ev); + component.CurrentlySteppedOn.Add(otherUid); + component.Dirty(); return false; } From 028fc732269d55051ef36ba27350c4fd185bdae2 Mon Sep 17 00:00:00 2001 From: wrexbe <81056464+wrexbe@users.noreply.github.com> Date: Fri, 27 May 2022 21:48:02 -0700 Subject: [PATCH 3/6] Update Content.Shared/StepTrigger/StepTriggerSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> --- Content.Shared/StepTrigger/StepTriggerSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/StepTrigger/StepTriggerSystem.cs b/Content.Shared/StepTrigger/StepTriggerSystem.cs index ae451d6cd120..3d82e75ebafb 100644 --- a/Content.Shared/StepTrigger/StepTriggerSystem.cs +++ b/Content.Shared/StepTrigger/StepTriggerSystem.cs @@ -73,7 +73,7 @@ private bool UpdateColliding(StepTriggerComponent component, TransformComponent RaiseLocalEvent(component.Owner, ref ev); component.CurrentlySteppedOn.Add(otherUid); - component.Dirty(); + Dirty(component); return false; } From 0f3186cc7cbcd5e4a7fff64a3b5633cae41f62d1 Mon Sep 17 00:00:00 2001 From: wrexbe <81056464+wrexbe@users.noreply.github.com> Date: Fri, 27 May 2022 21:48:34 -0700 Subject: [PATCH 4/6] Update Content.Shared/StepTrigger/StepTriggerSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> --- Content.Shared/StepTrigger/StepTriggerSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/StepTrigger/StepTriggerSystem.cs b/Content.Shared/StepTrigger/StepTriggerSystem.cs index 3d82e75ebafb..023d0f2f7ada 100644 --- a/Content.Shared/StepTrigger/StepTriggerSystem.cs +++ b/Content.Shared/StepTrigger/StepTriggerSystem.cs @@ -42,7 +42,7 @@ private bool Update(StepTriggerComponent component, TransformComponent transform component.Colliding.Remove(otherUid); component.CurrentlySteppedOn.Remove(otherUid); - component.Dirty(); + Dirty(component); } return false; } From e1779bd0ec76c05e143c07ffb9cc6dcd669872e1 Mon Sep 17 00:00:00 2001 From: wrexbe <81056464+wrexbe@users.noreply.github.com> Date: Fri, 27 May 2022 21:48:54 -0700 Subject: [PATCH 5/6] Update StepTriggerSystem.cs --- Content.Shared/StepTrigger/StepTriggerSystem.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Content.Shared/StepTrigger/StepTriggerSystem.cs b/Content.Shared/StepTrigger/StepTriggerSystem.cs index 023d0f2f7ada..97609ca77b27 100644 --- a/Content.Shared/StepTrigger/StepTriggerSystem.cs +++ b/Content.Shared/StepTrigger/StepTriggerSystem.cs @@ -29,8 +29,7 @@ public override void Update(float frameTime) private bool Update(StepTriggerComponent component, TransformComponent transform) { - if (component.Deleted || - !component.Active || + if (!component.Active || component.Colliding.Count == 0) return true; From c74d6545ddd7c5406fe66d727422d0354d146807 Mon Sep 17 00:00:00 2001 From: wrexbe <81056464+wrexbe@users.noreply.github.com> Date: Fri, 27 May 2022 21:49:29 -0700 Subject: [PATCH 6/6] Update StepTriggerSystem.cs --- Content.Shared/StepTrigger/StepTriggerSystem.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Content.Shared/StepTrigger/StepTriggerSystem.cs b/Content.Shared/StepTrigger/StepTriggerSystem.cs index 97609ca77b27..2c242f0a589e 100644 --- a/Content.Shared/StepTrigger/StepTriggerSystem.cs +++ b/Content.Shared/StepTrigger/StepTriggerSystem.cs @@ -48,8 +48,7 @@ private bool Update(StepTriggerComponent component, TransformComponent transform private bool UpdateColliding(StepTriggerComponent component, TransformComponent ownerTransform, EntityUid otherUid) { - if (!otherUid.IsValid() || - !TryComp(otherUid, out PhysicsComponent? otherPhysics)) + if (!TryComp(otherUid, out PhysicsComponent? otherPhysics)) return true; if (component.CurrentlySteppedOn.Contains(otherUid) ||