Mercurial > hg > openttd
changeset 6127:a8303346cd9c draft
(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)
author | KUDr <KUDr@openttd.org> |
---|---|
date | Fri, 23 Feb 2007 20:51:10 +0000 |
parents | 31f85e2d5100 |
children | f47815f367a2 |
files | src/helpers.hpp src/rail.h src/rail_cmd.cpp src/town_cmd.cpp |
diffstat | 4 files changed, 12 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -138,25 +138,19 @@ } }; -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 */
--- a/src/rail.h +++ b/src/rail.h @@ -261,7 +261,7 @@ { 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 @@ { 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;
--- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -450,7 +450,7 @@ (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 @@ 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 @@ 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;