/// <summary>
 /// Merge the two instance such that they have the same chunks and share the same ready counter. Common
 /// chunks are reset to non-ready. If one of the instances is null, the non-null instance is returned.
 /// </summary>
 /// <param name="first">The first instance.</param>
 /// <param name="second">The second instance.</param>
 /// <returns>The merged instance.</returns>
 public static SynchronisedUpdate MergeAndReset(SynchronisedUpdate first, SynchronisedUpdate second)
 {
     if (first != null)
     {
         if (second != null)
         {
             first.MergeAndReset(second);
             return first;
         }
         else
         {
             return first;
         }
     }
     else
     {
         return second;
     }
 }
 /// <summary>
 /// Merge the two instance such that they have the same chunks and share the same ready counter. Common
 /// chunks are reset to non-ready.
 /// </summary>
 /// <param name="other">The other instance.</param>
 public void MergeAndReset(SynchronisedUpdate other)
 {
     if (other != null)
     {
         // Update the references such that both instances have the same content
         this.content.MergeAndReset(other.content);
         other.content = this.content;
     }
 }
 /// <summary>
 /// Reserves a UpdateMeshFilter job.
 /// </summary>
 public void ReserveUpdateMeshFilter()
 {
     this.updateMeshFilterInProgress = true;
     this.updateMeshFilterRequired = false;
     this.meshFilterSync = null;
 }
        /// <summary>
        /// Reserves a DigCircle job.
        /// </summary>
        /// <param name="chunk">The chunk in which the origin lies.</param>
        /// <param name="origin">The circle origin.</param>
        /// <param name="radius">The circle radius.</param>
        /// <param name="toSync">The chunks requiring synchronisation such that their mesh filters are updated in
        /// the same frame.</param>
        public void ReserveDigCircle(Vector2I chunk, Vector2I origin, int radius, SynchronisedUpdate toSync)
        {
            if (chunk == this.Chunk)
            {
                lock ((this.digCircleInProgress as ICollection).SyncRoot)
                {
                    if (this.digCircleInProgress.ContainsKey(origin))
                    {
                        this.digCircleInProgress[origin] = radius;
                    }
                    else
                    {
                        this.digCircleInProgress.Add(origin, radius);
                    }
                }
            }

            this.rebuildMeshRequired = true;
            this.meshFilterSync = SynchronisedUpdate.MergeAndReset(this.meshFilterSync, toSync);
        }