Fix glue puddle slowdown (#17260)

This commit is contained in:
Leon Friedrich
2023-06-12 05:04:42 +12:00
committed by GitHub
parent 1825f19a8e
commit fc07ed403c

View File

@@ -10,6 +10,8 @@ public sealed class SlowContactsSystem : EntitySystem
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly MovementSpeedModifierSystem _speedModifierSystem = default!;
// TODO full-game-save
// Either these need to be processed before a map is saved, or slowed/slowing entities need to update on init.
private HashSet<EntityUid> _toUpdate = new();
private HashSet<EntityUid> _toRemove = new();
@@ -19,6 +21,7 @@ public sealed class SlowContactsSystem : EntitySystem
SubscribeLocalEvent<SlowContactsComponent, StartCollideEvent>(OnEntityEnter);
SubscribeLocalEvent<SlowContactsComponent, EndCollideEvent>(OnEntityExit);
SubscribeLocalEvent<SlowedByContactComponent, RefreshMovementSpeedModifiersEvent>(MovementSpeedCheck);
SubscribeLocalEvent<SlowContactsComponent, ComponentShutdown>(OnShutdown);
UpdatesAfter.Add(typeof(SharedPhysicsSystem));
}
@@ -56,6 +59,16 @@ public sealed class SlowContactsSystem : EntitySystem
component.WalkSpeedModifier = walkSpeed;
component.SprintSpeedModifier = sprintSpeed;
Dirty(component);
_toUpdate.UnionWith(_physics.GetContactingEntities(uid));
}
private void OnShutdown(EntityUid uid, SlowContactsComponent component, ComponentShutdown args)
{
if (!TryComp(uid, out PhysicsComponent? phys))
return;
// Note that the entity may not be getting deleted here. E.g., glue puddles.
_toUpdate.UnionWith(_physics.GetContactingEntities(uid, phys));
}
private void MovementSpeedCheck(EntityUid uid, SlowedByContactComponent component, RefreshMovementSpeedModifiersEvent args)
@@ -90,7 +103,6 @@ public sealed class SlowContactsSystem : EntitySystem
private void OnEntityExit(EntityUid uid, SlowContactsComponent component, ref EndCollideEvent args)
{
var otherUid = args.OtherEntity;
if (HasComp<MovementSpeedModifierComponent>(otherUid))
_toUpdate.Add(otherUid);
}