/// <summary> /// If conditions have changed to allow finalizing creation of any pending attachment points, /// do it now. /// </summary> private void ProcessPendingAttachmentPoints() { if (CurrentFragmentId.IsKnown() && pendingAttachments.Count > 0) { // We have a valid destination fragment. Note that since this queue is in order of submission, // if an attachment point depends on a second attachment point for context, // that second will be either earlier in the list (because there was no valid current fragment when it was // created) or it will have a valid fragment. So by the time we get to the one with a dependency (pending.context != null), // its dependency will have a valid fragment id. int pendingCount = pendingAttachments.Count; for (int i = 0; i < pendingCount; ++i) { AttachmentPoint target = pendingAttachments[i].target; Vector3 frozenPosition = pendingAttachments[i].target.ObjectPosition; IAttachmentPoint context = pendingAttachments[i].context; SetupAttachmentPoint(plugin, target, context); FragmentId fragmentId = CurrentFragmentId; if (context != null) { fragmentId = context.FragmentId; } Debug.Assert(fragmentId.IsKnown(), $"FragmentId {fragmentId.FormatStr()} invalid from {(context != null ? "context" : "head")} in processing pending"); Fragment fragment = EnsureFragment(fragmentId); Debug.Assert(fragment != null, "Valid fragmentId but no fragment found"); fragment.AddAttachmentPoint(target); } // All pending must now be in a good home fragment, clear the to-do list. pendingAttachments.Clear(); } }
/// <inheritdoc /> public void Update(bool autoRefreeze, bool autoMerge) { CurrentFragmentId = plugin.GetMostSignificantFragmentId(); Debug.Assert(CurrentFragmentId.IsKnown(), $"F={Time.frameCount} - Update shouldn't be called with no active fragment."); if (!CurrentFragmentId.IsKnown()) { return; } EnsureFragment(CurrentFragmentId); if (plugin.Metrics.RefitRefreezeIndicated && autoRefreeze) { Refreeze(); } else if (plugin.Metrics.RefitMergeIndicated && autoMerge) { // there are multiple mergeable fragments -- do the merge and show the result Merge(); } // There are multiple mergeable fragments with valid adjustments, but we show only the current one ApplyActiveCurrentFragment(); ProcessPendingAttachmentPoints(); }