Refactor disposals to ECS (#4418)
* ECS up disposals Also significantly reduced its CPU usage. * Make update significantly less S L O W * Start units pressurised * Client-side flush lerping * Fix powered not toggling UI * Fix flush button * InteractUsing * Minor optimisations * Fix collisions * Make visual state ECS * Almost done with shared * Most stuff moved * Optimise item sleeping
This commit is contained in:
@@ -1,23 +1,73 @@
|
||||
using Content.Shared.Disposal.Components;
|
||||
using System;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.Throwing;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Disposal
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class SharedDisposalUnitSystem : EntitySystem
|
||||
public abstract class SharedDisposalUnitSystem : EntitySystem
|
||||
{
|
||||
public override void Update(float frameTime)
|
||||
[Dependency] protected readonly IGameTiming GameTiming = default!;
|
||||
|
||||
protected static TimeSpan ExitAttemptDelay = TimeSpan.FromSeconds(0.5);
|
||||
|
||||
// Percentage
|
||||
public const float PressurePerSecond = 0.05f;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
foreach (var comp in ComponentManager.EntityQuery<SharedDisposalUnitComponent>(true))
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SharedDisposalUnitComponent, PreventCollideEvent>(HandlePreventCollide);
|
||||
}
|
||||
|
||||
private void HandlePreventCollide(EntityUid uid, SharedDisposalUnitComponent component, PreventCollideEvent args)
|
||||
{
|
||||
var otherBody = args.BodyB.Owner.Uid;
|
||||
|
||||
// Items dropped shouldn't collide but items thrown should
|
||||
if (ComponentManager.HasComponent<SharedItemComponent>(otherBody) &&
|
||||
!ComponentManager.HasComponent<ThrownItemComponent>(otherBody))
|
||||
{
|
||||
comp.Update(frameTime);
|
||||
args.Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var comp in ComponentManager.EntityQuery<SharedDisposalMailingUnitComponent>(true))
|
||||
if (component.RecentlyEjected.Contains(otherBody))
|
||||
{
|
||||
comp.Update(frameTime);
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool CanInsert(SharedDisposalUnitComponent component, IEntity entity)
|
||||
{
|
||||
if (!component.Owner.Transform.Anchored)
|
||||
return false;
|
||||
|
||||
// TODO: Probably just need a disposable tag.
|
||||
if (!entity.TryGetComponent(out SharedItemComponent? storable) &&
|
||||
!entity.HasComponent<SharedBodyComponent>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!entity.TryGetComponent(out IPhysBody? physics) ||
|
||||
!physics.CanCollide && storable == null)
|
||||
{
|
||||
if (!(entity.TryGetComponent(out IMobStateComponent? damageState) && damageState.IsDead())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user