Changeset - r18846:940300a5be9b
[Not reviewed]
master
0 1 0
smatz - 12 years ago 2012-01-01 17:32:45
smatz@openttd.org
(svn r23705) -Codechange: cache the last processed station in FindStationsAroundTiles() in order to make the code a bit faster
1 file changed with 8 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -3407,12 +3407,19 @@ void FindStationsAroundTiles(const TileA
 
	if (max_x >= MapSizeX()) max_x = MapSizeX() - 1;
 
	if (max_y >= MapSizeY()) max_y = MapSizeY() - 1;
 

	
 
	StationID last = INVALID_STATION;
 

	
 
	for (uint cy = min_y; cy < max_y; cy++) {
 
		for (uint cx = min_x; cx < max_x; cx++) {
 
			TileIndex cur_tile = TileXY(cx, cy);
 
			if (!IsTileType(cur_tile, MP_STATION)) continue;
 

	
 
			Station *st = Station::GetByTile(cur_tile);
 
			StationID sid = GetStationIndex(cur_tile);
 
			/* Stop early if we met the same station again. */
 
			if (sid == last) continue;
 
			last = sid;
 

	
 
			Station *st = Station::GetIfValid(sid);
 
			/* st can be NULL in case of waypoints */
 
			if (st == NULL) continue;
 

	
0 comments (0 inline, 0 general)