Esempio n. 1
0
        public MyVoxelNavigationMesh GetVoxelMapNavmesh(MyVoxelBase map)
        {
            MyVoxelNavigationMesh retval = null;

            m_navigationMeshes.TryGetValue(map, out retval);
            return(retval);
        }
Esempio n. 2
0
        public MyNavigationPrimitive FindClosestPrimitive(Vector3D point, bool highLevel, ref double closestDistanceSq, MyVoxelBase voxelMap = null)
        {
            MyNavigationPrimitive retval = null;

            if (voxelMap != null)
            {
                MyVoxelNavigationMesh mesh = null;
                if (m_navigationMeshes.TryGetValue(voxelMap, out mesh))
                {
                    retval = mesh.FindClosestPrimitive(point, highLevel, ref closestDistanceSq);
                }
            }
            else
            {
                foreach (var entry in m_navigationMeshes)
                {
                    MyNavigationPrimitive closest = entry.Value.FindClosestPrimitive(point, highLevel, ref closestDistanceSq);
                    if (closest != null)
                    {
                        retval = closest;
                    }
                }
            }

            return(retval);
        }
Esempio n. 3
0
        public MyVoxelNavigationMesh GetVoxelMapNavmesh(MyVoxelBase map)
        {
            MyVoxelNavigationMesh mesh = null;

            this.m_navigationMeshes.TryGetValue(map, out mesh);
            return(mesh);
        }
Esempio n. 4
0
        private void PerformCellMarking(List <Vector3D> updatePositions)
        {
            ProfilerShort.Begin("Cell marking");
            Vector3D offset = new Vector3D(1.0f);

            foreach (var pos in updatePositions)
            {
                BoundingBoxD box = new BoundingBoxD(pos - offset, pos + offset);

                ProfilerShort.Begin("GetVoxelMaps");
                m_tmpVoxelMaps.Clear();
                MyGamePruningStructure.GetAllVoxelMapsInBox(ref box, m_tmpVoxelMaps);
                ProfilerShort.End();

                foreach (var map in m_tmpVoxelMaps)
                {
                    MyVoxelNavigationMesh mesh = null;
                    m_navigationMeshes.TryGetValue(map, out mesh);
                    if (mesh == null)
                    {
                        continue;
                    }

                    mesh.MarkBoxForAddition(box);
                }
            }
            m_tmpVoxelMaps.Clear();
            ProfilerShort.End();
        }
Esempio n. 5
0
        public MyNavigationPrimitive FindClosestPrimitive(Vector3D point, bool highLevel, ref double closestDistanceSq, MyVoxelBase voxelMap = null)
        {
            MyNavigationPrimitive primitive = null;

            if (voxelMap != null)
            {
                MyVoxelNavigationMesh mesh = null;
                if (this.m_navigationMeshes.TryGetValue(voxelMap, out mesh))
                {
                    primitive = mesh.FindClosestPrimitive(point, highLevel, ref closestDistanceSq);
                }
            }
            else
            {
                foreach (KeyValuePair <MyVoxelBase, MyVoxelNavigationMesh> pair in this.m_navigationMeshes)
                {
                    MyNavigationPrimitive primitive2 = pair.Value.FindClosestPrimitive(point, highLevel, ref closestDistanceSq);
                    if (primitive2 != null)
                    {
                        primitive = primitive2;
                    }
                }
            }
            return(primitive);
        }
Esempio n. 6
0
 public MyVoxelHighLevelHelper(MyVoxelNavigationMesh mesh)
 {
     this.m_mesh                   = mesh;
     this.m_triangleList           = new MyIntervalList();
     this.m_triangleLists          = new Dictionary <ulong, MyIntervalList>();
     this.m_exploredCells          = new MyVector3ISet();
     this.m_navmeshComponents      = new MyNavmeshComponents();
     this.m_currentCellConnections = new List <List <ConnectionInfo> >();
     for (int i = 0; i < 8; i++)
     {
         this.m_currentCellConnections.Add(new List <ConnectionInfo>());
     }
 }
        public MyVoxelHighLevelHelper(MyVoxelNavigationMesh mesh)
        {
            m_mesh = mesh;
            m_triangleList = new MyIntervalList();

            m_triangleLists = new Dictionary<ulong, MyIntervalList>();
            m_exploredCells = new MyVector3ISet();
            m_navmeshComponents = new MyNavmeshComponents();

            m_currentCellConnections = new List<List<ConnectionInfo>>();
            for (int i = 0; i < 8; ++i)
            {
                m_currentCellConnections.Add(new List<ConnectionInfo>());
            }
        }
