Changeset - r7982:bd7f4c5a45b3
[Not reviewed]
master
0 1 0
skidd13 - 17 years ago 2007-11-28 21:59:06
skidd13@openttd.org
(svn r11538) -Codechange: Rewrite GetNthSetBit in a more uncontroversial way and add its documentation
1 file changed with 13 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/town_gui.cpp
Show inline comments
 
@@ -109,15 +109,22 @@ uint GetMaskOfTownActions(int *nump, Pla
 
	return buttons;
 
}
 

	
 
/**
 
 * Get the position of the Nth set bit.
 
 *
 
 * If there is no Nth bit set return -1
 
 *
 
 * @param bits The value to search in
 
 * @param n The Nth set bit from which we want to know the position
 
 * @return The position of the Nth set bit
 
 */
 
static int GetNthSetBit(uint32 bits, int n)
 
{
 
	int i = 0;
 

	
 
	if (n >= 0) {
 
		do {
 
			if (bits & 1 && --n < 0) return i;
 
			i++;
 
		} while (bits >>= 1);
 
		for (uint i = 0; bits != 0; bits >>= 1, i++) {
 
			if (bits & 1) n--;
 
			if (n < 0) return i;
 
		}
 
	}
 
	return -1;
 
}
0 comments (0 inline, 0 general)