Esempio n. 1
0
        private void CollectEdgesBetweenFloorLists(int bx, int by,
                                                   List <NavMeshBuilderFloorDesc> center, int nx, int ny,
                                                   Dictionary <EdgeVertex, List <EdgeVertex> > edgesOut)
        {
            List <NavMeshBuilderFloorDesc> neighbor = GetFloorDescListNoCheck(nx, ny);

            if (neighbor == null)
            {
                return;
            }

            var directionToNeighbor   = NavMeshUtil.DetermineDirection(bx, by, nx, ny);
            var directionFromNeighbor = NavMeshUtil.GetInverseDirection(directionToNeighbor);


            foreach (var floor in center)
            {
                // check if direction to neighbor is blocked.
                if ((floor.DirectionFlags & directionToNeighbor) != 0)
                {
                    continue;
                }

                List <EdgeVertex> list = null;
                foreach (var neighborFloor in neighbor)
                {
                    // check if direction from neighbor is blocked.
                    if ((neighborFloor.DirectionFlags & directionFromNeighbor) != 0)
                    {
                        continue;
                    }

                    if (Math.Abs(floor.Z100i - neighborFloor.Z100i) / 100.0f > m_maxZStep)
                    {
                        continue;
                    }

                    if (list == null)
                    {
                        var p0 = new EdgeVertex {
                            BX = (ushort)bx, BY = (ushort)by, Z100i = floor.Z100i
                        };
                        if (!edgesOut.TryGetValue(p0, out list))
                        {
                            list = new List <EdgeVertex>();
                            edgesOut.Add(p0, list);
                        }
                    }

                    list.Add(new EdgeVertex {
                        BX = (ushort)nx, BY = (ushort)ny, Z100i = neighborFloor.Z100i
                    });

                    break; // each floor connects to 0 or 1 neighbor in 1 direction.
                }
            }
        }
Esempio n. 2
0
        //private void RemoveSteepEdges(Dictionary<EdgeVertex, List<EdgeVertex>> edges)
        //{
        //    // foreach KEY,
        //    //  if slope is too steep to vertex in VALUE,
        //    //   remove vertex from VALUE
        //    //   find KEY=vertex, remove KEY from vertex's VALUE.
        //    // remove all KEYs with VALUE count = 0
        //    //
        //}

        private List <HashSet <EdgeVertex> > ComputeSubgraphs(Dictionary <EdgeVertex, List <EdgeVertex> > edges)
        {
            var subgraphs    = new List <HashSet <EdgeVertex> >();
            var totalVisited = new HashSet <EdgeVertex>();

            foreach (var startVertex in edges.Keys)
            {
                if (totalVisited.Contains(startVertex))
                {
                    continue;
                }

                // start gathering a new subgraph.
                var pleaseVisit = new Queue <EdgeVertex>();
                pleaseVisit.Enqueue(startVertex);

                // walk all connected edges and add to this subgraph.
                var currentSubgraph = new HashSet <EdgeVertex>();
                while (pleaseVisit.Count > 0)
                {
                    EdgeVertex cur = pleaseVisit.Dequeue();
                    if (currentSubgraph.Contains(cur))
                    {
                        continue;
                    }
                    currentSubgraph.Add(cur);
                    totalVisited.Add(cur);
                    foreach (var v in edges[cur])
                    {
                        pleaseVisit.Enqueue(v);
                    }
                }

                subgraphs.Add(currentSubgraph);
            }
            return(subgraphs);
        }