Fix fast kudzu (#20875)
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
|
||||||
|
|
||||||
namespace Content.Server.Spreader;
|
namespace Content.Server.Spreader;
|
||||||
|
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed partial class SpreaderGridComponent : Component
|
public sealed partial class SpreaderGridComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("nextUpdate", customTypeSerializer:typeof(TimeOffsetSerializer))]
|
[DataField]
|
||||||
public TimeSpan NextUpdate = TimeSpan.Zero;
|
public float UpdateAccumulator = SpreaderSystem.SpreadCooldownSeconds;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ using Robust.Shared.Map;
|
|||||||
using Robust.Shared.Map.Components;
|
using Robust.Shared.Map.Components;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.Spreader;
|
namespace Content.Server.Spreader;
|
||||||
@@ -19,13 +18,10 @@ namespace Content.Server.Spreader;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class SpreaderSystem : EntitySystem
|
public sealed class SpreaderSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _timing = default!;
|
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||||
|
|
||||||
private static readonly TimeSpan SpreadCooldown = TimeSpan.FromSeconds(SpreadCooldownSeconds);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cached maximum number of updates per spreader prototype. This is applied per-grid.
|
/// Cached maximum number of updates per spreader prototype. This is applied per-grid.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,7 +32,7 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private Dictionary<EntityUid, Dictionary<string, int>> _gridUpdates = new();
|
private Dictionary<EntityUid, Dictionary<string, int>> _gridUpdates = new();
|
||||||
|
|
||||||
private const float SpreadCooldownSeconds = 1;
|
public const float SpreadCooldownSeconds = 1;
|
||||||
|
|
||||||
[ValidatePrototypeId<TagPrototype>]
|
[ValidatePrototypeId<TagPrototype>]
|
||||||
private const string IgnoredTag = "SpreaderIgnore";
|
private const string IgnoredTag = "SpreaderIgnore";
|
||||||
@@ -47,8 +43,6 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<AirtightChanged>(OnAirtightChanged);
|
SubscribeLocalEvent<AirtightChanged>(OnAirtightChanged);
|
||||||
SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
|
SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
|
||||||
|
|
||||||
SubscribeLocalEvent<SpreaderGridComponent, EntityUnpausedEvent>(OnGridUnpaused);
|
|
||||||
|
|
||||||
SubscribeLocalEvent<EdgeSpreaderComponent, EntityTerminatingEvent>(OnTerminating);
|
SubscribeLocalEvent<EdgeSpreaderComponent, EntityTerminatingEvent>(OnTerminating);
|
||||||
SetupPrototypes();
|
SetupPrototypes();
|
||||||
_prototype.PrototypesReloaded += OnPrototypeReload;
|
_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)
|
private void OnGridInit(GridInitializeEvent ev)
|
||||||
{
|
{
|
||||||
EnsureComp<SpreaderGridComponent>(ev.EntityUid);
|
EnsureComp<SpreaderGridComponent>(ev.EntityUid);
|
||||||
@@ -111,19 +100,18 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
var curTime = _timing.CurTime;
|
|
||||||
|
|
||||||
// Check which grids are valid for spreading
|
// Check which grids are valid for spreading
|
||||||
var spreadGrids = EntityQueryEnumerator<SpreaderGridComponent>();
|
var spreadGrids = EntityQueryEnumerator<SpreaderGridComponent>();
|
||||||
|
|
||||||
_gridUpdates.Clear();
|
_gridUpdates.Clear();
|
||||||
while (spreadGrids.MoveNext(out var uid, out var grid))
|
while (spreadGrids.MoveNext(out var uid, out var grid))
|
||||||
{
|
{
|
||||||
if (grid.NextUpdate > curTime)
|
grid.UpdateAccumulator -= frameTime;
|
||||||
|
if (grid.UpdateAccumulator > 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_gridUpdates[uid] = _prototypeUpdates.ShallowClone();
|
_gridUpdates[uid] = _prototypeUpdates.ShallowClone();
|
||||||
grid.NextUpdate += SpreadCooldown;
|
grid.UpdateAccumulator += SpreadCooldownSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_gridUpdates.Count == 0)
|
if (_gridUpdates.Count == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user