private void _SerializeCommitToStream(PhotonStream stream, InventoryCommit commit) { byte commitTypeId = commitTypeIdTable[commit.GetType()]; stream.SendNext(commitTypeId); commit.Serialize(stream); }
private bool _IsFloating(InventoryCommit commit) { for (LinkedListNode<InventoryCommit> node = _GetFloatingTale(); node != null; node = node.Next) { if (node.Value == commit) return true; } return false; }
private bool _IsLocked(InventoryCommit commit) { if (m_head == null) return false; foreach (InventoryCommit inventoryCommit in m_commits) { if (commit == inventoryCommit) return true; if (inventoryCommit == m_head.Value) return false; } return false; }
private bool _CheckMergeWithHead(InventoryCommit floatingCommit) { if (m_head == null) return true; InventoryCommit lockedCommit = m_head.Value; MethodInfo method = m_head.Value.GetType().GetMethod("CanMergeWith", new Type[] { floatingCommit.GetType() }); Assert.IsNotNull(method); bool canMerge = (bool)method.Invoke(m_head.Value, new object[] { floatingCommit }); return canMerge; }
//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; }
private bool _RemoveFromFloating(InventoryCommit commit) { LinkedListNode<InventoryCommit> commitNode = _GetCommitFromFloating(commit.CommitNumber); if (commitNode == null) return false; for (LinkedListNode<InventoryCommit> node = m_commits.Last; node != commitNode; node = node.Previous) { node.Value.Revert(this); } commitNode.Value.Revert(this); LinkedListNode<InventoryCommit> removingNode = commitNode; commitNode = commitNode.Next; m_commits.Remove(removingNode); while (commitNode != null) { InventoryCommit floatingCommit = commitNode.Value; if (!floatingCommit.Apply(this)) { removingNode = commitNode; commitNode = commitNode.Next; m_commits.Remove(removingNode); } else { commitNode = commitNode.Next; } } return true; }
private bool _CommitOnFloating(InventoryCommit commit) { if (commit.Apply(this)) return false; m_commits.AddLast(commit); return true; }
/// <summary> /// Pushes the commit onto the floating timeline and to the owner. /// </summary> /// <param name="commit">The commit to push.</param> /// <returns>True if the commit could be pushed, false otherwise.</returns> private bool _PushCommitAsPeer(InventoryCommit commit) { Assert.IsFalse(IsMine); if (!_CommitOnFloating(commit)) return false; PhotonStream data = new PhotonStream(false, null); _SerializeCommitToStream(data, commit); photonView.RpcOwner("_RequestCommit", data); return true; }
/// <summary> /// Pushes the commit onto the locked timeline and to all other peers. /// </summary> /// <param name="commit">The commit to push.</param> /// <returns>True if the commit could be pushed, false otherwise.</returns> private bool _PushCommitAsOwner(InventoryCommit commit) { Assert.IsTrue(IsMine); if (_InsertOnLocked(commit)) { PhotonStream data = new PhotonStream(true, null); _SerializeCommitToStream(data, commit); photonView.RPC("_RecieveCommit", PhotonTargets.Others, data); return true; } return false; }
private bool _PushCommit(InventoryCommit commit) { bool isMine = IsMine; if (isMine) { return _PushCommitAsOwner(commit); } else { return _PushCommitAsPeer(commit); } }
public bool CanMergeWith(InventoryCommit commit) { return commit.Index == Index; }