]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix fast kudzu (#20875)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Tue, 10 Oct 2023 03:32:34 +0000 (23:32 -0400)
committerGitHub <noreply@github.com>
Tue, 10 Oct 2023 03:32:34 +0000 (20:32 -0700)
Content.Server/Spreader/SpreaderGridComponent.cs
Content.Server/Spreader/SpreaderSystem.cs

index 102678a251c395e289a2c46fa82e30888b4de0b7..401b7d491656571cfda6f0ee0718152c155d309e 100644 (file)
@@ -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;
 }
index 4cd575cbd4a36d756a71ac869e499c4ece762a3c..d61cf303d6bde692c14c7987738b4fda8520caba 100644 (file)
@@ -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;
 /// </summary>
 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);
-
     /// <summary>
     /// Cached maximum number of updates per spreader prototype. This is applied per-grid.
     /// </summary>
@@ -36,7 +32,7 @@ public sealed class SpreaderSystem : EntitySystem
     /// </summary>
     private Dictionary<EntityUid, Dictionary<string, int>> _gridUpdates = new();
 
-    private const float SpreadCooldownSeconds = 1;
+    public const float SpreadCooldownSeconds = 1;
 
     [ValidatePrototypeId<TagPrototype>]
     private const string IgnoredTag = "SpreaderIgnore";
@@ -47,8 +43,6 @@ public sealed class SpreaderSystem : EntitySystem
         SubscribeLocalEvent<AirtightChanged>(OnAirtightChanged);
         SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
 
-        SubscribeLocalEvent<SpreaderGridComponent, EntityUnpausedEvent>(OnGridUnpaused);
-
         SubscribeLocalEvent<EdgeSpreaderComponent, EntityTerminatingEvent>(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<SpreaderGridComponent>(ev.EntityUid);
@@ -111,19 +100,18 @@ public sealed class SpreaderSystem : EntitySystem
     /// <inheritdoc/>
     public override void Update(float frameTime)
     {
-        var curTime = _timing.CurTime;
-
         // Check which grids are valid for spreading
         var spreadGrids = EntityQueryEnumerator<SpreaderGridComponent>();
 
         _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)