(svn r11962) -Cleanup: OPF is no longer used to update signals
authorsmatz
Wed, 23 Jan 2008 17:30:28 +0000
changeset 8888 94cc8a25185f
parent 8887 4bc5c9811562
child 8889 a3633be104ff
(svn r11962) -Cleanup: OPF is no longer used to update signals
src/ai/default/default.cpp
src/pathfind.cpp
src/pathfind.h
src/roadveh_cmd.cpp
src/ship_cmd.cpp
--- a/src/ai/default/default.cpp	Wed Jan 23 17:08:35 2008 +0000
+++ b/src/ai/default/default.cpp	Wed Jan 23 17:30:28 2008 +0000
@@ -1898,7 +1898,7 @@
 	arpfd.tile2 = _players_ai[p->index].cur_tile_a;
 	arpfd.flag = false;
 	arpfd.count = 0;
-	FollowTrack(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a), 0x2000 | TRANSPORT_RAIL, 0, ReverseDiagDir(_players_ai[p->index].cur_dir_a),
+	FollowTrack(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a), TRANSPORT_RAIL, 0, ReverseDiagDir(_players_ai[p->index].cur_dir_a),
 		(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
 	return arpfd.count > 8;
 }
@@ -2866,7 +2866,7 @@
 
 	uint i;
 	FOR_EACH_SET_BIT(i, bits) {
-		FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, ROADTYPES_ROAD, (DiagDirection)_dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are);
+		FollowTrack(tile, 0x1000 | TRANSPORT_ROAD, ROADTYPES_ROAD, (DiagDirection)_dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are);
 	}
 
 	if (DistanceManhattan(tile, are.dest) <= are.best_dist) return false;
--- a/src/pathfind.cpp	Wed Jan 23 17:08:35 2008 +0000
+++ b/src/pathfind.cpp	Wed Jan 23 17:30:28 2008 +0000
@@ -230,13 +230,42 @@
 	return flotr.tile;
 }
 
-static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction);
+static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
+{
+	TileIndex tile_org = tile;
 
-/** Most code of the "Normal" case of TPF Mode 1; for signals special tricks
- * have to be done, but those happen in TPFMode1; this is just to prevent
- * gotos ;). */
-static inline void TPFMode1_NormalCase(TrackPathFinder* tpf, TileIndex tile, TileIndex tile_org, DiagDirection direction)
-{
+	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
+		if (IsTunnel(tile)) {
+			if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
+				return;
+			}
+			/* Only skip through the tunnel if heading inwards. We can
+			 * be headed outwards if our starting position was in a
+			 * tunnel and we're pathfinding backwards */
+			if (GetTunnelBridgeDirection(tile) == direction) {
+				tile = SkipToEndOfTunnel(tpf, tile, direction);
+			} else if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
+				/* We don't support moving through the sides of a tunnel
+				 * entrance :-) */
+				return;
+			}
+		} else { // IsBridge(tile)
+			TileIndex tile_end;
+			if (GetTunnelBridgeDirection(tile) != direction ||
+					GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
+				return;
+			}
+			//fprintf(stderr, "%s: Planning over bridge\n", __func__);
+			// TODO doesn't work - WHAT doesn't work?
+			TPFSetTileBit(tpf, tile, 14);
+			tile_end = GetOtherBridgeEnd(tile);
+			tpf->rd.cur_length += DistanceManhattan(tile, tile_end);
+			tile = tile_end;
+			TPFSetTileBit(tpf, tile, 14);
+		}
+	}
+	tile += TileOffsByDiagDir(direction);
+
 	/* Check in case of rail if the owner is the same */
 	if (tpf->tracktype == TRANSPORT_RAIL) {
 		/* don't enter train depot from the back */
@@ -294,84 +323,6 @@
 	}
 }
 
