Exemplo n.º 1
0
        public static int RequestPath(PathRequest pr)
        {
            pr.ID = ++_counter;

            lock (PathsRequested)
            {
                PathsRequested.Enqueue(pr);
            }

            return(pr.ID);
        }
Exemplo n.º 2
0
        public void Run()
        {
            PathRequest pr;
            Path        p;

            while (true)
            {
                // check if any paths are requested
                lock (PathsRequested)
                {
                    if (PathsRequested.Count == 0)
                    {
                        continue;
                    }

                    // get the first one off the queue if so
                    pr = PathsRequested.Dequeue();
                }

                // generate the path
                if (pr.Ends == null)
                {
                    p = Pathfinder.Generate(Collisions, Map, pr.Start, pr.End, pr.Validation);
                }
                else
                {
                    p = Pathfinder.Generate(Collisions, Map, pr.Start, pr.Ends, pr.Validation);
                }

                // add the path to the completion dictionary
                lock (PathsCreated)
                {
                    PathsCreated.Add(pr.ID, p);
                }

                Thread.Sleep(1);
            }
        }