(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.

- Codechange: [NPF] Removed NPF_MARKROUTE macro, to mark routes just specify a npf debugging level >= 1 on the commandline.
This commit is contained in:
matthijs 2005-04-11 19:53:44 +00:00
parent b02dde1982
commit f5d9cb58eb
4 changed files with 29 additions and 42 deletions

View File

@ -13,6 +13,7 @@ int _debug_ms_level;
int _debug_net_level; int _debug_net_level;
int _debug_spritecache_level; int _debug_spritecache_level;
int _debug_oldloader_level; int _debug_oldloader_level;
int _debug_npf_level;
void CDECL debug(const char *s, ...) void CDECL debug(const char *s, ...)
@ -48,7 +49,8 @@ void SetDebugString(const char *s)
DEBUG_LEVEL(ms), DEBUG_LEVEL(ms),
DEBUG_LEVEL(net), DEBUG_LEVEL(net),
DEBUG_LEVEL(spritecache), DEBUG_LEVEL(spritecache),
DEBUG_LEVEL(oldloader) DEBUG_LEVEL(oldloader),
DEBUG_LEVEL(npf)
}; };
#undef DEBUG_LEVEL #undef DEBUG_LEVEL

View File

@ -14,6 +14,7 @@
extern int _debug_net_level; extern int _debug_net_level;
extern int _debug_spritecache_level; extern int _debug_spritecache_level;
extern int _debug_oldloader_level; extern int _debug_oldloader_level;
extern int _debug_npf_level;
#endif #endif
void CDECL debug(const char *s, ...); void CDECL debug(const char *s, ...);

64
npf.c
View File

