Example #1
0
        private void RefineFoundPath(ref Vector3D begin, ref Vector3D end, MyPath <MyNavigationPrimitive> path)
        {
            Debug.Assert(MyPerGameSettings.EnablePathfinding, "Pathfinding is not enabled!");
            if (!MyPerGameSettings.EnablePathfinding)
            {
                return;
            }

            if (path == null)
            {
                Debug.Assert(false, "Path to refine was null!");
                return;
            }

            m_currentPrimitive = path[path.Count - 1].Vertex as MyNavigationPrimitive;
            if (m_hlBegin != null && !m_pathNodes.Contains(m_hlBegin))
            {
                m_hlBegin.Parent.StopObservingPrimitive(m_hlBegin, this);
            }
            m_hlBegin = m_currentPrimitive.GetHighLevelPrimitive();
            if (m_hlBegin != null && !m_pathNodes.Contains(m_hlBegin))
            {
                m_hlBegin.Parent.ObservePrimitive(m_hlBegin, this);
            }

            ProfilerShort.Begin("Path refining and post-processing");
            IMyNavigationGroup prevGroup = null;
            int     groupStart           = 0;
            int     groupEnd             = 0;
            Vector3 prevBegin            = default(Vector3);
            Vector3 prevEnd = default(Vector3);

            for (int i = 0; i < path.Count; ++i)
            {
                var primitive = path[i].Vertex as MyNavigationPrimitive;
                var group     = primitive.Group;

                if (prevGroup == null)
                {
                    prevGroup = group;
                    prevBegin = prevGroup.GlobalToLocal(begin);
                }

                bool lastPrimitive = i == path.Count - 1;

                if (group != prevGroup)
                {
                    groupEnd = i - 1;
                    prevEnd  = prevGroup.GlobalToLocal(primitive.WorldPosition);
                }
                else if (lastPrimitive)
                {
                    groupEnd = i;
                    prevEnd  = prevGroup.GlobalToLocal(end);
                }
                else
                {
                    continue;
                }

                int refinedBegin = m_expandedPath.Count;
                prevGroup.RefinePath(path, m_expandedPath, ref prevBegin, ref prevEnd, groupStart, groupEnd);
                int refinedEnd = m_expandedPath.Count;
                for (int j = refinedBegin; j < refinedEnd; ++j)
                {
                    Vector3D position = new Vector3D(m_expandedPath[j]);
                    position = prevGroup.LocalToGlobal(position);

                    m_expandedPath[j] = new Vector4D(position, m_expandedPath[j].W);
                }

                if (lastPrimitive && group != prevGroup)
                {
                    m_expandedPath.Add(new Vector4D(primitive.WorldPosition, m_expandedPath[refinedEnd - 1].W));
                }

                prevGroup  = group;
                groupStart = i;
                if (m_expandedPath.Count != 0)
                {
                    prevBegin = group.GlobalToLocal(new Vector3D(m_expandedPath[m_expandedPath.Count - 1]));
                }
            }

            m_pathNodePosition++;

            //m_expandedPath.RemoveAt(0);
            m_expandedPathPosition = 0;

            ProfilerShort.End();
        }
Example #2
0
 private void RefineFoundPath(ref Vector3D begin, ref Vector3D end, MyPath <MyNavigationPrimitive> path)
 {
     if (MyPerGameSettings.EnablePathfinding && (path != null))
     {
         this.m_currentPrimitive = path[path.Count - 1].Vertex as MyNavigationPrimitive;
         if ((this.m_hlBegin != null) && !this.m_pathNodes.Contains(this.m_hlBegin))
         {
             this.m_hlBegin.Parent.StopObservingPrimitive(this.m_hlBegin, this);
         }
         this.m_hlBegin = this.m_currentPrimitive.GetHighLevelPrimitive();
         if ((this.m_hlBegin != null) && !this.m_pathNodes.Contains(this.m_hlBegin))
         {
             this.m_hlBegin.Parent.ObservePrimitive(this.m_hlBegin, this);
         }
         IMyNavigationGroup objB = null;
         int     num             = 0;
         int     num2            = 0;
         Vector3 startPoint      = new Vector3();
         Vector3 endPoint        = new Vector3();
         int     num3            = 0;
         while (true)
         {
             while (true)
             {
                 if (num3 >= path.Count)
                 {
                     this.m_pathNodePosition++;
                     this.m_expandedPathPosition = 0;
                     return;
                 }
                 MyNavigationPrimitive vertex = path[num3].Vertex as MyNavigationPrimitive;
                 IMyNavigationGroup    group  = vertex.Group;
                 if (objB == null)
                 {
                     objB       = group;
                     startPoint = objB.GlobalToLocal(begin);
                 }
                 bool flag = num3 == (path.Count - 1);
                 if (!ReferenceEquals(group, objB))
                 {
                     num2     = num3 - 1;
                     endPoint = objB.GlobalToLocal(vertex.WorldPosition);
                 }
                 else
                 {
                     if (!flag)
                     {
                         break;
                     }
                     num2     = num3;
                     endPoint = objB.GlobalToLocal(end);
                 }
                 objB.RefinePath(path, this.m_expandedPath, ref startPoint, ref endPoint, num, num2);
                 int count = this.m_expandedPath.Count;
                 int num5  = this.m_expandedPath.Count;
                 while (true)
                 {
                     if (num5 >= count)
                     {
                         if (flag && !ReferenceEquals(group, objB))
                         {
                             this.m_expandedPath.Add(new Vector4D(vertex.WorldPosition, this.m_expandedPath[count - 1].W));
                         }
                         objB = group;
                         num  = num3;
                         if (this.m_expandedPath.Count != 0)
                         {
                             startPoint = group.GlobalToLocal(new Vector3D(this.m_expandedPath[this.m_expandedPath.Count - 1]));
                         }
                         break;
                     }
                     Vector3D vectord = new Vector3D(this.m_expandedPath[num5]);
                     vectord = objB.LocalToGlobal((Vector3)vectord);
                     this.m_expandedPath[num5] = new Vector4D(vectord, this.m_expandedPath[num5].W);
                     num5++;
                 }
                 break;
             }
             num3++;
         }
     }
 }