From ca52fcb2c03ec577388252d3f139d95df22a5f3b Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Wed, 13 May 2009 20:05:33 +0000 Subject: [PATCH] Streamline the path-finding interface a bit to prepare for more data being used to evaluate paths. We now pass the entire PATHJOB struct to the A* function. No actual behavioural changes yet. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@7408 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/astar.c | 20 ++++++-------------- src/astar.h | 4 +++- src/fpath.c | 12 +----------- src/fpath.h | 11 +++++++++++ src/map.c | 10 +++++++++- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/astar.c b/src/astar.c index c14f51b87..19da4e5f8 100644 --- a/src/astar.c +++ b/src/astar.c @@ -369,16 +369,16 @@ BOOL fpathTileLOS(SDWORD x1,SDWORD y1, SDWORD x2,SDWORD y2) return !obstruction; } -SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, SDWORD sx, SDWORD sy, SDWORD fx, SDWORD fy, PROPULSION_TYPE propulsion) +SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, PATHJOB *psJob) { FP_NODE *psFound, *psCurr, *psNew, *psParent, *psNext; FP_NODE *psNearest, *psRoute; SDWORD dir, x,y, currDist; SDWORD retval = ASR_OK; - const int tileSX = map_coord(sx); - const int tileSY = map_coord(sy); - const int tileFX = map_coord(fx); - const int tileFY = map_coord(fy); + const int tileSX = map_coord(psJob->origX); + const int tileSY = map_coord(psJob->origY); + const int tileFX = map_coord(psJob->destX); + const int tileFY = map_coord(psJob->destY); fpathTableReset(); @@ -448,15 +448,13 @@ SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, SDWORD sx, SDWORD sy, SDWORD fx, SD if (psFound && psFound->dist <= currDist) { // already visited node by a shorter route -// debug( LOG_NEVER, "blocked (%d) : %3d, %3d dist %d\n", psFound->type, x, y, currDist ); continue; } // If the tile hasn't been visited see if it is a blocking tile - if (!psFound && fpathBlockingTile(x, y, propulsion)) + if (!psFound && fpathBlockingTile(x, y, psJob->propulsion)) { // tile is blocked, skip it -// debug( LOG_NEVER, "blocked : %3d, %3d\n", x, y ); continue; } @@ -473,7 +471,6 @@ SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, SDWORD sx, SDWORD sy, SDWORD fx, SD psNew->est = (SWORD)fpathEstimate(x,y, tileFX, tileFY); fpathOpenAdd(psNew); fpathAddNode(psNew); -// debug( LOG_NEVER, "new : %3d, %3d (%d,%d) = %d\n", x, y, currDist, psNew->est, currDist + psNew->est ); } } else if (psFound->type == NT_OPEN) @@ -483,7 +480,6 @@ SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, SDWORD sx, SDWORD sy, SDWORD fx, SD // already in the open list but this is shorter psFound->dist = (SWORD)currDist; psFound->psRoute = psCurr; -// debug( LOG_NEVER, "replace open : %3d, %3d dist %d\n", x, y, currDist, psFound->est, currDist + psFound->est ); } else if (psFound->type == NT_CLOSED) { @@ -492,7 +488,6 @@ SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, SDWORD sx, SDWORD sy, SDWORD fx, SD psFound->dist = (SWORD)currDist; psFound->psRoute = psCurr; fpathOpenAdd(psFound); -// debug( LOG_NEVER, "replace closed : %3d, %3d dist %d\n", x, y, currDist, psFound->est, currDist + psFound->est ); } else { @@ -503,15 +498,12 @@ SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, SDWORD sx, SDWORD sy, SDWORD fx, SD // add the current point to the closed nodes // fpathAddNode(psCurr); psCurr->type = NT_CLOSED; -// debug( LOG_NEVER, "HashAdd - closed : %3d,%3d (%d,%d) = %d\n", psCurr->pos.x, psCurr->pos.y, psCurr->dist, psCurr->est, psCurr->dist+psCurr->est ); } // return the nearest route if no actual route was found if (!psRoute && psNearest) { psRoute = psNearest; - fx = world_coord(psNearest->x) + TILE_UNITS / 2; - fy = world_coord(psNearest->y) + TILE_UNITS / 2; retval = ASR_NEAREST; } diff --git a/src/astar.h b/src/astar.h index 613f7772d..1098a77af 100644 --- a/src/astar.h +++ b/src/astar.h @@ -21,6 +21,8 @@ #ifndef __INCLUDED_SRC_ASTART_H__ #define __INCLUDED_SRC_ASTART_H__ +#include "fpath.h" + /** Reset the A* counters * * This function resets astarInner among others. @@ -44,7 +46,7 @@ enum * * @ingroup pathfinding */ -SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, SDWORD sx, SDWORD sy, SDWORD fx, SDWORD fy, PROPULSION_TYPE propulsion); +SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, PATHJOB *psJob); /** Check LOS (Line Of Sight) between two tiles */ diff --git a/src/fpath.c b/src/fpath.c index e59f78221..a0fccacc3 100644 --- a/src/fpath.c +++ b/src/fpath.c @@ -53,16 +53,6 @@ static volatile bool fpathQuit = false; #define LIFT_BLOCK_HEIGHT_MEDIUMBODY 350 #define LIFT_BLOCK_HEIGHT_HEAVYBODY 350 -typedef struct _jobNode -{ - PROPULSION_TYPE propulsion; - DROID_TYPE droidType; - int destX, destY; - int origX, origY; - UDWORD droidID; - struct _jobNode *next; -} PATHJOB; - typedef struct _jobDone { UDWORD droidID; ///< Unique droid ID. @@ -570,7 +560,7 @@ FPATH_RETVAL fpathDroidRoute(DROID* psDroid, SDWORD tX, SDWORD tY) // Run only from path thread static void fpathExecute(PATHJOB *psJob, PATHRESULT *psResult) { - FPATH_RETVAL retval = fpathAStarRoute(&psResult->sMove, psJob->origX, psJob->origY, psJob->destX, psJob->destY, psJob->propulsion); + FPATH_RETVAL retval = fpathAStarRoute(&psResult->sMove, psJob); ASSERT(retval != ASR_OK || psResult->sMove.asPath, "Ok result but no path in result"); switch (retval) diff --git a/src/fpath.h b/src/fpath.h index 596972e73..44b108af1 100644 --- a/src/fpath.h +++ b/src/fpath.h @@ -31,6 +31,17 @@ * @ingroup pathfinding * @{ */ + +typedef struct _jobNode +{ + PROPULSION_TYPE propulsion; + DROID_TYPE droidType; + int destX, destY; + int origX, origY; + UDWORD droidID; + struct _jobNode *next; +} PATHJOB; + typedef enum _fpath_retval { FPR_OK, ///< found a route diff --git a/src/map.c b/src/map.c index 3ae60bb3b..2f7305961 100644 --- a/src/map.c +++ b/src/map.c @@ -2128,9 +2128,17 @@ static void astarTest(const char *name, int x1, int y1, int x2, int y2) route.asPath = NULL; for (i = 0; i < 100; i++) { + PATHJOB job; + route.numPoints = 0; astarResetCounters(); - asret = fpathAStarRoute(&route, x, y, endx, endy, PROPULSION_TYPE_WHEELED); + job.origX = x; + job.origY = y; + job.destX = endx; + job.destY = endy; + job.propulsion = PROPULSION_TYPE_WHEELED; + job.droidID = 1; + asret = fpathAStarRoute(&route, &job); free(route.asPath); route.asPath = NULL; }