Add TryQueueDeleteEntity (#5281)

Having to check deleted by hand up front is annoying.
This commit is contained in:
metalgearsloth
2024-07-10 07:32:17 +10:00
committed by GitHub
parent 4091ad4837
commit 7ad2925f2c
4 changed files with 29 additions and 7 deletions

View File

@@ -33,10 +33,7 @@ public class EntityPrototypeView : SpriteView
_currentPrototype = entProto;
SetEntity(null);
if (_ourEntity != null)
{
EntMan.DeleteEntity(_ourEntity);
}
EntMan.DeleteEntity(_ourEntity);
if (_currentPrototype != null)
{
@@ -57,8 +54,6 @@ public class EntityPrototypeView : SpriteView
protected override void ExitedTree()
{
base.ExitedTree();
if (!EntMan.Deleted(_ourEntity))
EntMan.QueueDeleteEntity(_ourEntity);
EntMan.TryQueueDeleteEntity(_ourEntity);
}
}

View File

@@ -468,6 +468,21 @@ namespace Robust.Shared.GameObjects
ent.Comp4.LastModifiedTick = CurrentTick;
}
public bool TryQueueDeleteEntity(EntityUid? uid)
{
if (uid == null)
return false;
if (Deleted(uid.Value))
return false;
if (!QueuedDeletionsSet.Add(uid.Value))
return false;
QueueDeleteEntity(uid);
return true;
}
/// <summary>
/// Shuts-down and removes given Entity. This is also broadcast to all clients.
/// </summary>

View File

@@ -705,6 +705,13 @@ public partial class EntitySystem
EntityManager.QueueDeleteEntity(uid);
}
/// <inheritdoc cref="IEntityManager.TryQueueDeleteEntity(EntityUid?)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected bool TryQueueDel(EntityUid? uid)
{
return EntityManager.TryQueueDeleteEntity(uid);
}
#endregion
#region Entity Spawning

View File

@@ -153,6 +153,11 @@ namespace Robust.Shared.GameObjects
where T3 : IComponent
where T4 : IComponent;
/// <summary>
/// Tries to QueueDeleteEntity if the entity is not already deleted.
/// </summary>
public bool TryQueueDeleteEntity(EntityUid? uid);
public void QueueDeleteEntity(EntityUid? uid);
public bool IsQueuedForDeletion(EntityUid uid);