-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Footprints Performance Updates (#1439)
# Description This is a port of Fansana/floofstation1#445 Except I despise that this wasn't upstreamed so much that I didn't even cherrypick it. # Changelog :cl: - add: Footprints are now cleaned in a small radius around the mouse cursor when mopping them.
- Loading branch information
Showing
9 changed files
with
171 additions
and
108 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
Content.Server/Fluids/EntitySystems/AbsorbentSystem.Footprints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Linq; | ||
using Content.Shared.Chemistry.Components; | ||
using Content.Shared.Fluids; | ||
using Content.Shared.FootPrint; | ||
|
||
namespace Content.Server.Fluids.EntitySystems; | ||
|
||
public sealed partial class AbsorbentSystem | ||
{ | ||
[Dependency] private readonly EntityLookupSystem _lookup = default!; | ||
|
||
/// <summary> | ||
/// Tries to clean a number of footprints in a range determined by the component. Returns the number of cleaned footprints. | ||
/// </summary> | ||
private int TryCleanNearbyFootprints(EntityUid user, EntityUid used, Entity<AbsorbentComponent> target, Entity<SolutionComponent> absorbentSoln) | ||
{ | ||
var footprintQuery = GetEntityQuery<FootPrintComponent>(); | ||
var targetCoords = Transform(target).Coordinates; | ||
var entities = _lookup.GetEntitiesInRange<FootPrintComponent>(targetCoords, target.Comp.FootprintCleaningRange, LookupFlags.Uncontained); | ||
|
||
// Take up to [MaxCleanedFootprints] footprints closest to the target | ||
var cleaned = entities.AsEnumerable() | ||
.Select(uid => (uid, dst: Transform(uid).Coordinates.TryDistance(EntityManager, _transform, targetCoords, out var dst) ? dst : 0f)) | ||
.Where(ent => ent.dst > 0f) | ||
.OrderBy(ent => ent.dst) | ||
.Select(ent => (ent.uid, comp: footprintQuery.GetComponent(ent.uid))); | ||
|
||
// And try to interact with each one of them, ignoring useDelay | ||
var processed = 0; | ||
foreach (var (uid, footprintComp) in cleaned) | ||
{ | ||
if (TryPuddleInteract(user, used, uid, target.Comp, useDelay: null, absorbentSoln)) | ||
processed++; | ||
|
||
if (processed >= target.Comp.MaxCleanedFootprints) | ||
break; | ||
} | ||
|
||
return processed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.