Esempio n. 1
0
 public static void free(NavigationGraph p_navigationGraph)
 {
     if (NavigationGraphContainer.UniqueNavigationGraph == p_navigationGraph)
     {
         NavigationGraphContainer.UniqueNavigationGraph = null;
     }
 }
Esempio n. 2
0
        public static NavigationNode instanciateAndAddNode(NavigationGraph p_navigationGraph)
        {
            NavigationNode l_navigationNode = NavigationNode.alloc();

            p_navigationGraph.NavigationNodes.Add(l_navigationNode);
            return(l_navigationNode);
        }
Esempio n. 3
0
 public static void takeSnapshot(NavigationGraph p_navigationGraph)
 {
     p_navigationGraph.NavigationGraphSnapshot = NavigationGraphSnapshot.alloc(
         p_navigationGraph.NodeLinksIndexedByStartNode,
         p_navigationGraph.NodeLinksIndexedByEndNode
         );
 }
Esempio n. 4
0
        /*
         *  Alter NavigationNodeLinks by restoring NavigationLinks following the rule dictated by p_navigationLinkAlterationMethod (see ENavigationLinkRemovalMethod for more).
         *  - NavigationNodeLinks are restored from the NavigationGraphSnapshot.
         */
        public static void restoreNavigationLinksFromSnapshot(NavigationGraph p_navigationGraph, ENavigationLinkAlterationMethod p_navigationLinkAlterationMethod, NavigationNode p_involvedNode)
        {
            switch (p_navigationLinkAlterationMethod)
            {
            case ENavigationLinkAlterationMethod.TO:

                // We have to :
                //    * copy NavigationLinks going to the p_involvedNode (retrieved from snapshot)
                //    * add NavigationLinks coming from NavigationNodes that goes to the p_involvedNode
                List <NavigationLink> l_linksThatPointsTowardsInvolvedNode = p_navigationGraph.NodeLinksIndexedByEndNode[p_involvedNode];
                l_linksThatPointsTowardsInvolvedNode.Clear();
                l_linksThatPointsTowardsInvolvedNode.AddRange(p_navigationGraph.NavigationGraphSnapshot.NodeLinksIndexedByEndNode[p_involvedNode]);

                for (int i = 0; i < l_linksThatPointsTowardsInvolvedNode.Count; i++)
                {
                    NavigationLink l_linkTo = l_linksThatPointsTowardsInvolvedNode[i];

                    var l_linksFrom_snapshot_enumerator = p_navigationGraph.NavigationGraphSnapshot.NodeLinksIndexedByStartNode[l_linkTo.StartNode].GetEnumerator();
                    while (l_linksFrom_snapshot_enumerator.MoveNext())
                    {
                        NavigationLink l_referenceFromLink = l_linksFrom_snapshot_enumerator.Current;

                        if (l_referenceFromLink.EndNode == p_involvedNode)
                        {
                            p_navigationGraph.NodeLinksIndexedByStartNode[l_referenceFromLink.StartNode].Add(l_referenceFromLink);
                        }
                    }
                }
                break;
            }
        }
Esempio n. 5
0
 private void InstanciateNavigationLinks(NavigationGraph l_navigationGraph, ref Dictionary <int, NavigationNode> l_serializedKeyToNavigationNode)
 {
     foreach (var l_navigationLinkEntry in NavigationLinks)
     {
         NavigationGraph.createLinkBetween(l_navigationGraph, l_serializedKeyToNavigationNode[l_navigationLinkEntry.StartNode], l_serializedKeyToNavigationNode[l_navigationLinkEntry.EndNode], l_navigationLinkEntry.TravelCost);
     }
 }
Esempio n. 6
0
 public void ClearForNewInstance()
 {
     NavigationGraph = null;
     BeginNode       = null;
     EndNode         = null;
     NodesElligibleForNextCurrent.Clear();
     NavigationPath.reset(ref ResultPath);
 }
Esempio n. 7
0
 public static void prepareForCalculation(CalculatePathRequest p_request, NavigationGraph p_navigationGraph, NavigationNode p_beginNode, NavigationNode p_endNode,
                                          PathCalculationParameters p_pathCalculationParameters)
 {
     p_request.NavigationGraph           = p_navigationGraph;
     p_request.BeginNode                 = p_beginNode;
     p_request.EndNode                   = p_endNode;
     p_request.PathCalculationParameters = p_pathCalculationParameters;
 }
