]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Misc state-handling changes (#16444)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Mon, 15 May 2023 02:22:17 +0000 (14:22 +1200)
committerGitHub <noreply@github.com>
Mon, 15 May 2023 02:22:17 +0000 (12:22 +1000)
Content.Client/Actions/ActionsSystem.cs
Content.Client/IconSmoothing/IconSmoothSystem.cs
Content.Shared/Actions/ActionTypes/ActionType.cs
Content.Shared/Actions/ActionsComponent.cs
Content.Shared/Storage/Components/SharedMapLayerData.cs
Content.Shared/Storage/EntitySystems/SharedItemMapperSystem.cs

index 767e7ac3258dc16257e760625860c25cd1d29f79..c4f3b14495c7ae6b1f16faf5981837a42c994b0c 100644 (file)
@@ -59,7 +59,8 @@ namespace Content.Client.Actions
             if (args.Current is not ActionsComponentState state)
                 return;
 
-            var serverActions = new SortedSet<ActionType>(state.Actions);
+            state.SortedActions ??= new SortedSet<ActionType>(state.Actions);
+            var serverActions = state.SortedActions;
             var removed = new List<ActionType>();
 
             foreach (var act in component.Actions.ToList())
index 529d0dd1ae283eadd7911a6dfbd271522c165207..f3cb004887502a3e3c602f7af051cbfefb789a13 100644 (file)
@@ -123,7 +123,7 @@ namespace Content.Client.IconSmoothing
         public void DirtyNeighbours(EntityUid uid, IconSmoothComponent? comp = null, TransformComponent? transform = null, EntityQuery<IconSmoothComponent>? smoothQuery = null)
         {
             smoothQuery ??= GetEntityQuery<IconSmoothComponent>();
-            if (!smoothQuery.Value.Resolve(uid, ref comp))
+            if (!smoothQuery.Value.Resolve(uid, ref comp) || !comp.Running)
                 return;
 
             _dirtyEntities.Enqueue(uid);
@@ -195,8 +195,9 @@ namespace Content.Client.IconSmoothing
             // Generation on the component is set after an update so we can cull updates that happened this generation.
             if (!smoothQuery.Resolve(uid, ref smooth, false)
                 || smooth.Mode == IconSmoothingMode.NoSprite
-                || smooth.UpdateGeneration == _generation ||
-                !smooth.Enabled)
+                || smooth.UpdateGeneration == _generation
+                || !smooth.Enabled
+                || !smooth.Running)
             {
                 if (smooth is { Enabled: true } &&
                     TryComp<SmoothEdgeComponent>(uid, out var edge) &&
index 202465a4fe382268962d951cd98c74fd50adba0b..1a295d6628c8584403e55cfa6a1b742d9183a5f4 100644 (file)
@@ -37,6 +37,13 @@ public abstract class ActionType : IEquatable<ActionType>, IComparable, ICloneab
     [DataField("name")]
     public string DisplayName = string.Empty;
 
+    /// <summary>
+    /// This is just <see cref="DisplayName"/> with localized strings resolved and markup removed. If null, will be
+    /// inferred from <see cref="DisplayName"/>. This is cached to speed up game state handling.
+    /// </summary>
+    [NonSerialized]
+    public string? RawName;
+
     /// <summary>
     ///     Description to show in UI. Accepts formatting.
     /// </summary>
@@ -179,10 +186,11 @@ public abstract class ActionType : IEquatable<ActionType>, IComparable, ICloneab
         if (Priority != otherAction.Priority)
             return otherAction.Priority - Priority;
 
-        var name = FormattedMessage.RemoveMarkup(Loc.GetString(DisplayName));
-        var otherName = FormattedMessage.RemoveMarkup(Loc.GetString(otherAction.DisplayName));
-        if (name != otherName)
-            return string.Compare(name, otherName, StringComparison.CurrentCulture);
+        RawName ??= FormattedMessage.RemoveMarkup(Loc.GetString(DisplayName));
+        otherAction.RawName ??= FormattedMessage.RemoveMarkup(Loc.GetString(otherAction.DisplayName));
+        var cmp = string.Compare(RawName, otherAction.RawName, StringComparison.CurrentCulture);
+        if (cmp != 0)
+            return cmp;
 
         if (Provider != otherAction.Provider)
         {
@@ -217,6 +225,7 @@ public abstract class ActionType : IEquatable<ActionType>, IComparable, ICloneab
         Icon = toClone.Icon;
         IconOn = toClone.IconOn;
         DisplayName = toClone.DisplayName;
+        RawName = null;
         Description = toClone.Description;
         Provider = toClone.Provider;
         AttachedEntity = toClone.AttachedEntity;
index ba2aedb6da81a7d531cd0d76e560d3aabe2f2e0c..d422fcdbc229543e2fd7a29c5809acffbae59d6e 100644 (file)
@@ -22,6 +22,9 @@ public sealed class ActionsComponentState : ComponentState
 {
     public readonly List<ActionType> Actions;
 
+    [NonSerialized]
+    public SortedSet<ActionType>? SortedActions;
+
     public ActionsComponentState(List<ActionType> actions)
     {
         Actions = actions;
index 112a7874019fd8181290c60de0fe94cdb0c7c97f..741f832af756f1568eb3328e88abd7b3f22f066b 100644 (file)
@@ -1,3 +1,4 @@
+using System.Collections.ObjectModel;
 using Content.Shared.Whitelist;
 using Robust.Shared.Serialization;
 
@@ -37,21 +38,22 @@ namespace Content.Shared.Storage.Components
     [Serializable, NetSerializable]
     public sealed class ShowLayerData : ICloneable
     {
-        public IReadOnlyList<string> QueuedEntities { get; internal set; }
+        public readonly IReadOnlyList<string> QueuedEntities;
 
         public ShowLayerData()
         {
             QueuedEntities = new List<string>();
         }
 
-        public ShowLayerData(IEnumerable<string> other)
+        public ShowLayerData(IReadOnlyList<string> other)
         {
-            QueuedEntities = new List<string>(other);
+            QueuedEntities = other;
         }
 
         public object Clone()
         {
-            return new ShowLayerData(QueuedEntities);
+            // QueuedEntities should never be getting modified after this object is created.
+            return this;
         }
     }
 }
index fcd76e151532b69efe210a4b0b044f6e2e02402a..0688d35400e2a38a453be66e292e499fcae2d9ab 100644 (file)
@@ -79,7 +79,7 @@ namespace Content.Shared.Storage.EntitySystems
         /// <returns>false if <c>msg.Container.Owner</c> is not a storage, true otherwise.</returns>
         private bool TryGetLayers(ContainerModifiedMessage msg,
             ItemMapperComponent itemMapper,
-            out IReadOnlyList<string> showLayers)
+            out List<string> showLayers)
         {
             var containedLayers = _container.GetAllContainers(msg.Container.Owner)
                 .Where(c => itemMapper.ContainerWhitelist?.Contains(c.ID) ?? true).SelectMany(cont => cont.ContainedEntities).ToArray();