Skip to content

Commit

Permalink
Spread out expensive system updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Partmedia committed Dec 15, 2024
1 parent ee73146 commit 1e9efb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Content.Server/Body/Systems/MetabolizerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override void Initialize()

private void OnMapInit(Entity<MetabolizerComponent> ent, ref MapInitEvent args)
{
ent.Comp.NextUpdate = _gameTiming.CurTime + ent.Comp.UpdateInterval;
ent.Comp.NextUpdate = _gameTiming.CurTime + ent.Comp.UpdateInterval * (1+_random.NextFloat());
}

private void OnUnpaused(Entity<MetabolizerComponent> ent, ref EntityUnpausedEvent args)
Expand Down
7 changes: 7 additions & 0 deletions Content.Server/Fluids/EntitySystems/DrainSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public override void Initialize()
SubscribeLocalEvent<DrainComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<DrainComponent, AfterInteractUsingEvent>(OnInteract);
SubscribeLocalEvent<DrainComponent, DrainDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<DrainComponent, ComponentInit>(OnComponentInit);
}

private void OnComponentInit(EntityUid uid, DrainComponent component, ComponentInit args)
{
// Randomize accumulator on init to try to spread out all drain updates as much as possible.
component.Accumulator = _random.NextFloat() * component.DrainFrequency;
}

private void AddEmptyVerb(Entity<DrainComponent> entity, ref GetVerbsEvent<Verb> args)
Expand Down

0 comments on commit 1e9efb5

Please sign in to comment.