diff options
author | truelight <truelight@openttd.org> | 2006-08-22 15:33:35 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2006-08-22 15:33:35 +0000 |
commit | 0461d896123b918b492a3d16439bb46b041528cd (patch) | |
tree | 618708068f10739a382af83313db9c96b4744ef5 /waypoint.c | |
parent | 4c2abf1de53e28a5c3c6c6920efabc4653693c4c (diff) | |
download | openttd-0461d896123b918b492a3d16439bb46b041528cd.tar.xz |
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
-Codechange: use IsValidXXX where ever possible
Note: both changes to prepare for new pool system, which needs those changes.
For every pool there are 2 ugly lines, which will be removed when done
implementing new pool system.
Based on FS#13 by blathijs, partly implemented.
Diffstat (limited to 'waypoint.c')
-rw-r--r-- | waypoint.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/waypoint.c b/waypoint.c index eb198da4f..378c959cc 100644 --- a/waypoint.c +++ b/waypoint.c @@ -35,7 +35,9 @@ static void WaypointPoolNewBlock(uint start_item) { Waypoint *wp; - FOR_ALL_WAYPOINTS_FROM(wp, start_item) wp->index = start_item++; + /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. + * TODO - This is just a temporary stage, this will be removed. */ + for (wp = GetWaypoint(start_item); wp != NULL; wp = (wp->index + 1 < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1) : NULL) wp->index = start_item++; } /* Initialize the town-pool */ @@ -46,8 +48,10 @@ static Waypoint* AllocateWaypoint(void) { Waypoint *wp; - FOR_ALL_WAYPOINTS(wp) { - if (wp->xy == 0) { + /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. + * TODO - This is just a temporary stage, this will be removed. */ + for (wp = GetWaypoint(0); wp != NULL; wp = (wp->index + 1 < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1) : NULL) { + if (!IsValidWaypoint(wp)) { uint index = wp->index; memset(wp, 0, sizeof(*wp)); @@ -87,7 +91,7 @@ void UpdateAllWaypointSigns(void) Waypoint *wp; FOR_ALL_WAYPOINTS(wp) { - if (wp->xy != 0) UpdateWaypointSign(wp); + UpdateWaypointSign(wp); } } @@ -124,7 +128,7 @@ static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile) uint thres = 8; FOR_ALL_WAYPOINTS(wp) { - if (wp->deleted && wp->xy != 0) { + if (wp->deleted) { uint cur_dist = DistanceManhattan(tile, wp->xy); if (cur_dist < thres) { @@ -383,8 +387,6 @@ void FixOldWaypoints(void) /* Convert the old 'town_or_string', to 'string' / 'town' / 'town_cn' */ FOR_ALL_WAYPOINTS(wp) { - if (wp->xy == 0) continue; - wp->town_index = ClosestTownFromTile(wp->xy, (uint)-1)->index; wp->town_cn = 0; if (wp->string & 0xC000) { @@ -421,10 +423,8 @@ static void Save_WAYP(void) Waypoint *wp; FOR_ALL_WAYPOINTS(wp) { - if (wp->xy != 0) { - SlSetArrayIndex(wp->index); - SlObject(wp, _waypoint_desc); - } + SlSetArrayIndex(wp->index); + SlObject(wp, _waypoint_desc); } } |