Reduce some state handling allocs (#14301)
This commit is contained in:
@@ -108,9 +108,10 @@ public abstract class SharedDoorSystem : EntitySystem
|
||||
if (args.Current is not DoorComponentState state)
|
||||
return;
|
||||
|
||||
if (!door.CurrentlyCrushing.Equals(state.CurrentlyCrushing))
|
||||
if (!door.CurrentlyCrushing.SetEquals(state.CurrentlyCrushing))
|
||||
{
|
||||
door.CurrentlyCrushing = new(state.CurrentlyCrushing);
|
||||
door.CurrentlyCrushing.Clear();
|
||||
door.CurrentlyCrushing.UnionWith(state.CurrentlyCrushing);
|
||||
}
|
||||
|
||||
door.State = state.DoorState;
|
||||
|
||||
@@ -104,7 +104,12 @@ public partial class MobStateSystem : EntitySystem
|
||||
return;
|
||||
|
||||
component.CurrentState = state.CurrentState;
|
||||
component.AllowedStates = new HashSet<MobState>(state.AllowedStates);
|
||||
|
||||
if (!component.AllowedStates.SetEquals(state.AllowedStates))
|
||||
{
|
||||
component.AllowedStates.Clear();
|
||||
component.AllowedStates.UnionWith(state.AllowedStates);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetComponentState(EntityUid uid, MobStateComponent component, ref ComponentGetState args)
|
||||
|
||||
@@ -340,7 +340,17 @@ public sealed class MobThresholdSystem : EntitySystem
|
||||
if (args.Current is not MobThresholdComponentState state)
|
||||
return;
|
||||
|
||||
component.Thresholds = new SortedDictionary<FixedPoint2, MobState>(state.Thresholds);
|
||||
if (component.Thresholds.Count != state.Thresholds.Count ||
|
||||
!component.Thresholds.SequenceEqual(state.Thresholds))
|
||||
{
|
||||
component.Thresholds.Clear();
|
||||
|
||||
foreach (var threshold in state.Thresholds)
|
||||
{
|
||||
component.Thresholds.Add(threshold.Key, threshold.Value);
|
||||
}
|
||||
}
|
||||
|
||||
component.CurrentThresholdState = state.CurrentThresholdState;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,11 +150,17 @@ public sealed class StepTriggerSystem : EntitySystem
|
||||
component.IntersectRatio = state.IntersectRatio;
|
||||
component.Active = state.Active;
|
||||
|
||||
component.CurrentlySteppedOn.Clear();
|
||||
component.Colliding.Clear();
|
||||
if (!component.CurrentlySteppedOn.SetEquals(state.CurrentlySteppedOn))
|
||||
{
|
||||
component.CurrentlySteppedOn.Clear();
|
||||
component.CurrentlySteppedOn.UnionWith(state.CurrentlySteppedOn);
|
||||
}
|
||||
|
||||
component.CurrentlySteppedOn.UnionWith(state.CurrentlySteppedOn);
|
||||
component.Colliding.UnionWith(state.Colliding);
|
||||
if (!component.Colliding.SetEquals(state.Colliding))
|
||||
{
|
||||
component.Colliding.Clear();
|
||||
component.Colliding.UnionWith(state.Colliding);
|
||||
}
|
||||
|
||||
if (component.Colliding.Count > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user