From 3b1e6d30e72170aa39a891613ea6b1221d067b78 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 8 Aug 2023 03:27:46 +1000 Subject: [PATCH] Remove GCQueue (#18820) --- Content.Client/Entry/EntryPoint.cs | 1 - .../Atmos/EntitySystems/AirtightSystem.cs | 2 +- .../Components/GC/GCAbleObjectComponent.cs | 21 --- .../Worldgen/Prototypes/GCQueuePrototype.cs | 41 ------ .../Debris/DebrisFeaturePlacerSystem.cs | 17 --- .../Worldgen/Systems/GC/GCQueueSystem.cs | 124 ------------------ .../Entities/World/Debris/asteroids.yml | 2 - .../Entities/World/Debris/wrecks.yml | 2 - Resources/Prototypes/GC/world.yml | 4 - 9 files changed, 1 insertion(+), 213 deletions(-) delete mode 100644 Content.Server/Worldgen/Components/GC/GCAbleObjectComponent.cs delete mode 100644 Content.Server/Worldgen/Prototypes/GCQueuePrototype.cs delete mode 100644 Content.Server/Worldgen/Systems/GC/GCQueueSystem.cs delete mode 100644 Resources/Prototypes/GC/world.yml diff --git a/Content.Client/Entry/EntryPoint.cs b/Content.Client/Entry/EntryPoint.cs index 860b1634ad..8939956570 100644 --- a/Content.Client/Entry/EntryPoint.cs +++ b/Content.Client/Entry/EntryPoint.cs @@ -120,7 +120,6 @@ namespace Content.Client.Entry _prototypeManager.RegisterIgnore("noiseChannel"); _prototypeManager.RegisterIgnore("spaceBiome"); _prototypeManager.RegisterIgnore("worldgenConfig"); - _prototypeManager.RegisterIgnore("gcQueue"); _prototypeManager.RegisterIgnore("gameRule"); _prototypeManager.RegisterIgnore("worldSpell"); _prototypeManager.RegisterIgnore("entitySpell"); diff --git a/Content.Server/Atmos/EntitySystems/AirtightSystem.cs b/Content.Server/Atmos/EntitySystems/AirtightSystem.cs index 2493c2a512..9a97c88035 100644 --- a/Content.Server/Atmos/EntitySystems/AirtightSystem.cs +++ b/Content.Server/Atmos/EntitySystems/AirtightSystem.cs @@ -53,7 +53,7 @@ namespace Content.Server.Atmos.EntitySystems private void OnAirtightPositionChanged(EntityUid uid, AirtightComponent airtight, ref AnchorStateChangedEvent args) { - var xform = Transform(uid); + var xform = args.Transform; if (!TryComp(xform.GridUid, out MapGridComponent? grid)) return; diff --git a/Content.Server/Worldgen/Components/GC/GCAbleObjectComponent.cs b/Content.Server/Worldgen/Components/GC/GCAbleObjectComponent.cs deleted file mode 100644 index 3957c7d8b1..0000000000 --- a/Content.Server/Worldgen/Components/GC/GCAbleObjectComponent.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Content.Server.Worldgen.Prototypes; -using Content.Server.Worldgen.Systems.GC; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; - -namespace Content.Server.Worldgen.Components.GC; - -/// -/// This is used for whether or not a GCable object is "dirty". Firing GCDirtyEvent on the object is the correct way to -/// set this up. -/// -[RegisterComponent] -[Access(typeof(GCQueueSystem))] -public sealed class GCAbleObjectComponent : Component -{ - /// - /// Which queue to insert this object into when GCing - /// - [DataField("queue", required: true, customTypeSerializer: typeof(PrototypeIdSerializer))] - public string Queue = default!; -} - diff --git a/Content.Server/Worldgen/Prototypes/GCQueuePrototype.cs b/Content.Server/Worldgen/Prototypes/GCQueuePrototype.cs deleted file mode 100644 index 94e6cf5fa3..0000000000 --- a/Content.Server/Worldgen/Prototypes/GCQueuePrototype.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Robust.Shared.Prototypes; - -namespace Content.Server.Worldgen.Prototypes; - -/// -/// This is a prototype for a GC queue. -/// -[Prototype("gcQueue")] -public sealed class GCQueuePrototype : IPrototype -{ - /// - [IdDataField] - public string ID { get; } = default!; - - /// - /// How deep the GC queue is at most. If this value is ever exceeded entities get processed automatically regardless of - /// tick-time cap. - /// - [DataField("depth", required: true)] - public int Depth { get; } - - /// - /// The maximum amount of time that can be spent processing this queue. - /// - [DataField("maximumTickTime")] - public TimeSpan MaximumTickTime { get; } = TimeSpan.FromMilliseconds(1); - - /// - /// The minimum depth before entities in the queue actually get processed for deletion. - /// - [DataField("minDepthToProcess", required: true)] - public int MinDepthToProcess { get; } - - /// - /// Whether or not the GC should fire an event on the entity to see if it's eligible to skip the queue. - /// Useful for making it so only objects a player has actually interacted with get put in the collection queue. - /// - [DataField("trySkipQueue")] - public bool TrySkipQueue { get; } -} - diff --git a/Content.Server/Worldgen/Systems/Debris/DebrisFeaturePlacerSystem.cs b/Content.Server/Worldgen/Systems/Debris/DebrisFeaturePlacerSystem.cs index bcfb761c72..b2d8df4de9 100644 --- a/Content.Server/Worldgen/Systems/Debris/DebrisFeaturePlacerSystem.cs +++ b/Content.Server/Worldgen/Systems/Debris/DebrisFeaturePlacerSystem.cs @@ -2,7 +2,6 @@ using System.Numerics; using Content.Server.Worldgen.Components; using Content.Server.Worldgen.Components.Debris; -using Content.Server.Worldgen.Systems.GC; using Content.Server.Worldgen.Tools; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -17,7 +16,6 @@ namespace Content.Server.Worldgen.Systems.Debris; /// public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem { - [Dependency] private readonly GCQueueSystem _gc = default!; [Dependency] private readonly NoiseIndexSystem _noiseIndex = default!; [Dependency] private readonly PoissonDiskSampler _sampler = default!; [Dependency] private readonly TransformSystem _xformSys = default!; @@ -35,19 +33,10 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem SubscribeLocalEvent(OnChunkUnloaded); SubscribeLocalEvent(OnDebrisShutdown); SubscribeLocalEvent(OnDebrisMove); - SubscribeLocalEvent(OnTryCancelGC); SubscribeLocalEvent( OnTryGetPlacableDebrisEvent); } - /// - /// Handles GC cancellation in case the chunk is still loaded. - /// - private void OnTryCancelGC(EntityUid uid, OwnedDebrisComponent component, ref TryCancelGC args) - { - args.Cancelled |= HasComp(component.OwningController); - } - /// /// Handles debris moving, and making sure it stays parented to a chunk for loading purposes. /// @@ -102,12 +91,6 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem private void OnChunkUnloaded(EntityUid uid, DebrisFeaturePlacerControllerComponent component, ref WorldChunkUnloadedEvent args) { - foreach (var (_, debris) in component.OwnedDebris) - { - if (debris is not null) - _gc.TryGCEntity(debris.Value); // gonb. - } - component.DoSpawns = true; } diff --git a/Content.Server/Worldgen/Systems/GC/GCQueueSystem.cs b/Content.Server/Worldgen/Systems/GC/GCQueueSystem.cs deleted file mode 100644 index 98d17afd2b..0000000000 --- a/Content.Server/Worldgen/Systems/GC/GCQueueSystem.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System.Linq; -using Content.Server.Worldgen.Components.GC; -using Content.Server.Worldgen.Prototypes; -using Content.Shared.CCVar; -using JetBrains.Annotations; -using Robust.Shared.Configuration; -using Robust.Shared.Prototypes; -using Robust.Shared.Random; -using Robust.Shared.Timing; - -namespace Content.Server.Worldgen.Systems.GC; - -/// -/// This handles delayed garbage collection of entities, to avoid overloading the tick in particularly expensive cases. -/// -public sealed class GCQueueSystem : EntitySystem -{ - [Dependency] private readonly IConfigurationManager _cfg = default!; - [Dependency] private readonly IPrototypeManager _proto = default!; - [Dependency] private readonly IRobustRandom _random = default!; - - [ViewVariables] private TimeSpan _maximumProcessTime = TimeSpan.Zero; - - [ViewVariables] private readonly Dictionary> _queues = new(); - - /// - public override void Initialize() - { - _cfg.OnValueChanged(CCVars.GCMaximumTimeMs, s => _maximumProcessTime = TimeSpan.FromMilliseconds(s), - true); - } - - /// CCVars - public override void Update(float frameTime) - { - var overallWatch = new Stopwatch(); - var queueWatch = new Stopwatch(); - var queues = _queues.ToList(); - _random.Shuffle(queues); // Avert resource starvation by always processing in random order. - overallWatch.Start(); - foreach (var (pId, queue) in queues) - { - if (overallWatch.Elapsed > _maximumProcessTime) - return; - - var proto = _proto.Index(pId); - if (queue.Count < proto.MinDepthToProcess) - continue; - - queueWatch.Restart(); - while (queueWatch.Elapsed < proto.MaximumTickTime && queue.Count >= proto.MinDepthToProcess && - overallWatch.Elapsed < _maximumProcessTime) - { - var e = queue.Dequeue(); - if (!Deleted(e)) - { - var ev = new TryCancelGC(); - RaiseLocalEvent(e, ref ev); - - if (!ev.Cancelled) - Del(e); - } - } - } - } - - /// - /// Attempts to GC an entity. This functions as QueueDel if it can't. - /// - /// Entity to GC. - public void TryGCEntity(EntityUid e) - { - if (!TryComp(e, out var comp)) - { - QueueDel(e); // not our problem :) - return; - } - - if (!_queues.TryGetValue(comp.Queue, out var queue)) - { - queue = new Queue(); - _queues[comp.Queue] = queue; - } - - var proto = _proto.Index(comp.Queue); - if (queue.Count > proto.Depth) - { - QueueDel(e); // whelp, too full. - return; - } - - if (proto.TrySkipQueue) - { - var ev = new TryGCImmediately(); - RaiseLocalEvent(e, ref ev); - if (!ev.Cancelled) - { - QueueDel(e); - return; - } - } - - queue.Enqueue(e); - } -} - -/// -/// Fired by GCQueueSystem to check if it can simply immediately GC an entity, for example if it was never fully -/// loaded. -/// -/// Whether or not the immediate deletion attempt was cancelled. -[ByRefEvent] -[PublicAPI] -public record struct TryGCImmediately(bool Cancelled = false); - -/// -/// Fired by GCQueueSystem to check if the collection of the given entity should be cancelled, for example it's chunk -/// being loaded again. -/// -/// Whether or not the deletion attempt was cancelled. -[ByRefEvent] -[PublicAPI] -public record struct TryCancelGC(bool Cancelled = false); - diff --git a/Resources/Prototypes/Entities/World/Debris/asteroids.yml b/Resources/Prototypes/Entities/World/Debris/asteroids.yml index 99b46be9a6..f1d6f029ba 100644 --- a/Resources/Prototypes/Entities/World/Debris/asteroids.yml +++ b/Resources/Prototypes/Entities/World/Debris/asteroids.yml @@ -41,8 +41,6 @@ - id: WallRockArtifactFragment prob: 0.01 orGroup: rock - - type: GCAbleObject - queue: SpaceDebris - type: IFF flags: HideLabel color: "#d67e27" diff --git a/Resources/Prototypes/Entities/World/Debris/wrecks.yml b/Resources/Prototypes/Entities/World/Debris/wrecks.yml index a3cfaf9788..4c5a3be48f 100644 --- a/Resources/Prototypes/Entities/World/Debris/wrecks.yml +++ b/Resources/Prototypes/Entities/World/Debris/wrecks.yml @@ -45,8 +45,6 @@ prob: 0.2 - id: SalvageMobSpawner prob: 0.7 - - type: GCAbleObject - queue: SpaceDebris - type: IFF flags: HideLabel color: "#88b0d1" diff --git a/Resources/Prototypes/GC/world.yml b/Resources/Prototypes/GC/world.yml deleted file mode 100644 index b58a68158c..0000000000 --- a/Resources/Prototypes/GC/world.yml +++ /dev/null @@ -1,4 +0,0 @@ -- type: gcQueue - id: SpaceDebris - depth: 512 # So there's a decent bit of time before roids unload. - minDepthToProcess: 256