(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too

This commit is contained in:
rubidium
2009-03-15 00:32:18 +00:00
parent d72273d1f3
commit b25a4f8231
130 changed files with 1724 additions and 1727 deletions

View File

@@ -19,7 +19,7 @@ public:
typedef typename Node::Key Key; ///< key to hash tables
protected:
/// to access inherited path finder
/** to access inherited path finder */
Tpf& Yapf()
{
return *static_cast<Tpf*>(this);
@@ -27,12 +27,12 @@ protected:
int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)
{
// height of the center of the current tile
/* height of the center of the current tile */
int x1 = TileX(tile) * TILE_SIZE;
int y1 = TileY(tile) * TILE_SIZE;
int z1 = GetSlopeZ(x1 + TILE_SIZE / 2, y1 + TILE_SIZE / 2);
// height of the center of the next tile
/* height of the center of the next tile */
int x2 = TileX(next_tile) * TILE_SIZE;
int y2 = TileY(next_tile) * TILE_SIZE;
int z2 = GetSlopeZ(x2 + TILE_SIZE / 2, y2 + TILE_SIZE / 2);
@@ -48,7 +48,7 @@ protected:
FORCEINLINE int OneTileCost(TileIndex tile, Trackdir trackdir)
{
int cost = 0;
// set base cost
/* set base cost */
if (IsDiagonalTrackdir(trackdir)) {
cost += YAPF_TILE_LENGTH;
switch (GetTileType(tile)) {
@@ -69,7 +69,7 @@ protected:
break;
}
} else {
// non-diagonal trackdir
/* non-diagonal trackdir */
cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
}
return cost;
@@ -82,57 +82,57 @@ public:
FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower *tf)
{
int segment_cost = 0;
// start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment
/* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
TileIndex tile = n.m_key.m_tile;
Trackdir trackdir = n.m_key.m_td;
while (true) {
// base tile cost depending on distance between edges
/* base tile cost depending on distance between edges */
segment_cost += Yapf().OneTileCost(tile, trackdir);
const Vehicle *v = Yapf().GetVehicle();
// we have reached the vehicle's destination - segment should end here to avoid target skipping
/* we have reached the vehicle's destination - segment should end here to avoid target skipping */
if (Yapf().PfDetectDestinationTile(tile, trackdir)) break;
// stop if we have just entered the depot
/* stop if we have just entered the depot */
if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
// next time we will reverse and leave the depot
/* next time we will reverse and leave the depot */
break;
}
// if there are no reachable trackdirs on new tile, we have end of road
/* if there are no reachable trackdirs on new tile, we have end of road */
TrackFollower F(Yapf().GetVehicle());
if (!F.Follow(tile, trackdir)) break;
// if there are more trackdirs available & reachable, we are at the end of segment
/* if there are more trackdirs available & reachable, we are at the end of segment */
if (KillFirstBit(F.m_new_td_bits) != TRACKDIR_BIT_NONE) break;
Trackdir new_td = (Trackdir)FindFirstBit2x64(F.m_new_td_bits);
// stop if RV is on simple loop with no junctions
/* stop if RV is on simple loop with no junctions */
if (F.m_new_tile == n.m_key.m_tile && new_td == n.m_key.m_td) return false;
// if we skipped some tunnel tiles, add their cost
/* if we skipped some tunnel tiles, add their cost */
segment_cost += F.m_tiles_skipped * YAPF_TILE_LENGTH;
// add hilly terrain penalty
/* add hilly terrain penalty */
segment_cost += Yapf().SlopeCost(tile, F.m_new_tile, trackdir);
// add min/max speed penalties
/* add min/max speed penalties */
int min_speed = 0;
int max_speed = F.GetSpeedLimit(&min_speed);
if (max_speed < v->max_speed) segment_cost += 1 * (v->max_speed - max_speed);
if (min_speed > v->max_speed) segment_cost += 10 * (min_speed - v->max_speed);
// move to the next tile
/* move to the next tile */
tile = F.m_new_tile;
trackdir = new_td;
};
// save end of segment back to the node
/* save end of segment back to the node */
n.m_segment_last_tile = tile;
n.m_segment_last_td = trackdir;
// save also tile cost
/* save also tile cost */
int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0;
n.m_cost = parent_cost + segment_cost;
return true;
@@ -149,13 +149,13 @@ public:
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
typedef typename Node::Key Key; ///< key to hash tables
/// to access inherited path finder
/** to access inherited path finder */
Tpf& Yapf()
{
return *static_cast<Tpf*>(this);
}
/// Called by YAPF to detect if node ends in the desired destination
/** Called by YAPF to detect if node ends in the desired destination */
FORCEINLINE bool PfDetectDestination(Node& n)
{
bool bDest = IsRoadDepotTile(n.m_segment_last_tile);
@@ -198,14 +198,14 @@ public:
}
protected:
/// to access inherited path finder
/** to access inherited path finder */
Tpf& Yapf()
{
return *static_cast<Tpf*>(this);
}
public:
/// Called by YAPF to detect if node ends in the desired destination
/** Called by YAPF to detect if node ends in the desired destination */
FORCEINLINE bool PfDetectDestination(Node& n)
{
bool bDest = (n.m_segment_last_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.m_segment_last_td)) != TRACKDIR_BIT_NONE);
@@ -257,7 +257,7 @@ public:
typedef typename Node::Key Key; ///< key to hash tables
protected:
/// to access inherited path finder
/** to access inherited path finder */
FORCEINLINE Tpf& Yapf()
{
return *static_cast<Tpf*>(this);
@@ -276,7 +276,7 @@ public:
}
}
/// return debug report character to identify the transportation type
/** return debug report character to identify the transportation type */
FORCEINLINE char TransportTypeChar() const
{
return 'r';
@@ -290,39 +290,39 @@ public:
FORCEINLINE Trackdir ChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir)
{
// handle special case - when next tile is destination tile
/* handle special case - when next tile is destination tile */
if (tile == v->dest_tile) {
// choose diagonal trackdir reachable from enterdir
/* choose diagonal trackdir reachable from enterdir */
return DiagDirToDiagTrackdir(enterdir);
}
// our source tile will be the next vehicle tile (should be the given one)
/* our source tile will be the next vehicle tile (should be the given one) */
TileIndex src_tile = tile;
// get available trackdirs on the start tile
/* get available trackdirs on the start tile */
TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes));
// select reachable trackdirs only
/* select reachable trackdirs only */
src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
// get available trackdirs on the destination tile
/* get available trackdirs on the destination tile */
TileIndex dest_tile = v->dest_tile;
TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes));
// set origin and destination nodes
/* set origin and destination nodes */
Yapf().SetOrigin(src_tile, src_trackdirs);
Yapf().SetDestination(dest_tile, dest_trackdirs);
// find the best path
/* find the best path */
Yapf().FindPath(v);
// if path not found - return INVALID_TRACKDIR
/* if path not found - return INVALID_TRACKDIR */
Trackdir next_trackdir = INVALID_TRACKDIR;
Node *pNode = Yapf().GetBestNode();
if (pNode != NULL) {
// path was found or at least suggested
// walk through the path back to its origin
/* path was found or at least suggested
* walk through the path back to its origin */
while (pNode->m_parent != NULL) {
pNode = pNode->m_parent;
}
// return trackdir from the best origin node (one of start nodes)
/* return trackdir from the best origin node (one of start nodes) */
Node& best_next_node = *pNode;
assert(best_next_node.GetTile() == tile);
next_trackdir = best_next_node.GetTrackdir();
@@ -338,29 +338,29 @@ public:
FORCEINLINE uint DistanceToTile(const Vehicle *v, TileIndex dst_tile)
{
// handle special case - when current tile is the destination tile
/* handle special case - when current tile is the destination tile */
if (dst_tile == v->tile) {
// distance is zero in this case
/* distance is zero in this case */
return 0;
}
if (!SetOriginFromVehiclePos(v)) return UINT_MAX;
// set destination tile, trackdir
// get available trackdirs on the destination tile
/* set destination tile, trackdir
* get available trackdirs on the destination tile */
TrackdirBits dst_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes));
Yapf().SetDestination(dst_tile, dst_td_bits);
// if path not found - return distance = UINT_MAX
/* if path not found - return distance = UINT_MAX */
uint dist = UINT_MAX;
// find the best path
/* find the best path */
if (!Yapf().FindPath(v)) return dist;
Node *pNode = Yapf().GetBestNode();
if (pNode != NULL) {
// path was found
// get the path cost estimate
/* path was found
* get the path cost estimate */
dist = pNode->GetCostEstimate();
}
@@ -370,12 +370,12 @@ public:
/** Return true if the valid origin (tile/trackdir) was set from the current vehicle position. */
FORCEINLINE bool SetOriginFromVehiclePos(const Vehicle *v)
{
// set origin (tile, trackdir)
/* set origin (tile, trackdir) */
TileIndex src_tile = v->tile;
Trackdir src_td = GetVehicleTrackdir(v);
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
// sometimes the roadveh is not on the road (it resides on non-existing track)
// how should we handle that situation?
/* sometimes the roadveh is not on the road (it resides on non-existing track)
* how should we handle that situation? */
return false;
}
Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
@@ -390,15 +390,15 @@ public:
FORCEINLINE Depot *FindNearestDepot(const Vehicle *v, TileIndex tile, Trackdir td)
{
// set origin and destination nodes
/* set origin and destination nodes */
Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
// find the best path
/* find the best path */
bool bFound = Yapf().FindPath(v);
if (!bFound) return false;
// some path found
// get found depot tile
/* some path found
* get found depot tile */
Node *n = Yapf().GetBestNode();
TileIndex depot_tile = n->m_segment_last_tile;
assert(IsRoadDepotTile(depot_tile));
@@ -432,11 +432,11 @@ struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNod
Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir)
{
// default is YAPF type 2
/* default is YAPF type 2 */
typedef Trackdir (*PfnChooseRoadTrack)(const Vehicle*, TileIndex, DiagDirection);
PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg
// check if non-default YAPF type should be used
/* check if non-default YAPF type should be used */
if (_settings_game.pf.yapf.disable_node_optimization) {
pfnChooseRoadTrack = &CYapfRoad1::stChooseRoadTrack; // Trackdir, allow 90-deg
}
@@ -447,18 +447,18 @@ Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection ent
uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile)
{
// default is YAPF type 2
/* default is YAPF type 2 */
typedef uint (*PfnDistanceToTile)(const Vehicle*, TileIndex);
PfnDistanceToTile pfnDistanceToTile = &CYapfRoad2::stDistanceToTile; // default: ExitDir, allow 90-deg
// check if non-default YAPF type should be used
/* check if non-default YAPF type should be used */
if (_settings_game.pf.yapf.disable_node_optimization) {
pfnDistanceToTile = &CYapfRoad1::stDistanceToTile; // Trackdir, allow 90-deg
}
// measure distance in YAPF units
/* measure distance in YAPF units */
uint dist = pfnDistanceToTile(v, tile);
// convert distance to tiles
/* convert distance to tiles */
if (dist != UINT_MAX) {
dist = (dist + YAPF_TILE_LENGTH - 1) / YAPF_TILE_LENGTH;
}
@@ -474,17 +474,17 @@ Depot *YapfFindNearestRoadDepot(const Vehicle *v)
return NULL;
}
// handle the case when our vehicle is already in the depot tile
/* handle the case when our vehicle is already in the depot tile */
if (IsRoadDepotTile(tile)) {
// only what we need to return is the Depot*
/* only what we need to return is the Depot* */
return GetDepotByTile(tile);
}
// default is YAPF type 2
/* default is YAPF type 2 */
typedef Depot *(*PfnFindNearestDepot)(const Vehicle*, TileIndex, Trackdir);
PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot;
// check if non-default YAPF type should be used
/* check if non-default YAPF type should be used */
if (_settings_game.pf.yapf.disable_node_optimization) {
pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg
}