コード例 #1
0
        static void ParallelFind(IEnvironmentObject env, IntVector3 src, IntVector3 dest, DirectionSet positioning, out AStarResult resBackward, out AStarResult resForward)
        {
            Debug.Assert(env != null);

            // Do pathfinding to both directions simultaneously to detect faster if the destination is blocked
            CancellationTokenSource cts = new CancellationTokenSource();

            AStarResult rb = null;
            AStarResult rf = null;

            var taskForward = new Task(delegate
            {
                rf = Find(env, src, DirectionSet.Exact, dest, positioning, 200000, cts.Token);
            });

            taskForward.Start();

            var taskBackward = new Task(delegate
            {
                rb = Find(env, dest, positioning.Reverse(), src, DirectionSet.Exact, 200000, cts.Token);
            });

            taskBackward.Start();

            Task.WaitAny(taskBackward, taskForward);

            cts.Cancel();

            Task.WaitAll(taskBackward, taskForward);

            resForward  = rf;
            resBackward = rb;
        }
コード例 #2
0
        /* Parallel */

        /// <summary>
        /// Returns if dst can be reached from src
        /// </summary>
        public static bool CanReach(IEnvironmentObject env, IntVector3 src, IntVector3 dst, DirectionSet dstPositioning)
        {
            Debug.Assert(env != null);

            // Do pathfinding to both directions simultaneously to detect faster if the destination is blocked
            CancellationTokenSource cts = new CancellationTokenSource();

            AStarResult resBackward = null;
            AStarResult resForward  = null;

            var taskForward = new Task(delegate
            {
                resForward = Find(env, src, DirectionSet.Exact, dst, dstPositioning, 200000, cts.Token);
            });

            taskForward.Start();

            var taskBackward = new Task(delegate
            {
                resBackward = Find(env, dst, dstPositioning.Reverse(), src, DirectionSet.Exact, 200000, cts.Token);
            });

            taskBackward.Start();

            Task.WaitAny(taskBackward, taskForward);

            cts.Cancel();

            Task.WaitAll(taskBackward, taskForward);

            if (resForward.Status == AStarStatus.Found || resBackward.Status == AStarStatus.Found)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
        static void ParallelFind(IEnvironmentObject env, IntVector3 src, IntVector3 dest, DirectionSet positioning, out AStarResult resBackward, out AStarResult resForward)
        {
            Debug.Assert(env != null);

            // Do pathfinding to both directions simultaneously to detect faster if the destination is blocked
            CancellationTokenSource cts = new CancellationTokenSource();

            AStarResult rb = null;
            AStarResult rf = null;

            var taskForward = new Task(delegate
            {
                rf = Find(env, src, DirectionSet.Exact, dest, positioning, 200000, cts.Token);
            });
            taskForward.Start();

            var taskBackward = new Task(delegate
            {
                rb = Find(env, dest, positioning.Reverse(), src, DirectionSet.Exact, 200000, cts.Token);
            });
            taskBackward.Start();

            Task.WaitAny(taskBackward, taskForward);

            cts.Cancel();

            Task.WaitAll(taskBackward, taskForward);

            resForward = rf;
            resBackward = rb;
        }