Esempio n. 1
0
    //update the graph by replacing the used nodes for obstacle at index with nodes stored in nodeGroups
    public void updateGraph(int index, List <List <Node> > nodeGroups, bool isStandingStill)
    {
        pathCrossesAgentPath = false;

        timeFrameOffset = followPathScript.getCurrentTimeFrame();

        //if obstacle is not moving we want to fill it's current position in all time frames
        //we don't shift back to prevent loss of nodes at the end where they overflow.
        if (isStandingStill)
        {
            timeFrameOffset = 0;
        }

        //if path for index exist
        if (obstPaths.Count > index)
        {
            cleanObstPath(index, false);
            obstPaths[index] = new List <List <Node> >();

            foreach (List <Node> nodeGroup in nodeGroups)
            {
                List <Node[]> nodeList = getNodeListAndMarkNodes(nodeGroup);

                List <Node> beforeNodes  = new List <Node>();
                List <Node> currentNodes = new List <Node>();
                List <Node> afterNodes   = new List <Node>();

                foreach (Node[] nodeBeforeAfterCurrent in nodeList)
                {
                    beforeNodes.Add(nodeBeforeAfterCurrent[0]);
                    currentNodes.Add(nodeBeforeAfterCurrent[1]);
                    afterNodes.Add(nodeBeforeAfterCurrent[2]);
                }
                beforeNodes.RemoveAll(item => item == null);
                currentNodes.RemoveAll(item => item == null);
                afterNodes.RemoveAll(item => item == null);

                //in first iteration we add lists for current, after and before(if it exists)
                //in second iteration the current nodes get added to the previous after list
                //and before nodes get added to the previous current list
                if (obstPaths[index].Count == 0)
                {
                    if (beforeNodes.Count > 0)
                    {
                        obstPaths[index].Add(beforeNodes);
                    }

                    obstPaths[index].Add(currentNodes);
                }
                else
                {
                    foreach (Node node in beforeNodes)
                    {
                        obstPaths[index][obstPaths[index].Count - 2].Add(node);
                    }
                    foreach (Node node in currentNodes)
                    {
                        obstPaths[index][obstPaths[index].Count - 1].Add(node);
                    }
                }

                if (obstPaths[index].Count < GridSizeZ)
                {
                    obstPaths[index].Add(afterNodes);
                }
            }
        }

        visObstManagerScript.addToRecalcObstCounter();
        //pathCrossesAgent path is global var that gets set in the markNodeWithOffset method
        //this happens as soon as any collision with the agent path is found
        if (pathCrossesAgentPath)
        {
            findPathScript.addToRecalcQueue(index);
        }
    }