Beispiel #1
0
        public IMyHighLevelComponent GetComponent(MyHighLevelPrimitive primitive)
        {
            ulong num;

            Base6Directions.DirectionFlags flags;
            if (!this.m_navmeshComponents.GetComponentCell(primitive.Index, out num))
            {
                return(null);
            }
            if (!this.m_navmeshComponents.GetComponentInfo(primitive.Index, num, out flags))
            {
                return(null);
            }
            MyCellCoord coord = new MyCellCoord();

            coord.SetUnpack(num);
            foreach (Base6Directions.Direction direction in Base6Directions.EnumDirections)
            {
                Base6Directions.DirectionFlags directionFlag = Base6Directions.GetDirectionFlag(direction);
                if (!flags.HasFlag(directionFlag))
                {
                    Vector3I position = (Vector3I)(coord.CoordInLod + Base6Directions.GetIntVector(direction));
                    if (this.m_exploredCells.Contains(ref position))
                    {
                        flags |= directionFlag;
                    }
                }
            }
            return(new Component(primitive.Index, flags));
        }
Beispiel #2
0
        public MyHighLevelPrimitive TryGetPrimitive(int index)
        {
            MyHighLevelPrimitive primitive = null;

            this.m_primitives.TryGetValue(index, out primitive);
            return(primitive);
        }
Beispiel #3
0
        public void Invalidate()
        {
            if (m_valid == false)
            {
                return;
            }

            ClearPathNodes();

            m_expandedPath.Clear();
            m_expandedPathPosition = 0;

            m_currentPrimitive = null;

            if (m_goal.IsValid)
            {
                m_goal.Invalidate();
            }
            if (m_hlBegin != null)
            {
                m_hlBegin.Parent.StopObservingPrimitive(m_hlBegin, this);
            }
            m_hlBegin = null;

            m_valid = false;
        }
Beispiel #4
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;
     }
 }
Beispiel #5
0
        public void StopObservingPrimitive(MyHighLevelPrimitive primitive, IMyHighLevelPrimitiveObserver observer)
        {
            Debug.Assert(primitive.Parent == this);
            if (primitive.Parent != this)
            {
                return;
            }

            List <IMyHighLevelPrimitiveObserver> observers = null;
            int index = primitive.Index;

            // This primitive is being removed currently, so all observers will be removed from it anyway.
            if (index == m_removingPrimitive)
            {
                return;
            }

            if (m_primitiveObservers.TryGetValue(index, out observers))
            {
                observers.Remove(observer);
                if (observers.Count == 0)
                {
                    m_primitiveObservers.Remove(index);
                }
            }
            else
            {
                Debug.Assert(false, "The path is not observing this primitive anymore!");
            }
        }
Beispiel #6
0
        public MyHighLevelPrimitive TryGetPrimitive(int index)
        {
            MyHighLevelPrimitive retval = null;

            m_primitives.TryGetValue(index, out retval);
            return(retval);
        }
Beispiel #7
0
        private MyHighLevelPrimitive GetClosestHighLevelPrimitive(ref Vector3 point, ref float closestDistanceSq)
        {
            MyHighLevelPrimitive primitive = null;

            m_tmpIntList.Clear();
            Vector3I vectori = Vector3I.Round((point + (this.m_voxelMap.PositionComp.GetPosition() - this.m_voxelMap.PositionLeftBottomCorner)) / this.m_cellSize);

            for (int i = 0; i < 8; i++)
            {
                Vector3I coordInLod  = (Vector3I)(vectori + m_cornerOffsets[i]);
                ulong    packedCoord = new MyCellCoord(0, coordInLod).PackId64();
                this.m_higherLevelHelper.CollectComponents(packedCoord, m_tmpIntList);
            }
            foreach (int num3 in m_tmpIntList)
            {
                MyHighLevelPrimitive primitive2 = this.m_higherLevel.GetPrimitive(num3);
                if (primitive2 != null)
                {
                    float num4 = Vector3.DistanceSquared(primitive2.Position, point);
                    if (num4 < closestDistanceSq)
                    {
                        closestDistanceSq = num4;
                        primitive         = primitive2;
                    }
                }
            }
            m_tmpIntList.Clear();
            return(primitive);
        }
