Optimize doafters (#7428)
This commit is contained in:
@@ -11,4 +11,10 @@ namespace Content.Server.DoAfter
|
|||||||
// we'll just send them the index. Doesn't matter if it wraps around.
|
// we'll just send them the index. Doesn't matter if it wraps around.
|
||||||
public byte RunningIndex;
|
public byte RunningIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Added to entities that are currently performing any doafters.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class ActiveDoAfterComponent : Component {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace Content.Server.DoAfter
|
|||||||
public void Add(DoAfterComponent component, DoAfter doAfter)
|
public void Add(DoAfterComponent component, DoAfter doAfter)
|
||||||
{
|
{
|
||||||
component.DoAfters.Add(doAfter, component.RunningIndex);
|
component.DoAfters.Add(doAfter, component.RunningIndex);
|
||||||
|
EnsureComp<ActiveDoAfterComponent>(component.Owner);
|
||||||
component.RunningIndex++;
|
component.RunningIndex++;
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
}
|
}
|
||||||
@@ -37,6 +38,11 @@ namespace Content.Server.DoAfter
|
|||||||
|
|
||||||
component.DoAfters.Remove(doAfter);
|
component.DoAfters.Remove(doAfter);
|
||||||
|
|
||||||
|
if (component.DoAfters.Count == 0)
|
||||||
|
{
|
||||||
|
RemComp<ActiveDoAfterComponent>(component.Owner);
|
||||||
|
}
|
||||||
|
|
||||||
RaiseNetworkEvent(new CancelledDoAfterMessage(component.Owner, index));
|
RaiseNetworkEvent(new CancelledDoAfterMessage(component.Owner, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +56,11 @@ namespace Content.Server.DoAfter
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
component.DoAfters.Remove(doAfter);
|
component.DoAfters.Remove(doAfter);
|
||||||
|
|
||||||
|
if (component.DoAfters.Count == 0)
|
||||||
|
{
|
||||||
|
RemComp<ActiveDoAfterComponent>(component.Owner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDoAfterGetState(EntityUid uid, DoAfterComponent component, ref ComponentGetState args)
|
private void OnDoAfterGetState(EntityUid uid, DoAfterComponent component, ref ComponentGetState args)
|
||||||
@@ -105,7 +116,7 @@ namespace Content.Server.DoAfter
|
|||||||
{
|
{
|
||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
|
|
||||||
foreach (var comp in EntityManager.EntityQuery<DoAfterComponent>())
|
foreach (var (_, comp) in EntityManager.EntityQuery<ActiveDoAfterComponent, DoAfterComponent>())
|
||||||
{
|
{
|
||||||
foreach (var (doAfter, _) in comp.DoAfters.ToArray())
|
foreach (var (doAfter, _) in comp.DoAfters.ToArray())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user