-static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
-{
-	TileIndex tile_org = tile;
-
-	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
-		if (IsTunnel(tile)) {
-			if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
-				return;
-			}
-			/* Only skip through the tunnel if heading inwards. We can
-			 * be headed outwards if our starting position was in a
-			 * tunnel and we're pathfinding backwards */
-			if (GetTunnelBridgeDirection(tile) == direction) {
-				tile = SkipToEndOfTunnel(tpf, tile, direction);
-			} else if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
-				/* We don't support moving through the sides of a tunnel
-				 * entrance :-) */
-				return;
-			}
-		} else { // IsBridge(tile)
-			TileIndex tile_end;
-			if (GetTunnelBridgeDirection(tile) != direction ||
-					GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
-				return;
-			}
-			//fprintf(stderr, "%s: Planning over bridge\n", __func__);
-			// TODO doesn't work - WHAT doesn't work?
-			TPFSetTileBit(tpf, tile, 14);
-			tile_end = GetOtherBridgeEnd(tile);
-			tpf->rd.cur_length += DistanceManhattan(tile, tile_end);
-			tile = tile_end;
-			TPFSetTileBit(tpf, tile, 14);
-		}
-	}
-	tile += TileOffsByDiagDir(direction);
-
-	TPFMode1_NormalCase(tpf, tile, tile_org, direction);
-
-	/* the next is only used when signals are checked.
-	 * seems to go in 2 directions simultaneously */
-
-	/* if i can get rid of this, tail end recursion can be used to minimize
-	 * stack space dramatically. */
-
-	/* If we are doing signal setting, we must reverse at evere tile, so we
-	 * iterate all the tracks in a signal block, even when a normal train would
-	 * not reach it (for example, when two lines merge */
-	if (tpf->hasbit_13)
-		return;
-
-	direction = ReverseDiagDir(direction);
-	tile += TileOffsByDiagDir(direction);
-
-	uint bits = GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type);
-	bits |= (bits >> 8);
-
-	if ( (byte)bits != tpf->var2) {
-		bits &= _bits_mask[direction];
-	}
-
-	bits &= 0xBF;
-	if (bits == 0)
-		return;
-
-	do {
-		uint i = FIND_FIRST_BIT(bits);
-		bits = KillFirstBit(bits);
-
-		tpf->the_dir = (Trackdir)((_otherdir_mask[direction] & (byte)(1 << i)) ? (i + 8) : i);
-		RememberData rd = tpf->rd;
-		if (TPFSetTileBit(tpf, tile, tpf->the_dir) &&
-				!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length, &tpf->rd.pft_var6) ) {
-			TPFMode1(tpf, tile, _tpf_new_direction[tpf->the_dir]);
-		}
-		tpf->rd = rd;
-	} while (bits != 0);
-}
-
 void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
 {
 	TrackPathFinder tpf;
@@ -391,7 +342,6 @@
 	tpf.var2 = HasBit(flags, 15) ? 0x43 : 0xFF; // 0x8000
 
 	tpf.disable_tile_hash = HasBit(flags, 12);  // 0x1000
-	tpf.hasbit_13         = HasBit(flags, 13);  // 0x2000
 
 
 	tpf.tracktype = (TransportType)(flags & 0xFF);
--- a/src/pathfind.h	Wed Jan 23 17:08:35 2008 +0000
+++ b/src/pathfind.h	Wed Jan 23 17:30:28 2008 +0000
@@ -60,7 +60,6 @@
 
 	byte var2;
 	bool disable_tile_hash;
-	bool hasbit_13;
 
 	uint16 hash_head[0x400];
 	TileIndex hash_tile[0x400];       ///< stores the link index when multi link.
--- a/src/roadveh_cmd.cpp	Wed Jan 23 17:08:35 2008 +0000
+++ b/src/roadveh_cmd.cpp	Wed Jan 23 17:30:28 2008 +0000
@@ -439,7 +439,7 @@
 
 		/* search in all directions */
 		for (DiagDirection i = DIAGDIR_BEGIN; i != DIAGDIR_END; i++) {
-			FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, v->u.road.compatible_roadtypes, i, EnumRoadSignalFindDepot, NULL, &rfdd);
+			FollowTrack(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, i, EnumRoadSignalFindDepot, NULL, &rfdd);
 		}
 
 		if (rfdd.best_length == (uint)-1) return NULL;
@@ -1280,7 +1280,7 @@
 			if (best_track == INVALID_TRACKDIR) best_track = (Trackdir)i; // in case we don't find the path, just pick a track
 			frd.maxtracklen = (uint)-1;
 			frd.mindist = (uint)-1;
-			FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, v->u.road.compatible_roadtypes, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd);
+			FollowTrack(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd);
 
 			if (frd.mindist < best_dist || (frd.mindist == best_dist && frd.maxtracklen < best_maxlen)) {
 				best_dist = frd.mindist;
--- a/src/ship_cmd.cpp	Wed Jan 23 17:08:35 2008 +0000
+++ b/src/ship_cmd.cpp	Wed Jan 23 17:30:28 2008 +0000
@@ -479,7 +479,7 @@
 		pfs.best_bird_dist = (uint)-1;
 		pfs.best_length = (uint)-1;
 
-		FollowTrack(tile, 0x3800 | TRANSPORT_WATER, 0, (DiagDirection)_ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs);
+		FollowTrack(tile, 0x1800 | TRANSPORT_WATER, 0, (DiagDirection)_ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs);
 
 		if (best_track != INVALID_TRACK) {
 			if (pfs.best_bird_dist != 0) {