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:
metalgearsloth
2021-08-12 13:40:38 +10:00
committed by GitHub
parent b17555903f
commit 4da74d0ee4
21 changed files with 756 additions and 1856 deletions

View File

@@ -0,0 +1,57 @@
using System.Collections.Generic;
using Content.Client.Disposal.Components;
using Content.Client.Disposal.UI;
using Content.Shared.Disposal;
using Robust.Client.GameObjects;
namespace Content.Client.Disposal.Systems
{
public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
{
public List<DisposalUnitComponent> PressuringDisposals = new();
public void UpdateActive(DisposalUnitComponent component, bool active)
{
if (active)
{
if (!PressuringDisposals.Contains(component))
PressuringDisposals.Add(component);
}
else
{
PressuringDisposals.Remove(component);
}
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
for (var i = PressuringDisposals.Count - 1; i >= 0; i--)
{
var comp = PressuringDisposals[i];
if (!UpdateInterface(comp)) continue;
PressuringDisposals.RemoveAt(i);
}
}
private bool UpdateInterface(DisposalUnitComponent component)
{
if (component.Deleted) return true;
if (!component.Owner.TryGetComponent(out ClientUserInterfaceComponent? userInterface)) return true;
var state = component.UiState;
if (state == null) return true;
foreach (var inter in userInterface.Interfaces)
{
if (inter is DisposalUnitBoundUserInterface disposals)
{
return disposals.Window?.UpdateState(state) != false;
}
}
return true;
}
}
}