Make doors event-based rather than EntityQuery based (#2195)
* Event-based door updates Slight perf increase * Optimise CheckCrush too Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using Content.Server.GameObjects.Components.Doors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Doors;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
@@ -31,19 +34,44 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
/// <summary> Allows everyone to open all doors. </summary>
|
||||
AllowAll
|
||||
}
|
||||
|
||||
private List<ServerDoorComponent> _activeDoors = new List<ServerDoorComponent>();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
AccessType = AccessTypes.Id;
|
||||
SubscribeLocalEvent<DoorStateMessage>(HandleDoorState);
|
||||
}
|
||||
|
||||
private void HandleDoorState(DoorStateMessage message)
|
||||
{
|
||||
switch (message.State)
|
||||
{
|
||||
case ServerDoorComponent.DoorState.Closed:
|
||||
_activeDoors.Remove(message.Component);
|
||||
break;
|
||||
case ServerDoorComponent.DoorState.Open:
|
||||
_activeDoors.Add(message.Component);
|
||||
break;
|
||||
case ServerDoorComponent.DoorState.Closing:
|
||||
case ServerDoorComponent.DoorState.Opening:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var comp in ComponentManager.EntityQuery<ServerDoorComponent>())
|
||||
for (var i = _activeDoors.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var comp = _activeDoors[i];
|
||||
if (comp.Deleted)
|
||||
_activeDoors.RemoveAt(i);
|
||||
|
||||
comp.OnUpdate(frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user