Esempio n. 8
0
 private void InstanciateNavigationNodes(NavigationGraph l_navigationGraph, ref Dictionary <int, NavigationNode> l_serializedKeyToNavigationNode)
 {
     foreach (var l_navigationNodeEntry in NavigationNodes)
     {
         NavigationNode l_instanciatedNavigationNode = NavigationGraph.instanciateAndAddNode(l_navigationGraph);
         l_instanciatedNavigationNode.LocalPosition = l_navigationNodeEntry.Value.LocalPosition;
         l_serializedKeyToNavigationNode[l_navigationNodeEntry.Key] = l_instanciatedNavigationNode;
     }
 }
Esempio n. 9
0
        public static NavigationGraph alloc()
        {
            NavigationGraph l_instanciatedNavigationGraph = new NavigationGraph();

            l_instanciatedNavigationGraph.NavigationNodes             = new List <NavigationNode>();
            l_instanciatedNavigationGraph.NodeLinksIndexedByStartNode = new Dictionary <NavigationNode, List <NavigationLink> >();
            l_instanciatedNavigationGraph.NodeLinksIndexedByEndNode   = new Dictionary <NavigationNode, List <NavigationLink> >();
            NavigationGraphContainer.UniqueNavigationGraph            = l_instanciatedNavigationGraph;
            return(l_instanciatedNavigationGraph);
        }
Esempio n. 10
0
        /// <summary>
        /// Intanciate a new <see cref="NavigationGraph"/> object from this asset.
        /// </summary>
        /// <param name="out_instanciatedNodes"> All <see cref="NavigationNode"/> instanciated.</param>
        /// <returns></returns>
        public NavigationGraph InstanciateNavigationGraph()
        {
            NavigationGraph l_navigationGraph = NavigationGraph.alloc();
            Dictionary <int, NavigationNode> l_serializedKeyToNavigationNode = new Dictionary <int, NavigationNode>(NavigationNodes.Count);

            InstanciateNavigationNodes(l_navigationGraph, ref l_serializedKeyToNavigationNode);
            InstanciateNavigationLinks(l_navigationGraph, ref l_serializedKeyToNavigationNode);
            NavigationGraph.takeSnapshot(l_navigationGraph);
            return(l_navigationGraph);
        }