@ -179,9 +179,7 @@ int32 NPFCalcStationOrTileHeuristic(AyStar* as, AyStarNode* current, OpenListNod
ftd->best_bird_dist = dist; ftd->best_bird_dist = dist;
ftd->best_trackdir = current->user_data[NPF_TRACKDIR_CHOICE]; ftd->best_trackdir = current->user_data[NPF_TRACKDIR_CHOICE];
} }
#ifdef NPF_DEBUG DEBUG(npf, 4)("Calculating H for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), dist);
debug("Calculating H for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), dist);
#endif
return dist; return dist;
} }
@ -196,9 +194,7 @@ void NPFFillTrackdirChoice(AyStarNode* current, OpenListNode* parent)
/* This is a first order decision, so we'd better save the /* This is a first order decision, so we'd better save the
* direction we chose */ * direction we chose */
current->user_data[NPF_TRACKDIR_CHOICE] = trackdir; current->user_data[NPF_TRACKDIR_CHOICE] = trackdir;
#ifdef NPF_DEBUG DEBUG(npf, 6)("Saving trackdir: %#x", trackdir);
debug("Saving trackdir: %#x", trackdir);
#endif
} else { } else {
/* We've already made the decision, so just save our parent's /* We've already made the decision, so just save our parent's
* decision */ * decision */
@ -250,18 +246,24 @@ uint NPFSlopeCost(AyStarNode* current) {
* there is only one level of steepness... */ * there is only one level of steepness... */
} }
/* Mark tiles by mowing the grass when npf debug level >= 1 */
void NPFMarkTile(TileIndex tile) { void NPFMarkTile(TileIndex tile) {
switch(GetTileType(tile)) { #ifdef NO_DEBUG_MESSAGES
case MP_RAILWAY: return;
case MP_STREET: #else
/* DEBUG: mark visited tiles by mowing the grass under them if (_debug_npf_level >= 1)
* ;-) */ switch(GetTileType(tile)) {
_map2[tile] &= ~15; case MP_RAILWAY:
MarkTileDirtyByTile(tile); case MP_STREET:
break; /* DEBUG: mark visited tiles by mowing the grass under them
default: * ;-) */
break; _map2[tile] &= ~15;
} MarkTileDirtyByTile(tile);
break;
default:
break;
}
#endif
} }
int32 NPFWaterPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) { int32 NPFWaterPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
@ -304,12 +306,8 @@ int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
/* Check for turns */ /* Check for turns */
//TODO //TODO
#ifdef NPF_MARKROUTE
NPFMarkTile(tile); NPFMarkTile(tile);
#endif DEBUG(npf, 4)("Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost);
#ifdef NPF_DEBUG
debug("Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost);
#endif
return cost; return cost;
} }
@ -395,12 +393,8 @@ int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
/* Check for occupied track */ /* Check for occupied track */
//TODO //TODO
#ifdef NPF_MARKROUTE
NPFMarkTile(tile); NPFMarkTile(tile);
#endif DEBUG(npf, 4)("Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost);
#ifdef NPF_DEBUG
debug("Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost);
#endif
return cost; return cost;
} }
@ -468,9 +462,7 @@ void NPFFollowTrack(AyStar* aystar, OpenListNode* current) {
TransportType type = aystar->user_data[NPF_TYPE]; TransportType type = aystar->user_data[NPF_TYPE];
/* Initialize to 0, so we can jump out (return) somewhere an have no neighbours */ /* Initialize to 0, so we can jump out (return) somewhere an have no neighbours */
aystar->num_neighbours = 0; aystar->num_neighbours = 0;
#ifdef NPF_DEBUG DEBUG(npf, 4)("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
debug("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
#endif
/* Find dest tile */ /* Find dest tile */
if (IsTileType(src_tile, MP_TUNNELBRIDGE) && (_map5[src_tile] & 0xF0)==0 && (_map5[src_tile] & 3) == src_exitdir) { if (IsTileType(src_tile, MP_TUNNELBRIDGE) && (_map5[src_tile] & 0xF0)==0 && (_map5[src_tile] & 3) == src_exitdir) {
@ -544,25 +536,19 @@ void NPFFollowTrack(AyStar* aystar, OpenListNode* current) {
} }
trackdirs = ts & 0x3F3F; /* Filter out signal status and the unused bits */ trackdirs = ts & 0x3F3F; /* Filter out signal status and the unused bits */
#ifdef NPF_DEBUG DEBUG(npf, 4)("Next node: (%d, %d) [%d], possible trackdirs: %#x", TileX(dst_tile), TileY(dst_tile), dst_tile, trackdirs);
debug("Next node: (%d, %d) [%d], possible trackdirs: %#x", TileX(dst_tile), TileY(dst_tile), dst_tile, trackdirs);
#endif
/* Select only trackdirs we can reach from our current trackdir */ /* Select only trackdirs we can reach from our current trackdir */
trackdirs &= _trackdir_reaches_trackdirs[src_trackdir]; trackdirs &= _trackdir_reaches_trackdirs[src_trackdir];
if (_patches.forbid_90_deg && (type == TRANSPORT_RAIL || type == TRANSPORT_WATER)) /* Filter out trackdirs that would make 90 deg turns for trains */ if (_patches.forbid_90_deg && (type == TRANSPORT_RAIL || type == TRANSPORT_WATER)) /* Filter out trackdirs that would make 90 deg turns for trains */
trackdirs &= ~_trackdir_crosses_trackdirs[src_trackdir]; trackdirs &= ~_trackdir_crosses_trackdirs[src_trackdir];
#ifdef NPF_DEBUG DEBUG(npf,6)("After filtering: (%d, %d), possible trackdirs: %#x", TileX(dst_tile), TileY(dst_tile), trackdirs);
debug("After filtering: (%d, %d), possible trackdirs: %#x", TileX(dst_tile), TileY(dst_tile), trackdirs);
#endif
/* Enumerate possible track */ /* Enumerate possible track */
while (trackdirs != 0) { while (trackdirs != 0) {
byte dst_trackdir; byte dst_trackdir;
dst_trackdir = FindFirstBit2x64(trackdirs); dst_trackdir = FindFirstBit2x64(trackdirs);
trackdirs = KillFirstBit2x64(trackdirs); trackdirs = KillFirstBit2x64(trackdirs);
#ifdef NPF_DEBUG DEBUG(npf, 5)("Expanded into trackdir: %d, remaining trackdirs: %#x", dst_trackdir, trackdirs);
debug("Expanded into trackdir: %d, remaining trackdirs: %#x", dst_trackdir, trackdirs);
#endif
/* Check for oneway signal against us */ /* Check for oneway signal against us */
if (IsTileType(dst_tile, MP_RAILWAY) && (_map5[dst_tile]&0xC0) == 0x40) { if (IsTileType(dst_tile, MP_RAILWAY) && (_map5[dst_tile]&0xC0) == 0x40) {

2
npf.h
View File

@ -5,8 +5,6 @@
#include "aystar.h" #include "aystar.h"
#include "vehicle.h" #include "vehicle.h"
//#define NPF_DEBUG
//#define NPF_MARKROUTE //Mark the routes considered by the pathfinder by
//mowing grass //mowing grass
enum { enum {
NPF_HASH_BITS = 12, /* The size of the hash used in pathfinding. Just changing this value should be sufficient to change the hash size. Should be an even value. */ NPF_HASH_BITS = 12, /* The size of the hash used in pathfinding. Just changing this value should be sufficient to change the hash size. Should be an even value. */