From 99ecfe4061f8e6404e18f5fcef7cdb13990fb252 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 11 May 2010 21:02:26 +0000 Subject: [PATCH] (svn r19792) -Change: use the typed FOR_EACH_SET_BIT for Tracks (adf88) --- src/elrail.cpp | 35 ++++++++++++++++----------------- src/pathfinder/follow_track.hpp | 6 +++--- src/pathfinder/npf/npf.cpp | 6 +++--- src/track_func.h | 11 +++++++++++ src/train_cmd.cpp | 7 ++----- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/elrail.cpp b/src/elrail.cpp index 41b0d5a740..1474ff932a 100644 --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -429,27 +429,26 @@ static void DrawCatenaryRailway(const TileInfo *ti) SpriteID wire_base = GetWireBase(ti->tile); /* Drawing of pylons is finished, now draw the wires */ - for (Track t = TRACK_BEGIN; t < TRACK_END; t++) { - if (HasBit(wireconfig[TS_HOME], t)) { - byte PCPconfig = HasBit(PCPstatus, PCPpositions[t][0]) + - (HasBit(PCPstatus, PCPpositions[t][1]) << 1); + Track t; + FOR_EACH_SET_TRACK(t, wireconfig[TS_HOME]) { + byte PCPconfig = HasBit(PCPstatus, PCPpositions[t][0]) + + (HasBit(PCPstatus, PCPpositions[t][1]) << 1); - const SortableSpriteStruct *sss; - int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3; // tileh for the slopes, 0 otherwise + const SortableSpriteStruct *sss; + int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3; // tileh for the slopes, 0 otherwise - assert(PCPconfig != 0); // We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) - assert(!IsSteepSlope(tileh[TS_HOME])); - sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]]; + assert(PCPconfig != 0); // We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) + assert(!IsSteepSlope(tileh[TS_HOME])); + sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]]; - /* - * The "wire"-sprite position is inside the tile, i.e. 0 <= sss->?_offset < TILE_SIZE. - * Therefore it is safe to use GetSlopeZ() for the elevation. - * Also note, that the result of GetSlopeZ() is very special for bridge-ramps. - */ - AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, - sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + sss->z_offset, - IsTransparencySet(TO_CATENARY)); - } + /* + * The "wire"-sprite position is inside the tile, i.e. 0 <= sss->?_offset < TILE_SIZE. + * Therefore it is safe to use GetSlopeZ() for the elevation. + * Also note, that the result of GetSlopeZ() is very special for bridge-ramps. + */ + AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, + sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + sss->z_offset, + IsTransparencySet(TO_CATENARY)); } } diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index 33e861c414..70660d6537 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -160,9 +160,9 @@ struct CFollowTrackT /* Mask already reserved trackdirs. */ m_new_td_bits &= ~TrackBitsToTrackdirBits(reserved); /* Mask out all trackdirs that conflict with the reservation. */ - int i; - FOR_EACH_SET_BIT(i, TrackdirBitsToTrackBits(m_new_td_bits)) { - if (TracksOverlap(reserved | TrackToTrackBits((Track)i))) m_new_td_bits &= ~TrackToTrackdirBits((Track)i); + Track t; + FOR_EACH_SET_TRACK(t, TrackdirBitsToTrackBits(m_new_td_bits)) { + if (TracksOverlap(reserved | TrackToTrackBits(t))) m_new_td_bits &= ~TrackToTrackdirBits(t); } if (m_new_td_bits == TRACKDIR_BIT_NONE) { m_err = EC_RESERVED; diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 05ff2f4b06..1e656e547a 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -921,9 +921,9 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current) TrackBits reserved = GetReservedTrackbits(dst_tile); trackdirbits &= ~TrackBitsToTrackdirBits(reserved); - int i; - FOR_EACH_SET_BIT(i, TrackdirBitsToTrackBits(trackdirbits)) { - if (TracksOverlap(reserved | TrackToTrackBits((Track)i))) trackdirbits &= ~TrackToTrackdirBits((Track)i); + Track t; + FOR_EACH_SET_TRACK(t, TrackdirBitsToTrackBits(trackdirbits)) { + if (TracksOverlap(reserved | TrackToTrackBits(t))) trackdirbits &= ~TrackToTrackdirBits(t); } } diff --git a/src/track_func.h b/src/track_func.h index 2c2ec8e520..853863f584 100644 --- a/src/track_func.h +++ b/src/track_func.h @@ -16,6 +16,17 @@ #include "track_type.h" #include "slope_func.h" +/** + * Iterate through each set Track in a TrackBits value. + * For more informations see FOR_EACH_SET_BIT_EX. + * + * @param var Loop index variable that stores fallowing set track. Must be of type Track. + * @param track_bits The value to iterate through (any expression). + * + * @see FOR_EACH_SET_BIT_EX + */ +#define FOR_EACH_SET_TRACK(var, track_bits) FOR_EACH_SET_BIT_EX(Track, var, TrackBits, track_bits) + /** * Convert an Axis to the corresponding Track * AXIS_X -> TRACK_X diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 99098c44f7..fc8ec02532 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3517,11 +3517,8 @@ static void DeleteLastWagon(Train *v) /* It is important that these two are the first in the loop, as reservation cannot deal with every trackbit combination */ assert(TRACK_BEGIN == TRACK_X && TRACK_Y == TRACK_BEGIN + 1); - for (Track t = TRACK_BEGIN; t < TRACK_END; t++) { - if (HasBit(remaining_trackbits, t)) { - TryReserveRailTrack(tile, t); - } - } + Track t; + FOR_EACH_SET_TRACK(t, remaining_trackbits) TryReserveRailTrack(tile, t); } /* check if the wagon was on a road/rail-crossing */