Remove imagesharp and StatusEffectAddedEvent from FlashOverlay (#28930)

remove imagesharp and StatusEffectAddedEvent from FlashOverlay
This commit is contained in:
slarticodefast
2024-07-13 08:10:04 +02:00
committed by GitHub
parent 49096cf14f
commit eb4ce85354
2 changed files with 9 additions and 32 deletions

View File

@@ -1,27 +1,22 @@
using Content.Shared.Flash; using Content.Shared.Flash;
using Content.Shared.Flash.Components; using Content.Shared.Flash.Components;
using Content.Shared.StatusEffect; using Content.Shared.StatusEffect;
using Content.Client.Viewport;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.State;
using Robust.Client.Player; using Robust.Client.Player;
using Robust.Shared.Enums; using Robust.Shared.Enums;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using SixLabors.ImageSharp.PixelFormats;
namespace Content.Client.Flash namespace Content.Client.Flash
{ {
public sealed class FlashOverlay : Overlay public sealed class FlashOverlay : Overlay
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IClyde _displayManager = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
private readonly StatusEffectsSystem _statusSys; private readonly StatusEffectsSystem _statusSys;
public override OverlaySpace Space => OverlaySpace.WorldSpace; public override OverlaySpace Space => OverlaySpace.WorldSpace;
private readonly ShaderInstance _shader; private readonly ShaderInstance _shader;
@@ -56,20 +51,6 @@ namespace Content.Client.Flash
PercentComplete = timeDone / lastsFor; PercentComplete = timeDone / lastsFor;
} }
public void ReceiveFlash()
{
if (_stateManager.CurrentState is IMainViewportState state)
{
// take a screenshot
// note that the callback takes a while and ScreenshotTexture will be null the first few Draws
state.Viewport.Viewport.Screenshot(image =>
{
var rgba32Image = image.CloneAs<Rgba32>(SixLabors.ImageSharp.Configuration.Default);
ScreenshotTexture = _displayManager.LoadTextureFromImage(rgba32Image);
});
}
}
protected override bool BeforeDraw(in OverlayDrawArgs args) protected override bool BeforeDraw(in OverlayDrawArgs args)
{ {
if (!_entityManager.TryGetComponent(_playerManager.LocalEntity, out EyeComponent? eyeComp)) if (!_entityManager.TryGetComponent(_playerManager.LocalEntity, out EyeComponent? eyeComp))
@@ -82,6 +63,11 @@ namespace Content.Client.Flash
protected override void Draw(in OverlayDrawArgs args) protected override void Draw(in OverlayDrawArgs args)
{ {
if (RequestScreenTexture && ScreenTexture != null)
{
ScreenshotTexture = ScreenTexture;
RequestScreenTexture = false; // we only need the first frame, so we can stop the request now for performance reasons
}
if (ScreenshotTexture == null) if (ScreenshotTexture == null)
return; return;
@@ -96,7 +82,6 @@ namespace Content.Client.Flash
{ {
base.DisposeBehavior(); base.DisposeBehavior();
ScreenshotTexture = null; ScreenshotTexture = null;
PercentComplete = 1.0f;
} }
} }
} }

View File

@@ -22,7 +22,6 @@ public sealed class FlashSystem : SharedFlashSystem
SubscribeLocalEvent<FlashedComponent, ComponentShutdown>(OnShutdown); SubscribeLocalEvent<FlashedComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<FlashedComponent, LocalPlayerAttachedEvent>(OnPlayerAttached); SubscribeLocalEvent<FlashedComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<FlashedComponent, LocalPlayerDetachedEvent>(OnPlayerDetached); SubscribeLocalEvent<FlashedComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
SubscribeLocalEvent<FlashedComponent, StatusEffectAddedEvent>(OnStatusAdded);
_overlay = new(); _overlay = new();
} }
@@ -34,8 +33,8 @@ public sealed class FlashSystem : SharedFlashSystem
private void OnPlayerDetached(EntityUid uid, FlashedComponent component, LocalPlayerDetachedEvent args) private void OnPlayerDetached(EntityUid uid, FlashedComponent component, LocalPlayerDetachedEvent args)
{ {
_overlay.PercentComplete = 1.0f;
_overlay.ScreenshotTexture = null; _overlay.ScreenshotTexture = null;
_overlay.RequestScreenTexture = false;
_overlayMan.RemoveOverlay(_overlay); _overlayMan.RemoveOverlay(_overlay);
} }
@@ -43,6 +42,7 @@ public sealed class FlashSystem : SharedFlashSystem
{ {
if (_player.LocalEntity == uid) if (_player.LocalEntity == uid)
{ {
_overlay.RequestScreenTexture = true;
_overlayMan.AddOverlay(_overlay); _overlayMan.AddOverlay(_overlay);
} }
} }
@@ -51,17 +51,9 @@ public sealed class FlashSystem : SharedFlashSystem
{ {
if (_player.LocalEntity == uid) if (_player.LocalEntity == uid)
{ {
_overlay.PercentComplete = 1.0f;
_overlay.ScreenshotTexture = null; _overlay.ScreenshotTexture = null;
_overlay.RequestScreenTexture = false;
_overlayMan.RemoveOverlay(_overlay); _overlayMan.RemoveOverlay(_overlay);
} }
} }
private void OnStatusAdded(EntityUid uid, FlashedComponent component, StatusEffectAddedEvent args)
{
if (_player.LocalEntity == uid && args.Key == FlashedKey)
{
_overlay.ReceiveFlash();
}
}
} }