Files
wwdpublic/Content.Server/Chemistry/EntitySystems/SolutionRegenerationSystem.cs
VMSolidus 151e1b60a3 TCJ Makes A Rage Performance PR (#2298)
# Description

I got baited by Ectoplasm, so I then spent 3 hours shaving off a
sizeable chunk of this game's performance cost, including by taking 3 of
the "Top 10 frametime consumers", and reducing their performance costs
by 99% each. Along with various examples of slimming down some of the
worst EQE's.

Oh, and I fixed EmitSoundOnMove being desynced with actual movement. As
part of making EmitSoundOnMove use 99% less CPU time, it was also
synchronized with the MoverController.

# Changelog

🆑
- fix: Fixed items such as tactical webbing, bell collars, and hardsuits
being desynced with character movement.
- tweak: Made various large performance improvements.

(cherry picked from commit 684e8175443167beb0e20e3323a05b5f493b3374)
2025-04-26 11:45:35 +03:00

50 lines
1.8 KiB
C#

using Content.Server.Chemistry.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.FixedPoint;
using Robust.Shared.Timing;
namespace Content.Server.Chemistry.EntitySystems;
public sealed class SolutionRegenerationSystem : EntitySystem
{
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly IGameTiming _timing = default!;
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<SolutionRegenerationComponent>();
while (query.MoveNext(out var uid, out var regen))
{
if (_timing.CurTime < regen.NextRegenTime
|| !TryComp(uid, out SolutionContainerManagerComponent? manager))
continue;
// timer ignores if its full, it's just a fixed cycle
regen.NextRegenTime = _timing.CurTime + regen.Duration;
if (_solutionContainer.ResolveSolution((uid, manager), regen.SolutionName, ref regen.SolutionRef, out var solution))
{
var amount = FixedPoint2.Min(solution.AvailableVolume, regen.Generated.Volume);
if (amount <= FixedPoint2.Zero)
continue;
// dont bother cloning and splitting if adding the whole thing
Solution generated;
if (amount == regen.Generated.Volume)
{
generated = regen.Generated;
}
else
{
generated = regen.Generated.Clone().SplitSolution(amount);
}
_solutionContainer.TryAddSolution(regen.SolutionRef.Value, generated);
}
}
}
}