]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Remove imagesharp and StatusEffectAddedEvent from FlashOverlay (#28930)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Sat, 13 Jul 2024 06:10:04 +0000 (08:10 +0200)
committerGitHub <noreply@github.com>
Sat, 13 Jul 2024 06:10:04 +0000 (16:10 +1000)
remove imagesharp and StatusEffectAddedEvent from FlashOverlay

Content.Client/Flash/FlashOverlay.cs
Content.Client/Flash/FlashSystem.cs

index 9ea00275e842cc4d5b02931fcb50a4442d03a696..046be2aa62142c4e1cb2a51909fef1ada4097aa9 100644 (file)
@@ -1,27 +1,22 @@
 using Content.Shared.Flash;
 using Content.Shared.Flash.Components;
 using Content.Shared.StatusEffect;
-using Content.Client.Viewport;
 using Robust.Client.Graphics;
-using Robust.Client.State;
 using Robust.Client.Player;
 using Robust.Shared.Enums;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Timing;
-using SixLabors.ImageSharp.PixelFormats;
 
 namespace Content.Client.Flash
 {
     public sealed class FlashOverlay : Overlay
     {
         [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 IPlayerManager _playerManager = default!;
         [Dependency] private readonly IGameTiming _timing = default!;
 
-       private readonly StatusEffectsSystem _statusSys;
+        private readonly StatusEffectsSystem _statusSys;
 
         public override OverlaySpace Space => OverlaySpace.WorldSpace;
         private readonly ShaderInstance _shader;
@@ -56,20 +51,6 @@ namespace Content.Client.Flash
             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)
         {
             if (!_entityManager.TryGetComponent(_playerManager.LocalEntity, out EyeComponent? eyeComp))
@@ -82,6 +63,11 @@ namespace Content.Client.Flash
 
         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)
                 return;
 
@@ -96,7 +82,6 @@ namespace Content.Client.Flash
         {
             base.DisposeBehavior();
             ScreenshotTexture = null;
-            PercentComplete = 1.0f;
         }
     }
 }
index 9a0579f6aa389696b63fb615a951ac78708f5985..146d84b990f5562552e4aebcfbcfa00e988a4577 100644 (file)
@@ -22,7 +22,6 @@ public sealed class FlashSystem : SharedFlashSystem
         SubscribeLocalEvent<FlashedComponent, ComponentShutdown>(OnShutdown);
         SubscribeLocalEvent<FlashedComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
         SubscribeLocalEvent<FlashedComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
-        SubscribeLocalEvent<FlashedComponent, StatusEffectAddedEvent>(OnStatusAdded);
 
         _overlay = new();
     }
@@ -34,8 +33,8 @@ public sealed class FlashSystem : SharedFlashSystem
 
     private void OnPlayerDetached(EntityUid uid, FlashedComponent component, LocalPlayerDetachedEvent args)
     {
-        _overlay.PercentComplete = 1.0f;
         _overlay.ScreenshotTexture = null;
+        _overlay.RequestScreenTexture = false;
         _overlayMan.RemoveOverlay(_overlay);
     }
 
@@ -43,6 +42,7 @@ public sealed class FlashSystem : SharedFlashSystem
     {
         if (_player.LocalEntity == uid)
         {
+            _overlay.RequestScreenTexture = true;
             _overlayMan.AddOverlay(_overlay);
         }
     }
@@ -51,17 +51,9 @@ public sealed class FlashSystem : SharedFlashSystem
     {
         if (_player.LocalEntity == uid)
         {
-            _overlay.PercentComplete = 1.0f;
             _overlay.ScreenshotTexture = null;
+            _overlay.RequestScreenTexture = false;
             _overlayMan.RemoveOverlay(_overlay);
         }
     }
-
-    private void OnStatusAdded(EntityUid uid, FlashedComponent component, StatusEffectAddedEvent args)
-    {
-        if (_player.LocalEntity == uid && args.Key == FlashedKey)
-        {
-            _overlay.ReceiveFlash();
-        }
-    }
 }