コード例 #1
0
 public void Init(Vector3D start, MySmartGoal goal)
 {
     this.m_lastInitTime     = MySandboxGame.TotalGamePlayTimeInMilliseconds;
     this.m_startPoint       = start;
     this.m_goal             = goal;
     this.m_currentPrimitive = this.m_pathfinding.FindClosestPrimitive(start, false, null);
     if (this.m_currentPrimitive != null)
     {
         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);
         }
     }
     if (this.m_currentPrimitive == null)
     {
         this.m_currentPrimitive = null;
         this.Invalidate();
     }
     else
     {
         this.m_pathNodePosition     = 0;
         this.m_expandedPathPosition = 0;
         this.m_expandedPath.Clear();
         this.m_pathNodes.Clear();
         this.m_usedWholePath = false;
         this.m_valid         = true;
     }
 }
コード例 #2
0
 public MyPath <MyNavigationPrimitive> FindHighLevelPath(MyPathfinding pathfinding, MyHighLevelPrimitive startPrimitive)
 {
     m_pathfindingStatic = this;
     pathfinding.LastHighLevelTimestamp = pathfinding.GetCurrentTimestamp();
     m_pathfindingStatic = null;
     return(pathfinding.FindPath(startPrimitive, m_hlPathfindingHeuristic, m_hlTerminationCriterion, null, false));
 }
コード例 #3
0
        public IMyPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, MyEntity entity = null)
        {
            if (!MyPerGameSettings.EnablePathfinding)
            {
                return(null);
            }
            MySmartGoal goal  = new MySmartGoal(end, entity);
            MySmartPath path1 = new MySmartPath(this);

            path1.Init(begin, goal);
            return(path1);
        }
コード例 #4
0
        // MW:TODO optimize or change
        public bool ReachableUnderThreshold(Vector3D begin, IMyDestinationShape end, float thresholdDistance)
        {
            m_reachPredicateDistance = thresholdDistance;
            var beginPrimitive = FindClosestPrimitive(begin, false);
            var endPrimitive   = FindClosestPrimitive(end.GetDestination(), false);

            if (beginPrimitive == null || endPrimitive == null)
            {
                return(false);
            }

            var beginHL = beginPrimitive.GetHighLevelPrimitive();
            var endHL   = endPrimitive.GetHighLevelPrimitive();

            ProfilerShort.Begin("HL");
            MySmartGoal goal = new MySmartGoal(end);
            var         path = goal.FindHighLevelPath(this, beginHL);

            ProfilerShort.End();
            if (path == null)
            {
                return(false);
            }

            m_reachEndPrimitive = endPrimitive;
            ProfilerShort.Begin("Prepare for travesal");
            PrepareTraversal(beginPrimitive, null, ReachablePredicate);
            ProfilerShort.End();
            ProfilerShort.Begin("checking for vertices");
            try
            {
                foreach (var vertex in this)
                {
                    if (vertex.Equals(m_reachEndPrimitive))
                    {
                        return(true);
                    }
                }
            }
            finally
            {
                ProfilerShort.End();
            }

            return(false);
        }
コード例 #5
0
ファイル: MySmartPath.cs プロジェクト: feiyuren233/vrage
        public void Init(Vector3D start, MySmartGoal goal)
        {
            ProfilerShort.Begin("MySmartPath.Init()");
            Debug.Assert(m_valid == false);

            m_lastInitTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            m_startPoint = start;
            m_goal       = goal;

            ProfilerShort.Begin("Find start primitive");
            ProfilerShort.Begin("FindClosestPrimitive");
            m_currentPrimitive = m_pathfinding.FindClosestPrimitive(start, highLevel: false);
            if (m_currentPrimitive != null)
            {
                ProfilerShort.BeginNextBlock("GetHighLevelPrimitive");
                m_hlBegin = m_currentPrimitive.GetHighLevelPrimitive();
                Debug.Assert(m_hlBegin != null, "Start primitive did not have a high-level primitive!");

                if (m_hlBegin != null && !m_pathNodes.Contains(m_hlBegin))
                {
                    ProfilerShort.BeginNextBlock("ObservePrimitive");
                    m_hlBegin.Parent.ObservePrimitive(m_hlBegin, this);
                }
            }
            ProfilerShort.End();
            ProfilerShort.End();

            if (m_currentPrimitive == null)
            {
                // CH: TODO: Starting primitive was not found. What to do now?
                m_currentPrimitive = null;
                Invalidate();
                ProfilerShort.End();
                return;
            }

            m_pathNodePosition     = 0;
            m_expandedPathPosition = 0;
            m_expandedPath.Clear();
            m_pathNodes.Clear();
            m_usedWholePath = false;

            m_valid = true;
            ProfilerShort.End();
        }