Esempio n. 8
0
        private void PerformCellMarking(List <Vector3D> updatePositions)
        {
            Vector3D vectord = new Vector3D(1.0);

            foreach (Vector3D vectord2 in updatePositions)
            {
                BoundingBoxD box = new BoundingBoxD(vectord2 - vectord, vectord2 + vectord);
                this.m_tmpVoxelMaps.Clear();
                MyGamePruningStructure.GetAllVoxelMapsInBox(ref box, this.m_tmpVoxelMaps);
                foreach (MyVoxelBase base2 in this.m_tmpVoxelMaps)
                {
                    MyVoxelNavigationMesh mesh = null;
                    this.m_navigationMeshes.TryGetValue(base2, out mesh);
                    if (mesh != null)
                    {
                        mesh.MarkBoxForAddition(box);
                    }
                }
            }
            this.m_tmpVoxelMaps.Clear();
        }
Esempio n. 9
0
 public void LogCellRemoval(MyVoxelNavigationMesh navMesh, Vector3I cell)
 {
     m_log.WriteLine("NMOP: " + navMesh.ToString() + " REM " + cell.ToString());
 }
Esempio n. 10
0
 public void LogCellAddition(MyVoxelNavigationMesh navMesh, Vector3I cell)
 {
     m_log.WriteLine("NMOP: " + navMesh.ToString() + " ADD " + cell.ToString());
 }
 public void LogCellRemoval(MyVoxelNavigationMesh navMesh, Vector3I cell)
 {
     m_log.WriteLine("NMOP: " + navMesh.ToString() + " REM " + cell.ToString());
 }
 public void LogCellAddition(MyVoxelNavigationMesh navMesh, Vector3I cell)
 {
     m_log.WriteLine("NMOP: " + navMesh.ToString() + " ADD " + cell.ToString());
 }
Esempio n. 13
0
        public void Update()
        {
            ProfilerShort.Begin("MyVoxelPathfinding.Update");

            if (++m_updateCtr >= UPDATE_PERIOD)
            {
                m_tmpUpdatePositions.Clear();
                m_updateCtr = 0;

                var players = Sync.Players.GetOnlinePlayers();
                foreach (var player in players)
                {
                    var controlledEntity = player.Controller.ControlledEntity;
                    if (controlledEntity == null)
                    {
                        continue;
                    }

                    m_tmpUpdatePositions.Add(controlledEntity.Entity.PositionComp.GetPosition());
                }

                m_tmpNavmeshes.Clear();

                ProfilerShort.Begin("Cell marking");
                Vector3D offset = new Vector3D(20.0f);
                foreach (var pos in m_tmpUpdatePositions)
                {
                    BoundingBoxD box = new BoundingBoxD(pos - offset, pos + offset);

                    ProfilerShort.Begin("GetVoxelMaps");
                    m_tmpVoxelMaps.Clear();
                    MyGamePruningStructure.GetAllVoxelMapsInBox(ref box, m_tmpVoxelMaps);
                    ProfilerShort.End();

                    foreach (var map in m_tmpVoxelMaps)
                    {
                        MyVoxelNavigationMesh mesh = null;
                        m_navigationMeshes.TryGetValue(map, out mesh);
                        Debug.Assert(mesh != null, "Navigation mesh for a voxel map is not generated!");
                        if (mesh == null)
                        {
                            continue;
                        }

                        mesh.MarkBoxForAddition(box);

                        if (!m_tmpNavmeshes.Contains(mesh))
                        {
                            m_tmpNavmeshes.Add(mesh);
                        }
                    }
                }
                m_tmpVoxelMaps.Clear();
                ProfilerShort.End();

                m_tmpNavmeshes.Clear();

                ProfilerShort.Begin("Cell additions");
                foreach (var mesh in m_navigationMeshes)
                {
                    m_tmpNavmeshes.Add(mesh.Value);
                }
                m_tmpNavmeshes.ShuffleList();

                foreach (var mesh in m_tmpNavmeshes)
                {
                    if (mesh.AddOneMarkedCell())
                    {
                        // Break after the first added cell
                        break;
                    }
                }
                ProfilerShort.End();

                ProfilerShort.Begin("Cell removals");
                foreach (var mesh in m_tmpNavmeshes)
                {
                    if (mesh.RemoveOneUnusedCell(m_tmpUpdatePositions))
                    {
                        // Break after the first removed cell
                        break;
                    }
                }
                ProfilerShort.End();

                m_tmpNavmeshes.Clear();
                m_tmpUpdatePositions.Clear();
            }

            ProfilerShort.End();
        }