Esempio n. 11
0
 /// <summary>
 /// Checks if the <paramref name="p_requestedNode1"/> and <paramref name="p_requestedNode2"/> have a direct <see cref="NavigationLink"/> connection.
 /// The checked <see cref="NavigationLink"/> is oriented from <paramref name="p_requestedNode1"/> to <paramref name="p_requestedNode2"/>.
 /// </summary>
 public static bool areNavigationNodesNeighbors(NavigationGraph p_navigationGraph, NavigationNode p_requestedNode1, NavigationNode p_requestedNode2, NavigationGraphFlag p_navigationGraphFlag)
 {
     foreach (NavigationNode l_reachableNavigationNode in getReachableNeighborNavigationNodes(p_navigationGraph, p_requestedNode1, p_navigationGraphFlag))
     {
         if (l_reachableNavigationNode == p_requestedNode2)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 12
0
        /// <summary>
        /// Find all NavigationNodes that the <paramref name="p_requestedNode"/> can travel to and have direct <see cref="NavigationLink"/> between them.
        /// - "Reachable" : Means that it exists a path between the <paramref name="p_requestedNode"/> and the returned NavigationNode
        /// - "Neighbor" : Means that the <paramref name="p_requestedNode"/> and the returned NavigationNode have a direct NavigationLink between them.
        /// </summary>
        public static IEnumerable <NavigationNode> getReachableNeighborNavigationNodes(NavigationGraph p_navigationGraph, NavigationNode p_requestedNode, NavigationGraphFlag p_navigationGraphFlag)
        {
            var l_navigationLinksGoingFromTheRequestedNode = NavigationGraph.get_nodeLinksIndexedByStartNode(p_navigationGraph, p_navigationGraphFlag)[p_requestedNode];

            var l_navigationLinksGoingFromTheRequestedNodeEnumerator = l_navigationLinksGoingFromTheRequestedNode.GetEnumerator();

            while (l_navigationLinksGoingFromTheRequestedNodeEnumerator.MoveNext())
            {
                yield return(l_navigationLinksGoingFromTheRequestedNodeEnumerator.Current.EndNode);
            }
        }
Esempio n. 13
0
        private void Awake()
        {
            NavigationGraph = NavigationGraphAsset.InstanciateNavigationGraph();
            NavigationGraphComponentContainer.UniqueNavigationGraphComponent = this;

            for (int i = 0; i < NavigationGraph.NavigationNodes.Count; i++)
            {
                NavigationNodeGameRepresentation[NavigationGraph.NavigationNodes[i]] = NavigationNodeComponent.instanciateFromPrefab(transform, NavigationGraph.NavigationNodes[i], NavigationNodeComponentPrefab);
            }

            NavigationEngine = NavigationEngine.alloc();
        }
Esempio n. 14
0
        public static NavigationNode getNearestNode(NavigationGraph p_navigationGraph, float3 p_localPosition)
        {
            NavigationNode l_nearestNavigationNode = p_navigationGraph.NavigationNodes[0];

            for (int i = 1; i < p_navigationGraph.NavigationNodes.Count; i++)
            {
                if (math.distance(l_nearestNavigationNode.LocalPosition, p_localPosition) >
                    math.distance(l_nearestNavigationNode.LocalPosition, p_navigationGraph.NavigationNodes[i].LocalPosition))
                {
                    l_nearestNavigationNode = p_navigationGraph.NavigationNodes[i];
                }
            }
            return(l_nearestNavigationNode);
        }
Esempio n. 15
0
        public static void createLinkBetween(NavigationGraph p_navigationGraph, NavigationNode p_startNode, NavigationNode p_endNode, float p_travelCost)
        {
            NavigationLink l_instanciatedNavigationLink = NavigationLink.alloc(p_startNode, p_endNode, p_travelCost);

            if (!p_navigationGraph.NodeLinksIndexedByStartNode.ContainsKey(p_startNode))
            {
                p_navigationGraph.NodeLinksIndexedByStartNode.Add(p_startNode, new List <NavigationLink>());
            }
            if (!p_navigationGraph.NodeLinksIndexedByEndNode.ContainsKey(p_endNode))
            {
                p_navigationGraph.NodeLinksIndexedByEndNode.Add(p_endNode, new List <NavigationLink>());
            }

            p_navigationGraph.NodeLinksIndexedByStartNode[p_startNode].Add(l_instanciatedNavigationLink);
            p_navigationGraph.NodeLinksIndexedByEndNode[p_endNode].Add(l_instanciatedNavigationLink);
        }
Esempio n. 16
0
 /*
  * Alter NavigationNodeLinks by removing the NavigationLinks following the rule dictated by p_navigationLinkAlterationMethod (see ENavigationLinkRemovalMethod for more).
  */
 public static void removeNavigationLinks(NavigationGraph p_navigationGraph, ENavigationLinkAlterationMethod p_navigationLinkAlterationMethod, NavigationNode p_involvedNode)
 {
     switch (p_navigationLinkAlterationMethod)
     {
     case ENavigationLinkAlterationMethod.TO:
         // We have to :
         //    * gets NavigationLinks going to the p_involvedNode
         //    * clear NavigationLinks coming from NavigationNodes that goes to the p_involvedNode
         //    * clear NavigationLinks going to the p_involvedNode
         List <NavigationLink> l_nodesToList = p_navigationGraph.NodeLinksIndexedByEndNode[p_involvedNode];
         for (int i = 0; i < l_nodesToList.Count; i++)
         {
             NavigationLink        l_linkTo     = l_nodesToList[i];
             List <NavigationLink> l_targetList = p_navigationGraph.NodeLinksIndexedByStartNode[l_linkTo.StartNode];
             l_targetList.Remove(l_linkTo);
         }
         p_navigationGraph.NodeLinksIndexedByEndNode[p_involvedNode].Clear();
         break;
     }
 }
Esempio n. 17
0
 public static Dictionary <NavigationNode, List <NavigationLink> > get_nodeLinksIndexedByStartNode(NavigationGraph p_navigationGraph, NavigationGraphFlag p_navigationGraphFlag)
 {
     if (p_navigationGraphFlag == NavigationGraphFlag.CURRENT)
     {
         return(p_navigationGraph.NodeLinksIndexedByStartNode);
     }
     else if (p_navigationGraphFlag == NavigationGraphFlag.SNAPSHOT)
     {
         return(p_navigationGraph.NavigationGraphSnapshot.NodeLinksIndexedByStartNode);
     }
     return(null);
 }
Esempio n. 18
0
 public static NavigationNode pickRandomNode(NavigationGraph p_navigationGraph)
 {
     return(p_navigationGraph.NavigationNodes[MyRandom.Random.NextInt(0, p_navigationGraph.NavigationNodes.Count)]);
 }