Exemplo n.º 1
0
        private void IncreaseGridLinkCounter(MyGridPathfinding.CubeId candidate)
        {
            int num = 0;

            num = this.m_gridLinkCounter.TryGetValue(candidate, out num) ? (num + 1) : 1;
            this.m_gridLinkCounter[candidate] = num;
        }
Exemplo n.º 2
0
 public override bool Equals(object obj)
 {
     if (!(obj is MyGridPathfinding.CubeId))
     {
         return(false);
     }
     MyGridPathfinding.CubeId id = (MyGridPathfinding.CubeId)obj;
     return(ReferenceEquals(id.Grid, this.Grid) && (id.Coords == this.Coords));
 }
Exemplo n.º 3
0
        private void IncreaseGridLinkCounter(MyGridPathfinding.CubeId candidate)
        {
            int counter = 0;

            if (!m_gridLinkCounter.TryGetValue(candidate, out counter))
            {
                counter = 1;
            }
            else
            {
                counter++;
            }
            m_gridLinkCounter[candidate] = counter;
        }
Exemplo n.º 4
0
        public void RemoveGridNavmeshLinks(MyCubeGrid grid)
        {
            var navmesh = m_gridPathfinding.GetNavmesh(grid);

            if (navmesh == null)
            {
                Debug.Assert(false, "Navmesh for a grid not found!");
                return;
            }

            m_tmpNavPrims.Clear();

            var enumerator = navmesh.GetCubes();

            while (enumerator.MoveNext())
            {
                MyGridPathfinding.CubeId cubeId = new MyGridPathfinding.CubeId()
                {
                    Grid = grid, Coords = enumerator.Current
                };
                int counter;
                if (m_gridLinkCounter.TryGetValue(cubeId, out counter))
                {
                    m_tmpNavTris.Clear();
                    navmesh.GetCubeTriangles(enumerator.Current, m_tmpNavTris);

                    foreach (var tri in m_tmpNavTris)
                    {
                        m_links.RemoveAllLinks(tri);

                        var hlPrim = tri.GetHighLevelPrimitive();
                        if (!m_tmpNavPrims.Contains(hlPrim))
                        {
                            m_tmpNavPrims.Add(hlPrim);
                        }
                    }

                    m_tmpNavTris.Clear();
                    m_gridLinkCounter.Remove(cubeId);
                }
            }
            enumerator.Dispose();

            foreach (var highLevelPrim in m_tmpNavPrims)
            {
                m_highLevelLinks.RemoveAllLinks(highLevelPrim);
            }
            m_tmpNavPrims.Clear();
        }
Exemplo n.º 5
0
        private void DecreaseGridLinkCounter(MyGridPathfinding.CubeId candidate)
        {
            int num = 0;

            if (this.m_gridLinkCounter.TryGetValue(candidate, out num))
            {
                num--;
                if (num == 0)
                {
                    this.m_gridLinkCounter.Remove(candidate);
                }
                else
                {
                    this.m_gridLinkCounter[candidate] = num;
                }
            }
        }
Exemplo n.º 6
0
        public void RemoveGridNavmeshLinks(MyCubeGrid grid)
        {
            MyGridNavigationMesh navmesh = this.m_gridPathfinding.GetNavmesh(grid);

            if (navmesh != null)
            {
                m_tmpNavPrims.Clear();
                MyVector3ISet.Enumerator cubes = navmesh.GetCubes();
                while (cubes.MoveNext())
                {
                    int num;
                    MyGridPathfinding.CubeId key = new MyGridPathfinding.CubeId {
                        Grid   = grid,
                        Coords = cubes.Current
                    };
                    if (this.m_gridLinkCounter.TryGetValue(key, out num))
                    {
                        m_tmpNavTris.Clear();
                        navmesh.GetCubeTriangles(cubes.Current, m_tmpNavTris);
                        foreach (MyNavigationTriangle triangle in m_tmpNavTris)
                        {
                            this.m_links.RemoveAllLinks(triangle);
                            MyHighLevelPrimitive highLevelPrimitive = triangle.GetHighLevelPrimitive();
                            if (!m_tmpNavPrims.Contains(highLevelPrimitive))
                            {
                                m_tmpNavPrims.Add(highLevelPrimitive);
                            }
                        }
                        m_tmpNavTris.Clear();
                        this.m_gridLinkCounter.Remove(key);
                    }
                }
                cubes.Dispose();
                foreach (MyNavigationPrimitive primitive2 in m_tmpNavPrims)
                {
                    this.m_highLevelLinks.RemoveAllLinks(primitive2);
                }
                m_tmpNavPrims.Clear();
            }
        }
