//Commit a commit on floating to the locked timeline private bool _MoveToLocked(InventoryCommit commit) { LinkedListNode<InventoryCommit> floatingNodeTail = _GetFloatingTale(); if (floatingNodeTail == null || floatingNodeTail.Value != commit) { m_commits.Remove(floatingNodeTail); return false; } if (!commit.Lock(this, floatingNodeTail)) return false; m_head = floatingNodeTail; return true; }
//Inserts a commit between float and locked without moving it from float to locked first private bool _InsertOnLocked(InventoryCommit commit) { commit.Data.PickedupWithInventory(this, commit.Index); //Revert back to the head LinkedListNode<InventoryCommit> node; for (node = m_commits.Last; node != null && node != m_head; node = node.Previous) { node.Value.Revert(this); } //Apply the new commit onto the head. if (commit.Apply(this)) { LinkedListNode<InventoryCommit> newHead; if (m_head != null) newHead = m_commits.AddAfter(m_head, commit); else newHead = m_commits.AddFirst(commit); if (commit.Lock(this, newHead)) { m_head = newHead; } else { m_commits.Remove(newHead); } } else { commit.Revert(this); return false; } //Push floating commits back onto inventory. for (node = _GetFloatingTale(); node != null;) { InventoryCommit floatingCommit = node.Value; if (!floatingCommit.Apply(this)) { LinkedListNode<InventoryCommit> removingNode = node; node = node.Next; m_commits.Remove(removingNode); } else { node = node.Next; } } return true; }