コード例 #1
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
        /* 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;
        }
コード例 #2
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;
        }
コード例 #3
0
ファイル: Designation.cs プロジェクト: jaenudin86/dwarrowdelf
        /// <summary>
        /// trivial validity check to remove AStar process for totally blocked tiles
        /// </summary>
        bool GetTileReachableSimple(IntVector3 p, DesignationType type)
        {
            DirectionSet dirs = GetDesignationPositioning(p, type);

            dirs = dirs.Reverse();
            return(dirs.ToSurroundingPoints(p).Any(this.Environment.CanEnter));
        }
コード例 #4
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);
            }
        }
コード例 #5
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;
        }