Skip to content

Commit

Permalink
Revert "Optimize Debris Code (#1374)" (#1383)
Browse files Browse the repository at this point in the history
This reverts commit 4220e4d.
  • Loading branch information
Cheackraze authored May 18, 2024
1 parent 79ad11d commit b89bf7e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 56 deletions.
5 changes: 3 additions & 2 deletions Content.Server/Worldgen/Prototypes/GCQueuePrototype.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Prototypes;

namespace Content.Server.Worldgen.Prototypes;

Expand All @@ -23,7 +23,7 @@ public sealed class GCQueuePrototype : IPrototype
/// The maximum amount of time that can be spent processing this queue.
/// </summary>
[DataField("maximumTickTime")]
public TimeSpan MaximumTickTime { get; } = TimeSpan.FromMilliseconds(5); // Frontier 1<5
public TimeSpan MaximumTickTime { get; } = TimeSpan.FromMilliseconds(1);

/// <summary>
/// The minimum depth before entities in the queue actually get processed for deletion.
Expand All @@ -38,3 +38,4 @@ public sealed class GCQueuePrototype : IPrototype
[DataField("trySkipQueue")]
public bool TrySkipQueue { get; }
}

44 changes: 3 additions & 41 deletions Content.Server/Worldgen/Systems/LocalityLoaderSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Content.Server.Worldgen.Components;
using Content.Server.Worldgen.Components;
using Robust.Server.GameObjects;
using Content.Server._NF.Worldgen.Components.Debris; // Frontier
using Content.Shared.Humanoid; // Frontier
using Content.Shared.Mobs.Components; // Frontier
using Robust.Server.GameObjects; // Frontier
using Robust.Shared.Spawners; // Frontier

namespace Content.Server.Worldgen.Systems;

Expand All @@ -15,13 +10,6 @@ public sealed class LocalityLoaderSystem : BaseWorldSystem
{
[Dependency] private readonly TransformSystem _xformSys = default!;

private const float DebrisActiveDuration = 5*60; // Frontier - Duration to reset the despawn timer to when a debris is loaded into a player's view.

public override void Initialize() // Frontier
{
SubscribeLocalEvent<SpaceDebrisComponent, EntityTerminatingEvent>(OnDebrisDespawn);
}

/// <inheritdoc />
public override void Update(float frameTime)
{
Expand Down Expand Up @@ -57,8 +45,6 @@ public override void Update(float frameTime)
if ((_xformSys.GetWorldPosition(loaderXform) - _xformSys.GetWorldPosition(xform)).Length() > loadable.LoadingDistance)
continue;

ResetTimedDespawn(uid); // Frontier - Reset the TimedDespawnComponent's lifetime when loaded

RaiseLocalEvent(uid, new LocalStructureLoadedEvent());
RemCompDeferred<LocalityLoaderComponent>(uid);
done = true;
Expand All @@ -68,34 +54,10 @@ public override void Update(float frameTime)
}
}
}

// Frontier
private void ResetTimedDespawn(EntityUid uid)
{
if (TryComp<TimedDespawnComponent>(uid, out var timedDespawn))
{
timedDespawn.Lifetime = DebrisActiveDuration;
}
else
{
// Add TimedDespawnComponent if it does not exist
timedDespawn = AddComp<TimedDespawnComponent>(uid);
timedDespawn.Lifetime = DebrisActiveDuration;
}
}

private void OnDebrisDespawn(EntityUid entity, SpaceDebrisComponent component, EntityTerminatingEvent e)
{
var mobQuery = AllEntityQuery<HumanoidAppearanceComponent, MobStateComponent, TransformComponent>();

while (mobQuery.MoveNext(out var mob, out _, out _, out var xform))
if (xform.MapUid is not null && xform.GridUid == entity)
_xformSys.SetCoordinates(mob, new(xform.MapUid.Value, _xformSys.GetWorldPosition(xform)));
}
// Frontier
}

/// <summary>
/// An event fired on a loadable entity when a local loader enters its vicinity.
/// A directed fired on a loadable entity when a local loader enters it's vicinity.
/// </summary>
public record struct LocalStructureLoadedEvent;

This file was deleted.

2 changes: 0 additions & 2 deletions Resources/Prototypes/Entities/World/Debris/base_debris.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
components:
- type: OwnedDebris
- type: LocalityLoader
- type: TimedDespawn # Frontier
lifetime: 600 # Frontier
5 changes: 2 additions & 3 deletions Resources/Prototypes/GC/world.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- type: gcQueue
id: SpaceDebris
depth: 256 # Frontier
minDepthToProcess: 128 # Frontier
trySkipQueue: true # Frontier - Attempt immediate removal if possible
depth: 512 # So there's a decent bit of time before roids unload.
minDepthToProcess: 256

0 comments on commit b89bf7e

Please sign in to comment.