예제 #1
0
        private void GetObstaclesPerLayer(int currentLayer, ObstacleCollection obstacles)
        {
            var rawObstacles = GetBlockObstacles(currentLayer);
            var nodes = new LineNodeDictionary();
            nodes.CreateLineNodes(rawObstacles);

            while (nodes.Count > 0)
            {
                var currentFigure = new RawFigure(_map, currentLayer, nodes);
                nodes.Purge(currentFigure.Lines);
                currentFigure.Optimize();
                currentFigure.Tokenize(obstacles);
            }

            nodes.Clear();
            nodes.CreateLineNodes(rawObstacles, true);

            while (nodes.Count > 0)
            {
                var currentFigure = new SlopeFigure(_map, currentLayer, nodes);
                nodes.Purge(currentFigure.Lines);
                currentFigure.Optimize();
                currentFigure.Tokenize(obstacles);
            }
        }
예제 #2
0
        protected List<LineSegment> WalkFigure(LineNodeDictionary nodes)
        {
            var lines = new List<LineSegment>();
            var visitedItems = new List<Vector2>();
            var nodesToVisit = new Stack<LineSegment>();
            var origin = nodes.Keys.First();
            var lineSegment = new LineSegment(origin, origin);
            nodesToVisit.Push(lineSegment);
            while (nodesToVisit.Count > 0)
            {
                var currentItem = nodesToVisit.Pop();
                var connectedNodes = GetConnectedNodes(currentItem.End, nodes);
                if (connectedNodes.Count == 1) //only the item I come from
                    ForlornStartNodes.Add(currentItem.End);
                if (connectedNodes.Count > 2 && !SwitchPoints.ContainsKey(currentItem.End))
                    SwitchPoints.Add(currentItem.End, new SwitchPoint(new List<Vector2>(connectedNodes)));
                connectedNodes.Remove(currentItem.Start);
                foreach (var connectedNode in connectedNodes)
                {
                    if (visitedItems.Contains(connectedNode))
                        continue;
                    lineSegment = AddLine(currentItem.End, connectedNode, lines);
                    nodesToVisit.Push(lineSegment);
                }
                visitedItems.Add(currentItem.End);
            }

            if (GetConnectedNodes(origin, nodes).Count <= 2)
                SwitchPoints.Remove(origin); //remove start point, it's not really a switch point

            return lines;
        }
예제 #3
0
파일: RawFigure.cs 프로젝트: jpires/gta2net
 public RawFigure(Map.Map map, int layer, LineNodeDictionary nodes)
     : base(map, layer)
 {
     PrepareBasePriorityTable();
     Nodes = new LineNodeDictionary();
     Lines = WalkFigure(nodes);
 }
예제 #4
0
 public SlopeFigure(Map.Map map, int layer, LineNodeDictionary nodes)
     : base(map, layer, nodes)
 {
 }