Exemplo n.º 7
0
        private void DecreaseGridLinkCounter(MyGridPathfinding.CubeId candidate)
        {
            int counter = 0;

            if (!m_gridLinkCounter.TryGetValue(candidate, out counter))
            {
                Debug.Assert(false, "Grid link counter is inconsistent!");
                return;
            }
            else
            {
                counter--;
            }

            if (counter == 0)
            {
                m_gridLinkCounter.Remove(candidate);
            }
            else
            {
                m_gridLinkCounter[candidate] = counter;
            }
        }
        public void RemoveGridNavmeshLinks(MyCubeGrid grid)
        {
            var navmesh = m_gridPathfinding.GetNavmesh(grid);
            if (navmesh == null)
            {
                Debug.Assert(false, "Navmesh for a grid not found!");
                return;
            }

            m_tmpNavPrims.Clear();

            var enumerator = navmesh.GetCubes();
            while (enumerator.MoveNext())
            {
                MyGridPathfinding.CubeId cubeId = new MyGridPathfinding.CubeId() { Grid = grid, Coords = enumerator.Current };
                int counter;
                if (m_gridLinkCounter.TryGetValue(cubeId, out counter))
                {
                    m_tmpNavTris.Clear();
                    navmesh.GetCubeTriangles(enumerator.Current, m_tmpNavTris);

                    foreach (var tri in m_tmpNavTris)
                    {
                        m_links.RemoveAllLinks(tri);

                        var hlPrim = tri.GetHighLevelPrimitive();
                        if (!m_tmpNavPrims.Contains(hlPrim))
                        {
                            m_tmpNavPrims.Add(hlPrim);
                        }
                    }

                    m_tmpNavTris.Clear();
                    m_gridLinkCounter.Remove(cubeId);
                }
            }
            enumerator.Dispose();

            foreach (var highLevelPrim in m_tmpNavPrims)
            {
                m_highLevelLinks.RemoveAllLinks(highLevelPrim);
            }
            m_tmpNavPrims.Clear();
        }
Exemplo n.º 9
0
        public void TestVoxelNavmeshTriangle(ref Vector3D a, ref Vector3D b, ref Vector3D c, List <MyCubeGrid> gridsToTest, List <MyGridPathfinding.CubeId> linkCandidatesOutput, out bool intersecting)
        {
            Vector3D point = ((a + b) + c) / 3.0;

            if (this.m_obstacles.IsInObstacle(point))
            {
                intersecting = true;
                return;
            }
            Vector3D zero = Vector3D.Zero;

            if (MyPerGameSettings.NavmeshPresumesDownwardGravity)
            {
                zero = Vector3.Down * 2f;
            }
            m_tmpLinkCandidates.Clear();
            intersecting = false;
            using (List <MyCubeGrid> .Enumerator enumerator = gridsToTest.GetEnumerator())
            {
                goto TR_0016;
TR_0008:
                if (intersecting)
                {
                    goto TR_0006;
                }
TR_0016:
                while (true)
                {
                    if (enumerator.MoveNext())
                    {
                        Vector3D   vectord2;
                        Vector3D   vectord3;
                        Vector3D   vectord4;
                        Vector3D   vectord5;
                        MyCubeGrid current = enumerator.Current;
                        MatrixD    worldMatrixNormalizedInv = current.PositionComp.WorldMatrixNormalizedInv;
                        Vector3D.Transform(ref a, ref worldMatrixNormalizedInv, out vectord2);
                        Vector3D.Transform(ref b, ref worldMatrixNormalizedInv, out vectord3);
                        Vector3D.Transform(ref c, ref worldMatrixNormalizedInv, out vectord4);
                        Vector3D.TransformNormal(ref zero, ref worldMatrixNormalizedInv, out vectord5);
                        BoundingBoxD xd = new BoundingBoxD(Vector3D.MaxValue, Vector3D.MinValue);
                        xd.Include(ref vectord2, ref vectord3, ref vectord4);
                        Vector3I vectori  = current.LocalToGridInteger((Vector3)xd.Min);
                        Vector3I vectori2 = current.LocalToGridInteger((Vector3)xd.Max);
                        Vector3I start    = vectori - Vector3I.One;
                        Vector3I end      = (Vector3I)(vectori2 + Vector3I.One);
                        Vector3I_RangeIterator iterator = new Vector3I_RangeIterator(ref start, ref end);
                        while (iterator.IsValid())
                        {
                            if (current.GetCubeBlock(start) != null)
                            {
                                Vector3      min     = (Vector3)((start - Vector3.One) * current.GridSize);
                                Vector3      max     = (start + Vector3.One) * current.GridSize;
                                Vector3      vector3 = (Vector3)((start - Vector3.Half) * current.GridSize);
                                Vector3      vector4 = (start + Vector3.Half) * current.GridSize;
                                BoundingBoxD xd3     = new BoundingBoxD(min, max);
                                BoundingBoxD xd4     = new BoundingBoxD(vector3, vector4);
                                xd3.Include(min + vectord5);
                                xd3.Include(max + vectord5);
                                xd4.Include(vector3 + vectord5);
                                xd4.Include(vector4 + vectord5);
                                if (xd3.IntersectsTriangle(ref vectord2, ref vectord3, ref vectord4))
                                {
                                    if (xd4.IntersectsTriangle(ref vectord2, ref vectord3, ref vectord4))
                                    {
                                        intersecting = true;
                                        break;
                                    }
                                    int num3 = Math.Min(Math.Abs((int)(vectori.Z - start.Z)), Math.Abs((int)(vectori2.Z - start.Z)));
                                    if (((Math.Min(Math.Abs((int)(vectori.X - start.X)), Math.Abs((int)(vectori2.X - start.X))) + Math.Min(Math.Abs((int)(vectori.Y - start.Y)), Math.Abs((int)(vectori2.Y - start.Y)))) + num3) < 3)
                                    {
                                        MyGridPathfinding.CubeId item = new MyGridPathfinding.CubeId {
                                            Grid   = current,
                                            Coords = start
                                        };
                                        m_tmpLinkCandidates.Add(item);
                                    }
                                }
                            }
                            iterator.GetNext(out start);
                        }
                    }
                    else
                    {
                        goto TR_0006;
                    }
                    break;
                }
                goto TR_0008;
            }
TR_0006:
            if (!intersecting)
            {
                for (int i = 0; i < m_tmpLinkCandidates.Count; i++)
                {
                    linkCandidatesOutput.Add(m_tmpLinkCandidates[i]);
                }
            }
            m_tmpLinkCandidates.Clear();
        }