1
0
Fork 0

(svn r8864) -Codechange: make ClrBitT(), SetBitT() and ToggleBitT more like CLRBIT() and so on (modify value of the first parameter instead or returning the result)

release/0.6
KUDr 2007-02-23 20:51:10 +00:00
parent 20405f56b4
commit dac3cd622f
4 changed files with 12 additions and 18 deletions

View File

@ -138,25 +138,19 @@ template <typename Tenum_t> struct TinyEnumT
}
};
template <typename T> FORCEINLINE T ClrBitT(T t, int bit_index)
template <typename T> void ClrBitT(T &t, int bit_index)
{
int val = t;
CLRBIT(val, bit_index);
return (T)val;
t = (T)(t & ~((T)1 << bit_index));
}
template <typename T> FORCEINLINE T SetBitT(T t, int bit_index)
template <typename T> void SetBitT(T &t, int bit_index)
{
int val = t;
SETBIT(val, bit_index);
return (T)val;
t = (T)(t | ((T)1 << bit_index));
}
template <typename T> FORCEINLINE T ToggleBitT(T t, int bit_index)
template <typename T> void ToggleBitT(T &t, int bit_index)
{
int val = t;
TOGGLEBIT(val, bit_index);
return (T)val;
t = (T)(t ^ ((T)1 << bit_index));
}
#endif /* HELPERS_HPP */

View File

@ -261,7 +261,7 @@ static inline Track RemoveFirstTrack(TrackBits *tracks)
{
if (*tracks != TRACK_BIT_NONE && *tracks != INVALID_TRACK_BIT) {
Track first = (Track)FIND_FIRST_BIT(*tracks);
*tracks = ClrBitT(*tracks, first);
ClrBitT(*tracks, first);
return first;
}
return INVALID_TRACK;
@ -274,7 +274,7 @@ static inline Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
{
if (*trackdirs != TRACKDIR_BIT_NONE && *trackdirs != INVALID_TRACKDIR_BIT) {
Trackdir first = (Trackdir)FindFirstBit2x64(*trackdirs);
*trackdirs = ClrBitT(*trackdirs, first);
ClrBitT(*trackdirs, first);
return first;
}
return INVALID_TRACKDIR;

View File

@ -450,7 +450,7 @@ static int32 ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileIndex end
(trdy >= 0 && dy < 0)
) {
if (!HASBIT(*trackdir, 3)) { // first direction is invalid, try the other
*trackdir = SetBitT(*trackdir, 3); // reverse the direction
SetBitT(*trackdir, 3); // reverse the direction
trdx = -trdx;
trdy = -trdy;
} else { // other direction is invalid too, invalid drag
@ -513,7 +513,7 @@ static int32 CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32
tile += ToTileIndexDiff(_trackdelta[trackdir]);
// toggle railbit for the non-diagonal tracks
if (!IsDiagonalTrackdir(trackdir)) trackdir = ToggleBitT(trackdir, 0);
if (!IsDiagonalTrackdir(trackdir)) ToggleBitT(trackdir, 0);
}
return (total_cost == 0) ? CMD_ERROR : total_cost;
@ -777,7 +777,7 @@ static int32 CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint3
signal_ctr++;
// toggle railbit for the non-diagonal tracks (|, -- tracks)
if (!IsDiagonalTrackdir(trackdir)) trackdir = ToggleBitT(trackdir, 0);
if (!IsDiagonalTrackdir(trackdir)) ToggleBitT(trackdir, 0);
}
return error ? CMD_ERROR : total_cost;

View File

@ -730,7 +730,7 @@ static int GrowTownAtRoad(Town *t, TileIndex tile)
// Exclude the source position from the bitmask
// and return if no more road blocks available
mask = ClrBitT(mask, (block ^ 2));
ClrBitT(mask, (block ^ 2));
if (mask == 0)
return _grow_town_result;