Describes a position a chunk can be aligned at to another one.
コード例 #1
0
ファイル: Context3D.cs プロジェクト: npruehs/bychance
        /// <summary>
        /// Checks whether this context is within <paramref name="offset"/> to <paramref name="other"/>
        /// in terms of the Euclidean norm.
        /// </summary>
        /// <param name="other">Context to check the adjacency to.</param>
        /// <param name="offset">Offset within this context is considered to be adjacent to <paramref name="other"/>.</param>
        /// <returns><c>true</c>, if <paramref name="other"/> is within <paramref name="offset"/> to this one, and <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentException">Context to check the adjacency to is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">Context to check the adjacency to is not of type <see cref="Context3D"/>.</exception>
        public override bool IsAdjacentTo(Context other, float offset)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            Context3D context3D = other as Context3D;

            if (context3D == null)
            {
                throw new ArgumentException("Passed context is not of type Context3D.", "other");
            }

            return context3D.AbsolutePosition.Distance(this.AbsolutePosition) <= offset;
        }
コード例 #2
0
ファイル: Context.cs プロジェクト: npruehs/bychance
        /// <summary>
        /// Aligns this context to <paramref name="other"/>, making <see cref="Target"/> of both contexts point to each other.
        /// </summary>
        /// <param name="other">Context to align this one to.</param>
        /// <seealso cref="Target"/>
        /// <exception cref="ArgumentNullException"><paramref name="other"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">This context or <paramref name="other"/> is already aligned to another context.</exception>
        /// <exception cref="ArgumentException"><paramref name="other"/> has a different type than this context.</exception>
        public void AlignTo(Context other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (this.Target != null)
            {
                throw new InvalidOperationException(
                    "The source context is already aligned to another context. "
                    + "Make sure to clear the target of the source context before aligning it to another one.");
            }

            if (other.Target != null)
            {
                throw new InvalidOperationException(
                    "The target context is already aligned to another context. "
                    + "Make sure to clear the target of the target context before aligning it to another one.");
            }

            if (this.GetType() != other.GetType())
            {
                throw new ArgumentException(
                    "The target context has a different type than the source context. "
                    + "Aligned contexts have to be of the same type.",
                    "other");
            }

            this.Target = other;
            other.Target = this;
        }
コード例 #3
0
ファイル: Chunk.cs プロジェクト: npruehs/bychance
        /// <summary>
        /// Removes passed context from the chunk's list of contexts.
        /// </summary>
        /// <param name="context">Context to be removed.</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> is null.</exception>
        /// <returns><c>true</c>, if the context has been removed, and <c>false</c> otherwise.</returns>
        public bool RemoveContext(Context context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (this.ChunkContexts.Remove(context))
            {
                context.ClearTarget();
                return true;
            }

            return false;
        }
コード例 #4
0
ファイル: Context.cs プロジェクト: npruehs/bychance
 /// <summary>
 /// Checks whether this context is within <paramref name="offset"/> to <paramref name="other"/>.
 /// </summary>
 /// <param name="other">Context to check the adjacency to.</param>
 /// <param name="offset">Offset within this context is considered to be adjacent to <paramref name="other"/>.</param>
 /// <returns><c>true</c>, if <paramref name="other"/> is within <paramref name="offset"/> to this one, and <c>false</c> otherwise.</returns>
 public abstract bool IsAdjacentTo(Context other, float offset);
コード例 #5
0
ファイル: Context.cs プロジェクト: npruehs/bychance
        /// <summary>
        /// Breaks the connection between this context and its target, setting <see cref="Target"/> of both contexts to <c>null</c>.
        /// </summary>
        public void ClearTarget()
        {
            if (this.Target == null)
            {
                return;
            }

            this.Target.Target = null;
            this.Target = null;
        }
コード例 #6
0
ファイル: ChunkDistribution.cs プロジェクト: npruehs/bychance
 /// <summary>
 /// Gets the effective weight of a chunk.
 /// <para>
 /// Most simple implementation is to just return the weight of the chunk candidate to which <paramref name="chunkCandidateContext"/> belongs to.
 /// <paramref name="freeLevelContext"/> and <paramref name="level"/> are passed for custom implementations by clients. 
 /// </para>
 /// </summary>
 /// <param name="freeLevelContext">Open context of the existing chunk to which the new chunk candidate will be attached to.</param>
 /// <param name="chunkCandidateContext">Open context of the chunk candidate.</param>
 /// <param name="level">Current generated level.</param>
 /// <returns>Non-negative integer that represents the effective weight of the chunk candidate.</returns>
 public int GetEffectiveWeight(Context freeLevelContext, Context chunkCandidateContext, object level)
 {
     return chunkCandidateContext.Source.Weight;
 }
コード例 #7
0
ファイル: ChunkTemplate2D.cs プロジェクト: npruehs/bychance
 /// <summary>
 /// Adds the passed context to the list of contexts of this chunk
 /// template and sets its chunk-wide unique index.
 /// </summary>
 /// <param name="context">Context to add to this template.</param>
 private void AddContext(Context context)
 {
     context.Index = this.ContextCount;
     this.ChunkTemplateContexts.Add(context);
 }
コード例 #8
0
 /// <summary>
 /// Used by <see cref="DiscardOpenContextsPolicy"/> to check whether to discard the passed open
 /// context, or not. Returns <c>true</c>.
 /// </summary>
 /// <param name="context">Context to be discarded.</param>
 /// <returns><c>true</c></returns>
 public bool ShouldDiscardContext(Context context)
 {
     return true;
 }