Skip to content

Combine predicted deletion - #7059

Open
maciejwalendziuk wants to merge 5 commits into
space-wizards:masterfrom
maciejwalendziuk:combine-predicted-deletion
Open

maciejwalendziuk wants to merge 5 commits into
space-wizards:masterfrom
maciejwalendziuk:combine-predicted-deletion

Conversation

@maciejwalendziuk

Copy link
Copy Markdown
  • Client DeleteEntity and QueueDeleteEntity now predict deletions of networked entities by detaching them to nullspace which is what PredictedDeleteEntity and PredictedQueueDeleteEntity did. They're obsolete aliases now along with the PredictedDel and PredictedQueueDel
  • Removed the client's separate predicted deletion queue
  • Fixed TryQueueDeleteEntity ignoring the predicted deletion queues and returning true for entities that were already going away
  • Fixed predicted deletion state not being cleared on PVS reentry which left entities stuck detached
  • Fixed a queued deletion still running after it had been cancelled. The queue only checked the set on insert but didn't on dequeue

Client-side Del and QueueDel on a networked entity used to log an error and do nothing - now it detaches. The obsoletion warnings cover the PredictedDel -> Del rename but not this so anything that was quietly relying on the noop will start visibly deleting for a tick

I hope that is what metalgearsloth meant.


Solves: #7043

Comment on lines 307 to +312
while (QueuedDeletions.TryDequeue(out var uid))
{
// The deletion may have been canceled since it was queued.
if (!QueuedDeletionsSet.Remove(uid))
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would already be modifying the queue which in itself should not be touched so remove? At best make it a debug assert but these should always match 1-1.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are intentionally not 1-1 anymore. ClearPredictedDeletion cancels a queued deletion by removing it from the set (since we cant remove from a queue) and this check discards the stale queue entry. otherwise a rolled back deletion redetaches the entity after state application restores it - assert would fire on every rollback

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[ProxyFor(typeof(EntityManager), nameof(EntityManager.PredictedDeleteEntity))]
[Obsolete("Use Del")]
protected void PredictedDel(Entity<MetaDataComponent?, TransformComponent?> ent)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ProxyFor is still useful to keep the interim I would think, just direct it at the new method?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Del already has ProxyFor(DeleteEntity) and the analyzer will just suggest the first matching proxy so pointing it at DeleteEntity could make DeleteEntity calls warn "use PredictedDel". PredictedDeleteEntity callers still get the obsolete warning pointing at DeleteEntity. I could be missing something though...

Comment on lines 912 to 914
meta.Flags &= ~MetaDataFlags.Detached;
_entities.ClearPredictedDeletion(uid);
if (isEnteringPvs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anything is touching entities outside of PVS it should really be an assert instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its the rollback for predicted deletions. PredictedDetachNetworkedEntity sets Detached flag and when prediction reset doesnt run (for example prediction is disabled) reentry here is the only restore path. assert would fire on every one of those

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That still doesn't explain why a nullspace entity would ever be predicted deleted?

Comment on lines +105 to +124

await client.WaitPost(() =>
{
var entMan = (ClientEntityManager) client.EntMan;
EntityUid? raised = null;
void OnQueueDeleted(EntityUid uid) => raised = uid;

entMan.EntityQueueDeleted += OnQueueDeleted;
try
{
entMan.QueueDeleteEntity(clientTarget);
}
finally
{
entMan.EntityQueueDeleted -= OnQueueDeleted;
}

// Physics relies on this to purge contacts before the entity gets detached.
Assert.That(raised, Is.EqualTo(clientTarget));
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suss?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants