Beispiel #1
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();
        }
Beispiel #2
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();
        }
        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();
        }