Beispiel #8
0
 public void IgnoreHighLevel(MyHighLevelPrimitive primitive)
 {
     if (!this.m_ignoredPrimitives.Contains(primitive))
     {
         primitive.Parent.ObservePrimitive(primitive, this);
         this.m_ignoredPrimitives.Add(primitive);
     }
 }
Beispiel #9
0
 public void GetPrimitivesOnPath(ref List <MyHighLevelPrimitive> primitives)
 {
     foreach (KeyValuePair <int, List <IMyHighLevelPrimitiveObserver> > pair in this.m_primitiveObservers)
     {
         MyHighLevelPrimitive item = this.TryGetPrimitive(pair.Key);
         primitives.Add(item);
     }
 }
Beispiel #10
0
        private void UpdateHighLevelPrimitives(ref MyNavmeshComponents.ClosedCellInfo cellInfo)
        {
            int startingIndex = cellInfo.StartingIndex;

            foreach (MyNavigationTriangle triangle in this.m_tmpComponentTriangles)
            {
                if (triangle == null)
                {
                    startingIndex++;
                    continue;
                }
                triangle.ComponentIndex = startingIndex;
            }
            this.m_tmpComponentTriangles.Clear();
            if (!cellInfo.NewCell && (cellInfo.ComponentNum != cellInfo.OldComponentNum))
            {
                for (int j = 0; j < cellInfo.OldComponentNum; j++)
                {
                    this.m_mesh.HighLevelGroup.RemovePrimitive(cellInfo.OldStartingIndex + j);
                }
            }
            if (cellInfo.NewCell || (cellInfo.ComponentNum != cellInfo.OldComponentNum))
            {
                for (int j = 0; j < cellInfo.ComponentNum; j++)
                {
                    this.m_mesh.HighLevelGroup.AddPrimitive(cellInfo.StartingIndex + j, this.m_navmeshComponents.GetComponentCenter(j));
                }
            }
            if (!cellInfo.NewCell && (cellInfo.ComponentNum == cellInfo.OldComponentNum))
            {
                for (int j = 0; j < cellInfo.ComponentNum; j++)
                {
                    this.m_mesh.HighLevelGroup.GetPrimitive(cellInfo.StartingIndex + j).UpdatePosition(this.m_navmeshComponents.GetComponentCenter(j));
                }
            }
            for (int i = 0; i < cellInfo.ComponentNum; i++)
            {
                int index = cellInfo.StartingIndex + i;
                this.m_mesh.HighLevelGroup.GetPrimitive(index).GetNeighbours(this.m_tmpNeighbors);
                foreach (ConnectionInfo info in this.m_currentCellConnections[i])
                {
                    if (!this.m_tmpNeighbors.Remove(info.ComponentIndex))
                    {
                        this.m_mesh.HighLevelGroup.ConnectPrimitives(index, info.ComponentIndex);
                    }
                }
                foreach (int num7 in this.m_tmpNeighbors)
                {
                    MyHighLevelPrimitive primitive = this.m_mesh.HighLevelGroup.TryGetPrimitive(num7);
                    if ((primitive != null) && primitive.IsExpanded)
                    {
                        this.m_mesh.HighLevelGroup.DisconnectPrimitives(index, num7);
                    }
                }
                this.m_tmpNeighbors.Clear();
                this.m_currentCellConnections[i].Clear();
            }
        }
Beispiel #11
0
        public MyHighLevelPrimitive GetPrimitive(int index)
        {
            MyHighLevelPrimitive retval = null;

            m_primitives.TryGetValue(index, out retval);

            Debug.Assert(retval != null, "High-level primitive not found!");
            return(retval);
        }
Beispiel #12
0
 public void IgnoreHighLevel(MyHighLevelPrimitive primitive)
 {
     if (!m_ignoredPrimitives.Contains(primitive))
     {
         primitive.Parent.ObservePrimitive(primitive, this);
         bool added = m_ignoredPrimitives.Add(primitive);
         Debug.Assert(added);
     }
 }
