(svn r19788) -Codechange: make FOR_EACH_SET_BIT not change the value of the passed bit variable, i.e. allow expressions as parameter

This commit is contained in:
rubidium 2010-05-11 20:48:06 +00:00
parent 26bf9a13de
commit be504a6ef0
5 changed files with 12 additions and 14 deletions

View File

@ -310,16 +310,18 @@ static FORCEINLINE T ROR(const T x, const uint8 n)
* Do an operation for each set set bit in a value.
*
* This macros is used to do an operation for each set
* bit in a variable. The first variable can be reused
* in the operation due to it's the bit position counter.
* The second variable will be cleared during the usage
* bit in a variable. The first parameter is a variable
* that is used as the bit position counter.
* The second parameter is an expression of the bits
* we need to iterate over. This expression will be
* evaluated once.
*
* @param i The position counter
* @param b The value which we check for set bits
*/
#define FOR_EACH_SET_BIT(i, b) \
for (i = 0; b != 0; i++, b >>= 1) \
if (b & 1)
for (uint __FESB_bits = (i = 0, b); __FESB_bits != 0; i++, __FESB_bits >>= 1) \
if (__FESB_bits & 1)
#if defined(__APPLE__)

View File

@ -160,9 +160,8 @@ struct CFollowTrackT
/* Mask already reserved trackdirs. */
m_new_td_bits &= ~TrackBitsToTrackdirBits(reserved);
/* Mask out all trackdirs that conflict with the reservation. */
uint bits = (uint)TrackdirBitsToTrackBits(m_new_td_bits);
int i;
FOR_EACH_SET_BIT(i, bits) {
FOR_EACH_SET_BIT(i, TrackdirBitsToTrackBits(m_new_td_bits)) {
if (TracksOverlap(reserved | TrackToTrackBits((Track)i))) m_new_td_bits &= ~TrackToTrackdirBits((Track)i);
}
if (m_new_td_bits == TRACKDIR_BIT_NONE) {

View File

@ -921,9 +921,8 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current)
TrackBits reserved = GetReservedTrackbits(dst_tile);
trackdirbits &= ~TrackBitsToTrackdirBits(reserved);
uint bits = TrackdirBitsToTrackBits(trackdirbits);
int i;
FOR_EACH_SET_BIT(i, bits) {
FOR_EACH_SET_BIT(i, TrackdirBitsToTrackBits(trackdirbits)) {
if (TracksOverlap(reserved | TrackToTrackBits((Track)i))) trackdirbits &= ~TrackToTrackdirBits((Track)i);
}
}

View File

@ -567,7 +567,7 @@ public:
FOR_EACH_SET_BIT(i, this->facilities) {
this->RaiseWidget(i + SLW_TRAIN);
}
SetBit(this->facilities, widget - SLW_TRAIN);
this->facilities = 1 << (widget - SLW_TRAIN);
this->LowerWidget(widget);
}
this->stations.ForceRebuild();

View File

@ -1008,9 +1008,8 @@ void TileLoop_Water(TileIndex tile)
case FLOOD_DRYUP: {
Slope slope_here = GetFoundationSlope(tile, NULL) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
uint check_dirs = _flood_from_dirs[slope_here];
uint dir;
FOR_EACH_SET_BIT(dir, check_dirs) {
FOR_EACH_SET_BIT(dir, _flood_from_dirs[slope_here]) {
TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir((Direction)dir));
if (dest == INVALID_TILE) continue;
@ -1048,9 +1047,8 @@ void ConvertGroundTilesIntoWaterTiles()
break;
default:
uint check_dirs = _flood_from_dirs[slope & ~SLOPE_STEEP];
uint dir;
FOR_EACH_SET_BIT(dir, check_dirs) {
FOR_EACH_SET_BIT(dir, _flood_from_dirs[slope & ~SLOPE_STEEP]) {
TileIndex dest = TILE_ADD(tile, TileOffsByDir((Direction)dir));
Slope slope_dest = GetTileSlope(dest, NULL) & ~SLOPE_STEEP;
if (slope_dest == SLOPE_FLAT || IsSlopeWithOneCornerRaised(slope_dest)) {