# HG changeset patch # User KUDr # Date 1172263870 0 # Node ID a8303346cd9cf0b24ab6c710bd778e3d340ae306 # Parent 31f85e2d51008f7fda21d9461f2a6e9634852797 (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) diff --git a/src/helpers.hpp b/src/helpers.hpp --- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -138,25 +138,19 @@ } }; -template FORCEINLINE T ClrBitT(T t, int bit_index) +template 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 FORCEINLINE T SetBitT(T t, int bit_index) +template 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 FORCEINLINE T ToggleBitT(T t, int bit_index) +template 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 */ diff --git a/src/rail.h b/src/rail.h --- 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; diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp --- 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; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -730,7 +730,7 @@ // 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;