Ejemplo n.º 1
0
        /// <summary>
        /// Validates the structure of the the corner buffers. (No content validation is performed.)
        /// </summary>
        /// <param name="buffer">The buffer to validate.</param>
        /// <param name="forMarshalling">True if the buffer must be sized for marshalling.</param>
        /// <returns>True if the structure of the corner buffers is valid.</returns>
        public static bool IsValid(CornerData buffer, bool forMarshalling)
        {
            if (buffer.flags == null ||
                buffer.polyRefs == null ||
                buffer.verts == null)
            {
                return(false);
            }

            int size = (forMarshalling ? MarshalBufferSize : buffer.MaxCorners);

            if (size == 0)
            {
                return(false);
            }

            if (buffer.flags.Length == size &&
                buffer.polyRefs.Length == size &&
                buffer.verts.Length == 3 * size)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resizes the corner buffers.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Due to internal optimizations, the maximum number of detectable corners will be
        /// <c>(<paramref name="maxCorners"/> - 1)</c>.
        /// </para>
        /// <para>
        /// All possible corner buffer state will be preserved. (Some state may be lost if the
        /// buffer is reduced in size.)
        /// </para>
        /// </remarks>
        /// <param name="maxCorners">
        /// The maximum number of corners the corner buffer can hold. [Limit: >= 2]
        /// </param>
        public void ResizeCornerBuffer(int maxCorners)
        {
            CornerData nc = new CornerData(Math.Max(2, maxCorners));

            CornerData.Copy(mCorners, nc);
            mCorners = nc;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Finds the corners in the corridor from the position toward the target.
        /// (The straightened path.)
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method can be used to do corner searches that exceed the capacity of the
        /// corridor's normal corner buffers.
        /// </para>
        /// <para>
        /// This method performs essentially the same function as
        /// <see cref="NavmeshQuery.GetStraightPath"/>.
        /// </para>
        /// <para>
        /// Due to internal optimizations, the actual maximum number of corners returned
        /// will be <c>(buffer.MaxCorners - 1)</c>
        /// </para>
        /// <para>
        /// If the target is within range, it will be the last corner and have a polygon
        /// reference of zero.
        /// </para>
        /// <para>
        /// Behavior is undefined if the buffer structure is malformed. E.g. The flag and polygon
        /// buffers are different sizes.
        /// </para>
        /// </remarks>
        /// <param name="buffer">The buffer to load the results into. [Length: >= 2]</param>
        /// <returns>The number of corners returned in the buffers.</returns>
        public int FindCorners(CornerData buffer)
        {
            buffer.cornerCount = PathCorridorEx.dtpcFindCorners(mRoot
                                                                , buffer.verts, buffer.flags, buffer.polyRefs, buffer.polyRefs.Length
                                                                , mQuery.root, mFilter.root);

            return(buffer.cornerCount);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Copies the contents of the corner buffers from the source to destination.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Data will be lost if the destination buffers are too small to hold the corners
        /// contained by the source.
        /// </para>
        /// </remarks>
        /// <param name="source">The object to copy from.</param>
        /// <param name="desitation">The object to copy to.</param>
        public static void Copy(CornerData source, CornerData desitation)
        {
            int size = Math.Min(source.MaxCorners, desitation.MaxCorners);

            Array.Copy(source.flags, desitation.flags, size);
            Array.Copy(source.polyRefs, desitation.polyRefs, size);
            Array.Copy(source.verts, desitation.verts, size);
            desitation.cornerCount = Math.Min(size, source.cornerCount);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets the local corner data for the agent.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Only available after after a <see cref="CrowdManager"/> update.
 /// </para>
 /// <para>
 /// <b>Warning:</b> The buffer object must be sized to <see cref="CornerData.MarshalBufferSize"/>!
 /// </para>
 /// </remarks>
 /// <param name="buffer">
 /// The buffer to load with corner data. (Out) [Required:
 /// <see cref="CornerData.MaxCorners"/> = <see cref="CornerData.MarshalBufferSize"/>]
 /// </param>
 /// <returns>True if the data was sucessfully retrieved.</returns>
 public bool GetCornerData(CornerData buffer)
 {
     // This is only a partial argument validation.
     if (IsDisposed ||
         buffer == null ||
         buffer.polyRefs.Length != CornerData.MarshalBufferSize)
     {
         return(false);
     }
     CrowdAgentEx.dtcaGetAgentCorners(root, buffer);
     return(true);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <remarks>
        /// <para>
        /// <b>Important:</b> The <see cref="Reset"/> method must be called before the corridor
        /// can be used. (That is how the position is set.)
        /// </para>
        /// <para>
        /// Due to internal optimizations, the maximum number of detectable corners will be
        /// <c>(<paramref name="maxCorners"/> - 1)</c>.
        /// </para>
        /// <para>The query and filter parameters can be set to null.  This supports the ability
        /// to create pools of re-usable path corridor objects.  But it means that care needs to
        /// be taken not to use the corridor until query and filter objects have been set.
        /// See <see cref="ReleaseLocals"/> and <see cref="LoadLocals"/> for pool related utility
        /// functions.
        /// </para>
        /// </remarks>
        /// <param name="maxPathSize">
        /// The maximum path size that can be handled by the object. [Limit: >= 1]
        /// </param>
        /// <param name="maxCorners">
        /// The maximum number of corners the corner buffer can hold. [Limit: >= 2]
        /// </param>
        /// <param name="query">The query to be used by the corridor.</param>
        /// <param name="filter">The query filter to be used by the corridor.</param>
        public PathCorridor(int maxPathSize, int maxCorners
                            , NavmeshQuery query, NavmeshQueryFilter filter)
        {
            maxPathSize = Math.Max(1, maxPathSize);

            mRoot = PathCorridorEx.dtpcAlloc(maxPathSize);

            if (mRoot == IntPtr.Zero)
            {
                mMaxPathSize = 0;
                return;
            }

            mQuery       = query;
            mFilter      = filter;
            mMaxPathSize = maxPathSize;
            mCorners     = new CornerData(Math.Max(2, maxCorners));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Finds the corners in the corridor from the position toward the target. 
        /// (The straightened path.)
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method can be used to do corner searches that exceed the capacity of the 
        /// corridor's normal corner buffers.
        /// </para>
        /// <para>
        /// This method performs essentially the same function as 
        /// <see cref="NavmeshQuery.GetStraightPath"/>.
        /// </para>
        /// <para>
        /// Due to internal optimizations, the actual maximum number of corners returned 
        /// will be <c>(buffer.MaxCorners - 1)</c>
        /// </para>
        /// <para>
        /// If the target is within range, it will be the last corner and have a polygon 
        /// reference of zero.
        /// </para>
        /// <para>
        /// Behavior is undefined if the buffer structure is malformed. E.g. The flag and polygon 
        /// buffers are different sizes.
        /// </para>
        /// </remarks>
        /// <param name="buffer">The buffer to load the results into. [Length: >= 2]</param>
        /// <returns>The number of corners returned in the buffers.</returns>
        public int FindCorners(CornerData buffer)
        {
            buffer.cornerCount = PathCorridorEx.dtpcFindCorners(mRoot
                , buffer.verts, buffer.flags, buffer.polyRefs, buffer.polyRefs.Length
                , mQuery.root, mFilter.root);

            return buffer.cornerCount;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Resizes the corner buffers.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Due to internal optimizations, the maximum number of detectable corners will be 
 /// <c>(<paramref name="maxCorners"/> - 1)</c>.
 /// </para>
 /// <para>
 /// All possible corner buffer state will be preserved. (Some state may be lost if the 
 /// buffer is reduced in size.)
 /// </para>
 /// </remarks>
 /// <param name="maxCorners">
 /// The maximum number of corners the corner buffer can hold. [Limit: >= 2]
 /// </param>
 public void ResizeCornerBuffer(int maxCorners)
 {
     CornerData nc = new CornerData(Math.Max(2, maxCorners));
     CornerData.Copy(mCorners, nc);
     mCorners = nc;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <remarks>
        /// <para>
        /// <b>Important:</b> The <see cref="Reset"/> method must be called before the corridor 
        /// can be used. (That is how the position is set.)
        /// </para>
        /// <para>
        /// Due to internal optimizations, the maximum number of detectable corners will be 
        /// <c>(<paramref name="maxCorners"/> - 1)</c>.
        /// </para>
        /// <para>The query and filter parameters can be set to null.  This supports the ability 
        /// to create pools of re-usable path corridor objects.  But it means that care needs to 
        /// be taken not to use the corridor until query and filter objects have been set.
        /// See <see cref="ReleaseLocals"/> and <see cref="LoadLocals"/> for pool related utility 
        /// functions.
        /// </para>
        /// </remarks>
        /// <param name="maxPathSize">
        /// The maximum path size that can be handled by the object. [Limit: >= 1]
        /// </param>
        /// <param name="maxCorners">
        /// The maximum number of corners the corner buffer can hold. [Limit: >= 2]
        /// </param>
        /// <param name="query">The query to be used by the corridor.</param>
        /// <param name="filter">The query filter to be used by the corridor.</param>
        public PathCorridor(int maxPathSize, int maxCorners
            , NavmeshQuery query, NavmeshQueryFilter filter)
        {
            maxPathSize = Math.Max(1, maxPathSize);

            mRoot = PathCorridorEx.dtpcAlloc(maxPathSize);

            if (mRoot == IntPtr.Zero)
            {
                mMaxPathSize = 0;
                return;
            }

            mQuery = query;
            mFilter = filter;
            mMaxPathSize = maxPathSize;
            mCorners = new CornerData(Math.Max(2, maxCorners));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Validates the structure of the the corner buffers. (No content validation is performed.)
        /// </summary>
        /// <param name="buffer">The buffer to validate.</param>
        /// <param name="forMarshalling">True if the buffer must be sized for marshalling.</param>
        /// <returns>True if the structure of the corner buffers is valid.</returns>
        public static bool IsValid(CornerData buffer, bool forMarshalling)
        {
            if (buffer.flags == null
                || buffer.polyRefs == null
                || buffer.verts == null)
            {
                return false;
            }

            int size = (forMarshalling ? MarshalBufferSize : buffer.MaxCorners);

            if (size == 0)
                return false;

            if (buffer.flags.Length == size
                && buffer.polyRefs.Length == size
                && buffer.verts.Length == 3 * size)
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Copies the contents of the corner buffers from the source to destination.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Data will be lost if the destination buffers are too small to hold the corners 
        /// contained by the source.
        /// </para>
        /// </remarks>
        /// <param name="source">The object to copy from.</param>
        /// <param name="desitation">The object to copy to.</param>
        public static void Copy(CornerData source, CornerData desitation)
        {
            int size = Math.Min(source.MaxCorners, desitation.MaxCorners);

            Array.Copy(source.flags, desitation.flags, size);
            Array.Copy(source.polyRefs, desitation.polyRefs, size);
            Array.Copy(source.verts, desitation.verts, size);
            desitation.cornerCount = Math.Min(size, source.cornerCount);
        }
 /// <summary>
 /// Gets the local corner data for the agent.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Only available after after a <see cref="CrowdManager"/> update.
 /// </para>
 /// <para>
 /// <b>Warning:</b> The buffer object must be sized to <see cref="CornerData.MarshalBufferSize"/>!
 /// </para>
 /// </remarks>
 /// <param name="buffer">
 /// The buffer to load with corner data. (Out) [Required:
 /// <see cref="CornerData.MaxCorners"/> = <see cref="CornerData.MarshalBufferSize"/>]
 /// </param>
 /// <returns>True if the data was sucessfully retrieved.</returns>
 public bool GetCornerData(CornerData buffer)
 {
     // This is only a partial argument validation.
     if (IsDisposed
         || buffer == null
         || buffer.polyRefs.Length != CornerData.MarshalBufferSize)
     {
         return false;
     }
     CrowdAgentEx.dtcaGetAgentCorners(root, buffer);
     return true;
 }