From 3b04d5a66c4fce43b0865ba4d858fb0b3bb01291 Mon Sep 17 00:00:00 2001 From: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Date: Mon, 14 Apr 2025 16:00:03 +0200 Subject: [PATCH] [HOTFIX] Sprite fade review #36509 (#36552) cherry-picked --- Content.Client/Sprite/SpriteFadeSystem.cs | 36 ++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/Content.Client/Sprite/SpriteFadeSystem.cs b/Content.Client/Sprite/SpriteFadeSystem.cs index 949012d04a..0a028f596e 100644 --- a/Content.Client/Sprite/SpriteFadeSystem.cs +++ b/Content.Client/Sprite/SpriteFadeSystem.cs @@ -10,6 +10,7 @@ using Robust.Client.UserInterface; using Robust.Shared.Map; using Robust.Shared.Physics.Systems; using Robust.Shared.Physics; +using Robust.Shared.Physics.Components; namespace Content.Client.Sprite; @@ -22,21 +23,20 @@ public sealed class SpriteFadeSystem : EntitySystem [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IStateManager _stateManager = default!; + [Dependency] private readonly FixtureSystem _fixtures = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly IUserInterfaceManager _uiManager = default!; [Dependency] private readonly IInputManager _inputManager = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; + private List<(MapCoordinates Point, bool ExcludeBoundingBox)> _points = new(); + private readonly HashSet _comps = new(); private EntityQuery _spriteQuery; private EntityQuery _fadeQuery; private EntityQuery _fadingQuery; - - /// - /// Radius of the mouse point for the intersection test - /// - private static Vector2 MouseRadius = new Vector2(10f * float.Epsilon, 10f * float.Epsilon); + private EntityQuery _fixturesQuery; private const float TargetAlpha = 0.4f; private const float ChangeRate = 1f; @@ -48,6 +48,7 @@ public sealed class SpriteFadeSystem : EntitySystem _spriteQuery = GetEntityQuery(); _fadeQuery = GetEntityQuery(); _fadingQuery = GetEntityQuery(); + _fixturesQuery = GetEntityQuery(); SubscribeLocalEvent(OnFadingShutdown); } @@ -67,22 +68,22 @@ public sealed class SpriteFadeSystem : EntitySystem { var player = _playerManager.LocalEntity; // ExcludeBoundingBox is set if we don't want to fade this sprite within the collision bounding boxes for the given POI - var pointsOfInterest = new List<(MapCoordinates Point, bool ExcludeBoundingBox)>(); + _points.Clear(); if (_uiManager.CurrentlyHovered is IViewportControl vp && _inputManager.MouseScreenPosition.IsValid) { - pointsOfInterest.Add((vp.PixelToMap(_inputManager.MouseScreenPosition.Position), true)); + _points.Add((vp.PixelToMap(_inputManager.MouseScreenPosition.Position), true)); } if (TryComp(player, out TransformComponent? playerXform)) { - pointsOfInterest.Add((_transform.GetMapCoordinates(_playerManager.LocalEntity!.Value, xform: playerXform), false)); + _points.Add((_transform.GetMapCoordinates(_playerManager.LocalEntity!.Value, xform: playerXform), false)); } if (_stateManager.CurrentState is GameplayState state && _spriteQuery.TryGetComponent(player, out var playerSprite)) { - foreach (var (mapPos, excludeBB) in pointsOfInterest) + foreach (var (mapPos, excludeBB) in _points) { // Also want to handle large entities even if they may not be clickable. foreach (var ent in state.GetClickableEntities(mapPos, excludeFaded: false)) @@ -95,21 +96,28 @@ public sealed class SpriteFadeSystem : EntitySystem continue; } - if (excludeBB) + // If it intersects a fixture ignore it. + if (excludeBB && _fixturesQuery.TryComp(ent, out var body)) { - var test = new Box2Rotated(mapPos.Position - MouseRadius, mapPos.Position + MouseRadius); + var transform = _physics.GetPhysicsTransform(ent); var collided = false; - foreach (var fixture in _physics.GetCollidingEntities(mapPos.MapId, test)) + + foreach (var fixture in body.Fixtures.Values) { - if (fixture.Owner == ent) + if (!fixture.Hard) + continue; + + if (_fixtures.TestPoint(fixture.Shape, transform, mapPos.Position)) { collided = true; break; } } + + // Check next entity if (collided) { - break; + continue; } }