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
master
Per Inge Mathisen 2009-05-13 20:05:33 +00:00 committed by Git SVN Gateway
parent fb980b636c
commit ca52fcb2c0
5 changed files with 30 additions and 27 deletions

View File

@ -369,16 +369,16 @@ BOOL fpathTileLOS(SDWORD x1,SDWORD y1, SDWORD x2,SDWORD y2)
return !obstruction; 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 *psFound, *psCurr, *psNew, *psParent, *psNext;
FP_NODE *psNearest, *psRoute; FP_NODE *psNearest, *psRoute;
SDWORD dir, x,y, currDist; SDWORD dir, x,y, currDist;
SDWORD retval = ASR_OK; SDWORD retval = ASR_OK;
const int tileSX = map_coord(sx); const int tileSX = map_coord(psJob->origX);
const int tileSY = map_coord(sy); const int tileSY = map_coord(psJob->origY);
const int tileFX = map_coord(fx); const int tileFX = map_coord(psJob->destX);
const int tileFY = map_coord(fy); const int tileFY = map_coord(psJob->destY);
fpathTableReset(); fpathTableReset();
@ -448,15 +448,13 @@ SDWORD fpathAStarRoute(MOVE_CONTROL *psMove, SDWORD sx, SDWORD sy, SDWORD fx, SD
if (psFound && psFound->dist <= currDist) if (psFound && psFound->dist <= currDist)
{ {
// already visited node by a shorter route // already visited node by a shorter route
// debug( LOG_NEVER, "blocked (%d) : %3d, %3d dist %d\n", psFound->type, x, y, currDist );
continue; continue;
} }
// If the tile hasn't been visited see if it is a blocking tile // 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 // tile is blocked, skip it
// debug( LOG_NEVER, "blocked : %3d, %3d\n", x, y );
continue; 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); psNew->est = (SWORD)fpathEstimate(x,y, tileFX, tileFY);
fpathOpenAdd(psNew); fpathOpenAdd(psNew);
fpathAddNode(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) 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 // already in the open list but this is shorter
psFound->dist = (SWORD)currDist; psFound->dist = (SWORD)currDist;
psFound->psRoute = psCurr; 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) 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->dist = (SWORD)currDist;
psFound->psRoute = psCurr; psFound->psRoute = psCurr;
fpathOpenAdd(psFound); fpathOpenAdd(psFound);
// debug( LOG_NEVER, "replace closed : %3d, %3d dist %d\n", x, y, currDist, psFound->est, currDist + psFound->est );
} }
else 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 // add the current point to the closed nodes
// fpathAddNode(psCurr); // fpathAddNode(psCurr);
psCurr->type = NT_CLOSED; 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 // return the nearest route if no actual route was found
if (!psRoute && psNearest) if (!psRoute && psNearest)
{ {
psRoute = psNearest; psRoute = psNearest;
fx = world_coord(psNearest->x) + TILE_UNITS / 2;
fy = world_coord(psNearest->y) + TILE_UNITS / 2;
retval = ASR_NEAREST; retval = ASR_NEAREST;
} }

View File

@ -21,6 +21,8 @@
#ifndef __INCLUDED_SRC_ASTART_H__ #ifndef __INCLUDED_SRC_ASTART_H__
#define __INCLUDED_SRC_ASTART_H__ #define __INCLUDED_SRC_ASTART_H__
#include "fpath.h"
/** Reset the A* counters /** Reset the A* counters
* *
* This function resets astarInner among others. * This function resets astarInner among others.
@ -44,7 +46,7 @@ enum
* *
* @ingroup pathfinding * @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 /** Check LOS (Line Of Sight) between two tiles
*/ */

View File

@ -53,16 +53,6 @@ static volatile bool fpathQuit = false;
#define LIFT_BLOCK_HEIGHT_MEDIUMBODY 350 #define LIFT_BLOCK_HEIGHT_MEDIUMBODY 350
#define LIFT_BLOCK_HEIGHT_HEAVYBODY 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 typedef struct _jobDone
{ {
UDWORD droidID; ///< Unique droid ID. UDWORD droidID; ///< Unique droid ID.
@ -570,7 +560,7 @@ FPATH_RETVAL fpathDroidRoute(DROID* psDroid, SDWORD tX, SDWORD tY)
// Run only from path thread // Run only from path thread
static void fpathExecute(PATHJOB *psJob, PATHRESULT *psResult) 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"); ASSERT(retval != ASR_OK || psResult->sMove.asPath, "Ok result but no path in result");
switch (retval) switch (retval)

View File

@ -31,6 +31,17 @@
* @ingroup pathfinding * @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 typedef enum _fpath_retval
{ {
FPR_OK, ///< found a route FPR_OK, ///< found a route

View File

@ -2128,9 +2128,17 @@ static void astarTest(const char *name, int x1, int y1, int x2, int y2)
route.asPath = NULL; route.asPath = NULL;
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
PATHJOB job;
route.numPoints = 0; route.numPoints = 0;
astarResetCounters(); 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); free(route.asPath);
route.asPath = NULL; route.asPath = NULL;
} }