private void test() { Debug.Log("begin test"); /* AStarPathFinder pathFinder = new AStarPathFinder(mapData, new GameMoveCost(), new AStarHCostHuffman() //new AStarHCostEuclidean() //new AStarHCostChebyshev() ); IList<Vec2<short>> path = new List<Vec2<short>>(); Vec2<short> startPos = new Vec2<short>(3, 55), endPos = new Vec2<short>(70, 25); int err = (int)pathFinder.findPath(0, ref startPos, ref endPos, path); Debug.Log("found path with err=" + err); if (err == 0) printPath(path); //*/ //* _num = 10000; for (int i = 0; i < _num; ++i) { AStarPathFinder pathFinder = new AStarPathFinder(mapData, new GameMoveCost(), new AStarHCostHuffman() //new AStarHCostEuclidean() //new AStarHCostChebyshev() ); AsyncTask task = new AsyncTask(i + 1); task.getParamDict().Add(0, pathFinder); task.getParamDict().Add(1, i); task.onHandleTask = new OnHandleTask(onHandleTestTask); task.onCompleteTask = new OnCompleteTask(onCompleteTestTask); _dispatcher.dispatch(task); } //*/ Debug.Log("end test"); }
private int onHandleTestTask(AsyncTask task, IDictionary<int, object> oResult) { AStarPathFinder pathFinder = task.getParamDict()[0] as AStarPathFinder; IList<AStarNode> path = new Deque<AStarNode>(); oResult.Add(0, path); Vec2<short> startPos = new Vec2<short>(1, 1); Vec2<short> endPos = new Vec2<short>(70, 25); //Vec2<short> endPos = new Vec2<short>(789, 24); int err = (int)pathFinder.findPath(0, 1, startPos, endPos, path); return err; }
void onCompleteFindPath(AsyncTask task, int errCode, IDictionary<int, object> result) { //Log.debug("ENTER Map.onCompleteFindPath"); //switch ((TaskID)task.getTaskID()) //{ // case TaskID.FindPath: if (errCode == 0) { SpriteSoldier sn = task.getParamDict()[(int)TaskType.SpriteNode] as SpriteSoldier; IList<AStarNode> path = result[(int)TaskType.PathResult] as IList<AStarNode>; sn.soldier.paths = path; sn.move(); } // break; // } //Log.debug("LEAVE Map.onCompleteFindPath"); }
private void startFindPathLaunch(SpriteSoldier sn) { sn.stop(); _dispatcher.cancelTask(sn.soldier.Uid); AsyncTask task = new AsyncTask(sn.soldier.Uid); task.getParamDict().Add((int)TaskType.StartPos, new Vec2<short>((short)sn.soldier.x, (short)sn.soldier.y)); task.getParamDict().Add((int)TaskType.EndPos, new Vec2<short>(sn.soldier.destination.x, sn.soldier.destination.y)); task.getParamDict().Add((int)TaskType.SpriteNode, sn); task.getParamDict().Add((int)TaskType.MapData, _dispatcherMono.mapData); task.onHandleTask = new OnHandleTask(handleFindPath); task.onCompleteTask = new OnCompleteTask(onCompleteFindPath); _dispatcher.dispatch(task); }
private int handleFindPath(AsyncTask task, IDictionary<int, object> oResult) { int err = 0; short[,] mapData = (short[,])task.getParamDict()[(int)TaskType.MapData]; Vec2<short> startPos = (Vec2<short>)task.getParamDict()[(int)TaskType.StartPos]; Vec2<short> endPos = (Vec2<short>)task.getParamDict()[(int)TaskType.EndPos]; IList<AStarNode> path = new Deque<AStarNode>(); oResult.Add((int)TaskType.PathResult, path); AStarPathFinder pathFinder = new AStarPathFinder( mapData, new AsyncDispatchBehaviour.GameMoveCost()); err = (int)pathFinder.findPath(0, 1, startPos, endPos, path); return err; }