Reduce some state handling allocs (#14301)

This commit is contained in:
metalgearsloth
2023-03-01 03:05:29 +11:00
committed by GitHub
parent 644e2e2d60
commit b9a805b352
4 changed files with 30 additions and 8 deletions

View File

@@ -108,9 +108,10 @@ public abstract class SharedDoorSystem : EntitySystem
if (args.Current is not DoorComponentState state) if (args.Current is not DoorComponentState state)
return; 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; door.State = state.DoorState;

View File

@@ -104,7 +104,12 @@ public partial class MobStateSystem : EntitySystem
return; return;
component.CurrentState = state.CurrentState; 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) private void OnGetComponentState(EntityUid uid, MobStateComponent component, ref ComponentGetState args)

View File

@@ -340,7 +340,17 @@ public sealed class MobThresholdSystem : EntitySystem
if (args.Current is not MobThresholdComponentState state) if (args.Current is not MobThresholdComponentState state)
return; 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; component.CurrentThresholdState = state.CurrentThresholdState;
} }

View File

@@ -150,11 +150,17 @@ public sealed class StepTriggerSystem : EntitySystem
component.IntersectRatio = state.IntersectRatio; component.IntersectRatio = state.IntersectRatio;
component.Active = state.Active; component.Active = state.Active;
component.CurrentlySteppedOn.Clear(); if (!component.CurrentlySteppedOn.SetEquals(state.CurrentlySteppedOn))
component.Colliding.Clear(); {
component.CurrentlySteppedOn.Clear();
component.CurrentlySteppedOn.UnionWith(state.CurrentlySteppedOn);
}
component.CurrentlySteppedOn.UnionWith(state.CurrentlySteppedOn); if (!component.Colliding.SetEquals(state.Colliding))
component.Colliding.UnionWith(state.Colliding); {
component.Colliding.Clear();
component.Colliding.UnionWith(state.Colliding);
}
if (component.Colliding.Count > 0) if (component.Colliding.Count > 0)
{ {