コード例 #6
0
ファイル: MySmartPath.cs プロジェクト: 2asoft/SpaceEngineers
        public void Init(Vector3D start, MySmartGoal goal)
        {
            ProfilerShort.Begin("MySmartPath.Init()");
            Debug.Assert(m_valid == false);

            m_lastInitTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            m_startPoint = start;
            m_goal = goal;

            ProfilerShort.Begin("Find start primitive");
            ProfilerShort.Begin("FindClosestPrimitive");
            m_currentPrimitive = m_pathfinding.FindClosestPrimitive(start, highLevel: false);
            if (m_currentPrimitive != null)
            {
                ProfilerShort.BeginNextBlock("GetHighLevelPrimitive");
                m_hlBegin = m_currentPrimitive.GetHighLevelPrimitive();
                Debug.Assert(m_hlBegin != null, "Start primitive did not have a high-level primitive!");

                if (m_hlBegin != null && !m_pathNodes.Contains(m_hlBegin))
                {
                    ProfilerShort.BeginNextBlock("ObservePrimitive");
                    m_hlBegin.Parent.ObservePrimitive(m_hlBegin, this);
                }
            }
            ProfilerShort.End();
            ProfilerShort.End();

            if (m_currentPrimitive == null)
            {
                // CH: TODO: Starting primitive was not found. What to do now?
                m_currentPrimitive = null;
                Invalidate();
                ProfilerShort.End();
                return;
            }

            m_pathNodePosition = 0;
            m_expandedPathPosition = 0;
            m_expandedPath.Clear();
            m_pathNodes.Clear();
            m_usedWholePath = false;

            m_valid = true;
            ProfilerShort.End();
        }
コード例 #7
0
        public void Reinit(Vector3D newStart)
        {
            MySmartGoal goal      = this.m_goal;
            MyEntity    endEntity = goal.EndEntity;

            this.ClearPathNodes();
            this.m_expandedPath.Clear();
            this.m_expandedPathPosition = 0;
            this.m_currentPrimitive     = null;
            if (this.m_hlBegin != null)
            {
                this.m_hlBegin.Parent.StopObservingPrimitive(this.m_hlBegin, this);
            }
            this.m_hlBegin = null;
            this.m_valid   = false;
            this.m_goal.Reinit();
            this.Init(newStart, goal);
        }
コード例 #8
0
        public MySmartPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, MyEntity entity = null)
        {
            Debug.Assert(MyPerGameSettings.EnablePathfinding, "Pathfinding is not enabled!");
            if (!MyPerGameSettings.EnablePathfinding)
            {
                return(null);
            }

            ProfilerShort.Begin("MyPathfinding.FindPathGlobal");

            // CH: TODO: Use pooling
            MySmartPath newPath = new MySmartPath(this);
            MySmartGoal newGoal = new MySmartGoal(end, entity);

            newPath.Init(begin, newGoal);

            ProfilerShort.End();
            return(newPath);
        }
コード例 #9
0
ファイル: MySmartGoal.cs プロジェクト: Krulac/SpaceEngineers
        public MyPath<MyNavigationPrimitive> FindHighLevelPath(MyPathfinding pathfinding, MyHighLevelPrimitive startPrimitive)
        {
            m_pathfindingStatic = this;
            var path = pathfinding.FindPath(startPrimitive, m_hlPathfindingHeuristic, m_hlTerminationCriterion, null, returnClosest: false);
            pathfinding.LastHighLevelTimestamp = pathfinding.GetCurrentTimestamp();
            m_pathfindingStatic = null;

            return path;
        }