Misc state-handling changes (#16444)

This commit is contained in:
Leon Friedrich
2023-05-15 14:22:17 +12:00
committed by GitHub
parent a23de2f219
commit b20cc6f4d3
6 changed files with 29 additions and 13 deletions

View File

@@ -59,7 +59,8 @@ namespace Content.Client.Actions
if (args.Current is not ActionsComponentState state) if (args.Current is not ActionsComponentState state)
return; return;
var serverActions = new SortedSet<ActionType>(state.Actions); state.SortedActions ??= new SortedSet<ActionType>(state.Actions);
var serverActions = state.SortedActions;
var removed = new List<ActionType>(); var removed = new List<ActionType>();
foreach (var act in component.Actions.ToList()) foreach (var act in component.Actions.ToList())

View File

@@ -123,7 +123,7 @@ namespace Content.Client.IconSmoothing
public void DirtyNeighbours(EntityUid uid, IconSmoothComponent? comp = null, TransformComponent? transform = null, EntityQuery<IconSmoothComponent>? smoothQuery = null) public void DirtyNeighbours(EntityUid uid, IconSmoothComponent? comp = null, TransformComponent? transform = null, EntityQuery<IconSmoothComponent>? smoothQuery = null)
{ {
smoothQuery ??= GetEntityQuery<IconSmoothComponent>(); smoothQuery ??= GetEntityQuery<IconSmoothComponent>();
if (!smoothQuery.Value.Resolve(uid, ref comp)) if (!smoothQuery.Value.Resolve(uid, ref comp) || !comp.Running)
return; return;
_dirtyEntities.Enqueue(uid); _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. // 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) if (!smoothQuery.Resolve(uid, ref smooth, false)
|| smooth.Mode == IconSmoothingMode.NoSprite || smooth.Mode == IconSmoothingMode.NoSprite
|| smooth.UpdateGeneration == _generation || || smooth.UpdateGeneration == _generation
!smooth.Enabled) || !smooth.Enabled
|| !smooth.Running)
{ {
if (smooth is { Enabled: true } && if (smooth is { Enabled: true } &&
TryComp<SmoothEdgeComponent>(uid, out var edge) && TryComp<SmoothEdgeComponent>(uid, out var edge) &&

View File

@@ -37,6 +37,13 @@ public abstract class ActionType : IEquatable<ActionType>, IComparable, ICloneab
[DataField("name")] [DataField("name")]
public string DisplayName = string.Empty; 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> /// <summary>
/// Description to show in UI. Accepts formatting. /// Description to show in UI. Accepts formatting.
/// </summary> /// </summary>
@@ -179,10 +186,11 @@ public abstract class ActionType : IEquatable<ActionType>, IComparable, ICloneab
if (Priority != otherAction.Priority) if (Priority != otherAction.Priority)
return otherAction.Priority - Priority; return otherAction.Priority - Priority;
var name = FormattedMessage.RemoveMarkup(Loc.GetString(DisplayName)); RawName ??= FormattedMessage.RemoveMarkup(Loc.GetString(DisplayName));
var otherName = FormattedMessage.RemoveMarkup(Loc.GetString(otherAction.DisplayName)); otherAction.RawName ??= FormattedMessage.RemoveMarkup(Loc.GetString(otherAction.DisplayName));
if (name != otherName) var cmp = string.Compare(RawName, otherAction.RawName, StringComparison.CurrentCulture);
return string.Compare(name, otherName, StringComparison.CurrentCulture); if (cmp != 0)
return cmp;
if (Provider != otherAction.Provider) if (Provider != otherAction.Provider)
{ {
@@ -217,6 +225,7 @@ public abstract class ActionType : IEquatable<ActionType>, IComparable, ICloneab
Icon = toClone.Icon; Icon = toClone.Icon;
IconOn = toClone.IconOn; IconOn = toClone.IconOn;
DisplayName = toClone.DisplayName; DisplayName = toClone.DisplayName;
RawName = null;
Description = toClone.Description; Description = toClone.Description;
Provider = toClone.Provider; Provider = toClone.Provider;
AttachedEntity = toClone.AttachedEntity; AttachedEntity = toClone.AttachedEntity;

View File

@@ -22,6 +22,9 @@ public sealed class ActionsComponentState : ComponentState
{ {
public readonly List<ActionType> Actions; public readonly List<ActionType> Actions;
[NonSerialized]
public SortedSet<ActionType>? SortedActions;
public ActionsComponentState(List<ActionType> actions) public ActionsComponentState(List<ActionType> actions)
{ {
Actions = actions; Actions = actions;

View File

@@ -1,3 +1,4 @@
using System.Collections.ObjectModel;
using Content.Shared.Whitelist; using Content.Shared.Whitelist;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -37,21 +38,22 @@ namespace Content.Shared.Storage.Components
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed class ShowLayerData : ICloneable public sealed class ShowLayerData : ICloneable
{ {
public IReadOnlyList<string> QueuedEntities { get; internal set; } public readonly IReadOnlyList<string> QueuedEntities;
public ShowLayerData() public ShowLayerData()
{ {
QueuedEntities = new List<string>(); QueuedEntities = new List<string>();
} }
public ShowLayerData(IEnumerable<string> other) public ShowLayerData(IReadOnlyList<string> other)
{ {
QueuedEntities = new List<string>(other); QueuedEntities = other;
} }
public object Clone() public object Clone()
{ {
return new ShowLayerData(QueuedEntities); // QueuedEntities should never be getting modified after this object is created.
return this;
} }
} }
} }

View 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> /// <returns>false if <c>msg.Container.Owner</c> is not a storage, true otherwise.</returns>
private bool TryGetLayers(ContainerModifiedMessage msg, private bool TryGetLayers(ContainerModifiedMessage msg,
ItemMapperComponent itemMapper, ItemMapperComponent itemMapper,
out IReadOnlyList<string> showLayers) out List<string> showLayers)
{ {
var containedLayers = _container.GetAllContainers(msg.Container.Owner) var containedLayers = _container.GetAllContainers(msg.Container.Owner)
.Where(c => itemMapper.ContainerWhitelist?.Contains(c.ID) ?? true).SelectMany(cont => cont.ContainedEntities).ToArray(); .Where(c => itemMapper.ContainerWhitelist?.Contains(c.ID) ?? true).SelectMany(cont => cont.ContainedEntities).ToArray();