Beispiel #13
0
        private void Connect(int a, int b)
        {
            MyHighLevelPrimitive primitive  = this.GetPrimitive(a);
            MyHighLevelPrimitive primitive2 = this.GetPrimitive(b);

            if ((primitive != null) && (primitive2 != null))
            {
                primitive.Connect(b);
                primitive2.Connect(a);
            }
        }
Beispiel #14
0
 public void GetPrimitivesOnPath(ref List <MyHighLevelPrimitive> primitives)
 {
     // primitives on a path are observed...
     foreach (var v in m_primitiveObservers)
     {
         // get high level primitive
         MyHighLevelPrimitive primitive = TryGetPrimitive(v.Key);
         Debug.Assert(primitive != null); // observer primitive should be in primitives
         primitives.Add(primitive);
     }
 }
Beispiel #15
0
 public void DebugDraw()
 {
     if (MyFakes.DEBUG_DRAW_NAVMESH_EXPLORED_HL_CELLS)
     {
         foreach (Vector3I vectori in this.m_exploredCells)
         {
             BoundingBoxD xd;
             MyVoxelCoordSystems.GeometryCellCoordToWorldAABB(this.m_mesh.VoxelMapReferencePosition, ref vectori, out xd);
             MyRenderProxy.DebugDrawAABB(xd, Color.Sienna, 1f, 1f, false, false, false);
         }
     }
     if (MyFakes.DEBUG_DRAW_NAVMESH_FRINGE_HL_CELLS)
     {
         foreach (ulong num in this.m_navmeshComponents.GetPresentCells())
         {
             MyCellCoord coord = new MyCellCoord();
             coord.SetUnpack(num);
             Vector3I coordInLod = coord.CoordInLod;
             if (this.m_exploredCells.Contains(ref coordInLod))
             {
                 MyNavmeshComponents.CellInfo cellInfo = new MyNavmeshComponents.CellInfo();
                 if (this.m_navmeshComponents.TryGetCell(num, out cellInfo))
                 {
                     int num2 = 0;
                     while (num2 < cellInfo.ComponentNum)
                     {
                         int index = cellInfo.StartingIndex + num2;
                         MyHighLevelPrimitive        primitive      = this.m_mesh.HighLevelGroup.GetPrimitive(index);
                         Base6Directions.Direction[] enumDirections = Base6Directions.EnumDirections;
                         int num4 = 0;
                         while (true)
                         {
                             if (num4 >= enumDirections.Length)
                             {
                                 num2++;
                                 break;
                             }
                             Base6Directions.Direction      dir           = enumDirections[num4];
                             Base6Directions.DirectionFlags directionFlag = Base6Directions.GetDirectionFlag(dir);
                             if (!cellInfo.ExploredDirections.HasFlag(directionFlag) && !this.m_exploredCells.Contains((Vector3I)(coordInLod + Base6Directions.GetIntVector(dir))))
                             {
                                 Vector3 vector = Base6Directions.GetVector(dir);
                                 MyRenderProxy.DebugDrawLine3D(primitive.WorldPosition, primitive.WorldPosition + (vector * 3f), Color.Red, Color.Red, false, false);
                             }
                             num4++;
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #16
0
 public void ObservePrimitive(MyHighLevelPrimitive primitive, IMyHighLevelPrimitiveObserver observer)
 {
     if (ReferenceEquals(primitive.Parent, this))
     {
         List <IMyHighLevelPrimitiveObserver> list = null;
         int index = primitive.Index;
         if (!this.m_primitiveObservers.TryGetValue(index, out list))
         {
             list = new List <IMyHighLevelPrimitiveObserver>(4);
             this.m_primitiveObservers.Add(index, list);
         }
         list.Add(observer);
     }
 }
Beispiel #17
0
        public void DebugDraw(bool lite)
        {
            long lastHighLevelTimestamp = MyCestmirPathfindingShorts.Pathfinding.LastHighLevelTimestamp;

            foreach (KeyValuePair <int, MyHighLevelPrimitive> pair in this.m_primitives)
            {
                if (lite)
                {
                    MyRenderProxy.DebugDrawPoint(pair.Value.WorldPosition, Color.CadetBlue, false, false);
                    continue;
                }
                MyHighLevelPrimitive primitive = pair.Value;
                Vector3D             vectord   = MySector.MainCamera.WorldMatrix.Down * 0.30000001192092896;
                float num2  = (float)Vector3D.Distance(primitive.WorldPosition, MySector.MainCamera.Position);
                float scale = 7f / num2;
                if (scale > 30f)
                {
                    scale = 30f;
                }
                if (scale < 0.5f)
                {
                    scale = 0.5f;
                }
                if (num2 < 100f)
                {
                    List <IMyHighLevelPrimitiveObserver> list = null;
                    if (this.m_primitiveObservers.TryGetValue(pair.Key, out list))
                    {
                        MyRenderProxy.DebugDrawText3D(primitive.WorldPosition + vectord, list.Count.ToString(), Color.Red, scale * 3f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false);
                    }
                    MyRenderProxy.DebugDrawText3D(primitive.WorldPosition + vectord, pair.Key.ToString(), Color.CadetBlue, scale, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false);
                }
                int index = 0;
                while (true)
                {
                    if (index >= primitive.GetOwnNeighborCount())
                    {
                        if (primitive.PathfindingData.GetTimestamp() == lastHighLevelTimestamp)
                        {
                            MyRenderProxy.DebugDrawSphere(primitive.WorldPosition, 0.5f, Color.DarkRed, 1f, false, false, true, false);
                        }
                        break;
                    }
                    MyHighLevelPrimitive ownNeighbor = primitive.GetOwnNeighbor(index) as MyHighLevelPrimitive;
                    MyRenderProxy.DebugDrawLine3D(primitive.WorldPosition, ownNeighbor.WorldPosition, Color.CadetBlue, Color.CadetBlue, false, false);
                    index++;
                }
            }
        }
Beispiel #18
0
 public void StopObservingPrimitive(MyHighLevelPrimitive primitive, IMyHighLevelPrimitiveObserver observer)
 {
     if (ReferenceEquals(primitive.Parent, this))
     {
         List <IMyHighLevelPrimitiveObserver> list = null;
         int index = primitive.Index;
         if ((index != this.m_removingPrimitive) && this.m_primitiveObservers.TryGetValue(index, out list))
         {
             list.Remove(observer);
             if (list.Count == 0)
             {
                 this.m_primitiveObservers.Remove(index);
             }
         }
     }
 }
Beispiel #19
0
 private void ClearFirstPathNode()
 {
     using (List <MyHighLevelPrimitive> .Enumerator enumerator = this.m_pathNodes.GetEnumerator())
     {
         if (enumerator.MoveNext())
         {
             MyHighLevelPrimitive current = enumerator.Current;
             if (!ReferenceEquals(current, this.m_hlBegin))
             {
                 current.Parent.StopObservingPrimitive(current, this);
             }
         }
     }
     this.m_pathNodes.RemoveAt(0);
     this.m_pathNodePosition--;
 }
Beispiel #20
0
 public void ProcessCellComponents()
 {
     this.m_triangleLists.Add(this.m_packedCoord, this.m_triangleList.GetCopy());
     MyNavmeshComponents.ClosedCellInfo cellInfo = this.ConstructComponents();
     this.UpdateHighLevelPrimitives(ref cellInfo);
     this.MarkExploredDirections(ref cellInfo);
     for (int i = 0; i < cellInfo.ComponentNum; i++)
     {
         int index = cellInfo.StartingIndex + i;
         MyHighLevelPrimitive primitive = this.m_mesh.HighLevelGroup.GetPrimitive(index);
         if (primitive != null)
         {
             primitive.IsExpanded = true;
         }
     }
 }
Beispiel #21
0
        public void DebugDraw()
        {
            MatrixD  viewMatrix = MySector.MainCamera.ViewMatrix;
            Vector3D?nullable   = null;

            foreach (MyHighLevelPrimitive local1 in this.m_pathNodes)
            {
                Vector3D down = MyGravityProviderSystem.CalculateTotalGravityInPoint(local1.WorldPosition);
                if (Vector3D.IsZero(down, 0.001))
                {
                    down = Vector3D.Down;
                }
                down.Normalize();
                MyHighLevelPrimitive local2   = local1;
                Vector3D             position = local2.WorldPosition + (down * -10.0);
                MyRenderProxy.DebugDrawSphere(position, 1f, Color.IndianRed, 1f, false, false, true, false);
                MyRenderProxy.DebugDrawLine3D(local2.WorldPosition, position, Color.IndianRed, Color.IndianRed, false, false);
                if (nullable != null)
                {
                    MyRenderProxy.DebugDrawLine3D(position, nullable.Value, Color.IndianRed, Color.IndianRed, false, false);
                }
                nullable = new Vector3D?(position);
            }
            MyRenderProxy.DebugDrawSphere(this.m_startPoint, 0.5f, Color.HotPink, 1f, false, false, true, false);
            if (this.m_goal != null)
            {
                this.m_goal.DebugDraw();
            }
            if (MyFakes.DEBUG_DRAW_FOUND_PATH)
            {
                Vector3D?nullable2 = null;
                for (int i = 0; i < this.m_expandedPath.Count; i++)
                {
                    Vector3D position = new Vector3D(this.m_expandedPath[i]);
                    float    w        = (float)this.m_expandedPath[i].W;
                    Color    color    = (i == (this.m_expandedPath.Count - 1)) ? Color.OrangeRed : Color.Orange;
                    MyRenderProxy.DebugDrawPoint(position, color, false, false);
                    MyRenderProxy.DebugDrawText3D(position + (viewMatrix.Right * 0.10000000149011612), w.ToString(), color, 0.7f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false);
                    if (nullable2 != null)
                    {
                        MyRenderProxy.DebugDrawLine3D(nullable2.Value, position, Color.Pink, Color.Pink, false, false);
                    }
                    nullable2 = new Vector3D?(position);
                }
            }
        }
Beispiel #22
0
        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();
        }
Beispiel #23
0
 public void ClearCachedCell(ulong packedCoord)
 {
     MyNavmeshComponents.CellInfo info;
     this.m_triangleLists.Remove(packedCoord);
     if (this.m_navmeshComponents.TryGetCell(packedCoord, out info))
     {
         for (int i = 0; i < info.ComponentNum; i++)
         {
             int index = info.StartingIndex + i;
             MyHighLevelPrimitive primitive = this.m_mesh.HighLevelGroup.GetPrimitive(index);
             if (primitive != null)
             {
                 primitive.IsExpanded = false;
             }
         }
     }
 }
Beispiel #24
0
        public void RemovePrimitive(int index)
        {
            m_removingPrimitive = index;
            MyHighLevelPrimitive primitive = null;

            if (!m_primitives.TryGetValue(index, out primitive))
            {
                Debug.Assert(false, "Could not find the primitive to remove!");
                m_removingPrimitive = -1;
                return;
            }

            List <IMyHighLevelPrimitiveObserver> observers = null;

            if (m_primitiveObservers.TryGetValue(index, out observers))
            {
                foreach (var path in observers)
                {
                    path.Invalidate();
                }
            }
            m_primitiveObservers.Remove(index);

            m_links.RemoveAllLinks(primitive);

            m_tmpNeighbors.Clear();
            primitive.GetNeighbours(m_tmpNeighbors);

            foreach (var neighborIndex in m_tmpNeighbors)
            {
                MyHighLevelPrimitive neighbor = null;
                m_primitives.TryGetValue(neighborIndex, out neighbor);

                Debug.Assert(neighbor != null, "Could not find the neighbor of a high-level primitive!");
                if (neighbor == null)
                {
                    continue;
                }

                neighbor.Disconnect(index);
            }

            m_primitives.Remove(index);
            m_removingPrimitive = -1;
        }
Beispiel #25
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);
        }
Beispiel #26
0
        private static float HlCriterion(MyNavigationPrimitive primitive)
        {
            MyHighLevelPrimitive item = primitive as MyHighLevelPrimitive;

            if ((item == null) || m_pathfindingStatic.m_ignoredPrimitives.Contains(item))
            {
                return(float.PositiveInfinity);
            }
            float num = m_pathfindingStatic.m_destination.PointAdmissibility(primitive.WorldPosition, 8.7f);

            if (num < float.PositiveInfinity)
            {
                return(num * 4f);
            }
            IMyHighLevelComponent component = item.GetComponent();

            return((component != null) ? (component.FullyExplored ? float.PositiveInfinity : (((float)Vector3D.RectangularDistance(primitive.WorldPosition, m_pathfindingStatic.m_destinationCenter)) * 8f)) : float.PositiveInfinity);
        }
        private MyHighLevelPrimitive GetClosestHighLevelPrimitive(ref Vector3 point, ref float closestDistanceSq)
        {
            MyHighLevelPrimitive retval = null;

            // Convert from world matrix local coords to LeftBottomCorner-based coords
            Vector3 lbcPoint = point + (m_voxelMap.PositionComp.GetPosition() - m_voxelMap.PositionLeftBottomCorner);

            m_tmpIntList.Clear();

            // Collect components from the eight closest cells
            Vector3I closestCellCorner = Vector3I.Round(lbcPoint / m_cellSize);

            for (int i = 0; i < 8; ++i)
            {
                Vector3I cell = closestCellCorner + m_cornerOffsets[i];

                MyCellCoord coord       = new MyCellCoord(NAVMESH_LOD, cell);
                ulong       packedCoord = coord.PackId64();

                m_higherLevelHelper.CollectComponents(packedCoord, m_tmpIntList);
            }

            foreach (int componentIndex in m_tmpIntList)
            {
                var hlPrimitive = m_higherLevel.GetPrimitive(componentIndex);
                Debug.Assert(hlPrimitive != null, "Couldnt' find a high-level primitive for the index given by higher level helper!");
                if (hlPrimitive == null)
                {
                    continue;
                }

                float distSq = Vector3.DistanceSquared(hlPrimitive.Position, point);
                if (distSq < closestDistanceSq)
                {
                    closestDistanceSq = distSq;
                    retval            = hlPrimitive;
                }
            }

            m_tmpIntList.Clear();

            return(retval);
        }
        public IMyHighLevelComponent GetComponent(MyHighLevelPrimitive primitive)
        {
            ulong cellIndex;

            if (m_navmeshComponents.GetComponentCell(primitive.Index, out cellIndex))
            {
                Base6Directions.DirectionFlags exploredDirections;

                if (m_navmeshComponents.GetComponentInfo(primitive.Index, cellIndex, out exploredDirections))
                {
                    MyCellCoord coord = new MyCellCoord();
                    coord.SetUnpack(cellIndex);

                    // Look at present unexplored cells around this cell.
                    // Their direction can be marked as explored, because there was no geometry when they were being explored
                    foreach (var direction in Base6Directions.EnumDirections)
                    {
                        var directionFlag = Base6Directions.GetDirectionFlag(direction);
                        if (exploredDirections.HasFlag(directionFlag))
                        {
                            continue;
                        }

                        Vector3I neighbor = coord.CoordInLod + Base6Directions.GetIntVector(direction);
                        if (m_exploredCells.Contains(ref neighbor))
                        {
                            exploredDirections |= directionFlag;
                        }
                    }

                    return(new Component(primitive.Index, exploredDirections));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #29
0
 public void Invalidate()
 {
     if (this.m_valid)
     {
         this.ClearPathNodes();
         this.m_expandedPath.Clear();
         this.m_expandedPathPosition = 0;
         this.m_currentPrimitive     = null;
         if (this.m_goal.IsValid)
         {
             this.m_goal.Invalidate();
         }
         if (this.m_hlBegin != null)
         {
             this.m_hlBegin.Parent.StopObservingPrimitive(this.m_hlBegin, this);
         }
         this.m_hlBegin = null;
         this.m_valid   = false;
     }
 }
Beispiel #30
0
        public void ObservePrimitive(MyHighLevelPrimitive primitive, IMyHighLevelPrimitiveObserver observer)
        {
            Debug.Assert(primitive.Parent == this);
            if (primitive.Parent != this)
            {
                return;
            }

            List <IMyHighLevelPrimitiveObserver> observers = null;
            int index = primitive.Index;

            if (!m_primitiveObservers.TryGetValue(index, out observers))
            {
                observers = new List <IMyHighLevelPrimitiveObserver>(4);
                m_primitiveObservers.Add(index, observers);
            }

            Debug.Assert(!observers.Contains(observer), "The given path is already observing the primitive!");
            observers.Add(observer);
        }
 public override IMyHighLevelComponent GetComponent(MyHighLevelPrimitive highLevelPrimitive)
 {
     return m_higherLevelHelper.GetComponent(highLevelPrimitive);
 }
        public void Reinit(Vector3D newStart)
        {
            var previousGoal = m_goal;
            var previousEntity = previousGoal.EndEntity;

            ClearPathNodes();

            m_expandedPath.Clear();
            m_expandedPathPosition = 0;
            m_currentPrimitive = null;

            if (m_hlBegin != null)
            {
                m_hlBegin.Parent.StopObservingPrimitive(m_hlBegin, this);
            }
            m_hlBegin = null;

            m_valid = false;

            m_goal.Reinit();
            Init(newStart, previousGoal);
        }
        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();
        }
Beispiel #34
0
 public void IgnoreHighLevel(MyHighLevelPrimitive primitive)
 {
     if (!m_ignoredPrimitives.Contains(primitive))
     {
         primitive.Parent.ObservePrimitive(primitive, this);
         bool added = m_ignoredPrimitives.Add(primitive);
         Debug.Assert(added);
     }
 }
        public IMyHighLevelComponent GetComponent(MyHighLevelPrimitive primitive)
        {
            ulong cellIndex;
            if (m_navmeshComponents.GetComponentCell(primitive.Index, out cellIndex))
            {
                Base6Directions.DirectionFlags exploredDirections;
                
                if (m_navmeshComponents.GetComponentInfo(primitive.Index, cellIndex, out exploredDirections))
                {
                    MyCellCoord coord = new MyCellCoord();
                    coord.SetUnpack(cellIndex);

                    // Look at present unexplored cells around this cell.
                    // Their direction can be marked as explored, because there was no geometry when they were being explored
                    foreach (var direction in Base6Directions.EnumDirections)
                    {
                        var directionFlag = Base6Directions.GetDirectionFlag(direction);
                        if (exploredDirections.HasFlag(directionFlag))
                        {
                            continue;
                        }

                        Vector3I neighbor = coord.CoordInLod + Base6Directions.GetIntVector(direction);
                        if (m_exploredCells.Contains(ref neighbor))
                        {
                            exploredDirections |= directionFlag;
                        }
                    }

                    return new Component(primitive.Index, exploredDirections);
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
        public void Invalidate()
        {
            if (m_valid == false)
            {
                return;
            }

            ClearPathNodes();

            m_expandedPath.Clear();
            m_expandedPathPosition = 0;

            m_currentPrimitive = null;

            if (m_goal.IsValid)
            {
                m_goal.Invalidate();
            }
            if (m_hlBegin != null)
            {
                m_hlBegin.Parent.StopObservingPrimitive(m_hlBegin, this);
            }
            m_hlBegin = null;

            m_valid = false;
        }
Beispiel #37
0
        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;
        }
        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");
            m_currentPrimitive = m_pathfinding.FindClosestPrimitive(start, highLevel: false);
            if (m_currentPrimitive != null)
            {
                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))
                {
                    m_hlBegin.Parent.ObservePrimitive(m_hlBegin, this);
                }
            }
            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();
        }
 public override IMyHighLevelComponent GetComponent(MyHighLevelPrimitive highLevelPrimitive)
 {
     return new Component(this, highLevelPrimitive.Index);
 }