/// <summary> /// Sets the specified resources and resets the corridor. /// </summary> /// <remarks> /// <para> /// This method is useful when pooling path corridors for use by mulitple clients. /// </para> /// <para> /// See <see cref="Reset"/> for information on the effect of the reset. /// </para> /// <para> /// Existing references will be replaced by the new references. /// </para> /// <para> /// This method cannot be used to set references to null. Attempting to do so will result /// in a failure. /// </para> /// </remarks> /// <param name="corridor">The corridor to update.</param> /// <param name="position">The position to reset to corridor to.</param> /// <param name="query">The query object to use.</param> /// <param name="filter">The filter object to use.</param> /// <returns>True if successful.</returns> public static bool LoadLocals(PathCorridor corridor, NavmeshPoint position , NavmeshQuery query, NavmeshQueryFilter filter) { // Basic checks first. if (position.polyRef == 0|| corridor == null|| query == null|| filter == null) return false; // Validate optional parameters. // Assign and reset. corridor.mQuery = query; corridor.mFilter = filter; corridor.Reset(position); return true; }
/// <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)); }
/// <summary> /// Immediately frees all unmanaged resources allocated by the object. /// </summary> public override void RequestDisposal() { // There are no managed or local allocations. if (root != IntPtr.Zero) { mFilter.RequestDisposal(); mFilter = null; mGrid.Dispose(); mGrid = null; mQuery.RequestDisposal(); mQuery = null; mNavmesh = null; mMaxAgentRadius = -1; agentStates = null; for (int i = 0; i < mAgents.Length; i++) { if (mAgents[i] == null) continue; mAgents[i].Dispose(); mAgents[i] = null; } CrowdManagerEx.dtcDetourCrowdFree(root); root = IntPtr.Zero; } }
/// <summary> /// Creates a new navigation mesh query based on the provided navigation mesh. /// </summary> /// <param name="navmesh">A navigation mesh to query against.</param> /// <param name="maximumNodes"> /// The maximum number of nodes allowed when performing A* and Dijkstra searches. /// </param> /// <param name="resultQuery">A navigation mesh query object.</param> /// <returns>The <see cref="NavStatus" /> flags for the build request.</returns> public static NavStatus Create(Navmesh navmesh , int maximumNodes , out NavmeshQuery resultQuery) { IntPtr query = IntPtr.Zero; NavStatus status = NavmeshQueryEx.dtnqBuildDTNavQuery( navmesh.root , maximumNodes , ref query); if (NavUtil.Succeeded(status)) resultQuery = new NavmeshQuery(query, false, AllocType.External); else resultQuery = null; return status; }
private CrowdManager(IntPtr crowd, Navmesh navmesh, int maxAgents, float maxAgentRadius) : base(AllocType.External) { mMaxAgentRadius = maxAgentRadius; mNavmesh = navmesh; root = crowd; mAgents = new CrowdAgent[maxAgents]; agentStates = new CrowdAgentCoreState[maxAgents]; IntPtr ptr = CrowdManagerEx.dtcGetFilter(root); mFilter = new NavmeshQueryFilter(ptr, AllocType.ExternallyManaged); ptr = CrowdManagerEx.dtcGetGrid(root); mGrid = new CrowdProximityGrid(ptr); ptr = CrowdManagerEx.dtcGetNavMeshQuery(root); mQuery = new NavmeshQuery(ptr, true, AllocType.ExternallyManaged); }