Sprite fade review (#36509)

* Sprite fade review

* Skip non-hard fixtures

Probably fine.
This commit is contained in:
metalgearsloth
2025-04-14 08:22:05 +10:00
committed by GitHub
parent c9d71a4e45
commit 16c78aa8ee

View File

@@ -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<FadingSpriteComponent> _comps = new();
private EntityQuery<SpriteComponent> _spriteQuery;
private EntityQuery<SpriteFadeComponent> _fadeQuery;
private EntityQuery<FadingSpriteComponent> _fadingQuery;
/// <summary>
/// Radius of the mouse point for the intersection test
/// </summary>
private static Vector2 MouseRadius = new Vector2(10f * float.Epsilon, 10f * float.Epsilon);
private EntityQuery<FixturesComponent> _fixturesQuery;
private const float TargetAlpha = 0.4f;
private const float ChangeRate = 1f;
@@ -48,6 +48,7 @@ public sealed class SpriteFadeSystem : EntitySystem
_spriteQuery = GetEntityQuery<SpriteComponent>();
_fadeQuery = GetEntityQuery<SpriteFadeComponent>();
_fadingQuery = GetEntityQuery<FadingSpriteComponent>();
_fixturesQuery = GetEntityQuery<FixturesComponent>();
SubscribeLocalEvent<FadingSpriteComponent, ComponentShutdown>(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;
}
}