Beispiel #1
0
    public void RemoveRequest(IPathRequestQuery requestQuery)
    {
        if (!m_bInitialized)
        {
            UnityEngine.Debug.LogError("PathManagerComponent isn't yet fully intialized. Wait until Start() has been called. Can't call ConsumeRequest.");
            return;
        }

        if (requestQuery == null)
        {
            return;
        }

        PathRequest_Batch request = GetPathRequest_Batch(requestQuery);

        if (request == null)
        {
            return;
        }

        // In case the request is active, remove it.
        m_activeRequests.Remove(request);

        // Return the request back to the pool so that it can be used again.
        m_pathPlannerPool.Return(request.PathPlanner);
        m_requestPool.Enqueue(request);
    }
Beispiel #2
0
    private PathRequest_Batch GetPathRequest_Batch(IPathRequestQuery requestQuery)
    {
        PathRequest_Batch foundRequest = null;

        System.Diagnostics.Debug.Assert(requestQuery is PathRequest_Batch);
        if (requestQuery is PathRequest_Batch)
        {
            foundRequest = requestQuery as PathRequest_Batch;
        }
        return(foundRequest);
    }
Beispiel #3
0
 private void OnRequestCompleted(PathRequest_Batch request, bool bSucceeded)
 {
     if (bSucceeded)
     {
         OnRequestSucceeded(request);
     }
     else
     {
         OnRequestFailed(request);
     }
 }
Beispiel #4
0
    public IPathRequestQuery RequestPathPlan(PathPlanParams_Batch pathPlanParams, IPathAgent agent)
    {
        if (!m_bInitialized)
        {
            UnityEngine.Debug.LogError("PathManagerComponent isn't yet fully intialized. Wait until Start() has been called. Can't call RequestPathPlan.");
            return(null);
        }

        if (m_requestPool.Count == 0)
        {
            UnityEngine.Debug.Log("RequestPathPlan failed because it is already servicing the maximum number of requests: " +
                                  m_maxNumberOfPlanners.ToString());
            return(null);
        }

        if (m_pathPlannerPool.AvailableCount == 0)
        {
            UnityEngine.Debug.Log("RequestPathPlan failed because it is already servicing the maximum number of path requests: " +
                                  m_maxNumberOfPlanners.ToString());
            return(null);
        }

        // Clamp the start and goal positions within the terrain space, and make sure they are on the floor.
        //pathPlanParams.UpdateStartAndGoalPos( m_terrain.GetValidPathFloorPos(pathPlanParams.StartPos) );

        // Make sure this agent does not have an active request
        if (m_activeRequests.Count > 0)
        {
            foreach (PathRequest_Batch pathRequest in m_activeRequests)
            {
                if (pathRequest.Agent.GetHashCode() == agent.GetHashCode())
                {
                    System.Diagnostics.Debug.Assert(false, "Each agent can only have one path request at a time.");
                    return(null);
                }
            }
        }

        // Create the new request
        Pool <PathPlanner> .Node pathPlanner = m_pathPlannerPool.Get();
        PathRequest_Batch        request     = m_requestPool.Dequeue();

        request.Set(pathPlanParams, pathPlanner, agent);
        m_activeRequests.AddFirst(request);

        // Start the request
        pathPlanner.Item.StartANewPlan(request.PlanParams.GetCurrentIndex(), request.PlanParams.GetCurrentGoalIndexAndMoveNext());

        return(request);
    }
Beispiel #5
0
 private void OnRequestSucceeded(PathRequest_Batch request)
 {
     request.Agent.OnPathAgentRequestSucceeded(request);
 }
Beispiel #6
0
 private void OnRequestFailed(PathRequest_Batch request)
 {
     request.Agent.OnPathAgentRequestFailed();
 }