From 46d189084499a0e390bd5877aabbf6167ec6d81e Mon Sep 17 00:00:00 2001
From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Date: Mon, 9 Oct 2023 23:32:34 -0400
Subject: [PATCH] Fix fast kudzu (#20875)
---
.../Spreader/SpreaderGridComponent.cs | 6 ++----
Content.Server/Spreader/SpreaderSystem.cs | 20 ++++---------------
2 files changed, 6 insertions(+), 20 deletions(-)
diff --git a/Content.Server/Spreader/SpreaderGridComponent.cs b/Content.Server/Spreader/SpreaderGridComponent.cs
index 102678a251..401b7d4916 100644
--- a/Content.Server/Spreader/SpreaderGridComponent.cs
+++ b/Content.Server/Spreader/SpreaderGridComponent.cs
@@ -1,10 +1,8 @@
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
-
namespace Content.Server.Spreader;
[RegisterComponent]
public sealed partial class SpreaderGridComponent : Component
{
- [DataField("nextUpdate", customTypeSerializer:typeof(TimeOffsetSerializer))]
- public TimeSpan NextUpdate = TimeSpan.Zero;
+ [DataField]
+ public float UpdateAccumulator = SpreaderSystem.SpreadCooldownSeconds;
}
diff --git a/Content.Server/Spreader/SpreaderSystem.cs b/Content.Server/Spreader/SpreaderSystem.cs
index 4cd575cbd4..d61cf303d6 100644
--- a/Content.Server/Spreader/SpreaderSystem.cs
+++ b/Content.Server/Spreader/SpreaderSystem.cs
@@ -9,7 +9,6 @@ using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
-using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Server.Spreader;
@@ -19,13 +18,10 @@ namespace Content.Server.Spreader;
///
public sealed class SpreaderSystem : EntitySystem
{
- [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
- private static readonly TimeSpan SpreadCooldown = TimeSpan.FromSeconds(SpreadCooldownSeconds);
-
///
/// Cached maximum number of updates per spreader prototype. This is applied per-grid.
///
@@ -36,7 +32,7 @@ public sealed class SpreaderSystem : EntitySystem
///
private Dictionary> _gridUpdates = new();
- private const float SpreadCooldownSeconds = 1;
+ public const float SpreadCooldownSeconds = 1;
[ValidatePrototypeId]
private const string IgnoredTag = "SpreaderIgnore";
@@ -47,8 +43,6 @@ public sealed class SpreaderSystem : EntitySystem
SubscribeLocalEvent(OnAirtightChanged);
SubscribeLocalEvent(OnGridInit);
- SubscribeLocalEvent(OnGridUnpaused);
-
SubscribeLocalEvent(OnTerminating);
SetupPrototypes();
_prototype.PrototypesReloaded += OnPrototypeReload;
@@ -87,11 +81,6 @@ public sealed class SpreaderSystem : EntitySystem
}
}
- private void OnGridUnpaused(EntityUid uid, SpreaderGridComponent component, ref EntityUnpausedEvent args)
- {
- component.NextUpdate += args.PausedTime;
- }
-
private void OnGridInit(GridInitializeEvent ev)
{
EnsureComp(ev.EntityUid);
@@ -111,19 +100,18 @@ public sealed class SpreaderSystem : EntitySystem
///
public override void Update(float frameTime)
{
- var curTime = _timing.CurTime;
-
// Check which grids are valid for spreading
var spreadGrids = EntityQueryEnumerator();
_gridUpdates.Clear();
while (spreadGrids.MoveNext(out var uid, out var grid))
{
- if (grid.NextUpdate > curTime)
+ grid.UpdateAccumulator -= frameTime;
+ if (grid.UpdateAccumulator > 0)
continue;
_gridUpdates[uid] = _prototypeUpdates.ShallowClone();
- grid.NextUpdate += SpreadCooldown;
+ grid.UpdateAccumulator += SpreadCooldownSeconds;
}
if (_gridUpdates.Count == 0)
--
2.51.2